use of javax.ejb.TransactionAttributeType in project wildfly by wildfly.
the class TransactionAttributeMergingProcessor method handleDeploymentDescriptor.
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentDescription) throws DeploymentUnitProcessingException {
// CMT Tx attributes
//DO NOT USE componentConfiguration.getDescriptorData()
//It will return null if there is no <enterprise-beans/> declaration even if there is an assembly descriptor entry
EjbJarMetaData ejbJarMetadata = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMetadata != null) {
boolean wildcardAttributeSet = false;
boolean wildcardTimeoutSet = false;
ContainerTransactionMetaData global = null;
final AssemblyDescriptorMetaData assemblyDescriptor = ejbJarMetadata.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
final ContainerTransactionsMetaData globalTransactions = assemblyDescriptor.getContainerTransactionsByEjbName("*");
if (globalTransactions != null) {
if (globalTransactions.size() > 1) {
throw EjbLogger.ROOT_LOGGER.mustOnlyBeSingleContainerTransactionElementWithWildcard();
}
global = globalTransactions.iterator().next();
for (MethodMetaData method : global.getMethods()) {
if (!method.getMethodName().equals("*")) {
throw EjbLogger.ROOT_LOGGER.wildcardContainerTransactionElementsMustHaveWildcardMethodName();
}
}
}
final ContainerTransactionsMetaData containerTransactions = assemblyDescriptor.getContainerTransactionsByEjbName(componentDescription.getEJBName());
if (containerTransactions != null) {
for (final ContainerTransactionMetaData containerTx : containerTransactions) {
final TransactionAttributeType txAttr = containerTx.getTransAttribute();
final Integer timeout = timeout(containerTx);
final MethodsMetaData methods = containerTx.getMethods();
for (final MethodMetaData method : methods) {
final String methodName = method.getMethodName();
final MethodIntf defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodIntf.MESSAGE_ENDPOINT : MethodIntf.BEAN;
final MethodIntf methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
if (methodName.equals("*")) {
if (txAttr != null) {
wildcardAttributeSet = true;
componentDescription.getTransactionAttributes().setAttribute(methodIntf, null, txAttr);
}
if (timeout != null) {
wildcardTimeoutSet = true;
componentDescription.getTransactionTimeouts().setAttribute(methodIntf, null, timeout);
}
} else {
final MethodParametersMetaData methodParams = method.getMethodParams();
// update the session bean description with the tx attribute info
if (methodParams == null) {
if (txAttr != null)
componentDescription.getTransactionAttributes().setAttribute(methodIntf, txAttr, methodName);
if (timeout != null)
componentDescription.getTransactionTimeouts().setAttribute(methodIntf, timeout, methodName);
} else {
if (txAttr != null)
componentDescription.getTransactionAttributes().setAttribute(methodIntf, txAttr, null, methodName, this.getMethodParams(methodParams));
if (timeout != null)
componentDescription.getTransactionTimeouts().setAttribute(methodIntf, timeout, null, methodName, this.getMethodParams(methodParams));
}
}
}
}
}
}
if (global != null) {
if (!wildcardAttributeSet && global.getTransAttribute() != null) {
for (MethodMetaData method : global.getMethods()) {
final MethodIntf defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodIntf.MESSAGE_ENDPOINT : MethodIntf.BEAN;
final MethodIntf methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
componentDescription.getTransactionAttributes().setAttribute(methodIntf, null, global.getTransAttribute());
}
}
final Integer timeout = timeout(global);
if (!wildcardTimeoutSet && timeout != null) {
for (MethodMetaData method : global.getMethods()) {
final MethodIntf defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodIntf.MESSAGE_ENDPOINT : MethodIntf.BEAN;
final MethodIntf methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
componentDescription.getTransactionTimeouts().setAttribute(methodIntf, null, timeout);
}
}
}
}
}
use of javax.ejb.TransactionAttributeType in project wildfly by wildfly.
the class CMTTxInterceptor method processInvocation.
public Object processInvocation(InterceptorContext invocation) throws Exception {
final EJBComponent component = (EJBComponent) invocation.getPrivateData(Component.class);
final TransactionManager tm = component.getTransactionManager();
final int oldTimeout = getCurrentTransactionTimeout(component);
try {
final MethodIntf methodIntf = MethodIntfHelper.of(invocation);
final TransactionAttributeType attr = component.getTransactionAttributeType(methodIntf, invocation.getMethod());
final int timeoutInSeconds = component.getTransactionTimeout(methodIntf, invocation.getMethod());
switch(attr) {
case MANDATORY:
return mandatory(invocation, component);
case NEVER:
return never(invocation, component);
case NOT_SUPPORTED:
return notSupported(invocation, component);
case REQUIRED:
return required(invocation, component, timeoutInSeconds);
case REQUIRES_NEW:
return requiresNew(invocation, component, timeoutInSeconds);
case SUPPORTS:
return supports(invocation, component);
default:
throw EjbLogger.ROOT_LOGGER.unknownTxAttributeOnInvocation(attr, invocation);
}
} finally {
tm.setTransactionTimeout(oldTimeout == -1 ? 0 : oldTimeout);
}
}
use of javax.ejb.TransactionAttributeType in project wildfly by wildfly.
the class EjbIIOPTransactionInterceptor method processInvocation.
@Override
public Object processInvocation(final InterceptorContext invocation) throws Exception {
// Do we have a foreign transaction context?
Transaction tx = TxServerInterceptor.getCurrentTransaction();
if (tx instanceof ForeignTransaction) {
final EJBComponent component = (EJBComponent) invocation.getPrivateData(Component.class);
//for timer invocations there is no view, so the methodInf is attached directly
//to the context. Otherwise we retrieve it from the invoked view
MethodIntf methodIntf = invocation.getPrivateData(MethodIntf.class);
if (methodIntf == null) {
final ComponentView componentView = invocation.getPrivateData(ComponentView.class);
if (componentView != null) {
methodIntf = componentView.getPrivateData(MethodIntf.class);
} else {
methodIntf = MethodIntf.BEAN;
}
}
final TransactionAttributeType attr = component.getTransactionAttributeType(methodIntf, invocation.getMethod());
if (attr != TransactionAttributeType.NOT_SUPPORTED && attr != TransactionAttributeType.REQUIRES_NEW) {
throw EjbLogger.ROOT_LOGGER.transactionPropagationNotSupported();
}
}
return invocation.proceed();
}
use of javax.ejb.TransactionAttributeType in project wildfly by wildfly.
the class EJBComponentCreateService method processTxAttr.
protected void processTxAttr(final EJBComponentDescription ejbComponentDescription, final MethodIntf methodIntf, final Method method) {
if (this.getTransactionManagementType().equals(TransactionManagementType.BEAN)) {
// it's a BMT bean
return;
}
MethodIntf defaultMethodIntf = (ejbComponentDescription instanceof MessageDrivenComponentDescription) ? MethodIntf.MESSAGE_ENDPOINT : MethodIntf.BEAN;
TransactionAttributeType txAttr = ejbComponentDescription.getTransactionAttributes().getAttribute(methodIntf, method, defaultMethodIntf);
if (txAttr != null) {
txAttrs.put(new MethodTransactionAttributeKey(methodIntf, MethodIdentifier.getIdentifierForMethod(method)), txAttr);
}
Integer txTimeout = ejbComponentDescription.getTransactionTimeouts().getAttribute(methodIntf, method, defaultMethodIntf);
if (txTimeout != null) {
txTimeouts.put(new MethodTransactionAttributeKey(methodIntf, MethodIdentifier.getIdentifierForMethod(method)), txTimeout);
}
}
Aggregations