Package javax.transaction

Examples of javax.transaction.UserTransaction


  {
    super(ejbContainer, ejbName, moduleName, rawAnnType, annotatedType);

    InjectManager webBeans = InjectManager.create();
   
    UserTransaction ut = webBeans.getReference(UserTransaction.class);
    _lazyGenerator = lazyGenerator;
   
    // ejb/0fbl
    _context = new MessageDrivenContextImpl(this, ut);
  }
View Full Code Here


    private String action = "";

    public boolean mediate(MessageContext synCtx) {

        UserTransaction tx = null;
        final SynapseLog synLog = getLog(synCtx);

        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("Start : Transaction mediator (" + action + ")");

            if (synLog.isTraceTraceEnabled()) {
                synLog.traceTrace("Message : " + synCtx.getEnvelope());
            }
        }
        initContext(synCtx);
        try {
            tx = (UserTransaction) txContext.lookup(USER_TX_LOOKUP_STR);
        } catch (NamingException e) {
            handleException("Cloud not get the context name " + USER_TX_LOOKUP_STR, e, synCtx);
        }

        if (action.equals(ACTION_COMMIT)) {

            try {
                tx.commit();
            } catch (Exception e) {
                handleException("Unable to commit transaction", e, synCtx);
            }

        } else if (action.equals(ACTION_ROLLBACK)) {

            try {
                tx.rollback();
            } catch (Exception e) {
                handleException("Unable to rollback transaction", e, synCtx);
            }

        } else if (action.equals(ACTION_NEW)) {

            int status = Status.STATUS_UNKNOWN;
            try {
                status = tx.getStatus();
            } catch (Exception e) {
                handleException("Unable to query transaction status", e, synCtx);
            }

            if (status != Status.STATUS_NO_TRANSACTION) {
                throw new SynapseException("Require to begin a new transaction, " +
                        "but a transaction already exist");
            }

            try {
                tx.begin();
            } catch (Exception e) {
                handleException("Unable to begin a new transaction", e, synCtx);
            }

        } else if (action.equals(ACTION_USE_EXISTING_OR_NEW)) {

            int status = Status.STATUS_UNKNOWN;
            try {
                status = tx.getStatus();
            } catch (Exception e) {
                handleException("Unable to query transaction status", e, synCtx);
            }

            try {
                if (status == Status.STATUS_NO_TRANSACTION) {
                    tx.begin();
                }
            } catch (Exception e) {
                handleException("Unable to begin a new transaction", e, synCtx);
            }

        } else if (action.equals(ACTION_FAULT_IF_NO_TX)) {

            int status = Status.STATUS_UNKNOWN;
            try {
                status = tx.getStatus();
            } catch (Exception e) {
                handleException("Unable to query transaction status", e, synCtx);
            }

            if (status != Status.STATUS_ACTIVE)
View Full Code Here

        // get JtaEntityManagerRegistry
        JtaEntityManagerRegistry jtaEntityManagerRegistry = SystemInstance.get().getComponent(JtaEntityManagerRegistry.class);

        // bind UserTransaction if bean managed transactions
        UserTransaction userTransaction = null;
        if (beanManagedTransactions) {
            userTransaction = new CoreUserTransaction(transactionManager);
            bindings.put("java:comp/UserTransaction", userTransaction);
        }
View Full Code Here

            webModuleName = NameFactory.getModuleName(null, null, null, null, null, moduleJ2eeContext);
        } catch (MalformedObjectNameException e) {
            throw new DeploymentException("Could not construct module name", e);
        }

        UserTransaction userTransaction = new OnlineUserTransaction();
        //this may add to the web classpath with enhanced classes.
        Map compContext = buildComponentContext(earContext, webModule, webApp, tomcatWebApp, userTransaction, webClassLoader);

        GBeanData webModuleData = new GBeanData(webModuleName, TomcatWebAppContext.GBEAN_INFO);
        try {
View Full Code Here

      org.jboss.seam.transaction.UserTransaction transaction = Transaction.instance();
     
      boolean transactionActive = transaction.isActiveOrMarkedRollback()
              || transaction.isRolledBack(); //TODO: temp workaround, what should we really do in this case??
      boolean newTransactionRequired = isNewTransactionRequired(transactionActive);
      UserTransaction userTransaction = newTransactionRequired ? transaction : null;
     
      if (newTransactionRequired)
      {
         log.debug("beginning transaction");
         userTransaction.begin();
      }
     
      try
      {
         T result = work();
         if (newTransactionRequired)
         {
            if (transaction.isMarkedRollback())
            {
               log.debug("rolling back transaction");
               userTransaction.rollback();
            }
            else
            {
               log.debug("committing transaction");
               userTransaction.commit();
            }
         }
         return result;
      }
      catch (Exception e)
      {
         if (newTransactionRequired && userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION && isRollbackRequired(e, true))
         {
            log.debug("rolling back transaction");
            userTransaction.rollback();
         }
         throw e;
      }
     
   }
View Full Code Here

      getSynchronizations().afterTransactionBegin();
   }

   public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
   {
      UserTransaction userTransaction = ejbContext.getUserTransaction();
      boolean success = false;
      Synchronizations synchronizations = getSynchronizations();
      synchronizations.beforeTransactionCommit();
      try
      {
         userTransaction.commit();
         success = true;
      }
      finally
      {
         synchronizations.afterTransactionCompletion(success);
View Full Code Here

      }
   }

   public void rollback() throws IllegalStateException, SecurityException, SystemException
   {
      UserTransaction userTransaction = ejbContext.getUserTransaction();
      try
      {
         userTransaction.rollback();
      }
      finally
      {
         getSynchronizations().afterTransactionCompletion(false);
      }
View Full Code Here

    protected <T> T runInTransaction(EMCallable<T> call) throws Exception {
        T out = null;
        EntityManager em = emf.createEntityManager();

        UserTransaction utx = getUtx();
        try {
            utx.begin();
            em.joinTransaction();
            out = call.call(em);
            utx.commit();
        } catch (Exception e) {
            utx.rollback();
        } finally {
            em.close();
        }

        return out;
View Full Code Here

                            extendedEntityManager.getDelegate(),
                            em.getDelegate());
                }
                extendedEntityManager = em;

                UserTransaction userTransaction = ejbContext.getUserTransaction();
                userTransaction.begin();
                try {
                    em.getFlushMode();
                } finally {
                    userTransaction.commit();
                }
            } catch (Exception e) {
                e.printStackTrace();
                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
            }
View Full Code Here

                //
                // Note: this code also tests EBJ 3.0 Persistence spec 5.9.1 "UserTransaction is begun within the method, the
                // container associates the persistence context with the JTA transaction and calls EntityManager.joinTransaction."
                // If our the extended entity manager were not associted with the transaction, the non-extended entity manager would
                // not see it.
                UserTransaction userTransaction = ejbContext.getUserTransaction();
                userTransaction.begin();
                try {
                    Assert.assertSame("Extended non-extended entity manager to be same instance as extendend entity manager",
                            inheritedDelegate,
                            nonExtendedEm.getDelegate());
                } finally {
                    userTransaction.commit();
                }

                // When a stateful bean with an extended entity manager creates another stateful bean, the new bean will
                // inherit the extended entity manager (assuming it contains an extended entity manager for the same persistence
                // unit).
View Full Code Here

TOP

Related Classes of javax.transaction.UserTransaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.