Java Code Examples for org.hibernate.Transaction#wasCommitted()

The following examples show how to use org.hibernate.Transaction#wasCommitted() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void update(List<E> entityCollection) {
	Session session = getCurrentSession();
	Transaction tx = null;
	try {
		tx = session.beginTransaction();
		for (E e: entityCollection) {
			session.saveOrUpdate(e);
			session.flush();
			session.evict(e);
		}
		if (!tx.wasCommitted()) tx.commit();
	} catch (Exception ex) {
		logger.error("Update list failed", ex);
		tx.rollback();
		throw new HibernateException("Update list failed");
	}
}
 
Example 2
@Override
public void merge(List<E> entityCollection) {
	Session session = getCurrentSession();
	Transaction tx = null;
	try {
		tx = session.beginTransaction();
		for (E e: entityCollection) {
			session.merge(e);
			session.flush();
			session.evict(e);
		}
		if (!tx.wasCommitted()) tx.commit();
	} catch (Exception ex) {
		logger.error("Merge list failed", ex);
		tx.rollback();
		throw new HibernateException("Merge list failed");
	}

}
 
Example 3
@Override
public void save(List<E> entityCollection) {
	Session session = getCurrentSession();
	Transaction tx = null;
	try {
		tx = session.beginTransaction();
		for (E e: entityCollection) {
			session.save(e);
			session.flush();
			session.evict(e);
		}
		if (!tx.wasCommitted()) tx.commit();
	} catch (Exception ex) {
		logger.error("Save list failed", ex);
		tx.rollback();
		throw new HibernateException("Save list failed");
	}
}
 
Example 4
@Override
public void delete(List<E> entityCollection) {
	Session session = getCurrentSession();
	Transaction tx = null;
	try {
		tx = session.beginTransaction();
		for (E e: entityCollection) {
			session.buildLockRequest(LockOptions.UPGRADE).lock(e);
			session.delete(e);
			session.flush();
			session.evict(e);
		}
		if (!tx.wasCommitted()) tx.commit();
	} catch (Exception ex) {
		logger.error("Delete list failed", ex);
		tx.rollback();
		throw new HibernateException("Delete list failed");
	}
}
 
Example 5
@Override
public void commitTransaction() throws HibernateException {
    Transaction tx = threadTransaction.get();
    threadTransaction.set(null);
    if (tx != null && ! tx.wasCommitted() && ! tx.wasRolledBack()) {
        tx.commit();
    }
}
 
Example 6
@Override
public void rollbackTransaction() throws HibernateException {
    Transaction tx = threadTransaction.get();
    try {
        threadTransaction.set(null);
        if (tx != null && ! tx.wasCommitted() && ! tx.wasRolledBack()) {
            tx.rollback();
        }
    } finally {
        closeSession();
    }
}
 
Example 7
Source Project: webdsl   File: HibernateUtil.java    License: Apache License 2.0 5 votes vote down vote up
public void afterTransactionCompletion(Transaction tx) {
	try {
		if (tx.wasCommitted()) {
			afterTransactionCompletionCommitted_.afterTransactionCompletionCommitted_();
		}
		else if (tx.wasRolledBack()) {
			afterTransactionCompletionRolledBack_.afterTransactionCompletionRolledBack_();
		}
	}
	catch (Exception e) {
		ThreadLocalPage.get().exceptionInHibernateInterceptor = e;
	}
}
 
Example 8
/**
 * Commit transaction
 */
public static void commit(Transaction tx) {
	if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
		tx.commit();
	}
}
 
Example 9
/**
 * Rollback transaction
 */
public static void rollback(Transaction tx) {
	if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
		tx.rollback();
	}
}
 
Example 10
/**
 * Commit transaction
 */
public static void commit(Transaction tx) {
	if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
		tx.commit();
	}
}
 
Example 11
/**
 * Rollback transaction
 */
public static void rollback(Transaction tx) {
	if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
		tx.rollback();
	}
}