Package com.scooterframework.transaction

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


  public void test_transactional_executeSQL_inputs() {
    String countSql = "SELECT count(*) FROM pets";
//    String tType = (String)CurrentThreadCache.get("key.TransactionStarterType");
//    Object tr = CurrentThreadCache.get("key.Transactions");
   
        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", "Pingping");
      int insertCount = SqlServiceClient.executeSQL(sql, inputs);
      assertEquals("number of rows inserted", 1, insertCount);
     
      String sql2 = "SELECT name FROM pets WHERE name = 'Pingping'";
      Object data = SqlServiceClient.retrieveObjectBySQL(sql2);
      assertEquals("name of the new pet", "Pingping", 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 Pingping", "13", countAfterRollback.toString());
      }
      finally {
        tm.releaseResources();
      }
   
    Object countTheEnd = SqlServiceClient.retrieveObjectBySQL(countSql);
    assertEquals("Total rows countTheEnd", "13", countTheEnd.toString());
  }
View Full Code Here

TOP

Related Classes of com.scooterframework.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.