use of org.glassfish.ejb.deployment.descriptor.ContainerTransaction in project Payara by payara.
the class Generator method getTxAttribute.
protected String getTxAttribute(EjbDescriptor dd, Method method) {
// com.sun.ejb.Container.
if (dd instanceof EjbSessionDescriptor && ((EjbSessionDescriptor) dd).getTransactionType().equals("Bean"))
return "TX_BEAN_MANAGED";
String txAttr = null;
MethodDescriptor mdesc = new MethodDescriptor(method, ejbClassSymbol);
ContainerTransaction ct = dd.getContainerTransactionFor(mdesc);
if (ct != null) {
String attr = ct.getTransactionAttribute();
if (attr.equals(ContainerTransaction.NOT_SUPPORTED))
txAttr = "TX_NOT_SUPPORTED";
else if (attr.equals(ContainerTransaction.SUPPORTS))
txAttr = "TX_SUPPORTS";
else if (attr.equals(ContainerTransaction.REQUIRED))
txAttr = "TX_REQUIRED";
else if (attr.equals(ContainerTransaction.REQUIRES_NEW))
txAttr = "TX_REQUIRES_NEW";
else if (attr.equals(ContainerTransaction.MANDATORY))
txAttr = "TX_MANDATORY";
else if (attr.equals(ContainerTransaction.NEVER))
txAttr = "TX_NEVER";
}
if (txAttr == null) {
throw new RuntimeException("Transaction Attribute not found for method " + method);
}
return txAttr;
}
use of org.glassfish.ejb.deployment.descriptor.ContainerTransaction in project Payara by payara.
the class ContainerTransactionNode method endElement.
@Override
public boolean endElement(XMLElement element) {
boolean doneWithNode = super.endElement(element);
if (doneWithNode) {
ContainerTransaction ct = new ContainerTransaction(trans_attribute, description);
for (Iterator methodsIterator = methods.iterator(); methodsIterator.hasNext(); ) {
MethodDescriptor md = (MethodDescriptor) methodsIterator.next();
EjbBundleDescriptorImpl bundle = (EjbBundleDescriptorImpl) getParentNode().getDescriptor();
EjbDescriptor ejb = bundle.getEjbByName(md.getEjbName(), true);
ejb.getMethodContainerTransactions().put(md, ct);
}
}
return doneWithNode;
}
use of org.glassfish.ejb.deployment.descriptor.ContainerTransaction 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 org.glassfish.ejb.deployment.descriptor.ContainerTransaction in project Payara by payara.
the class EjbBundleTracerVisitor method accept.
protected void accept(EjbDescriptor ejb) {
logInfo("==================");
logInfo(ejb.getType() + " Bean " + ejb.getName());
logInfo("\thomeClassName " + ejb.getHomeClassName());
logInfo("\tremoteClassName " + ejb.getRemoteClassName());
logInfo("\tlocalhomeClassName " + ejb.getLocalHomeClassName());
logInfo("\tlocalClassName " + ejb.getLocalClassName());
logInfo("\tremoteBusinessIntfs " + ejb.getRemoteBusinessClassNames());
logInfo("\tlocalBusinessIntfs " + ejb.getLocalBusinessClassNames());
logInfo("\tjndiName " + ejb.getJndiName());
logInfo("\tejbClassName " + ejb.getEjbClassName());
logInfo("\ttransactionType " + ejb.getTransactionType());
if (ejb.getUsesCallerIdentity() == false) {
logInfo("\trun-as role " + ejb.getRunAsIdentity());
} else {
logInfo("\tuse-caller-identity " + ejb.getUsesCallerIdentity());
}
for (EjbReference aRef : ejb.getEjbReferenceDescriptors()) {
accept(aRef);
}
for (Iterator e = ejb.getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext(); ) {
MethodPermission mp = (MethodPermission) e.next();
Set methods = (Set) ejb.getPermissionedMethodsByPermission().get(mp);
accept(mp, methods);
}
if (ejb.getStyledPermissionedMethodsByPermission() != null) {
for (Iterator e = ejb.getStyledPermissionedMethodsByPermission().keySet().iterator(); e.hasNext(); ) {
MethodPermission mp = (MethodPermission) e.next();
Set methods = (Set) ejb.getStyledPermissionedMethodsByPermission().get(mp);
accept(mp, methods);
}
}
for (RoleReference roleRef : ejb.getRoleReferences()) {
accept(roleRef);
}
for (Iterator e = ejb.getMethodContainerTransactions().keySet().iterator(); e.hasNext(); ) {
MethodDescriptor md = (MethodDescriptor) e.next();
ContainerTransaction ct = (ContainerTransaction) ejb.getMethodContainerTransactions().get(md);
accept(md, ct);
}
for (EnvironmentProperty envProp : ejb.getEnvironmentProperties()) {
accept(envProp);
}
for (ResourceReferenceDescriptor next : ejb.getResourceReferenceDescriptors()) {
accept(next);
}
for (ResourceEnvReferenceDescriptor next : ejb.getResourceEnvReferenceDescriptors()) {
accept(next);
}
for (MessageDestinationReferencer next : ejb.getMessageDestinationReferenceDescriptors()) {
accept(next);
}
// referencer as well.
if (ejb.getType().equals(EjbMessageBeanDescriptor.TYPE)) {
MessageDestinationReferencer msgDestReferencer = (MessageDestinationReferencer) ejb;
if (msgDestReferencer.getMessageDestinationLinkName() != null) {
accept(msgDestReferencer);
}
}
for (ServiceReferenceDescriptor sref : ejb.getServiceReferenceDescriptors()) {
accept(sref);
}
if (ejb instanceof EjbCMPEntityDescriptor) {
EjbCMPEntityDescriptor cmp = (EjbCMPEntityDescriptor) ejb;
PersistenceDescriptor persistenceDesc = cmp.getPersistenceDescriptor();
for (Object fd : persistenceDesc.getCMPFields()) {
accept((FieldDescriptor) fd);
}
for (Object o : persistenceDesc.getQueriedMethods()) {
if (o instanceof MethodDescriptor) {
QueryDescriptor qd = persistenceDesc.getQueryFor((MethodDescriptor) o);
accept(qd);
}
}
}
}
use of org.glassfish.ejb.deployment.descriptor.ContainerTransaction 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();
}
Aggregations