Package javax.transaction

Examples of javax.transaction.TransactionManager


   }

   public void testFailure() throws Exception
   {

      TransactionManager tm = cache.getTransactionManager();
      try
      {
         tm.begin();
         cache.put("/a/b/c", "test", "test");
         assertTrue(cache.get("/a/b/c", "test").equals("test"));
         cache.removeNode("/a/b");
         assertTrue(!cache.exists("/a/b"));
         assertTrue(!cache.exists("/a/b/c"));
         cache.put("/a/b/d", "test1", "test1");
         assertTrue(!cache.exists("/a/b/c"));
         assertTrue(cache.exists("/a/b/d"));
         tm.commit();
         assertTrue(cache.peek(Fqn.fromString("/a/b/c"), true, true) == null);
         assertTrue(!cache.exists("/a/b/c"));
         assertTrue(cache.exists("/a/b/d"));
         dataContainer.printLockInfo();
      }
      catch (Exception ex) {
         tm.rollback();
         throw ex;
      }
      dataContainer.printLockInfo();
      try
      {
         tm.begin();
         Transaction t = tm.suspend();
         try
         {
            cache.putForExternalRead(Fqn.fromString("/a/b/c"), "test", "test");
         }
         catch (Exception ignore) {
            ignore.printStackTrace();
         }
         tm.resume(t);
         cache.put("/a/b/c", "test", "test");
         tm.commit();
      }
      catch (Exception ex) {
         tm.rollback();
         throw ex;
      }
   }
View Full Code Here


      assert "v2".equals(cache.get("/a/b/c", "k2"));
   }

   public void testBatchWithoutOngoingTMSuspension() throws Exception
   {
      TransactionManager tm = getTransactionManager(cache);
      assert tm.getTransaction() == null : "Should have no ongoing txs";
      cache.startBatch();
      cache.put("/a/b/c", "k", "v");
      assert tm.getTransaction() == null : "Should have no ongoing txs";
      cache.put("/a/b/c", "k2", "v2");

      assert getOnDifferentThread(cache, "/a/b/c", "k") == null;
      assert getOnDifferentThread(cache, "/a/b/c", "k2") == null;

      try
      {
         tm.commit(); // should have no effect
      }
      catch (Exception e)
      {
         // the TM may barf here ... this is OK.
      }

      assert tm.getTransaction() == null : "Should have no ongoing txs";

      assert getOnDifferentThread(cache, "/a/b/c", "k") == null;
      assert getOnDifferentThread(cache, "/a/b/c", "k2") == null;

      cache.endBatch(true); // should be a no op
View Full Code Here

      assert "v2".equals(getOnDifferentThread(cache, "/a/b/c", "k2"));
   }

   public void testBatchRollback() throws Exception
   {
      TransactionManager tm = getTransactionManager(cache);
      cache.startBatch();
      cache.put("/a/b/c", "k", "v");
      cache.put("/a/b/c", "k2", "v2");

      assert getOnDifferentThread(cache, "/a/b/c", "k") == null;
View Full Code Here

      cache1.stop();

      cache1.start();
      cache2.start();

      TransactionManager tm = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();

      listener.sameThreadExpected = true;
      listener.mainThread = Thread.currentThread();
      Fqn fqn = Fqn.fromString("/a/b/c");

      // basic node manipulation events
      if (tx)
         tm.begin();
      cache1.put(fqn, "k", "v");
      if (tx)
         tm.commit();
      if (tx)
         tm.begin();
      cache1.get(fqn, "k");
      if (tx)
         tm.commit();
      if (tx)
         tm.begin();
      cache1.put(fqn, "k", "v2");
      if (tx)
         tm.commit();
      if (tx)
         tm.begin();
      cache1.removeNode(fqn);
      if (tx)
         tm.commit();
      if (tx)
         tm.begin();
      cache1.put(fqn, "k", "v3");
      if (tx)
         tm.commit();
      if (tx)
         tm.begin();
      // eviction
      cache1.evict(fqn, true);
      if (tx)
         tm.commit();
      if (tx)
         tm.begin();
      // and cache loading or activation
      cache1.get(fqn, "k");
      if (tx)
         tm.commit();
      if (tx)
         tm.begin();
      // move event
      cache1.move(fqn, Fqn.ROOT);
      if (tx)
         tm.commit();

      // now a view-change - will be in a different thread
      listener.sameThreadExpected = false;
      cache2.stop();
View Full Code Here

     
      if (trace) { log.trace("Starting " + this); }        
     
      checkParams();
     
      TransactionManager tm = getTm();
     
      //There may already be a JTA transaction associated to the thread
     
      boolean ok;
     
      Transaction toResume = null;
      try
      {
         toResume = tm.suspend();
        
         ok = setupJMSObjects();
      }
      finally
      {
         if (toResume != null)
         {
            tm.resume(toResume);
         }
      }
     
      if (ok)
      {        
View Full Code Here

  
   private Transaction startTx() throws Exception
   {
      if (trace) { log.trace("Starting JTA transaction"); }
     
      TransactionManager tm = getTm();
     
      //Set timeout to a large value since we do not want to time out while waiting for messages
      //to arrive - 10 years should be enough
      tm.setTransactionTimeout(60 * 60 * 24 * 365 * 10);
     
      tm.begin();
        
      Transaction tx = tm.getTransaction();
     
      //Remove the association between current thread - we don't want it
      //we will be committing /rolling back directly on the transaction object
     
      tm.suspend();
     
      if (trace) { log.trace("Started JTA transaction"); }
     
      return tx;
   }
View Full Code Here

     
      super.startService();
     
      try
     
         TransactionManager tm = getTransactionManagerReference();
        
         userManager = new JDBCJMSUserManager(ds, tm, sqlProperties, createTablesOnStartup);
        
         userManager.start();
        
View Full Code Here

      ServiceContainer sc = new ServiceContainer("transaction, jca, database");
      sc.start();

      InitialContext ic = new InitialContext();

      TransactionManager tm = (TransactionManager)ic.lookup("java:/TransactionManager");
      DataSource ds = (DataSource)ic.lookup("java:/DefaultDS");
      Connection c;


      tm.begin();

      c = ds.getConnection();
      c.createStatement().executeUpdate("CREATE TABLE SOME_TABLE (SOME_FIELD VARCHAR)");

      tm.commit();

      tm.begin();
      c = ds.getConnection();
      c.createStatement().executeUpdate("INSERT INTO SOME_TABLE VALUES ('this shouldnt get into db')");

      tm.rollback();

      tm.begin();
      c = ds.getConnection();
      c.createStatement().executeUpdate("INSERT INTO SOME_TABLE VALUES ('some value')");

      tm.commit();


      c = ds.getConnection();
      ResultSet rs = c.createStatement().executeQuery("SELECT SOME_FIELD FROM SOME_TABLE");
      while (rs.next())
View Full Code Here

      return ds;
   }

   public TransactionManager getTransactionManager()
   {
      TransactionManager tm = null;
      try
      {
         InitialContext ic = new InitialContext();
         tm = (TransactionManager)ic.lookup(TRANSACTION_MANAGER_JNDI_NAME);
         ic.close();
View Full Code Here

      InitialContext ctx = new InitialContext();
     
      // We need to execute each drop in its own transaction otherwise postgresql will not execute
      // further commands after one fails

      TransactionManager mgr = (TransactionManager)ctx.lookup(TransactionManagerService.JNDI_NAME);
      DataSource ds = (DataSource)ctx.lookup("java:/DefaultDS");

      javax.transaction.Transaction txOld = mgr.suspend();
                 
      executeStatement(mgr, ds, "DROP TABLE JBM_POSTOFFICE");
     
      executeStatement(mgr, ds, "DROP TABLE JBM_MSG_REF");

      executeStatement(mgr, ds, "DROP TABLE JBM_MSG");
    
      executeStatement(mgr, ds, "DROP TABLE JBM_TX");
     
      executeStatement(mgr, ds, "DROP TABLE JBM_COUNTER");
     
      executeStatement(mgr, ds, "DROP TABLE JBM_USER");
     
      executeStatement(mgr, ds, "DROP TABLE JBM_ROLE");
     
      if (txOld != null)
      {
         mgr.resume(txOld);
      }

      log.debug("done with the database");
   }
View Full Code Here

TOP

Related Classes of javax.transaction.TransactionManager

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.