Search in sources :

Example 1 with UnitOfWorkException

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");
    }
}
Also used : UnitOfWorkException(org.qi4j.api.unitofwork.UnitOfWorkException) EntityReference(org.qi4j.api.entity.EntityReference) EntityInstance(org.qi4j.runtime.entity.EntityInstance) UnitOfWorkOptions(org.qi4j.api.unitofwork.UnitOfWorkOptions)

Aggregations

EntityReference (org.qi4j.api.entity.EntityReference)1 UnitOfWorkException (org.qi4j.api.unitofwork.UnitOfWorkException)1 UnitOfWorkOptions (org.qi4j.api.unitofwork.UnitOfWorkOptions)1 EntityInstance (org.qi4j.runtime.entity.EntityInstance)1