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();
}
}
}
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();
}
}
}
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);
}
}
}
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 & '-'");
}
}
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();
}
Aggregations