Permalink
Browse files

implemented clear for TX cache

  • Loading branch information...
DirkMahler committed Jan 7, 2019
1 parent 45d97d6 commit 07e800f113f5097a156c5e891449fcba923f8712
@@ -447,6 +447,11 @@
*/
void flush();

/**
* Clear caches, including pending changes.
*/
void clear();

/**
* Register an instance listener containing life cycle methods (e.g.
* annotated with {@link com.buschmais.xo.api.annotation.PostCreate}.
@@ -465,6 +465,11 @@ public void flush() {
sessionContext.getCacheSynchronizationService().flush();
}

@Override
public void clear() {
sessionContext.getCacheSynchronizationService().clear();
}

@Override
public <I> void registerInstanceListener(I instanceListener) {
sessionContext.getInstanceListenerService().registerInstanceListener(instanceListener);
@@ -59,14 +59,12 @@ public void clear() {

private <T> void clear(TransactionalCache<?> cache, AbstractInstanceManager<?, T> instanceManager, DatastorePropertyManager<T, ?> datastoreManager) {
Collection<?> instances = cache.readInstances();
List<T> entities = new ArrayList<>(instances.size());
for (Object instance : instances) {
T entity = instanceManager.getDatastoreType(instance);
if (entity != null) {
entities.add(entity);
datastoreManager.clear(entity);
}
}
datastoreManager.clear(entities);
cache.clear();
}

@@ -3,7 +3,7 @@
import java.util.Collection;

/**
* Transactional cache whcih handles read and write access to instances.
* Transactional cache which handles read and write access to instances.
*
* @param <Id>
* The datastore id type.
@@ -113,6 +113,8 @@ public void flush() {
* Clear the cache.
*/
public void clear() {
writeCache.clear();
readCache.clear();
}

/**
@@ -138,7 +138,7 @@ public void flush(Iterable<ObjectNode> objectNodes) {
}

@Override
public void clear(Iterable<ObjectNode> entities) {
public void clear(ObjectNode entity) {
}

/**
@@ -92,6 +92,6 @@ public void flush(Iterable<JsonRelation> entities) {
}

@Override
public void clear(Iterable<JsonRelation> entities) {
public void clear(JsonRelation relation) {
}
}
@@ -120,10 +120,8 @@ public void removeDiscriminators(TypeMetadataSet<EntityTypeMetadata<NodeMetadata
}

@Override
public void clear(Iterable<EmbeddedNode> nodes) {
for (EmbeddedNode node : nodes) {
node.clear();
}
public void clear(EmbeddedNode node) {
node.clear();
}

@Override
@@ -125,9 +125,7 @@ public void flush(Iterable<EmbeddedRelationship> relationships) {
}

@Override
public void clear(Iterable<EmbeddedRelationship> relationships) {
for (EmbeddedRelationship relationship : relationships) {
relationship.clear();
}
public void clear(EmbeddedRelationship relationship) {
relationship.clear();
}
}
@@ -70,10 +70,8 @@ protected void flush(StatementBatchBuilder batchBuilder, T entity, String patter
}

@Override
public final void clear(Iterable<T> entities) {
for (T entity : entities) {
entity.getState().clear();
}
public final void clear(T entity) {
entity.getState().clear();
}

protected final void ensureLoaded(T entity) {
@@ -58,10 +58,10 @@
void flush(Iterable<Element> entities);

/**
* Clear any tracked state for the given entities.
* Clear any tracked state for the given entity.
*
* @param entities
* The entities.
* @param entity
* The entity.
*/
void clear(Iterable<Element> entities);
void clear(Element entity);
}
@@ -90,7 +90,7 @@ public void flush(Iterable<Entity> entities) {
}

@Override
public void clear(Iterable<Entity> entities) {
delegate.clear(entities);
public void clear(Entity entity) {
delegate.clear(entity);
}
}
@@ -109,7 +109,7 @@ public void flush(Iterable<Relation> entities) {
}

@Override
public void clear(Iterable<Relation> relations) {
delegate.clear(relations);
public void clear(Relation relation) {
delegate.clear(relation);
}
}

0 comments on commit 07e800f

Please sign in to comment.