public static void commitTransaction() throws SQLException {
   Transaction tx = threadTransaction.get();
   try {
     if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) tx.commit();
     threadTransaction.set(null);
   } catch (HibernateException ex) {
     rollbackTransaction();
     throw new SQLException(ex);
   }
 }
Example #2
0
 public static void rollbackTransaction() {
   Transaction tx = threadTransaction.get();
   threadTransaction.set(null);
   try {
     if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
       tx.rollback();
     }
   } finally {
     closeSession();
   }
 }
Example #3
0
 /** Rollback the database transaction. */
 public static void rollbackTransaction() {
   Transaction tx = (Transaction) threadTransaction.get();
   try {
     threadTransaction.set(null);
     if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
       log.debug("Tyring to rollback database transaction of this thread.");
       tx.rollback();
     }
   } finally {
     closeSession();
   }
 }
Example #4
0
 /** Commit the database transaction. */
 public static void commitTransaction() {
   Transaction tx = (Transaction) threadTransaction.get();
   try {
     if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
       log.debug("Committing database transaction of this thread.");
       tx.commit();
     }
     threadTransaction.set(null);
   } catch (HibernateException e) {
     rollbackTransaction();
     throw e;
   }
 }
Example #5
0
 /**
  * Rollbacks the currently opened transaction.
  *
  * @throws PersistencyException
  */
 public static void rollbackTransaction() throws PersistencyException {
   threadRollback.set("");
   Transaction tx = (Transaction) threadTransaction.get();
   threadTransaction.set(null);
   try {
     if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
       tx.rollback();
     }
   } catch (HibernateException e) {
     throw new PersistencyException(e, PersistencyException.FATAL);
   } finally {
     closeSession();
   }
 }
  public static void rollbackTransaction() throws SQLException {

    Transaction tx = threadTransaction.get();
    try {
      threadTransaction.set(null);
      if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
        tx.rollback();
      }
    } catch (HibernateException ex) {
      throw new SQLException(ex);
    } finally {
      closeSession();
    }
  }
  //	@Test
  //	public void testConnection() throws Exception {
  //		DriverManager.registerDriver(new Driver());
  //
  //		DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  //		Properties properties = new Properties();
  //		properties.put("user", "pass");
  //		properties.put("password", "adesroot");
  //
  //		Connection conn = (Connection) DriverManager.getConnection(
  //				"jdbc:mysql://localhost:3301/pass_db", properties);
  //
  //		System.out.println("Connection acquired: " + conn);
  //
  //		assertNotNull(conn);
  //		assertFalse(conn.isClosed());
  //
  //		conn.close();
  //
  //	}
  //
  @Test
  public void testSampleTwoTransactions() throws Exception {
    System.out.println("Begin first transaction");
    PersistentTransaction transaction =
        PassPersistentManager.instance().getSession().beginTransaction();

    System.out.println("Begin second transaction");
    Session session =
        PassPersistentManager.instance().getSession().getSessionFactory().openSession();
    Transaction transaction2 =
        PassPersistentManager.instance()
            .getSession()
            .getSessionFactory()
            .openSession()
            .beginTransaction();
    try {

      System.out.println("transaction = " + transaction);
      System.out.println("transaction2 = " + transaction2);
      System.out.println(transaction == transaction2);

      assertFalse(transaction == transaction2);

      assertFalse(transaction.wasCommitted());
      assertFalse(transaction.wasRolledBack());

      transaction2.rollback();
      assertTrue(transaction2.wasRolledBack());
      assertTrue(session.isOpen());
    } finally {
      session.close();
      assertFalse(session.isOpen());
    }

    assertFalse(transaction.wasCommitted());
    assertFalse(transaction.wasRolledBack());

    transaction.commit();
    assertTrue(transaction.wasCommitted());
  }
  public String validateAndUpdateAnalyzerTestName(
      ActionMapping mapping, HttpServletRequest request, BaseActionForm dynaForm) {
    String forward = FWD_SUCCESS_INSERT;
    String analyzerId = dynaForm.getString("analyzerId");
    String testId = dynaForm.getString("testId");
    String analyzerTestName = dynaForm.getString("analyzerTestName");
    boolean newMapping = "0".equals(request.getParameter("ID"));

    ActionMessages errors = new ActionMessages();

    AnalyzerTestMapping analyzerTestNameMapping =
        validateAnalyzerAndTestName(analyzerId, analyzerTestName, testId, errors, newMapping);

    if (errors.size() > 0) {
      saveErrors(request, errors);
      return FWD_FAIL;
    }

    if (newMapping) {
      analyzerTestNameMapping = new AnalyzerTestMapping();
      analyzerTestNameMapping.setAnalyzerId(analyzerId);
      analyzerTestNameMapping.setAnalyzerTestName(analyzerTestName);
      analyzerTestNameMapping.setTestId(testId);
    }

    AnalyzerTestMappingDAO mappingDAO = new AnalyzerTestMappingDAOImpl();

    Transaction tx = HibernateUtil.getSession().beginTransaction();

    try {
      if (newMapping) {
        mappingDAO.insertData(analyzerTestNameMapping, currentUserId);
      } else {
        mappingDAO.updateMapping(analyzerTestNameMapping, currentUserId);
      }

    } catch (LIMSRuntimeException lre) {
      tx.rollback();

      ActionError error = null;
      if (lre.getException() instanceof org.hibernate.StaleObjectStateException) {
        error = new ActionError("errors.OptimisticLockException", null, null);
      } else {
        error = new ActionError("errors.UpdateException", null, null);
      }

      persisteError(request, error);

      disableNavigationButtons(request);
      forward = FWD_FAIL;
    } finally {
      if (!tx.wasRolledBack()) {
        tx.commit();
      }
      HibernateUtil.closeSession();
    }

    AnalyzerTestNameCache.instance().reloadCache();

    return forward;
  }
Example #9
0
 /** Rollback transaction */
 public static void rollback(Transaction tx) {
   if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
     tx.rollback();
   }
 }
 public boolean wasRolledBack() throws HibernateException {
   return realTxn.wasRolledBack();
 }