Complete Java Enterprise Edition 8 specification APIs providing all standardized enterprise application development interfaces
—
JTA API for declarative and programmatic transaction management with XA resource coordination.
public interface UserTransaction {
void begin() throws NotSupportedException, SystemException;
void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException;
void rollback() throws IllegalStateException, SecurityException, SystemException;
void setRollbackOnly() throws IllegalStateException, SystemException;
int getStatus() throws SystemException;
void setTransactionTimeout(int seconds) throws SystemException;
}
public interface TransactionManager extends UserTransaction {
Transaction getTransaction() throws SystemException;
void setTransactionTimeout(int seconds) throws SystemException;
Transaction suspend() throws SystemException;
void resume(Transaction tobj) throws InvalidTransactionException, IllegalStateException, SystemException;
}
public interface Transaction {
void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, SystemException;
void rollback() throws IllegalStateException, SystemException;
void setRollbackOnly() throws IllegalStateException, SystemException;
int getStatus() throws SystemException;
boolean enlistResource(XAResource xaRes) throws RollbackException, IllegalStateException, SystemException;
boolean delistResource(XAResource xaRes, int flag) throws IllegalStateException, SystemException;
void registerSynchronization(Synchronization sync) throws RollbackException, IllegalStateException, SystemException;
}@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Transactional {
TxType value() default TxType.REQUIRED;
Class[] rollbackOn() default {};
Class[] dontRollbackOn() default {};
}@Stateless
public class OrderService {
@Resource
private UserTransaction userTransaction;
@Transactional
public void processOrder(Order order) {
// Automatically wrapped in transaction
orderRepository.save(order);
inventoryService.updateStock(order.getItems());
}
public void manualTransaction() throws Exception {
userTransaction.begin();
try {
// Business logic
userTransaction.commit();
} catch (Exception e) {
userTransaction.rollback();
throw e;
}
}
}Install with Tessl CLI
npx tessl i tessl/maven-javax--javaee-api