Search in sources :

Example 16 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project wildfly by wildfly.

the class SFSB4LC method updateEmployeeAddress.

/**
 * Update Employee's address
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void updateEmployeeAddress(int id, String address, boolean fail) {
    EntityManager em = emf.createEntityManager();
    Employee emp = em.find(Employee.class, id);
    emp.setAddress(address);
    em.merge(emp);
    em.flush();
    if (fail) {
        // Asked to fail...throwing exception for rollback
        throw new RollbackException();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 17 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project wildfly by wildfly.

the class SFSBCMT method queryEmployeeNameRequireNewTX.

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Employee queryEmployeeNameRequireNewTX(int id) {
    Query q = em.createQuery("SELECT e FROM Employee e where id=?");
    q.setParameter(1, new Integer(id));
    return (Employee) q.getSingleResult();
}
Also used : Query(javax.persistence.Query) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 18 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project wildfly by wildfly.

the class TransactionalBean method intermittentCommitFailureTwoPhase.

@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void intermittentCommitFailureTwoPhase() {
    try {
        Transaction txn = tm.getTransaction();
        log.debugf("Invocation to #intermittentCommitFailure with transaction: %s", txn);
        txn.enlistResource(new TestCommitFailureXAResource(transactionCheckerSingleton));
        txn.enlistResource(new PersistentTestXAResource(transactionCheckerSingleton));
    } catch (Exception e) {
        throw new IllegalStateException("Cannot enlist one of the XAResources " + TestCommitFailureXAResource.class.getSimpleName() + " or " + PersistentTestXAResource.class.getSimpleName() + " to the transaction", e);
    }
}
Also used : PersistentTestXAResource(org.jboss.as.test.integration.transactions.PersistentTestXAResource) Transaction(javax.transaction.Transaction) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 19 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project wildfly by wildfly.

the class TransactionalBean method intermittentCommitFailure.

@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void intermittentCommitFailure() {
    try {
        Transaction txn = tm.getTransaction();
        log.debugf("Invocation to #intermittentCommitFailure with the transaction: %s", txn);
        txn.enlistResource(new TestCommitFailureXAResource(transactionCheckerSingleton));
    } catch (Exception e) {
        throw new IllegalStateException("Cannot enlist single " + TestCommitFailureXAResource.class.getSimpleName() + " to the transaction", e);
    }
}
Also used : Transaction(javax.transaction.Transaction) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 20 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project wildfly by wildfly.

the class TransactionalBean method enlistOnePersistentXAResource.

@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void enlistOnePersistentXAResource() {
    try {
        log.debugf("Invocation to #enlistOnePersistentXAResource with transaction", tm.getTransaction());
        tm.getTransaction().enlistResource(new PersistentTestXAResource(transactionCheckerSingleton));
    } catch (Exception e) {
        throw new IllegalStateException("Cannot enlist single " + PersistentTestXAResource.class.getSimpleName() + " to transaction", e);
    }
}
Also used : PersistentTestXAResource(org.jboss.as.test.integration.transactions.PersistentTestXAResource) TransactionAttribute(javax.ejb.TransactionAttribute)

Aggregations

TransactionAttribute (javax.ejb.TransactionAttribute)61 JMSException (javax.jms.JMSException)8 IOException (java.io.IOException)7 Connection (javax.jms.Connection)6 Session (javax.jms.Session)6 TextMessage (javax.jms.TextMessage)6 Query (javax.persistence.Query)5 Configuration (org.hibernate.cfg.Configuration)5 Dataset (edu.harvard.iq.dataverse.Dataset)4 ConfigMessageException (eu.europa.ec.fisheries.uvms.config.exception.ConfigMessageException)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 EJBException (javax.ejb.EJBException)4 Message (javax.jms.Message)4 MessageProducer (javax.jms.MessageProducer)4 DataFile (edu.harvard.iq.dataverse.DataFile)3 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)3 ExchangeMessageException (eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException)3 Properties (java.util.Properties)3 EntityManager (javax.persistence.EntityManager)3