PER_THREAD_PM.remove(); Transaction tx = pm.currentTransaction(); if (tx.isActive()) { tx.rollback();
Transaction txn = entityManager.getTransaction(); if (txn.isActive()) { try { txn.rollback(); } catch (PersistenceException | IllegalStateException e) { LOG.error("Transaction rollback failed.", e); } }
final Session session = HibernateUtil.getSession(); try { final Transaction tx = session.beginTransaction(); // do things tx.commit(); } finally { if (tx.isActive()) { try { tx.rollback(); } catch (Exception e) { logger.log("Error rolling back transaction", e); } } try { session.close(); } catch (Exception e) { logger.log("Error closing session", e); } }
protected <T> T doInTransaction(TransactionCallable<T> callable) { T result = null; Session session = null; Transaction txn = null; try { session = sf.openSession(); txn = session.beginTransaction(); result = callable.execute(session); txn.commit(); } catch (RuntimeException e) { if ( txn != null && txn.isActive() ) txn.rollback(); throw e; } finally { if (session != null) { session.close(); } } return result; }
pubic static abstract class TransactionCallable<T> { public abstract T execute(); } public class TransactionManager { pubic static <T> T doInTransaction(TransactionCallable<T> callable) { T result = null; Session session = null; Transaction txn = null; try { session = sf.openSession(); txn = session.beginTransaction(); result = callable.execute(); txn.commit(); } catch (RuntimeException e) { if ( txn != null && txn.isActive() ) txn.rollback(); throw e; } finally { if (session != null) { session.close(); } } return result; } }
if(tx!=null && tx.isActive())
Session session = sessionFactory.openSession() Transaction transaction; boolean productTaken = false; try { transaction = session.beginTransaction(); Product product = session.get(Product.class, id); if (product == null) throw ... Session.LockRequest lockRequest = session.buildLockRequest(LockOptions.UPGRADE); lockRequest.lock(product); productTaken = product.take(); if (productTaken) { session.update(product); transaction.commit(); } } finally { if (transaction != null && transaction.isActive()) transaction.rollback(); session.close(); }
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Transaction txn = datastore.beginTransaction(); try { /// your current code txn.commit(); } finally { if (txn.isActive()) { txn.rollback(); } }
}catch (Exception ex) { logger.error("UsersActiion.getThroHibConnTest() | ERROR | " , ex); if (tx != null && tx.isActive()) { try {
readWriteSessionTx.commit(); } catch (RuntimeException e) { if ( readWriteSessionTx != null && readWriteSessionTx.isActive() ) readWriteSessionTx.rollback(); throw e; writeOnlySessionTx.commit(); } catch (RuntimeException e) { if ( writeOnlySessionTx != null && writeOnlySessionTx.isActive() ) writeOnlySessionTx.rollback(); throw e;
protected <T> T doInTransaction(TransactionCallable<T> callable) { T result = null; Session session = null; Transaction txn = null; try { session = sf.openSession(); txn = session.beginTransaction(); session.doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { } }); result = callable.execute(session); txn.commit(); } catch (RuntimeException e) { if ( txn != null && txn.isActive() ) txn.rollback(); throw e; } finally { if (session != null) { session.close(); } } return result; }
public abstract class BaseClass { public Object executeTrans(Template template) { // PersistenceManager pm = ...; Transaction tx = pm.currentTransaction(); try { tx.begin(); template.doTransaction(); tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } } } }
// PersistenceManager pm = ...; Transaction tx = pm.currentTransaction(); User user = userService.currentUser(); List<Account> accounts = new ArrayList<Account>(); try { tx.begin(); Query query = pm.newQuery("select from Customer " + "where user == userParam " + "parameters User userParam"); List<Customer> customers = (List<Customer>) query.execute(user); query = pm.newQuery("select from Account " + "where parent-pk == keyParam " + "parameters Key keyParam"); for (Customer customer : customers) { accounts.addAll((List<Account>) query.execute(customer.key)); } } finally { if (tx.isActive()) { tx.rollback(); } }
if(tx.isActive()) { tx.rollback();
@ApiMethod(name = "storeUserModel") public UserModel storeUserModel(UserModel userModel) throws UserAlreadyExistsException, UserNotFoundException { logger.info("inside storeUser"); String email = userModel.getEmail(); UserModel checkUser = getUserModel(email); logger.info("after getUserModel with email " + email); if (checkUser == null) { logger.info("inside checkUser is NULL"); DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService(); Transaction txn = datastoreService.beginTransaction(); try { Entity userEntity = new Entity(UserModel.class.getSimpleName(), email); userEntity.setProperty("nickname", userModel.getNickname()); // TODO save the pheromones with the key of userEntity datastoreService.put(userEntity); txn.commit(); storePheromoneList(userModel.getPheromoneList(), userEntity.getKey(), datastoreService); } finally { if (txn.isActive()) { logger.severe("rolled back with email : " + email); txn.rollback(); } } } else { throw new UserAlreadyExistsException(); } return userModel; }