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.
}
}
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;
}
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.
}
}
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.
}
}
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);
}
}
Aggregations