Example usage for javax.persistence EntityTransaction rollback

List of usage examples for javax.persistence EntityTransaction rollback

Introduction

In this page you can find the example usage for javax.persistence EntityTransaction rollback.

Prototype

public void rollback();

Source Link

Document

Roll back the current resource transaction.

Usage

From source file:com.nandhootoo.services.ProductServiceImpl.java

public void persist(Product product) {
    EntityTransaction tx = null;
    try {//  w  ww .  ja v a  2 s .  com
        entityManager.persist(product);
    } catch (Exception ex) {
        if (tx != null && tx.isActive())
            tx.rollback();
        throw (RuntimeException) ex.getCause();
    }
}

From source file:com.nandhootoo.services.DepartmentServiceImpl.java

public void merge(Department department) {
    EntityTransaction tx = null;
    try {// w w w. j  a v a2  s .com
        entityManager.merge(department);
    } catch (Exception ex) {
        if (tx != null && tx.isActive())
            tx.rollback();
        throw (RuntimeException) ex.getCause();
    }
}

From source file:com.appdynamics.loan.persistence.BasePersistenceImpl.java

/**
 * The method to update the serailizable business objects into the database.
 * /*from   w w  w  .j  a va  2  s . c  o  m*/
 * @param object --
 *            serializable object
 * @throws PersistenceException
 */
@Transactional
public void update(final Serializable object) {
    EntityManager entityManager = getEntityManager();
    EntityTransaction txn = entityManager.getTransaction();
    txn.begin();
    try {
        entityManager.merge(object);
    } catch (Exception ex) {
        txn.rollback();
    } finally {
        if (!txn.getRollbackOnly()) {
            txn.commit();
        }
    }
}

From source file:com.appdynamics.loan.persistence.BasePersistenceImpl.java

@Transactional
public void delete(Serializable object) {
    EntityManager entityManager = getEntityManager();
    EntityTransaction txn = entityManager.getTransaction();
    txn.begin();/* w  ww  . j  a v  a2 s .  com*/
    try {
        entityManager.remove(object);
    } catch (Exception ex) {
        txn.rollback();
    } finally {
        if (!txn.getRollbackOnly()) {
            txn.commit();
        }
    }
}

From source file:com.nandhootoo.services.DepartmentServiceImpl.java

public void persist(Department department) {
    EntityTransaction tx = null;
    try {/*from   w  ww . j  av a  2 s. c  o  m*/
        entityManager.persist(department);
    } catch (Exception ex) {
        if (tx != null && tx.isActive())
            tx.rollback();
        throw (RuntimeException) ex.getCause();
    }
}

From source file:com.appdynamics.loan.persistence.BasePersistenceImpl.java

@Transactional
public void save(final Serializable object) {
    EntityManager entityManager = getEntityManager();
    EntityTransaction txn = entityManager.getTransaction();
    txn.begin();/* ww  w . ja va 2 s .  c  o  m*/
    try {
        entityManager.persist(object);
    } catch (Exception ex) {
        txn.rollback();
    } finally {
        if (!txn.getRollbackOnly()) {
            txn.commit();
        }
    }

}

From source file:org.spc.ofp.tubs.domain.purseseine.TripRepository.java

public void update(final PurseSeineTrip trip) {
    final EntityManager mgr = emf.createEntityManager();
    final EntityTransaction xa = mgr.getTransaction();
    try {/*www  . j av  a 2  s. co  m*/
        xa.begin();
        mgr.merge(trip);
        xa.commit();
    } catch (Exception ex) {
        if (xa.isActive()) {
            xa.rollback();
        }
    } finally {
        mgr.close();
    }
}

From source file:org.nuxeo.ecm.core.persistence.PersistenceProvider.java

protected void doRollback(EntityManager em) {
    try {/*from w w  w.  j  a  va2  s  .  co m*/
        em.flush();
    } catch (TransactionRequiredException e) {
        // ignore
    }
    EntityTransaction et = getTransaction(em);
    if (et == null || !et.isActive()) {
        return;
    }
    et.rollback();
}

From source file:au.com.cybersearch2.classyjpa.entity.LoaderTaskImpl.java

/**
 * Handle load complete on calling thread
 * @param loader the loader that completed the load
 * @param success Boolean object - Boolean.TRUE indicates successful result
 *///from   w w w  .  java2 s .  c o  m
@Override
public void onLoadComplete(Loader<Boolean> loader, Boolean success) {
    if (uncaughtException != null) {
        EntityTransaction transaction = transactionInfo.getTransaction();
        if ((transaction != null) && transaction.isActive())
            transaction.rollback();
        if (transactionInfo.getRollbackException() == null)
            transactionInfo.setRollbackException(uncaughtException);

    }
    Throwable rollbackException = transactionInfo.getRollbackException();
    if ((rollbackException != null) || (success == null))
        success = Boolean.FALSE;
    if (rollbackException != null) {
        persistenceWork.onRollback(rollbackException);
        log.error(TAG, "Persistence container rolled back transaction", rollbackException);
    } else
        persistenceWork.onPostExecute(success);
    if (success)
        workTracker.setStatus(WorkStatus.FINISHED);
    else
        workTracker.setStatus(WorkStatus.FAILED);
    // Notify waiting threads at very last point of exit
    synchronized (workTracker) {
        workTracker.notifyAll();
    }
}

From source file:org.apache.juddi.replication.ReplicationNotifier.java

/**
 * returns the latest version of the replication config or null if there
 * is no config// ww  w .  j av  a 2 s.  c  om
 *
 * @return
 */
public static org.uddi.repl_v3.ReplicationConfiguration FetchEdges() {

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = null;
    org.uddi.repl_v3.ReplicationConfiguration item = new org.uddi.repl_v3.ReplicationConfiguration();
    try {
        tx = em.getTransaction();
        tx.begin();
        Query q = em
                .createQuery("SELECT item FROM ReplicationConfiguration item order by item.serialNumber DESC");
        q.setMaxResults(1);
        ReplicationConfiguration results = (ReplicationConfiguration) q.getSingleResult();
        //   ReplicationConfiguration find = em.find(ReplicationConfiguration.class, null);
        if (results != null) {
            MappingModelToApi.mapReplicationConfiguration(results, item);
        }

        tx.commit();
        return item;
    } catch (Exception ex) {
        //log.error("error", ex);
        //no config available
        if (tx != null && tx.isActive()) {
            tx.rollback();
        }
    } finally {
        em.close();
    }
    return null;
}