Package javax.transaction

Examples of javax.transaction.UserTransaction


      return (JPACrashHelperRem) config.getNamingContext(serverName).lookup(CrashHelper.REMOTE_JNDI_NAME);
   }

   private UserTransaction startTx() throws NamingException, SystemException, NotSupportedException
   {
      UserTransaction tx = (UserTransaction) config.getNamingContext(serverName).lookup("UserTransaction");

      tx.begin();

      return tx;
   }
View Full Code Here


      return tx;
   }

   private boolean crashTest(ASFailureSpec[] sa, String testEntityPK, boolean reverseOrder) throws Exception
   {
      UserTransaction tx = null;

      try
      {
         CrashRem cr = lookupCrashBean(isCMT ? CrashRem.CMT_JNDI_NAME : CrashRem.BMT_JNDI_NAME);

         if (clientTx)
            tx = startTx();

         String res = cr.testXA(testEntityPK, reverseOrder, sa);

         return "Passed".equalsIgnoreCase(res);
      }
      catch (CannotConnectException e)
      {
         if (expectFailure)
         {
            print("Failure was expected: " + e.getMessage());

            return recoverUids();
         }
         else
         {
            System.err.println("XACrashTest:crashTest: Caught[1] " + e);

            e.printStackTrace();
         }
      }
      catch (EJBTransactionRolledbackException re)
      {
         // try to recover, this failure was expected maybe?!
         print("Failure was expected (maybe): " + re.getMessage());

         return recoverUids();
      }
      catch (RuntimeException re)
      {
         if (re.getCause() instanceof HeuristicMixedException)
         {
            // try to recover, this failure was expected maybe?!
            print("Failure was expected (maybe): " + re.getMessage());

            return recoverUids();
         }
         else
         {
            System.err.println("XACrashTest:crashTest: Caught[2] " + re);
            re.printStackTrace();           
         }
      }
      catch (Throwable t)
      {
         t.printStackTrace();
         System.err.println("XACrashTest:crashTest: Caught[3] " + t);
      }
      finally {
         if (clientTx)
            try
         {
               tx.commit();
         }
         catch (Throwable e)
         {
            System.out.println("User tx commit failure: " + e.getMessage());
         }
View Full Code Here

      getLog().debug(
         "**************************************************************");
      getLog().debug("     testUserTransaction()");
      CtsBmpHome home = getHome();
      UserTransaction ut;
      getLog().debug("Obtain UserTransaction...");
      Object o = new InitialContext().lookup("UserTransaction");
      ut = (UserTransaction)PortableRemoteObject.narrow(o, UserTransaction.class);
      assertTrue(ut != null);
View Full Code Here

         StatefulSessionHome.class);
      StatefulSession bean = home.create("testUserTx");   

      bean.setCounter(100);
      getLog().debug("Try to instantiate a UserTransaction");
      UserTransaction userTx = (UserTransaction)ctx.lookup("UserTransaction");
      userTx.begin();
         bean.incCounter();
         bean.incCounter();
      userTx.commit();
      int counter = bean.getCounter();
      assertTrue("counter == 102", counter == 102);

      bean.setCounter(100);
      userTx.begin();
         bean.incCounter();
         bean.incCounter();
      userTx.rollback();
      counter = bean.getCounter();
      assertTrue("counter == 100", counter == 100);

      bean.remove();
   }
View Full Code Here

         super(property);
      }

      public void inject(Object instance)
      {
         UserTransaction ut = ServerVMClientUserTransaction.getSingleton();
         property.set(instance, ut);
      }
View Full Code Here

      Properties env = new Properties(System.getProperties());
      env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory");
      env.setProperty(Context.PROVIDER_URL, "localhost:1099");
      env.setProperty("jnp.disableDiscovery", "true");
      InitialContext ctx = new InitialContext(env);
      UserTransaction ut = (UserTransaction) ctx.lookup("UserTransaction");
      ut.getStatus();

      ut.begin();
      CtsCmpHome home = (CtsCmpHome) ctx.lookup("ejbcts/CMPBean");
      AccountPK pk = new AccountPK("testWithInvalidDefaultJndiContext");
      CtsCmp bean = home.create(pk, "Scott");
      bean.setPersonsAge(40);
      ut.commit();

      assertTrue("age == 40", bean.getPersonsAge() == 40);

      ut.begin();
      bean.setPersonsAge(100);
      ut.rollback();
      assertTrue("age == 40", bean.getPersonsAge() == 40);

      bean.remove();
      ctx.close();
   }
View Full Code Here

   public void testWithDefaultJndiContext() throws Exception
   {
      log.info("+++ testWithDefaultJndiContext");
      System.setProperty(Context.PROVIDER_URL, "localhost:1099");
      InitialContext ctx = new InitialContext();
      UserTransaction ut = (UserTransaction) ctx.lookup("UserTransaction");
      ut.getStatus();

      ut.begin();
      CtsCmpHome home = (CtsCmpHome) ctx.lookup("ejbcts/CMPBean");
      AccountPK pk = new AccountPK("testWithDefaultJndiContext");
      CtsCmp bean = home.create(pk, "Scott");
      bean.setPersonsAge(40);
      ut.commit();

      assertTrue("age == 40", bean.getPersonsAge() == 40);

      ut.begin();
      bean.setPersonsAge(100);
      ut.rollback();
      assertTrue("age == 40", bean.getPersonsAge() == 40);

      bean.remove();
      ctx.close();
   }
View Full Code Here

   public void changeDatabase()
   {
      try
      {
         InitialContext ctx = new InitialContext();
         UserTransaction ut = sessionCtx.getUserTransaction();
         ut.setTransactionTimeout(5);
         ut.begin();
         try
         {
            DataSource ds = (DataSource) ctx.lookup("java:DefaultDS");
            Connection c = ds.getConnection();
            try
            {
               Statement stmt = c.createStatement();
               stmt.executeUpdate("insert into JCA_TRANSACTION_ACTIVE values ('101')");
               try
               {
                  Thread.sleep(10000);
               }
               catch (InterruptedException ignored)
               {
               }
               try
               {
                  stmt.executeUpdate("delete from JCA_TRANSACTION_ACTIVE where name='100'");
               }
               catch (SQLException expected)
               {
                  log.debug("Got expected exception: " + expected);
               }
            }
            finally
            {
               try
               {
                  c.close();
               }
               catch (Exception ignored)
               {
               }
            }
         }
         finally
         {
            try
            {
               ut.rollback();
            }
            catch (Exception ignored)
            {
            }
         }
View Full Code Here

   public void checkDatabase()
   {
      try
      {
         InitialContext ctx = new InitialContext();
         UserTransaction ut = sessionCtx.getUserTransaction();
         ut.begin();
         try
         {
            DataSource ds = (DataSource) ctx.lookup("java:DefaultDS");
            Connection c = ds.getConnection();
            try
            {
               Statement stmt = c.createStatement();
               ResultSet rs = stmt.executeQuery("select name from JCA_TRANSACTION_ACTIVE");
               if (rs.next() == false)
                  throw new RuntimeException("Expected a first row");
               String value = rs.getString(1);
               if ("100".equals(value) == false)
                  throw new RuntimeException("Expected first row to be 100 got " + value);
               if (rs.next())
                  throw new RuntimeException("Expected only one row");
            }
            finally
            {
               try
               {
                  c.close();
               }
               catch (Exception ignored)
               {
               }
            }
         }
         finally
         {
            try
            {
               ut.commit();
            }
            catch (Exception ignored)
            {
            }
         }
View Full Code Here

   {
      try
      {
         InitialContext ctx = new InitialContext();
         Queue queue = (Queue) ctx.lookup("queue/testQueue");
         UserTransaction ut = sessionCtx.getUserTransaction();
         ut.begin();
         try
         {
            ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");
            javax.jms.Connection c = cf.createConnection();
            try
            {
               c.start();
               Session s = c.createSession(true, Session.SESSION_TRANSACTED);
               MessageConsumer mc = s.createConsumer(queue);
               while (mc.receiveNoWait() != null);
               mc.close();
              
               MessageProducer p = s.createProducer(queue);
               Message m = s.createTextMessage("101");
               p.send(m);
            }
            finally
            {
               try
               {
                  c.close();
               }
               catch (Exception ignored)
               {
               }
            }
         }
         finally
         {
            try
            {
               ut.commit();
            }
            catch (Exception ignored)
            {
            }
         }
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.