Examples of TransactionManager


Examples of com.j256.ormlite.misc.TransactionManager

  private void useTransactions(ConnectionSource connectionSource) throws Exception {
    String name = "trans1";
    final Account account = new Account(name);
    assertEquals(1, accountDao.create(account));

    TransactionManager transactionManager = new TransactionManager(connectionSource);
    try {
      // try something in a transaction
      transactionManager.callInTransaction(new Callable<Void>() {
        public Void call() throws Exception {
          // we do the delete
          assertEquals(1, accountDao.delete(account));
          assertNull(accountDao.queryForId(account.getId()));
          // but then (as an example) we throw an exception which rolls back the delete
View Full Code Here

Examples of com.scooterframework.transaction.TransactionManager

 
  @Test
  public void test_retrieveTableDataBySQL() {
    String countSql = "SELECT count(*) FROM pets";
   
        TransactionManager tm =  TransactionManagerUtil.getTransactionManager();
        try{
          tm.beginTransaction();
     
      Object countBeforeInsert = SqlServiceClient.retrieveObjectBySQL(countSql);
      assertEquals("Total rows countBeforeInsert", "13", countBeforeInsert.toString());
     
      Object nextID = getNextPetID();
      String sql = "INSERT INTO pets (id, name, type_id, owner_id) VALUES (?id, ?name, 1, 10)";
      Map<String, Object> inputs = new HashMap<String, Object>();
      inputs.put("id", nextID);
      inputs.put("name", "Lingling");
      int insertCount = SqlServiceClient.executeSQL(sql, inputs);
      assertEquals("number of rows inserted", 1, insertCount);
     
      String sql2 = "SELECT name FROM pets WHERE name = 'Lingling'";
      Object data = SqlServiceClient.retrieveObjectBySQL(sql2);
      assertEquals("name of the new pet", "Lingling", data.toString());
     
      Object countAfterInsert = SqlServiceClient.retrieveObjectBySQL(countSql);
      assertEquals("Total rows countAfterInsert", "14", countAfterInsert.toString());
     
      //artificially creating an exception
      int i = 1;
      int j = 0;
      System.out.println("You should not see this line: " + i/j);
     
        tm.commitTransaction();
      }
      catch (Exception ex) {
        tm.rollbackTransaction();
     
      Object countAfterRollback = SqlServiceClient.retrieveObjectBySQL(countSql);
      assertEquals("Total rows countAfterRollback Lingling", "13", countAfterRollback.toString());
      }
      finally {
        tm.releaseResources();
      }
   
    Object countTheEnd = SqlServiceClient.retrieveObjectBySQL(countSql);
    assertEquals("Total rows countTheEnd", "13", countTheEnd.toString());
  }
View Full Code Here

Examples of com.sun.enterprise.ee.synchronization.tx.TransactionManager

     */
    void synchronizeInternal() throws SynchronizationException {

        final long startTime = System.currentTimeMillis();
        try {
            TransactionManager txMgr=TransactionManager.getTransactionManager();

            // pings the central repository admin
            Ping pc = getPingCommand();
            pc.execute();

            if ( pc.isAlive() ) { // central repository admin is responding
                SynchronizationRequest[] reqs = getAllRequests(pc);

                assert(reqs.length != 0);
                assert(_dpr != null);

                // begin a transaction for the synchronization
                Transaction tx = txMgr.begin(reqs.length);

                // requests from the meta data
                RequestMediator[] mReqs=new RequestMediator[reqs.length];

                // total synchronization request threads
View Full Code Here

Examples of com.yahoo.omid.client.TransactionManager

public class TestBasicTransaction extends OmidTestBase {
   private static final Log LOG = LogFactory.getLog(TestBasicTransaction.class);

   @Test public void runTestSimple() throws Exception {
      try {
         TransactionManager tm = new TransactionManager(conf);
         TransactionalTable tt = new TransactionalTable(conf, TEST_TABLE);
        
         TransactionState t1 = tm.beginTransaction();
         LOG.info("Transaction created " + t1);
        
         byte[] row = Bytes.toBytes("test-simple");
         byte[] fam = Bytes.toBytes(TEST_FAMILY);
         byte[] col = Bytes.toBytes("testdata");
         byte[] data1 = Bytes.toBytes("testWrite-1");
         byte[] data2 = Bytes.toBytes("testWrite-2");

         Put p = new Put(row);
         p.add(fam, col, data1);
         tt.put(t1, p);
         tm.tryCommit(t1);

         TransactionState tread = tm.beginTransaction();
         TransactionState t2 = tm.beginTransaction();
         p = new Put(row);
         p.add(fam, col, data2);
         tt.put(t2, p);
         tm.tryCommit(t2);

         Get g = new Get(row).setMaxVersions(1);
         Result r = tt.get(g);
         assertTrue("Unexpected value for read: " + Bytes.toString(r.getValue(fam, col)),
                    Bytes.equals(data2, r.getValue(fam, col)));
View Full Code Here

Examples of javax.transaction.TransactionManager

      assertEquals("value", cache1.get(fqn, "key"));
      assertNull("Should NOT have replicated!", cache2.getNode(fqn));

      // now make sure cache2 is in sync with cache1:
      // make sure this is in a tx
      TransactionManager txm = cache2.getTransactionManager();
      assertEquals("value", cache1.get(fqn, "key"));

      txm.begin();
      cache2.put(fqn, "key", "value");
      assertEquals("value", cache2.get(fqn, "key"));
      txm.commit();

      // since the node already exists even PL will not remove it - but will invalidate it's data
      Node n = cache1.getNode(fqn);
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");
      assertEquals("value", cache2.get(fqn, "key"));

      // now test the invalidation again
      txm = cache1.getTransactionManager();
      assertEquals("value", cache2.get(fqn, "key"));

      txm.begin();
      cache1.put(fqn, "key2", "value2");
      assertEquals("value2", cache1.get(fqn, "key2"));
      txm.commit();

      assertEquals("value2", cache1.get(fqn, "key2"));
      // since the node already exists even PL will not remove it - but will invalidate it's data
      n = cache2.getNode(fqn);
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");

      // test a rollback
      txm = cache2.getTransactionManager();
      assertEquals("value2", cache1.get(fqn, "key2"));

      txm.begin();
      cache2.put(fqn, "key", "value");
      assertEquals("value", cache2.get(fqn, "key"));
      txm.rollback();

      assertEquals("value2", cache1.get(fqn, "key2"));
      n = cache2.getNode(fqn);
      CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");
   }
View Full Code Here

Examples of javax.transaction.TransactionManager

      cache1.put("/a/b", "key", "value");
      assertEquals("value", cache1.get(fqn, "key"));
      assertNull(cache2.getNode(fqn));

      // start a tx that cacahe1 will have to send out an evict ...
      TransactionManager mgr1 = cache1.getTransactionManager();
      TransactionManager mgr2 = cache2.getTransactionManager();

      mgr1.begin();
      cache1.put(fqn, "key2", "value2");
      Transaction tx1 = mgr1.suspend();
      mgr2.begin();
      cache2.put(fqn, "key3", "value3");
      Transaction tx2 = mgr2.suspend();
      mgr1.resume(tx1);
      // this oughtta fail
      try
      {
         mgr1.commit();
         assertTrue("Ought to have failed!", false);
      }
      catch (RollbackException roll)
      {
         assertTrue("Ought to have failed!", true);
      }

      mgr2.resume(tx2);
      try
      {
         mgr2.commit();
         assertTrue("Ought to have succeeded!", true);
      }
      catch (RollbackException roll)
      {
         assertTrue("Ought to have succeeded!", false);
View Full Code Here

Examples of javax.transaction.TransactionManager

      assertNull("Should be null", cache1.getNode(fqn));
      assertNull("Should be null", cache2.getNode(fqn));

      // OK, here's the real test
      TransactionManager tm = cache2.getTransactionManager();
      tm.begin();
      try
      {
         // Remove a node that doesn't exist in cache2
         cache2.removeNode(fqn);
         tm.commit();
      }
      catch (Exception e)
      {
         String msg = "Unable to remove non-existent node " + fqn;
         fail(msg + " -- " + e);
View Full Code Here

Examples of javax.transaction.TransactionManager

      assertEquals("value", cache1.getNode(fqn).get("key"));
      assertNull("Should be null", cache2.getNode(fqn));

      // OK, here's the real test
      TransactionManager tm = cache2.getTransactionManager();
      tm.begin();
      try
      {
         // Remove a node that doesn't exist in cache2
         cache2.removeNode(fqn);
         tm.commit();
      }
      catch (Exception e)
      {
         String msg = "Unable to remove non-existent node " + fqn;
         fail(msg + " -- " + e);
View Full Code Here

Examples of javax.transaction.TransactionManager

      List<CacheSPI<Object, Object>> caches = createCachesWithSharedCL(true);
      cache1 = caches.get(0);
      cache2 = caches.get(1);

      Fqn fqn = Fqn.fromString("/a/b");
      TransactionManager mgr = caches.get(0).getTransactionManager();
      assertNull("Should be null", caches.get(0).get(fqn, "key"));
      assertNull("Should be null", caches.get(1).get(fqn, "key"));
      mgr.begin();
      caches.get(0).put(fqn, "key", "value");
      assertEquals("value", caches.get(0).get(fqn, "key"));
      assertNull("Should be null", caches.get(1).get(fqn, "key"));
      mgr.commit();
      assertEquals("value", caches.get(1).get(fqn, "key"));
      assertEquals("value", caches.get(0).get(fqn, "key"));

      mgr.begin();
      caches.get(0).put(fqn, "key2", "value2");
      assertEquals("value2", caches.get(0).get(fqn, "key2"));
      assertNull("Should be null", caches.get(1).get(fqn, "key2"));
      mgr.rollback();
      assertEquals("value", caches.get(1).get(fqn, "key"));
      assertEquals("value", caches.get(0).get(fqn, "key"));
      assertNull("Should be null", caches.get(0).get(fqn, "key2"));
      assertNull("Should be null", caches.get(1).get(fqn, "key2"));
   }
View Full Code Here

Examples of javax.transaction.TransactionManager

      cache1.put("/a/b", "key", "value");
      assertEquals("value", cache1.get(fqn, "key"));
      assertNull(cache2.getNode(fqn));

      // start a tx that cacahe1 will have to send out an evict ...
      TransactionManager mgr1 = cache1.getTransactionManager();
      TransactionManager mgr2 = cache2.getTransactionManager();

      mgr1.begin();
      cache1.put(fqn, "key2", "value2");
      Transaction tx1 = mgr1.suspend();
      mgr2.begin();
      cache2.put(fqn, "key3", "value3");
      Transaction tx2 = mgr2.suspend();
      mgr1.resume(tx1);
      // this oughtta fail
      try
      {
         mgr1.commit();
         assertTrue("Ought to have succeeded!", true);
      }
      catch (RollbackException roll)
      {
         assertTrue("Ought to have succeeded!", false);
      }

      mgr2.resume(tx2);
      try
      {
         mgr2.commit();
         assertTrue("Ought to have succeeded!", true);
      }
      catch (RollbackException roll)
      {
         assertTrue("Ought to have succeeded!", false);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.