Java Code Examples for org.hibernate.resource.transaction.spi.TransactionStatus#NOT_ACTIVE

The following examples show how to use org.hibernate.resource.transaction.spi.TransactionStatus#NOT_ACTIVE . 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: JtaTransactionAdapterTransactionManagerImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void begin() {
	try {
		if ( getStatus() == TransactionStatus.NOT_ACTIVE ) {
			log.trace( "Calling TransactionManager#begin" );
			transactionManager.begin();
			initiator = true;
			log.trace( "Called TransactionManager#begin" );
		}
		else {
			log.trace( "Skipping TransactionManager#begin due to already active transaction" );
		}
	}
	catch (Exception e) {
		throw new TransactionException( "JTA TransactionManager#begin failed", e );
	}
}
 
Example 2
Source File: JtaTransactionAdapterUserTransactionImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void begin() {
	try {
		if ( getStatus() == TransactionStatus.NOT_ACTIVE ) {
			log.trace( "Calling UserTransaction#begin" );
			userTransaction.begin();
			initiator = true;
			log.trace( "Called UserTransaction#begin" );
		}
		else {
			log.trace( "Skipping TransactionManager#begin due to already active transaction" );
		}
	}
	catch (Exception e) {
		throw new TransactionException( "JTA UserTransaction#begin failed", e );
	}
}
 
Example 3
Source File: JdbcResourceLocalTransactionCoordinatorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void rollback() {
	try {
		TransactionStatus status = jdbcResourceTransaction.getStatus();
		if ( ( rollbackOnly && status != TransactionStatus.NOT_ACTIVE ) || status == TransactionStatus.ACTIVE ) {
			jdbcResourceTransaction.rollback();
			JdbcResourceLocalTransactionCoordinatorImpl.this.afterCompletionCallback( false );
		}
	}
	finally {
		rollbackOnly = false;
	}

	// no-op otherwise.
}
 
Example 4
Source File: StatusTranslator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static TransactionStatus translate(int status) {
	TransactionStatus transactionStatus = null;
	switch ( status ) {
		case Status.STATUS_ACTIVE:
			transactionStatus = TransactionStatus.ACTIVE;
			break;
		case Status.STATUS_PREPARED:
			transactionStatus = TransactionStatus.ACTIVE;
			break;
		case Status.STATUS_PREPARING:
			transactionStatus = TransactionStatus.ACTIVE;
			break;
		case Status.STATUS_COMMITTING:
			transactionStatus = TransactionStatus.COMMITTING;
			break;
		case Status.STATUS_ROLLING_BACK:
			transactionStatus = TransactionStatus.ROLLING_BACK;
			break;
		case Status.STATUS_NO_TRANSACTION:
			transactionStatus = TransactionStatus.NOT_ACTIVE;
			break;
		case Status.STATUS_COMMITTED:
			transactionStatus = TransactionStatus.COMMITTED;
			break;
		case Status.STATUS_ROLLEDBACK:
			transactionStatus = TransactionStatus.ROLLED_BACK;
			break;
		case Status.STATUS_MARKED_ROLLBACK:
			transactionStatus = TransactionStatus.MARKED_ROLLBACK;
			break;
		default:
			break;
	}
	if ( transactionStatus == null ) {
		throw new TransactionException( "TransactionManager reported transaction status as unknwon" );
	}
	return transactionStatus;
}
 
Example 5
Source File: AbstractLogicalConnectionImplementor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void resetConnection(boolean initiallyAutoCommit) {
	try {
		if ( initiallyAutoCommit ) {
			log.trace( "re-enabling auto-commit on JDBC Connection after completion of JDBC-based transaction" );
			getConnectionForTransactionManagement().setAutoCommit( true );
			status = TransactionStatus.NOT_ACTIVE;
		}
	}
	catch ( Exception e ) {
		log.debug(
				"Could not re-enable auto-commit on JDBC Connection after completion of JDBC-based transaction : " + e
		);
	}
}
 
Example 6
Source File: TransactionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void rollback() {
	if ( !isActive() ) {
		if ( jpaCompliance.isJpaTransactionComplianceEnabled() ) {

			throw new IllegalStateException(
					"JPA compliance dictates throwing IllegalStateException when #rollback " +
							"is called on non-active transaction"
			);
		}
	}

	TransactionStatus status = getStatus();
	if ( status == TransactionStatus.ROLLED_BACK || status == TransactionStatus.NOT_ACTIVE ) {
		// Allow rollback() calls on completed transactions, just no-op.
		LOG.debug( "rollback() called on an inactive transaction" );
		return;
	}

	if ( !status.canRollback() ) {
		throw new TransactionException( "Cannot rollback transaction in current status [" + status.name() + "]" );
	}

	LOG.debug( "rolling back" );

	if ( status != TransactionStatus.FAILED_COMMIT || allowFailedCommitToPhysicallyRollback() ) {
		internalGetTransactionDriverControl().rollback();
	}
}
 
Example 7
Source File: TransactionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TransactionStatus getStatus() {
	if ( transactionDriverControl == null ) {
		if ( session.isOpen() ) {
			transactionDriverControl = transactionCoordinator.getTransactionDriverControl();
		}
		else {
			return TransactionStatus.NOT_ACTIVE;
		}
	}
	return transactionDriverControl.getStatus();
}