List of usage examples for org.springframework.transaction.support TransactionTemplate TransactionTemplate
public TransactionTemplate(PlatformTransactionManager transactionManager)
From source file:org.jasig.ssp.service.jobqueue.AbstractJobExecutor.java
protected void initTransactionTemplate() { final PlatformTransactionManager txnManager = getTransactionManager(); if (txnManager == null) { this.transactionTemplate = null; }/*from w ww . j a v a 2 s . c o m*/ this.transactionTemplate = new TransactionTemplate(txnManager); }
From source file:org.kuali.kpme.core.service.HrServiceLocator.java
public static TransactionTemplate getTransactionTemplate() { return new TransactionTemplate(getPlatformTransactionManager()); }
From source file:org.kuali.kpme.core.util.ClearDatabaseLifecycle.java
protected void clearTables(final PlatformTransactionManager transactionManager, final DataSource dataSource, final String schemaName) { LOG.info("Clearing tables for schema " + schemaName); Assert.assertNotNull("DataSource could not be located.", dataSource); if (schemaName == null || schemaName.equals("")) { Assert.fail("Empty schema name given"); }//from w w w .j ava2s.c o m new TransactionTemplate(transactionManager).execute(new TransactionCallback<Object>() { public Object doInTransaction(final TransactionStatus status) { verifyTestEnvironment(dataSource); return new JdbcTemplate(dataSource).execute(new StatementCallback<Object>() { public Object doInStatement(Statement statement) throws SQLException { final List<String> reEnableConstraints = new ArrayList<String>(); List<List<String>> tableLists = new ArrayList<List<String>>(2); tableLists.add(TABLES_TO_CLEAR); tableLists.add(alternativeTablesToClear); for (List<String> list : tableLists) { for (String tableName : list) { //if there is an id name that doesnt follow convention check and limit accordingly String idName = TABLE_TO_ID_MAP.get(tableName); String deleteStatement = null; Integer clearId = TABLE_START_CLEAR_ID.get(tableName) != null ? TABLE_START_CLEAR_ID.get(tableName) : START_CLEAR_ID; if (idName == null) { deleteStatement = "DELETE FROM " + tableName + " WHERE " + StringUtils.removeEnd(tableName, "_T") + "_ID" + " >= " + clearId; } else { deleteStatement = "DELETE FROM " + tableName + " WHERE " + idName + " >= " + clearId; } LOG.debug("Clearing contents using statement ->" + deleteStatement + "<-"); statement.addBatch(deleteStatement); } } for (final String constraint : reEnableConstraints) { LOG.debug("Enabling constraints using statement ->" + constraint + "<-"); statement.addBatch(constraint); } statement.executeBatch(); return null; } }); } }); LOG.info("Tables successfully cleared for schema " + schemaName); }
From source file:org.kuali.kpme.core.util.DatabaseCleanupDataLifecycle.java
public void loadData(final PlatformTransactionManager transactionManager, final DataSource dataSource, final String schemaName) { Assert.assertNotNull("DataSource could not be located.", dataSource); if (schemaName == null || schemaName.equals("")) { Assert.fail("Empty schema name given"); }//from w w w. j av a 2s. com new TransactionTemplate(transactionManager).execute(new TransactionCallback() { public Object doInTransaction(final TransactionStatus status) { verifyTestEnvironment(dataSource); return new JdbcTemplate(dataSource).execute(new StatementCallback() { public Object doInStatement(Statement statement) throws SQLException { List<String> sqlStatements = new ArrayList<String>(); // // djunk - add a per-class special test data loader, // loads <testclassname>.sql from the same directory // as the other SQL loaded. if (callingTestClass != null) { sqlStatements.addAll(getTestDataSQLStatements( "src/test/config/sql/" + callingTestClass.getSimpleName() + "-cleanup.sql")); } for (String sql : sqlStatements) { if (!sql.startsWith("#") && !sql.startsWith("//") && !StringUtils.isEmpty(sql.trim())) { // ignore comment lines in our sql reader. statement.addBatch(sql); } } statement.executeBatch(); return null; } }); } }); }
From source file:org.kuali.kpme.core.util.LoadDatabaseDataLifeCycle.java
public void loadData(final PlatformTransactionManager transactionManager, final DataSource dataSource, final String schemaName) { LOG.info("Populating tables for schema " + schemaName); Assert.assertNotNull("DataSource could not be located.", dataSource); if (schemaName == null || schemaName.equals("")) { Assert.fail("Empty schema name given"); }//from w ww . java2s .com new TransactionTemplate(transactionManager).execute(new TransactionCallback<Object>() { public Object doInTransaction(final TransactionStatus status) { verifyTestEnvironment(dataSource); return new JdbcTemplate(dataSource).execute(new StatementCallback<Object>() { public Object doInStatement(Statement statement) throws SQLException { if (callingTestClass != null) { List<String> sqlStatements = getTestDataSQLStatements( "src/test/config/sql/" + callingTestClass.getSimpleName() + ".sql"); for (String sql : sqlStatements) { if (!sql.startsWith("#") && !sql.startsWith("//") && !StringUtils.isEmpty(sql.trim())) { // ignore comment lines in our sql reader. statement.addBatch(sql); } } } statement.executeBatch(); return null; } }); } }); }
From source file:org.kuali.kpme.core.util.SQLDataLifeCycle.java
public void loadData(final PlatformTransactionManager transactionManager, final DataSource dataSource, final String schemaName) { LOG.info("Clearing tables for schema " + schemaName); Assert.assertNotNull("DataSource could not be located.", dataSource); if (schemaName == null || schemaName.equals("")) { Assert.fail("Empty schema name given"); }/*from w w w . j a v a 2 s . c o m*/ new TransactionTemplate(transactionManager).execute(new TransactionCallback<Object>() { public Object doInTransaction(final TransactionStatus status) { verifyTestEnvironment(dataSource); return new JdbcTemplate(dataSource).execute(new StatementCallback<Object>() { public Object doInStatement(Statement statement) throws SQLException { if (callingTestClass != null) { List<String> sqlStatements = getTestDataSQLStatements( "src/test/config/sql/" + callingTestClass.getSimpleName() + ".sql"); for (String sql : sqlStatements) { if (!sql.startsWith("#") && !sql.startsWith("//") && !StringUtils.isEmpty(sql.trim())) { // ignore comment lines in our sql reader. statement.addBatch(sql); } } } statement.executeBatch(); return null; } }); } }); }
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 ww.java2 s .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./*w ww . ja v a 2 s . 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.kra.infrastructure.TestUtilities.java
License:asdf
public static void clearTables(final PlatformTransactionManager transactionManager, final DataSource dataSource, final String edenSchemaName, final List<String> dontClear) { LOG.info("Clearing tables for schema " + edenSchemaName); if (dataSource == null) { Assert.fail("Null data source given"); }//from www .j a v a 2 s. co m if (edenSchemaName == null || edenSchemaName.equals("")) { Assert.fail("Empty eden schema name given"); } new TransactionTemplate(transactionManager).execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { verifyTestEnvironment(dataSource); JdbcTemplate template = new JdbcTemplate(dataSource); return template.execute(new StatementCallback() { public Object doInStatement(Statement statement) throws SQLException { List<String> reEnableConstraints = new ArrayList<String>(); ResultSet resultSet = statement.getConnection().getMetaData().getTables(null, edenSchemaName, null, new String[] { "TABLE" }); while (resultSet.next()) { String tableName = resultSet.getString("TABLE_NAME"); if (tableName.startsWith("EN_") && !dontClear.contains(tableName)) { ResultSet keyResultSet = statement.getConnection().getMetaData() .getExportedKeys(null, edenSchemaName, tableName); while (keyResultSet.next()) { String fkName = keyResultSet.getString("FK_NAME"); String fkTableName = keyResultSet.getString("FKTABLE_NAME"); statement.addBatch( "ALTER TABLE " + fkTableName + " DISABLE CONSTRAINT " + fkName); reEnableConstraints .add("ALTER TABLE " + fkTableName + " ENABLE CONSTRAINT " + fkName); } keyResultSet.close(); statement.addBatch("DELETE FROM " + tableName.toUpperCase()); } } for (String constraint : reEnableConstraints) { statement.addBatch(constraint); } statement.executeBatch(); resultSet.close(); return null; } }); } }); LOG.info("Tables successfully cleared for schema " + edenSchemaName); }
From source file:org.kuali.ole.module.purap.util.PurApRelatedViews.java
public List updateRelatedView(final Class<?> clazz, List<? extends AbstractRelatedView> relatedList, final boolean removeCurrentDocument) { if (relatedList == null) { TransactionTemplate template = new TransactionTemplate(getTransactionManager()); relatedList = template.execute(new TransactionCallback<List<? extends AbstractRelatedView>>() { @Override/* w ww . j a va 2 s.c om*/ public List<? extends AbstractRelatedView> doInTransaction(TransactionStatus status) { List<? extends AbstractRelatedView> relatedList = SpringContext.getBean(PurapService.class) .getRelatedViews(clazz, accountsPayablePurchasingDocumentLinkIdentifier); if (removeCurrentDocument) { for (AbstractRelatedView view : relatedList) { //KFSMI-4576 Mask/Unmask purapDocumentIdentifier field value maskPONumberIfUnapproved(view); if (documentNumber.equals(view.getDocumentNumber())) { relatedList.remove(view); break; } } } return relatedList; } }); } return relatedList; }