public UserTransactionPropertyInjector(BeanProperty property, InjectionContainer container) { super(property); if (container instanceof EJBContainer) { TransactionManagementType type = TxUtil.getTransactionManagementType(((EJBContainer) container).getAdvisor()); if (type != TransactionManagementType.BEAN) throw new IllegalStateException("Container " + ((Container) container).getEjbName() + ": it is illegal to inject UserTransaction into a CMT bean"); } }
public static UserTransaction getUserTransaction(BeanContext<?> ctx) { Invocation invocation = CurrentInvocation.getCurrentInvocation(); // TODO: also not allowed during construction if(InvocationHelper.isInjection(invocation)) throw new IllegalStateException("getUserTransaction() not allowed during injection (EJB3 4.4.1 & 4.5.2)"); Advisor advisor = invocation.getAdvisor(); TransactionManagementType type = TxUtil.getTransactionManagementType(advisor); if (type != TransactionManagementType.BEAN) throw new IllegalStateException("Container " + advisor.getName() + ": it is illegal to inject UserTransaction into a CMT bean"); return new UserTransactionImpl(); }
private static void check(String publicMethod, String specReferenceTxAttr) { // getRollbackOnly is not allowed during construction and injection EJB 3 4.4.1 and EJB 3 4.5.2 Invocation currentInvocation = CurrentInvocation.getCurrentInvocation(); if(currentInvocation == null) throw new IllegalStateException("It's not allowed to do " + publicMethod + " during construction and injection"); Advisor advisor = currentInvocation.getAdvisor(); String containerName = advisor.getName(); // EJB1.1 11.6.1: Must throw IllegalStateException if BMT TransactionManagementType type = TxUtil.getTransactionManagementType(advisor); if (type != TransactionManagementType.CONTAINER) throw new IllegalStateException("Container " + containerName + ": it is illegal to call " + publicMethod + " from BMT: " + type); if(isLifecycleCallback(currentInvocation)) throw new IllegalStateException(containerName + ": " + publicMethod + " not allowed during lifecycle callbacks (EJB3 4.4.1 & 4.5.2)"); // TODO: we should really ask a TxType object to handle getRollbackOnly() if(getTxType(currentInvocation) == TransactionAttributeType.SUPPORTS) throw new IllegalStateException(containerName + ": " + publicMethod + " not allowed with TransactionAttributeType.SUPPORTS (" + specReferenceTxAttr + ")"); }
public Object createPerJoinpoint(Advisor advisor, Joinpoint jp) { // We have to do this until AOP supports matching based on annotation attributes TransactionManagementType type = TxUtil.getTransactionManagementType(advisor); if (type != TransactionManagementType.BEAN) return new NullInterceptor(); TransactionManager tm = TxUtil.getTransactionManager(); boolean stateful = advisor.resolveAnnotation(Stateful.class) != null; // Both MessageDriven and Stateless are stateless if(stateful) return new StatefulBMTInterceptor(tm); else return new StatelessBMTInterceptor(tm); } }
public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException { TransactionManagementType mtype = TxUtil.getTransactionManagementType(container.getAdvisor()); if (mtype == javax.ejb.TransactionManagementType.BEAN) return false; // JBPAPP-1668: the method can be called by anybody using the interface method (== unadvised) Method advisedMethod = container.getMethodInfo(method).getAdvisedMethod(); TransactionAttribute attr = (TransactionAttribute)container.resolveAnnotation(advisedMethod, TransactionAttribute.class); if (attr == null) { attr =(TransactionAttribute)container.resolveAnnotation(TransactionAttribute.class); } TransactionAttributeType type = TransactionAttributeType.REQUIRED; if (attr != null) type = attr.value(); return type == javax.ejb.TransactionAttributeType.REQUIRED; }
TransactionManagementType type = TxUtil.getTransactionManagementType(advisor); if (type == TransactionManagementType.BEAN) return new NullInterceptor();