All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.webpieces.plugin.hibernate.TxCompleters Maven / Gradle / Ivy

There is a newer version: 2.1.109
Show newest version
package org.webpieces.plugin.hibernate;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import org.digitalforge.sneakythrow.SneakyThrow;

public class TxCompleters {

	public void commit(EntityTransaction tx, EntityManager em) {
		try {
			tx.commit();
			
			em.close();
		} catch(Throwable e) {
			closeEm(e, em);
			throw SneakyThrow.sneak(e);
		}
	}

	public void rollbackCloseSuppress(Throwable t, EntityManager mgr, EntityTransaction tx) {
		rollbackTx(t, tx);
		closeEm(t, mgr);
	}
	
	public void rollbackTx(Throwable t, EntityTransaction tx) {
		try {
			tx.rollback();
		} catch(Throwable e) {
			t.addSuppressed(e);
		}
	}
	
	public void closeEm(Throwable t, EntityManager em) {
		try {
			em.close();
		} catch(Throwable e) {
			t.addSuppressed(e);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy