Search in sources :

Example 21 with TransactionAttribute

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

the class TransactedQueueMessageSender method sendToQueueSuccessfully.

@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public void sendToQueueSuccessfully() throws Exception {
    Connection connection = null;
    Session session = null;
    try {
        logger.trace("Creating a Connection");
        connection = factory.createConnection();
        logger.trace("Creating a Session");
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        Message message = session.createTextMessage("Hello world!");
        logger.trace("Sending message");
        producer.send(message);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (session != null) {
            session.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : Message(javax.jms.Message) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) JMSException(javax.jms.JMSException) Session(javax.jms.Session) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 22 with TransactionAttribute

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

the class TransactedTopicMessageSender method sendToTopicSuccessfully.

@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public void sendToTopicSuccessfully() throws Exception {
    Connection connection = null;
    Session session = null;
    try {
        logger.trace("Creating a Connection");
        connection = factory.createConnection();
        logger.trace("Creating a Session");
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(topic);
        Message message = session.createTextMessage("Hello world!");
        logger.trace("Sending message");
        producer.send(message);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (session != null) {
            session.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : Message(javax.jms.Message) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) JMSException(javax.jms.JMSException) Session(javax.jms.Session) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 23 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project Payara by payara.

the class TransactionAttributeHandler method postProcessAnnotation.

/**
 * Set the default value (from class type annotation) on all
 * methods that don't have a value.
 */
public void postProcessAnnotation(AnnotationInfo ainfo, EjbContext ejbContext) throws AnnotationProcessorException {
    EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
    TransactionAttribute taAn = (TransactionAttribute) ainfo.getAnnotation();
    ContainerTransaction containerTransaction = getContainerTransaction(taAn.value());
    Class classAn = (Class) ainfo.getAnnotatedElement();
    Set txBusMethods = ejbDesc.getTxBusinessMethodDescriptors();
    for (Object mdObj : txBusMethods) {
        MethodDescriptor md = (MethodDescriptor) mdObj;
        // override by xml
        if (classAn.equals(ejbContext.getDeclaringClass(md)) && ejbDesc.getContainerTransactionFor(md) == null) {
            ejbDesc.setContainerTransactionFor(md, containerTransaction);
        }
    }
}
Also used : Set(java.util.Set) TransactionAttribute(javax.ejb.TransactionAttribute) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

Example 24 with TransactionAttribute

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

the class CustomerManagerEJB method createCustomer.

@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void createCustomer(String name) throws RemoteException, JMSException {
    logMessageManager.logCreateCustomer(name);
    Customer c1 = new Customer();
    c1.setName(name);
    entityManager.persist(c1);
    invoiceManager.createInvoice(name);
    // after the fact but before the transaction is committed.
    if (!nameIsValid(name)) {
        throw new EJBException("Invalid name: customer names should only contain letters & '-'");
    }
}
Also used : Customer(org.jboss.as.quickstarts.cmt.model.Customer) EJBException(javax.ejb.EJBException) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 25 with TransactionAttribute

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

the class StatelessBean method successOnCall.

/**
 * Stateless remote ejb method to be called from the client side.
 *
 * @return information about the host that this EJB resides on
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public String successOnCall() {
    log.debugf("Called '%s.successOnCall()' with transaction status %s", this.getClass().getName(), InfoUtils.getTransactionStatus());
    // transaction enlists XAResource #1
    try {
        tm.getTransaction().enlistResource(new MockXAResource());
    } catch (SystemException | RollbackException sre) {
        throw new IllegalStateException("Cannot enlist a " + MockXAResource.class.getName() + " to the current transaction", sre);
    }
    // transaction enlists XAResource #2
    em.persist(new CalleeUser("Bard", "The Bowman"));
    return InfoUtils.getHostInfo();
}
Also used : SystemException(javax.transaction.SystemException) MockXAResource(org.jboss.as.quickstarts.ejb.mock.MockXAResource) RollbackException(javax.transaction.RollbackException) CalleeUser(org.jboss.as.quickstarts.ejb.entity.CalleeUser) 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