Java Code Examples for org.springframework.transaction.support.DefaultTransactionStatus#getTransaction()

The following examples show how to use org.springframework.transaction.support.DefaultTransactionStatus#getTransaction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HibernateTransactionManager.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected void prepareForCommit(DefaultTransactionStatus status) {
	if (this.earlyFlushBeforeCommit && status.isNewTransaction()) {
		HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction();
		Session session = txObject.getSessionHolder().getSession();
		if (!session.getFlushMode().lessThan(FlushMode.COMMIT)) {
			logger.debug("Performing an early flush for Hibernate transaction");
			try {
				session.flush();
			}
			catch (HibernateException ex) {
				throw convertHibernateAccessException(ex);
			}
			finally {
				session.setFlushMode(FlushMode.MANUAL);
			}
		}
	}
}
 
Example 2
Source File: DatastoreTransactionManager.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus defaultTransactionStatus)
		throws TransactionException {
	Tx tx = (Tx) defaultTransactionStatus.getTransaction();
	try {
		if (tx.transaction.isActive()) {
			tx.transaction.rollback();
		}
		else {
			this.logger.debug(
					"Transaction was not rolled back because it is no longer active.");
		}
	}
	catch (DatastoreException ex) {
		throw new TransactionSystemException(
				"Cloud Datastore transaction failed to rollback.", ex);
	}
}
 
Example 3
Source File: JdoTransactionManager.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void doCommit(DefaultTransactionStatus status) {
	JdoTransactionObject txObject = (JdoTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Committing JDO transaction on PersistenceManager [" +
				txObject.getPersistenceManagerHolder().getPersistenceManager() + "]");
	}
	try {
		Transaction tx = txObject.getPersistenceManagerHolder().getPersistenceManager().currentTransaction();
		tx.commit();
	}
	catch (JDOException ex) {
		// Assumably failed to flush changes to database.
		throw convertJdoAccessException(ex);
	}
}
 
Example 4
Source File: JdoTransactionManager.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus status) {
	JdoTransactionObject txObject = (JdoTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Rolling back JDO transaction on PersistenceManager [" +
				txObject.getPersistenceManagerHolder().getPersistenceManager() + "]");
	}
	try {
		Transaction tx = txObject.getPersistenceManagerHolder().getPersistenceManager().currentTransaction();
		if (tx.isActive()) {
			tx.rollback();
		}
	}
	catch (JDOException ex) {
		throw new TransactionSystemException("Could not roll back JDO transaction", ex);
	}
}
 
Example 5
Source File: JpaTransactionManager.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus status) {
	JpaTransactionObject txObject = (JpaTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Rolling back JPA transaction on EntityManager [" +
				txObject.getEntityManagerHolder().getEntityManager() + "]");
	}
	try {
		EntityTransaction tx = txObject.getEntityManagerHolder().getEntityManager().getTransaction();
		if (tx.isActive()) {
			tx.rollback();
		}
	}
	catch (PersistenceException ex) {
		throw new TransactionSystemException("Could not roll back JPA transaction", ex);
	}
	finally {
		if (!txObject.isNewEntityManagerHolder()) {
			// Clear all pending inserts/updates/deletes in the EntityManager.
			// Necessary for pre-bound EntityManagers, to avoid inconsistent state.
			txObject.getEntityManagerHolder().getEntityManager().clear();
		}
	}
}
 
Example 6
Source File: JpaTransactionManager.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void doSetRollbackOnly(DefaultTransactionStatus status) {
	JpaTransactionObject txObject = (JpaTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Setting JPA transaction on EntityManager [" +
				txObject.getEntityManagerHolder().getEntityManager() + "] rollback-only");
	}
	txObject.setRollbackOnly();
}
 
Example 7
Source File: DataSourceTransactionManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus status) {
	DataSourceTransactionObject txObject = (DataSourceTransactionObject) status.getTransaction();
	Connection con = txObject.getConnectionHolder().getConnection();
	if (status.isDebug()) {
		logger.debug("Rolling back JDBC transaction on Connection [" + con + "]");
	}
	try {
		con.rollback();
	}
	catch (SQLException ex) {
		throw new TransactionSystemException("Could not roll back JDBC transaction", ex);
	}
}
 
Example 8
Source File: DataSourceTransactionManager.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void doSetRollbackOnly(DefaultTransactionStatus status) {
	DataSourceTransactionObject txObject = (DataSourceTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Setting JDBC transaction [" + txObject.getConnectionHolder().getConnection() +
				"] rollback-only");
	}
	txObject.setRollbackOnly();
}
 
Example 9
Source File: DataSourceTransactionManager.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus status) {
	DataSourceTransactionObject txObject = (DataSourceTransactionObject) status.getTransaction();
	Connection con = txObject.getConnectionHolder().getConnection();
	if (status.isDebug()) {
		logger.debug("Rolling back JDBC transaction on Connection [" + con + "]");
	}
	try {
		con.rollback();
	}
	catch (SQLException ex) {
		throw new TransactionSystemException("Could not roll back JDBC transaction", ex);
	}
}
 
Example 10
Source File: HibernateTransactionManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected void doSetRollbackOnly(DefaultTransactionStatus status) {
	HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Setting Hibernate transaction on Session [" +
				SessionFactoryUtils.toString(txObject.getSessionHolder().getSession()) + "] rollback-only");
	}
	txObject.setRollbackOnly();
}
 
Example 11
Source File: CciLocalTransactionManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected void doSetRollbackOnly(DefaultTransactionStatus status) {
	CciLocalTransactionObject txObject = (CciLocalTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Setting CCI local transaction [" + txObject.getConnectionHolder().getConnection() +
				"] rollback-only");
	}
	txObject.getConnectionHolder().setRollbackOnly();
}
 
Example 12
Source File: HibernateTransactionManager.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void doSetRollbackOnly(DefaultTransactionStatus status) {
	HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Setting Hibernate transaction on Session [" +
				txObject.getSessionHolder().getSession() + "] rollback-only");
	}
	txObject.setRollbackOnly();
}
 
Example 13
Source File: HibernateTransactionManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void doSetRollbackOnly(DefaultTransactionStatus status) {
	HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Setting Hibernate transaction on Session [" +
				txObject.getSessionHolder().getSession() + "] rollback-only");
	}
	txObject.setRollbackOnly();
}
 
Example 14
Source File: CciLocalTransactionManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void doSetRollbackOnly(DefaultTransactionStatus status) {
	CciLocalTransactionObject txObject = (CciLocalTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Setting CCI local transaction [" + txObject.getConnectionHolder().getConnection() +
				"] rollback-only");
	}
	txObject.getConnectionHolder().setRollbackOnly();
}
 
Example 15
Source File: SpannerTransactionManager.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus defaultTransactionStatus)
		throws TransactionException {
	Tx tx = (Tx) defaultTransactionStatus.getTransaction();
	if (tx.getTransactionManager() != null
			&& tx.getTransactionManager().getState() == TransactionManager.TransactionState.STARTED) {
		tx.getTransactionManager().rollback();
	}
	if (tx.isReadOnly()) {
		tx.getTransactionContext().close();
	}
}
 
Example 16
Source File: DataSourceTransactionManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected void doCommit(DefaultTransactionStatus status) {
	DataSourceTransactionObject txObject = (DataSourceTransactionObject) status.getTransaction();
	Connection con = txObject.getConnectionHolder().getConnection();
	if (status.isDebug()) {
		logger.debug("Committing JDBC transaction on Connection [" + con + "]");
	}
	try {
		con.commit();
	}
	catch (SQLException ex) {
		throw new TransactionSystemException("Could not commit JDBC transaction", ex);
	}
}
 
Example 17
Source File: MultipleDataSourcesTransactionManager.java    From cobarclient with Apache License 2.0 5 votes vote down vote up
@Override
protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
	@SuppressWarnings("unchecked")
	List<DefaultTransactionStatus> list = 
	      (List<DefaultTransactionStatus>) status.getTransaction();

	logger.info("prepare to commit transactions on multiple data sources.");
	Validate.isTrue(list.size() <= this.getTransactionManagers().size());

	TransactionException lastException = null;
	for(int i=list.size()-1; i>=0;i--){
		PlatformTransactionManager transactionManager=this.getTransactionManagers().get(i);
		TransactionStatus localTransactionStatus=list.get(i);
		
		try{
			transactionManager.commit(localTransactionStatus);
		}
		catch (TransactionException e) {
			lastException=e;
			logger.error("Error in commit", e);

		}
	}
	if (lastException != null) {
		throw lastException;
		// Rollback will ensue as long as rollbackOnCommitFailure=true
	}

}
 
Example 18
Source File: CciLocalTransactionManager.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void doSetRollbackOnly(DefaultTransactionStatus status) {
	CciLocalTransactionObject txObject = (CciLocalTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Setting CCI local transaction [" + txObject.getConnectionHolder().getConnection() +
				"] rollback-only");
	}
	txObject.getConnectionHolder().setRollbackOnly();
}
 
Example 19
Source File: JpaTransactionManager.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void doSetRollbackOnly(DefaultTransactionStatus status) {
	JpaTransactionObject txObject = (JpaTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Setting JPA transaction on EntityManager [" +
				txObject.getEntityManagerHolder().getEntityManager() + "] rollback-only");
	}
	txObject.setRollbackOnly();
}
 
Example 20
Source File: JmsTransactionManager.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected void doSetRollbackOnly(DefaultTransactionStatus status) {
	JmsTransactionObject txObject = (JmsTransactionObject) status.getTransaction();
	txObject.getResourceHolder().setRollbackOnly();
}