public SessionSynchronizationInterceptor() { this.tm = TxUtil.getTransactionManager(); }
public static void setRollbackOnly() { check("setRollbackOnly", "EJB 3.0 FR 13.6.2.8"); try { TransactionManager tm = TxUtil.getTransactionManager(); // The getRollbackOnly and setRollBackOnly method of the SessionContext interface should be used // only in the session bean methods that execute in the context of a transaction. if (tm.getTransaction() == null) throw new IllegalStateException("setRollbackOnly() not allowed without a transaction."); tm.setRollbackOnly(); } catch (SystemException e) { log.warn("failed to set rollback only; ignoring", e); } } }
public boolean getRollbackOnly() throws IllegalStateException { return TxUtil.getRollbackOnly(); } }
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 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"); } }
protected TransactionAttributeType getTxType(Advisor advisor, Joinpoint jp) { Method method = ((MethodJoinpoint) jp).getMethod(); return TxUtil.getTxType(advisor, method); }
public void handleInCallerTx(Invocation invocation, Throwable t, Transaction tx) throws Throwable ApplicationException ae = TxUtil.getApplicationException(t.getClass(), invocation);
public void setRollbackOnly() throws IllegalStateException { TxUtil.setRollbackOnly(); }
public UserTransaction getUserTransaction() throws IllegalStateException { return TxUtil.getUserTransaction(beanContext); }
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 TransactionAttributeType getTxType(Invocation invocation) { // Use the method tx attribute if we're invoking a business method, else the bean attribute Method method = null; if(invocation instanceof MethodInvocation) method = ((MethodInvocation) invocation).getActualMethod(); return getTxType(invocation.getAdvisor(), method); }
public void handleExceptionInOurTx(Invocation invocation, Throwable t, Transaction tx) throws Throwable { ApplicationException ae = TxUtil.getApplicationException(t.getClass(), invocation); if (ae != null) { if (ae.rollback()) setRollbackOnly(tx); throw t; } // if it's neither EJBException nor RemoteException if(!(t instanceof EJBException || t instanceof RemoteException)) { // errors and unchecked are wrapped into EJBException if(t instanceof Error) { t = new EJBException(formatException("Unexpected Error", t)); } else if (t instanceof RuntimeException) { t = new EJBException((Exception)t); } else { // an application exception throw t; } } setRollbackOnly(tx); throw t; }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.tm = TxUtil.getTransactionManager(); }
public static boolean getRollbackOnly() check("getRollbackOnly", "EJB 3.0 FR 13.6.2.9"); TransactionManager tm = TxUtil.getTransactionManager();
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; }
/** * Returns the TransactionManager * @return */ private TransactionManager getTransactionManager() { if (this.transactionManager == null) { this.transactionManager = TxUtil.getTransactionManager(); } return this.transactionManager; } }
TransactionManagementType type = TxUtil.getTransactionManagementType(advisor); if (type == TransactionManagementType.BEAN) return new NullInterceptor();
public UserTransactionImpl() { if (log.isDebugEnabled()) log.debug("new UserTx: " + this); this.tm = TxUtil.getTransactionManager(); }
private void cleanExtendedPCs() { try { Transaction tx = TxUtil.getTransactionManager().getTransaction(); if (tx != null && TxUtils.isActive(tx)) { tx.registerSynchronization(new XPCCloseSynchronization(this)); } else { closeExtendedPCs(); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Error cleaning PersistenceContexts in SFSB removal", e); } }