Search in sources :

Example 36 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project narayana by jbosstm.

the class MDBBlacktieService method onMessage.

/**
 * The onMessage method formats the JMS received bytes message into a format understood by the XATMI API.
 *
 * @param message The message received wrapping an XATMI invocation
 */
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void onMessage(Message message) {
    try {
        String serviceName = null;
        Destination jmsDestination = message.getJMSDestination();
        if (jmsDestination instanceof Queue) {
            serviceName = ((Queue) jmsDestination).getQueueName();
        } else {
            serviceName = ((Topic) jmsDestination).getTopicName();
        }
        serviceName = serviceName.substring(serviceName.indexOf('_') + 1);
        log.trace(serviceName);
        if (JtsTransactionImple.hasTransaction()) {
            throw new ConnectionException(Connection.TPEPROTO, "Blacktie services must not be called with a transactional context: " + getName() + ":" + serviceName);
        }
        BytesMessage bytesMessage = ((BytesMessage) message);
        org.jboss.narayana.blacktie.jatmibroker.core.transport.Message toProcess = convertFromBytesMessage(bytesMessage);
        log.debug("SERVER onMessage: transaction control ior: " + toProcess.control);
        processMessage(serviceName, toProcess);
        log.debug("Processed message");
    } catch (Throwable t) {
        log.error("Could not service the request", t);
    }
}
Also used : Destination(javax.jms.Destination) BytesMessage(javax.jms.BytesMessage) Queue(javax.jms.Queue) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 37 with TransactionAttribute

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

the class TransactionAttributeHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    TransactionAttribute taAn = (TransactionAttribute) ainfo.getAnnotation();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
        ContainerTransaction containerTransaction = getContainerTransaction(taAn.value());
        if (ElementType.TYPE.equals(ainfo.getElementType())) {
            ejbContext.addPostProcessInfo(ainfo, this);
        } else {
            Method annMethod = (Method) ainfo.getAnnotatedElement();
            Set txBusMethods = ejbDesc.getTxBusinessMethodDescriptors();
            for (Object next : txBusMethods) {
                MethodDescriptor nextDesc = (MethodDescriptor) next;
                Method m = nextDesc.getMethod(ejbDesc);
                if (TypeUtil.sameMethodSignature(m, annMethod) && ejbDesc.getContainerTransactionFor(nextDesc) == null) {
                    // override by xml
                    ejbDesc.setContainerTransactionFor(nextDesc, containerTransaction);
                }
            }
            if (ejbDesc instanceof EjbSessionDescriptor) {
                EjbSessionDescriptor sd = (EjbSessionDescriptor) ejbDesc;
                if (sd.isStateful() || sd.isSingleton()) {
                    ClassLoader loader = ejbDesc.getEjbBundleDescriptor().getClassLoader();
                    Set<LifecycleCallbackDescriptor> lcds = ejbDesc.getLifecycleCallbackDescriptors();
                    for (LifecycleCallbackDescriptor lcd : lcds) {
                        if (lcd.getLifecycleCallbackClass().equals(ejbDesc.getEjbClassName()) && lcd.getLifecycleCallbackMethod().equals(annMethod.getName())) {
                            try {
                                Method m = lcd.getLifecycleCallbackMethodObject(loader);
                                MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.LIFECYCLE_CALLBACK);
                                if (TypeUtil.sameMethodSignature(m, annMethod) && ejbDesc.getContainerTransactionFor(md) == null) {
                                    // stateful lifecycle callback txn attr type EJB spec
                                    if (sd.isStateful() && containerTransaction != null) {
                                        String txAttr = containerTransaction.getTransactionAttribute();
                                        if (txAttr != null && !txAttr.equals(ContainerTransaction.REQUIRES_NEW) && !txAttr.equals(ContainerTransaction.NOT_SUPPORTED)) {
                                            logger.log(Level.WARNING, localStrings.getLocalString("enterprise.deployment.annotation.handlers.sfsblifecycletxnattrtypewarn", "Stateful session bean {0} lifecycle callback method {1} has transaction " + "attribute {2} with container-managed transaction demarcation. " + "The transaction attribute should be either REQUIRES_NEW or NOT_SUPPORTED", new Object[] { (sd.getName() == null ? "" : sd.getName()), m.getName(), txAttr }));
                                        }
                                    }
                                    // override by xml
                                    ejbDesc.setContainerTransactionFor(md, containerTransaction);
                                    if (logger.isLoggable(Level.FINE)) {
                                        logger.log(Level.FINE, "Found matching callback method {0}<>{1} : {2}", new Object[] { ejbDesc.getEjbClassName(), md, containerTransaction });
                                    }
                                }
                            } catch (Exception e) {
                                if (logger.isLoggable(Level.FINE)) {
                                    logger.log(Level.FINE, "Transaction attribute for a lifecycle callback annotation processing error", e);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return getDefaultProcessedResult();
}
Also used : Set(java.util.Set) TransactionAttribute(javax.ejb.TransactionAttribute) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 38 with TransactionAttribute

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

the class SFSBTopLevel method createEmployeeNoTx.

// always throws a TransactionRequiredException
@TransactionAttribute(TransactionAttributeType.NEVER)
public void createEmployeeNoTx(String name, String address, int id) {
    Employee emp = new Employee();
    emp.setId(id);
    emp.setAddress(address);
    emp.setName(name);
    UserTransaction tx1 = sessionContext.getUserTransaction();
    try {
        tx1.begin();
        em.joinTransaction();
        em.persist(emp);
        tx1.commit();
    } catch (Exception e) {
        throw new RuntimeException("couldn't start tx", e);
    }
    // should throw TransactionRequiredException
    em.flush();
}
Also used : UserTransaction(javax.transaction.UserTransaction) NoResultException(javax.persistence.NoResultException) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 39 with TransactionAttribute

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

the class JMSSender method sendMessage.

@TransactionAttribute(NOT_SUPPORTED)
public void sendMessage(String payload) {
    try (JMSContext context = connectionFactory.createContext()) {
        JMSProducer producer = context.createProducer();
        producer.send(queue, payload);
    }
}
Also used : JMSProducer(javax.jms.JMSProducer) JMSContext(javax.jms.JMSContext) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 40 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)

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