List of usage examples for org.springframework.transaction.support TransactionTemplate setPropagationBehavior
public final void setPropagationBehavior(int propagationBehavior)
From source file:org.kuali.kra.award.awardhierarchy.sync.service.AwardSyncServiceImpl.java
/** * Save or delete object in a separate thread using {@link #SaveBo}. * @param object//from w w w. j av a 2s .c o m * @param delete * @param runnables */ protected void saveInTransaction(final Object object) { TransactionTemplate template = new TransactionTemplate( (PlatformTransactionManager) KcServiceLocator.getService("transactionManager")); template.setPropagationBehavior(Propagation.REQUIRES_NEW.value()); template.execute(new TransactionCallback() { @SuppressWarnings("unchecked") public Object doInTransaction(TransactionStatus status) { if (object instanceof PersistableBusinessObject) { getBusinessObjectService().save((PersistableBusinessObject) object); } else if (object instanceof List) { getBusinessObjectService().save((List) object); } return null; } }); }
From source file:org.kuali.kra.award.awardhierarchy.sync.service.AwardSyncServiceImpl.java
/** * Run the runnable in a separate transaction, commiting when finished or rolling back * if an exception is generated.//from w ww . ja va 2s. c o m * @param runnable */ protected void runInTransaction(final TransactionRunnable runnable) { final UserSession session = GlobalVariables.getUserSession(); syncExecutor.execute(new SyncRunnable() { public void run() { GlobalVariables.setUserSession(session); TransactionTemplate template = new TransactionTemplate( (PlatformTransactionManager) KcServiceLocator.getService("transactionManager")); template.setPropagationBehavior(Propagation.REQUIRES_NEW.value()); template.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { runnable.run(); return null; } }); } }); }
From source file:org.kuali.rice.ken.service.impl.ConcurrentJob.java
/** * Helper method for creating a TransactionTemplate initialized to create * a new transaction/* w ww. j ava2 s. c o m*/ * @return a TransactionTemplate initialized to create a new transaction */ protected TransactionTemplate createNewTransaction() { TransactionTemplate tt = new TransactionTemplate(txManager); tt.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW); return tt; }
From source file:org.lexevs.dao.database.operation.DefaultLexEvsDatabaseOperations.java
protected void doDropCodingSchemeTables(final String codingSchemeUri, final String version, final String prefix) { TransactionTemplate template = new TransactionTemplate(this.getTransactionManager()); template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); template.execute(new TransactionCallback() { @Override// w ww. java 2 s . c o m public Object doInTransaction(TransactionStatus status) { if (!getSystemVariables().isSingleTableMode()) { dropCodingSchemeHistoryTables(codingSchemeUri, version); } doExecuteSql(codingSchemeXmlDdl, new DropSchemaPlatformActor(), prefix); return null; } }); }
From source file:org.lexevs.dao.database.operation.DefaultLexEvsDatabaseOperations.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public void dropCodingSchemeTablesByPrefix(final String prefix) { TransactionTemplate template = new TransactionTemplate(this.getTransactionManager()); template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); template.execute(new TransactionCallback() { @Override/*w w w .j a v a 2s. co m*/ public Object doInTransaction(TransactionStatus status) { dropCodingSchemeHistoryTablesByPrefix(prefix); doExecuteSql(codingSchemeXmlDdl, new DropSchemaPlatformActor(), prefix); return null; } }); }
From source file:org.openiam.provision.service.DefaultProvisioningService.java
private ProvisionUserResponse addUser(final ProvisionUser pUser, final IdmAuditLog auditLog) { final List<ProvisionDataContainer> dataList = new LinkedList<ProvisionDataContainer>(); ProvisionUserResponse res = new ProvisionUserResponse(); res.setStatus(ResponseStatus.FAILURE); try {//from ww w .j a va2 s . c o m final TransactionTemplate transactionTemplate = new TransactionTemplate(platformTransactionManager); transactionTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED); res = transactionTemplate.execute(new TransactionCallback<ProvisionUserResponse>() { @Override public ProvisionUserResponse doInTransaction(TransactionStatus status) { IdmAuditLog idmAuditLog = new IdmAuditLog(); idmAuditLog.setRequestorUserId(pUser.getRequestorUserId()); idmAuditLog.setRequestorPrincipal(pUser.getRequestorLogin()); idmAuditLog.setAction(AuditAction.CREATE_USER.value()); idmAuditLog.setAuditDescription("Provisioning add user: " + pUser.getId() + " with first/last name: " + pUser.getFirstName() + "/" + pUser.getLastName()); if (auditLog != null) { auditLog.addChild(idmAuditLog); idmAuditLog.addParent(auditLog); idmAuditLog = auditLogService.save(idmAuditLog); } idmAuditLog = auditLogService.save(idmAuditLog); ProvisionUserResponse tmpRes = addModifyUser(pUser, true, dataList, idmAuditLog); idmAuditLog = auditLogService.save(idmAuditLog); return tmpRes; } }); if (res.isSuccess()) { provQueueService.enqueue(dataList); } } catch (Throwable t) { log.error("Can't add user", t); } return res; }
From source file:org.pentaho.aggdes.ui.exec.impl.JdbcTemplateSqlExecutor.java
public void execute(final String[] sql, final ExecutorCallback callback) throws DataAccessException { Exception exceptionDuringExecute = null; DatabaseMeta dbMeta = connectionModel.getDatabaseMeta(); String url = null;//from w w w . j ava 2s . c om try { url = dbMeta.getURL(); } catch (KettleDatabaseException e) { throw new DataAccessException("DatabaseMeta problem", e) { private static final long serialVersionUID = -3457360074729938909L; }; } // create the datasource DataSource ds = new SingleConnectionDataSource(dbMeta.getDriverClass(), url, dbMeta.getUsername(), dbMeta.getPassword(), false); // create the jdbc template final JdbcTemplate jt = new JdbcTemplate(ds); // create the transaction manager DataSourceTransactionManager tsMan = new DataSourceTransactionManager(ds); // create the transaction template TransactionTemplate txTemplate = new TransactionTemplate(tsMan); // set behavior txTemplate.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW); final String noCommentSql[] = removeCommentsAndSemicolons(connectionModel.getSchema(), sql); try { // run the code in a transaction txTemplate.execute(new TransactionCallbackWithoutResult() { public void doInTransactionWithoutResult(TransactionStatus status) { jt.batchUpdate(noCommentSql); } }); } catch (DataAccessException e) { if (logger.isErrorEnabled()) { logger.error("data access exception", e); } exceptionDuringExecute = e; } callback.executionComplete(exceptionDuringExecute); }
From source file:org.springframework.integration.jdbc.store.channel.AbstractTxTimeoutMessageStoreTests.java
public void test() throws InterruptedException { int maxMessages = 10; int maxWaitTime = 30000; final TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager); transactionTemplate.setIsolationLevel(Isolation.READ_COMMITTED.value()); transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); for (int i = 1; i <= maxMessages; ++i) { final String message = "TEST MESSAGE " + i; log.info("Sending message: " + message); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override//from w w w. j av a2 s .co m protected void doInTransactionWithoutResult(TransactionStatus status) { inputChannel.send(MessageBuilder.withPayload(message).build()); } }); log.info(String.format("Done sending message %s of %s: %s", i, maxMessages, message)); } log.info("Done sending " + maxMessages + " messages."); Assert.assertTrue(String.format("Contdown latch did not count down from " + "%s to 0 in %sms.", maxMessages, maxWaitTime), testService.await(maxWaitTime)); Thread.sleep(2000); Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(jdbcChannelMessageStore.getSizeOfIdCache())); Assert.assertEquals(Integer.valueOf(maxMessages), Integer.valueOf(testService.getSeenMessages().size())); Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(testService.getDuplicateMessagesCount())); }
From source file:org.springframework.session.jdbc.JdbcOperationsSessionRepository.java
private static TransactionTemplate createTransactionTemplate(PlatformTransactionManager transactionManager) { TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager); transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); transactionTemplate.afterPropertiesSet(); return transactionTemplate; }