Search in sources :

Example 6 with ConcurrentEntityModificationException

use of org.qi4j.api.unitofwork.ConcurrentEntityModificationException in project qi4j-sdk by Qi4j.

the class LoggingServiceMixin method log.

public void log(LogType type, Composite composite, String category, String message) {
    UnitOfWork uow = uowf.newUnitOfWork();
    try {
        List<Serializable> paramsList = new ArrayList<Serializable>();
        createLogRecord(uow, type, composite, category, message, paramsList);
        uow.complete();
    } catch (ConcurrentEntityModificationException e) {
    // ignore for now. Perhaps discard() and try again.
    } catch (UnitOfWorkCompletionException e) {
    // ignore for now. Perhaps discard() and try again.
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) ConcurrentEntityModificationException(org.qi4j.api.unitofwork.ConcurrentEntityModificationException) Serializable(java.io.Serializable) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException) ArrayList(java.util.ArrayList)

Example 7 with ConcurrentEntityModificationException

use of org.qi4j.api.unitofwork.ConcurrentEntityModificationException in project qi4j-sdk by Qi4j.

the class LoggingServiceMixin method log.

public void log(LogType type, Composite composite, String category, String message, Serializable param1, Serializable param2) {
    UnitOfWork uow = uowf.newUnitOfWork();
    try {
        List<Serializable> paramsList = new ArrayList<Serializable>();
        paramsList.add(param1);
        paramsList.add(param2);
        createLogRecord(uow, type, composite, category, message, paramsList);
        uow.complete();
    } catch (ConcurrentEntityModificationException e) {
    // ignore for now. Perhaps discard() and try again.
    } catch (UnitOfWorkCompletionException e) {
    // ignore for now. Perhaps discard() and try again.
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) ConcurrentEntityModificationException(org.qi4j.api.unitofwork.ConcurrentEntityModificationException) Serializable(java.io.Serializable) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException) ArrayList(java.util.ArrayList)

Example 8 with ConcurrentEntityModificationException

use of org.qi4j.api.unitofwork.ConcurrentEntityModificationException in project qi4j-sdk by Qi4j.

the class DebuggingServiceMixin method debug.

@Override
public void debug(Composite composite, String message, Serializable... params) {
    UnitOfWork uow = uowf.newUnitOfWork();
    try {
        List<Serializable> paramsList = new ArrayList<Serializable>(Arrays.asList(params));
        createDebugRecord(uow, composite, message, paramsList);
        uow.complete();
    } catch (ConcurrentEntityModificationException e) {
    // ignore for now. Perhaps discard() and try again.
    } catch (UnitOfWorkCompletionException e) {
    // ignore for now. Perhaps discard() and try again.
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) ConcurrentEntityModificationException(org.qi4j.api.unitofwork.ConcurrentEntityModificationException) Serializable(java.io.Serializable) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException) ArrayList(java.util.ArrayList)

Example 9 with ConcurrentEntityModificationException

use of org.qi4j.api.unitofwork.ConcurrentEntityModificationException in project qi4j-sdk by Qi4j.

the class UnitOfWorkInstance method applyChanges.

private List<StateCommitter> applyChanges() throws UnitOfWorkCompletionException {
    List<StateCommitter> committers = new ArrayList<>();
    for (EntityStoreUnitOfWork entityStoreUnitOfWork : storeUnitOfWork.values()) {
        try {
            StateCommitter committer = entityStoreUnitOfWork.applyChanges();
            committers.add(committer);
        } catch (Exception e) {
            // Cancel all previously prepared stores
            for (StateCommitter committer : committers) {
                committer.cancel();
            }
            if (e instanceof ConcurrentEntityStateModificationException) {
                // If we cancelled due to concurrent modification, then create the proper exception for it!
                ConcurrentEntityStateModificationException mee = (ConcurrentEntityStateModificationException) e;
                Collection<EntityReference> modifiedEntityIdentities = mee.modifiedEntities();
                Collection<EntityComposite> modifiedEntities = new ArrayList<>();
                for (EntityReference modifiedEntityIdentity : modifiedEntityIdentities) {
                    Collection<EntityInstance> instances = instanceCache.values();
                    for (EntityInstance instance : instances) {
                        if (instance.identity().equals(modifiedEntityIdentity)) {
                            modifiedEntities.add(instance.<EntityComposite>proxy());
                        }
                    }
                }
                throw new ConcurrentEntityModificationException(modifiedEntities);
            } else {
                throw new UnitOfWorkCompletionException(e);
            }
        }
    }
    return committers;
}
Also used : EntityComposite(org.qi4j.api.entity.EntityComposite) EntityStoreUnitOfWork(org.qi4j.spi.entitystore.EntityStoreUnitOfWork) ArrayList(java.util.ArrayList) EntityInstance(org.qi4j.runtime.entity.EntityInstance) ConcurrentEntityModificationException(org.qi4j.api.unitofwork.ConcurrentEntityModificationException) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException) UnitOfWorkException(org.qi4j.api.unitofwork.UnitOfWorkException) EntityTypeNotFoundException(org.qi4j.api.unitofwork.EntityTypeNotFoundException) NoSuchEntityException(org.qi4j.api.unitofwork.NoSuchEntityException) ConcurrentEntityStateModificationException(org.qi4j.spi.entitystore.ConcurrentEntityStateModificationException) EntityNotFoundException(org.qi4j.spi.entitystore.EntityNotFoundException) ConcurrentEntityModificationException(org.qi4j.api.unitofwork.ConcurrentEntityModificationException) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException) ConcurrentEntityStateModificationException(org.qi4j.spi.entitystore.ConcurrentEntityStateModificationException) EntityReference(org.qi4j.api.entity.EntityReference) Collection(java.util.Collection) StateCommitter(org.qi4j.spi.entitystore.StateCommitter)

Example 10 with ConcurrentEntityModificationException

use of org.qi4j.api.unitofwork.ConcurrentEntityModificationException in project qi4j-sdk by Qi4j.

the class DebuggingServiceMixin method debug.

@Override
public void debug(Composite composite, String message) {
    UnitOfWork uow = uowf.newUnitOfWork();
    try {
        List<Serializable> paramsList = new ArrayList<Serializable>();
        createDebugRecord(uow, composite, message, paramsList);
        uow.complete();
    } catch (ConcurrentEntityModificationException e) {
    // ignore for now. Perhaps discard() and try again.
    } catch (UnitOfWorkCompletionException e) {
    // ignore for now. Perhaps discard() and try again.
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) ConcurrentEntityModificationException(org.qi4j.api.unitofwork.ConcurrentEntityModificationException) Serializable(java.io.Serializable) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException) ArrayList(java.util.ArrayList)

Aggregations

ConcurrentEntityModificationException (org.qi4j.api.unitofwork.ConcurrentEntityModificationException)13 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)12 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)11 ArrayList (java.util.ArrayList)5 Serializable (java.io.Serializable)4 Test (org.junit.Test)3 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)3 Collection (java.util.Collection)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 AbstractRequestCycleListener (org.apache.wicket.request.cycle.AbstractRequestCycleListener)1 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)1 EntityBuilder (org.qi4j.api.entity.EntityBuilder)1 EntityComposite (org.qi4j.api.entity.EntityComposite)1 EntityReference (org.qi4j.api.entity.EntityReference)1 EntityTypeNotFoundException (org.qi4j.api.unitofwork.EntityTypeNotFoundException)1 NoSuchEntityException (org.qi4j.api.unitofwork.NoSuchEntityException)1 UnitOfWorkException (org.qi4j.api.unitofwork.UnitOfWorkException)1 Usecase (org.qi4j.api.usecase.Usecase)1 Function (org.qi4j.functional.Function)1 ServiceDebugRecordEntity (org.qi4j.logging.debug.records.ServiceDebugRecordEntity)1