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