org.hibernate.resource.transaction.spi.TransactionStatus Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-core Show documentation
Show all versions of hibernate-core Show documentation
JPMS Module-Info's for a few of the Jakarta Libraries just until they add them in themselves
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.resource.transaction.spi;
/**
* Enumeration of statuses in which a transaction facade ({@link org.hibernate.Transaction}) might be.
*
* @author Andrea Boriero
*/
public enum TransactionStatus {
/**
* The transaction has not yet been started.
*/
NOT_ACTIVE,
/**
* The transaction has been started, but not yet completed.
*/
ACTIVE,
/**
* The transaction has been completed successfully.
*/
COMMITTED,
/**
* The transaction has been rolled back.
*/
ROLLED_BACK,
/**
* The transaction has been marked for rollback only.
*/
MARKED_ROLLBACK,
/**
* The transaction attempted to commit, but failed.
*/
FAILED_COMMIT,
/**
* The transaction attempted to rollback, but failed.
*/
FAILED_ROLLBACK,
/**
* Status code indicating a transaction that has begun the second
* phase of the two-phase commit protocol, but not yet completed
* this phase.
*/
COMMITTING,
/**
* Status code indicating a transaction that is in the process of
* rolling back.
*/
ROLLING_BACK;
public boolean isOneOf(TransactionStatus... statuses) {
for ( TransactionStatus status : statuses ) {
if ( this == status ) {
return true;
}
}
return false;
}
public boolean isNotOneOf(TransactionStatus... statuses) {
return !isOneOf( statuses );
}
public boolean canRollback() {
return isOneOf(
TransactionStatus.ACTIVE,
TransactionStatus.FAILED_COMMIT,
TransactionStatus.MARKED_ROLLBACK
);
}
}