use of org.qi4j.api.unitofwork.UnitOfWorkException in project qi4j-sdk by Qi4j.
the class UnitOfWorkInstance method pause.
public void pause() {
if (!paused) {
paused = true;
getCurrent().pop();
UnitOfWorkOptions unitOfWorkOptions = metaInfo().get(UnitOfWorkOptions.class);
if (unitOfWorkOptions == null) {
unitOfWorkOptions = usecase().metaInfo(UnitOfWorkOptions.class);
}
if (unitOfWorkOptions != null) {
if (unitOfWorkOptions.isPruneOnPause()) {
List<EntityReference> prunedInstances = null;
for (EntityInstance entityInstance : instanceCache.values()) {
if (entityInstance.status() == EntityStatus.LOADED) {
if (prunedInstances == null) {
prunedInstances = new ArrayList<EntityReference>();
}
prunedInstances.add(entityInstance.identity());
}
}
if (prunedInstances != null) {
for (EntityReference prunedInstance : prunedInstances) {
instanceCache.remove(prunedInstance);
}
}
}
}
} else {
throw new UnitOfWorkException("Unit of work is not active");
}
}
Aggregations