use of org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter in project BroadleafCommerce by BroadleafCommerce.
the class SiteServiceImpl method retrieveSiteByIdentifier.
protected Site retrieveSiteByIdentifier(final String identifier, final boolean persistentResult) {
// only run the operation under a transaction if there is not already an entity manager in the view
if (identifier == null) {
return null;
}
final Site[] response = new Site[1];
transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
Site site = siteDao.retrieveSiteByIdentifier(identifier);
if (persistentResult) {
response[0] = site;
} else {
response[0] = getNonPersistentSite(site);
}
}
}, RuntimeException.class, !TransactionSynchronizationManager.hasResource(((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory()));
return response[0];
}
use of org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityRemoteService method add.
@Override
public PersistenceResponse add(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] = nonTransactionalAdd(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 DynamicEntityRemoteService method fetch.
@Override
public PersistenceResponse fetch(final PersistencePackage persistencePackage, final CriteriaTransferObject cto) 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] = nonTransactionalFetch(persistencePackage, cto);
}
}, 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 update.
@Override
public PersistenceResponse update(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] = nonTransactionalUpdate(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 SequenceGeneratorCorruptionDetection method onApplicationEvent.
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
if (detectSequenceGeneratorInconsistencies) {
for (Map<String, Map<String, Object>> targetModeMap : targetModeMaps) {
for (final String targetMode : targetModeMap.keySet()) {
final Map<String, Object> managerMap = targetModeMap.get(targetMode);
PlatformTransactionManager txManager = persistenceService.getTransactionManager(managerMap);
transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
EntityManager em = persistenceService.getEntityManager(managerMap);
Session hibernateSession = em.unwrap(Session.class);
patchSequenceGeneratorInconsistencies(em, hibernateSession);
}
}, RuntimeException.class, txManager);
}
}
}
}
Aggregations