Search in sources :

Example 16 with ConcurrentEntityModificationException

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

the class PersistedSequencingMixin method newSequenceValue.

@Override
public Long newSequenceValue() throws SequencingException {
    synchronized (this) {
        ConcurrentEntityModificationException exc = null;
        UnitOfWork uow = uowf.newUnitOfWork();
        try {
            for (int i = 0; i < 3; i++) {
                try {
                    Property<Long> property = sequence.get().currentValue();
                    long value = property.get();
                    value = value + 1;
                    property.set(value);
                    uow.complete();
                    return value;
                } catch (ConcurrentEntityModificationException e) {
                    // Ignore;
                    exc = e;
                }
            }
            throw new SequencingException("Unable to update sequence value.", exc);
        } catch (UnitOfWorkCompletionException e) {
            throw new SequencingException("Unable to update sequence value.", exc);
        }
    }
}
Also used : ConcurrentEntityModificationException(org.qi4j.api.unitofwork.ConcurrentEntityModificationException) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException)

Aggregations

ConcurrentEntityModificationException (org.qi4j.api.unitofwork.ConcurrentEntityModificationException)16 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)15 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)14 ArrayList (java.util.ArrayList)5 Serializable (java.io.Serializable)4 Test (org.junit.Test)4 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 AbstractRequestCycleListener (org.apache.wicket.request.cycle.AbstractRequestCycleListener)2 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)2 Collection (java.util.Collection)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