@Override public <G extends Throwable> void runTransactionalOperation(StreamCapableTransactionalOperation operation, Class<G> exceptionType, PlatformTransactionManager transactionManager) throws G { runOptionalTransactionalOperation(operation, exceptionType, true, TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.ISOLATION_DEFAULT, false, transactionManager); }
@Override public <G extends Throwable> void runTransactionalOperation(StreamCapableTransactionalOperation operation, Class<G> exceptionType) throws G { runOptionalTransactionalOperation(operation, exceptionType, true, TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.ISOLATION_DEFAULT, false, getTransactionManager()); }
@Override public <G extends Throwable> void runOptionalTransactionalOperation(StreamCapableTransactionalOperation operation, Class<G> exceptionType, boolean useTransaction, int transactionBehavior, int isolationLevel) throws G { runOptionalTransactionalOperation(operation, exceptionType, useTransaction, transactionBehavior, isolationLevel, false, getTransactionManager()); }
@Override public <G extends Throwable> void runTransactionalOperation(StreamCapableTransactionalOperation operation, Class<G> exceptionType, int transactionBehavior, int isolationLevel) throws G { runOptionalTransactionalOperation(operation, exceptionType, true, transactionBehavior, isolationLevel, false, getTransactionManager()); }
@Override public <G extends Throwable> void runOptionalTransactionalOperation(StreamCapableTransactionalOperation operation, Class<G> exceptionType, boolean useTransaction) throws G { runOptionalTransactionalOperation(operation, exceptionType, useTransaction, TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.ISOLATION_DEFAULT, false, getTransactionManager()); }
@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]; }
@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]; }
@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]; }
protected Site retrieveSiteByIdentifier(final String identifier, final boolean persistentResult) { //Since the methods on this class are frequently called during regular page requests and transactions are expensive, //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]; }
runOptionalTransactionalOperation(operation, exceptionType, true, transactionBehavior, isolationLevel, false, getTransactionManager()); if (em != null) {