Package javax.transaction

Examples of javax.transaction.TransactionManager


      Configuration c = new Configuration();
      c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
      CacheSPI<String, String> cache = (CacheSPI<String, String>) new UnitTestCacheFactory<String, String>().createCache(c, MarkAsRollbackTest.class);
      try
      {
         TransactionManager tm = cache.getTransactionManager();
         assert tm != null;
         tm.begin();
         cache.put(fqn, "k", "v");
         assert cache.get(fqn, "k").equals("v");
         assert cache.getRoot().getChildren().size() == 1;
         tm.setRollbackOnly();
         try
         {
            tm.commit();
            assert false : "Should have rolled back";
         }
         catch (RollbackException expected)
         {
         }

         assert tm.getTransaction() == null : "There should be no transaction in scope anymore!";
         assert cache.get(fqn, "k") == null : "Expected a null but was " + cache.get(fqn, "k");
         assert cache.getRoot().getChildren().size() == 0;
      }
      finally
      {
View Full Code Here


      Configuration c = new Configuration();
      c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
      CacheSPI<String, String> cache = (CacheSPI<String, String>) new UnitTestCacheFactory<String, String>().createCache(c, MarkAsRollbackTest.class);
      try
      {
         TransactionManager tm = cache.getTransactionManager();
         assert tm != null;
         tm.begin();
         tm.setRollbackOnly();
         try
         {
            cache.put(fqn, "k", "v");
            assert false : "Should have failed";
         }
         catch (CacheException expected)
         {
           assert expected.getCause() instanceof RollbackException : "exception wrapped and thrown should be RollbackException. Exception class "+expected.getCause().getClass();
         }
         try
         {
            tm.commit();
            assert false : "Should have rolled back";
         }
         catch (RollbackException expected)
         {

         }

         assert tm.getTransaction() == null : "There should be no transaction in scope anymore!";
         assert cache.get(fqn, "k") == null : "Expected a null but was " + cache.get(fqn, "k");
         assert cache.getRoot().getChildren().size() == 0;
      }
      finally
      {
View Full Code Here

   public void setUp()
   {
      icc = new InvocationContextContainer();
      icc.injectContextFactory(new MVCCContextFactory());
      lm = new MVCCLockManager();
      TransactionManager tm = getTransactionManager();
      lm.injectConfiguration(new Configuration());
      lm.injectDependencies(null, null, tm, icc);
      lm.startLockManager();
   }
View Full Code Here

      CacheSPI<Object, Object> cacheB = createCache("B");

      // Pause to give caches time to see each other
      TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cacheA, cacheB}, 60000);

      final TransactionManager tm = cacheB.getTransactionManager();
      tm.begin();
      final Transaction tx = tm.getTransaction();

      cacheB.put("/1/A", "1", "B");
      cacheB.put("/1/A", "2", "B");
      cacheB.put("/2/A", "1", "B");
      cacheB.put("/2/A", "2", "B");
      cacheB.put("/1/A/I", "1", "B");
      cacheB.put("/1/A/I", "2", "B");
      cacheB.put("/EXISTS", "KEY", "B");

      Object monitor = new Object();
      HangSync sync = new HangSync(monitor);
      tx.registerSynchronization(sync);

      Thread t = new Thread()
      {
         public void run()
         {
            try
            {
               tm.resume(tx);
               tm.commit();
            }
            catch (Exception e)
            {
            }
         }
      };

      synchronized (monitor)
      {
         t.start();

         while (!sync.hung)
         {
            monitor.wait(500);
         }
      }

      tm.suspend();

      // Confirm that B's tx replicated
      assertTrue(cacheA.peek(Fqn.fromString("/EXISTS"), false, false) != null);

      cacheB.stop();
View Full Code Here

      {
         public void run()
         {
            try
            {
               TransactionManager tx = startTransaction();

               // change VALUE in a transaction
               cache.removeNode(FQN);

               // notify the reading thread
               readerCanRead.countDown();

               readerDone.await();

               tx.commit();
            }
            catch (AssertionError e)
            {
               writerError = e;
            }
View Full Code Here

   }

   private TransactionManager startTransaction() throws SystemException, NotSupportedException
   {
      TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
      mgr.begin();
      return mgr;
   }
View Full Code Here

      {
         public void run()
         {
            try
            {
               TransactionManager tm = startTransaction();

               // Create an empty parent node and a node with data
               Fqn a1 = Fqn.fromRelativeElements(PARENT, "1");
               cache.put(a1, KEY, VALUE);

               // notify the second thread it can write
               secondCanWrite.countDown();

               // wait until the second thread writes and allows me to rollback or until I timeout
               firstCanRollback.await(3000, TimeUnit.MILLISECONDS);

               tm.rollback();

               assertNull("a1 empty", cache.get(a1, KEY));

               // notify the reading thread
               secondCanRead.countDown();
View Full Code Here

      }
   }

   private TransactionManager startTransaction() throws SystemException, NotSupportedException
   {
      TransactionManager mgr = cache.getTransactionManager();
      mgr.begin();
      return mgr;
   }
View Full Code Here

      {
         public void run()
         {
            try
            {
               TransactionManager tm = startTransaction();

               // change VALUE in a transaction
               cache.removeNode(FQN);

               // notify the reading thread
               readerCanRead.countDown();

               readerDone.await();

               tm.commit();
            }
            catch (AssertionError e)
            {
               writerError = e;
            }
View Full Code Here

   }

   private TransactionManager startTransaction() throws SystemException, NotSupportedException
   {
      TransactionManager mgr = cache.getTransactionManager();
      mgr.begin();
      return mgr;
   }
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.