Search in sources :

Example 6 with StreamCapableTransactionalOperationAdapter

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];
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter)

Example 7 with StreamCapableTransactionalOperationAdapter

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];
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager)

Example 8 with StreamCapableTransactionalOperationAdapter

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];
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager)

Example 9 with StreamCapableTransactionalOperationAdapter

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];
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager)

Example 10 with StreamCapableTransactionalOperationAdapter

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);
            }
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter) Map(java.util.Map) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Session(org.hibernate.Session)

Aggregations

StreamCapableTransactionalOperationAdapter (org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter)16 ServiceException (org.broadleafcommerce.common.exception.ServiceException)6 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)6 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)5 StaticAssetStorage (org.broadleafcommerce.cms.file.domain.StaticAssetStorage)3 IOException (java.io.IOException)2 Blob (java.sql.Blob)2 Map (java.util.Map)2 Session (org.hibernate.Session)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 EntityManager (javax.persistence.EntityManager)1 Site (org.broadleafcommerce.common.site.domain.Site)1 OfferCode (org.broadleafcommerce.core.offer.domain.OfferCode)1 OfferImpl (org.broadleafcommerce.core.offer.domain.OfferImpl)1