use of org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter in project BroadleafCommerce by BroadleafCommerce.
the class PersistenceServiceImpl method initializeEntityManagerCache.
protected void initializeEntityManagerCache() {
for (Map<String, Map<String, Object>> targetModeMap : targetModeMaps) {
for (final String targetMode : targetModeMap.keySet()) {
final Map<String, Object> managerMap = targetModeMap.get(targetMode);
transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
populateCaches(targetMode, managerMap);
}
}, RuntimeException.class, getTransactionManager(managerMap));
}
}
}
use of org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityRemoteService method inspect.
@Override
public PersistenceResponse inspect(final PersistencePackage persistencePackage) throws ServiceException {
final PersistenceResponse[] response = new PersistenceResponse[1];
try {
PlatformTransactionManager transactionManager = identifyTransactionManager(persistencePackage);
transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
response[0] = nonTransactionalInspect(persistencePackage);
}
}, RuntimeException.class, true, TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.ISOLATION_DEFAULT, true, transactionManager);
} catch (RuntimeException e) {
if (e.getCause() instanceof ServiceException) {
throw (ServiceException) e.getCause();
}
throw e;
}
return response[0];
}
use of org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityRemoteService method remove.
@Override
public PersistenceResponse remove(final PersistencePackage persistencePackage) throws ServiceException {
final PersistenceResponse[] response = new PersistenceResponse[1];
try {
PlatformTransactionManager transactionManager = identifyTransactionManager(persistencePackage);
transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
response[0] = nonTransactionalRemove(persistencePackage);
}
@Override
public boolean shouldRetryOnTransactionLockAcquisitionFailure() {
return super.shouldRetryOnTransactionLockAcquisitionFailure();
}
}, RuntimeException.class, transactionManager);
} catch (RuntimeException e) {
if (e.getCause() instanceof ServiceException) {
throw (ServiceException) e.getCause();
}
throw e;
}
return response[0];
}
use of org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter in project BroadleafCommerce by BroadleafCommerce.
the class GenericEntityDaoImpl method getCeilingImplClass.
@Override
public Class<?> getCeilingImplClass(final String className) {
final Class<?>[] clazz = new Class<?>[1];
try {
clazz[0] = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
// em.unwrap requires a transactional entity manager. We'll only take the hit to start a transaction here if one has not already been started.
transactionUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
Class<?>[] entitiesFromCeiling = daoHelper.getAllPolymorphicEntitiesFromCeiling(clazz[0], em.unwrap(Session.class).getSessionFactory(), true, true);
if (entitiesFromCeiling == null || entitiesFromCeiling.length < 1) {
clazz[0] = DynamicDaoHelperImpl.getNonProxyImplementationClassIfNecessary(clazz[0]);
entitiesFromCeiling = daoHelper.getAllPolymorphicEntitiesFromCeiling(clazz[0], em.unwrap(Session.class).getSessionFactory(), true, true);
}
if (entitiesFromCeiling == null || entitiesFromCeiling.length < 1) {
throw new IllegalArgumentException(String.format("Unable to find ceiling implementation for the requested class name (%s)", className));
}
clazz[0] = entitiesFromCeiling[entitiesFromCeiling.length - 1];
}
}, RuntimeException.class, !TransactionUtils.isTransactionalEntityManager(em));
return clazz[0];
}
use of org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter in project BroadleafCommerce by BroadleafCommerce.
the class MultiTenantCopier method copyEntitiesOfType.
/**
* Subclasses will generally call this method in their {@link #copyEntities(MultiTenantCopyContext)} implementation.
*
* @param clazz
* @param fromSite
* @param fromCatalog
* @param context
* @param <T>
* @throws ServiceException
* @throws CloneNotSupportedException
*/
protected <T extends MultiTenantCloneable> void copyEntitiesOfType(final Class<T> clazz, final Site fromSite, final Catalog fromCatalog, final MultiTenantCopyContext context) throws ServiceException, CloneNotSupportedException {
genericEntityService.flush();
genericEntityService.clear();
transUtil.runStreamingTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public Object[] retrievePage(int startPos, int pageSize) {
try {
Object[] temp = new Object[1];
List<T> results = readAll(clazz, pageSize, startPos, fromSite, fromCatalog);
temp[0] = results;
return temp;
} catch (ServiceException e) {
throw ExceptionHelper.refineException(e);
}
}
@Override
public void pagedExecute(Object[] param) throws Throwable {
try {
List<T> results = (List<T>) param[0];
for (T result : results) {
persistCopyObjectTree(new CopyOperation<T, CloneNotSupportedException>() {
@Override
public T execute(T original) throws CloneNotSupportedException {
return (T) original.createOrRetrieveCopyInstance(context).getClone();
}
}, clazz, result, context);
}
} finally {
genericEntityService.clear();
}
}
@Override
public Long retrieveTotalCount() {
try {
return readCount(clazz, fromSite, fromCatalog);
} catch (ServiceException e) {
throw ExceptionHelper.refineException(e);
}
}
@Override
public boolean shouldRetryOnTransactionLockAcquisitionFailure() {
return true;
}
}, RuntimeException.class);
}
Aggregations