Search in sources :

Example 6 with UnitOfWorkCompletionException

use of org.qi4j.api.unitofwork.UnitOfWorkCompletionException 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 UnitOfWorkCompletionException

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

the class AbstractDataSourceServiceImporterMixin method getConfiguration.

private DataSourceConfigurationValue getConfiguration(String identity) throws InstantiationException {
    DataSourceConfigurationValue config = configs.get(identity);
    if (config == null) {
        UnitOfWork uow = module.newUnitOfWork(UsecaseBuilder.newUsecase("Create DataSource pool configuration"));
        try {
            DataSourceConfiguration configEntity = uow.get(DataSourceConfiguration.class, identity);
            config = entityToValue.convert(DataSourceConfigurationValue.class, configEntity);
        } catch (NoSuchEntityException e) {
            EntityBuilder<DataSourceConfiguration> configBuilder = uow.newEntityBuilder(DataSourceConfiguration.class, identity);
            // Check for defaults
            String s = identity + ".properties";
            InputStream asStream = DataSourceConfiguration.class.getClassLoader().getResourceAsStream(s);
            if (asStream != null) {
                try {
                    PropertyMapper.map(asStream, configBuilder.instance());
                } catch (IOException e1) {
                    uow.discard();
                    InstantiationException exception = new InstantiationException("Could not read underlying Properties file.");
                    exception.initCause(e1);
                    throw exception;
                }
            }
            DataSourceConfiguration configEntity = configBuilder.newInstance();
            config = entityToValue.convert(DataSourceConfigurationValue.class, configEntity);
            // save
            try {
                uow.complete();
            } catch (UnitOfWorkCompletionException e2) {
                InstantiationException exception = new InstantiationException("Could not save configuration in JavaPreferences.");
                exception.initCause(e2);
                throw exception;
            }
        }
        configs.put(identity, config);
    }
    return config;
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException) InputStream(java.io.InputStream) EntityBuilder(org.qi4j.api.entity.EntityBuilder) IOException(java.io.IOException) NoSuchEntityException(org.qi4j.api.unitofwork.NoSuchEntityException)

Example 8 with UnitOfWorkCompletionException

use of org.qi4j.api.unitofwork.UnitOfWorkCompletionException 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 9 with UnitOfWorkCompletionException

use of org.qi4j.api.unitofwork.UnitOfWorkCompletionException 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 10 with UnitOfWorkCompletionException

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

the class UnitOfWorkInstance method notifyBeforeCompletion.

private void notifyBeforeCompletion(List<UnitOfWorkCallback> callbacks) throws UnitOfWorkCompletionException {
    // Notify explicitly registered callbacks
    if (callbacks != null) {
        for (UnitOfWorkCallback callback : callbacks) {
            callback.beforeCompletion();
        }
    }
    // Notify entities
    try {
        for (EntityInstance instance : instanceCache.values()) {
            boolean isCallback = instance.proxy() instanceof UnitOfWorkCallback;
            boolean isNotRemoved = !instance.status().equals(EntityStatus.REMOVED);
            if (isCallback && isNotRemoved) {
                UnitOfWorkCallback callback = UnitOfWorkCallback.class.cast(instance.proxy());
                callback.beforeCompletion();
            }
        }
    } catch (UnitOfWorkCompletionException e) {
        throw e;
    } catch (Exception e) {
        throw new UnitOfWorkCompletionException(e);
    }
}
Also used : UnitOfWorkCallback(org.qi4j.api.unitofwork.UnitOfWorkCallback) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException) 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)

Aggregations

UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)20 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)18 ConcurrentEntityModificationException (org.qi4j.api.unitofwork.ConcurrentEntityModificationException)12 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)5 Test (org.junit.Test)5 Serializable (java.io.Serializable)4 NoSuchEntityException (org.qi4j.api.unitofwork.NoSuchEntityException)3 UnitOfWorkCallback (org.qi4j.api.unitofwork.UnitOfWorkCallback)3 AssemblyException (org.qi4j.bootstrap.AssemblyException)3 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)3 File (java.io.File)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 AbstractRequestCycleListener (org.apache.wicket.request.cycle.AbstractRequestCycleListener)2 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)2 EntityTypeNotFoundException (org.qi4j.api.unitofwork.EntityTypeNotFoundException)2 UnitOfWorkException (org.qi4j.api.unitofwork.UnitOfWorkException)2 ConcurrentUoWFileModificationException (org.qi4j.library.uowfile.internal.ConcurrentUoWFileModificationException)2 EntityInstance (org.qi4j.runtime.entity.EntityInstance)2 ConcurrentEntityStateModificationException (org.qi4j.spi.entitystore.ConcurrentEntityStateModificationException)2