Example usage for javax.persistence EntityTransaction isActive

List of usage examples for javax.persistence EntityTransaction isActive

Introduction

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

Prototype

public boolean isActive();

Source Link

Document

Indicate whether a resource transaction is in progress.

Usage

From source file:org.sakaiproject.kernel.authz.simple.SubjectPermissionListener.java

/**
 * {@inheritDoc}/*from ww  w.ja va  2s. c o  m*/
 *
 * @see org.sakaiproject.kernel.jcr.api.JcrContentListener#onEvent(int,
 *      java.lang.String, java.lang.String, java.lang.String)
 */
public void onEvent(int type, String userID, String filePath, String fileName) {
    if (fileName.equals(KernelConstants.GROUP_FILE_NAME)) {
        InputStream in = null;
        try {
            in = jcrNodeFactoryService.getInputStream(filePath);
            String groupBody = IOUtils.readFully(in, "UTF-8");
            if (groupBody != null && groupBody.length() > 0) {
                EntityTransaction transaction = entityManager.getTransaction();

                if (!transaction.isActive()) {
                    transaction.begin();
                }
                // update the index for subjects and groups
                updateSubjectPermissionIndex(groupBody);

                // update the index used for searching sites
                updateSiteIndex(groupBody, filePath);

                transaction.commit();
            }
        } catch (UnsupportedEncodingException e) {
            LOG.error(e);
        } catch (IOException e) {
            LOG.warn("Failed to read userenv " + filePath + " cause :" + e.getMessage());
            if (debug)
                LOG.debug(e);
        } catch (RepositoryException e) {
            LOG.warn("Failed to read userenv for " + filePath + " cause :" + e.getMessage());
            if (debug)
                LOG.debug(e);
        } catch (JCRNodeFactoryServiceException e) {
            LOG.warn("Failed to read userenv for " + filePath + " cause :" + e.getMessage());
            if (debug)
                LOG.debug(e);
        } finally {
            try {
                in.close();
            } catch (Exception ex) {// not interested in this
            }

        }
    }

}

From source file:com.busimu.core.dao.impl.UserMngDaoPolicyJpaImpl.java

/**
 * {@inheritDoc}/*w  w w .j  av  a2s.com*/
 */
@Override
public void saveUser(User user) {
    EntityManager em = ((EntityManagerHolder) TransactionSynchronizationManager.getResource(emf))
            .getEntityManager();
    EntityTransaction tx = em.getTransaction();
    if (!tx.isActive()) {
        tx.begin();
    }
    em.persist(user);
    tx.commit();
}

From source file:com.busimu.core.dao.impl.UserMngDaoPolicyJpaImpl.java

/**
 * {@inheritDoc}/*  ww  w . j  ava  2  s.c  om*/
 */
@Override
public LoginHistory addLoginHistory(User user, Date loginDate, Date logoutDate) {
    EntityManager em = ((EntityManagerHolder) TransactionSynchronizationManager.getResource(emf))
            .getEntityManager();
    EntityTransaction tx = em.getTransaction();
    if (!tx.isActive()) {
        tx.begin();
    }
    LoginHistory history = user.addLoginHistory(loginDate, logoutDate);
    tx.commit();
    return history;
}

From source file:com.busimu.core.dao.impl.UserMngDaoPolicyJpaImpl.java

/**
 * {@inheritDoc}/*  w  w w.  ja va  2s . c  om*/
 */
@Override
public void storeLicenses(Set<License> licenses) {
    EntityManager em = ((EntityManagerHolder) TransactionSynchronizationManager.getResource(emf))
            .getEntityManager();
    EntityTransaction tx = em.getTransaction();
    if (!tx.isActive()) {
        tx.begin();
    }
    for (License l : licenses) {
        em.persist(l);
    }
    tx.commit();
}

From source file:fr.xebia.demo.wicket.blog.service.GenericService.java

protected void rollbackTransaction() throws ServiceException {
    try {//from  w  ww.  j  ava2  s.  c  o m
        EntityTransaction transaction = currentEntityManager().getTransaction();
        if (transaction.isActive()) {
            transaction.rollback();
        }
    } catch (PersistenceException e) {
        throw new ServiceException("Can't rollback transaction", e);
    }
}

From source file:fr.xebia.demo.wicket.blog.service.GenericService.java

protected void commitTransaction() throws ServiceException {
    try {//  w  w w  .j a  v  a 2s  . c om
        EntityTransaction transaction = currentEntityManager().getTransaction();
        if (transaction.isActive()) {
            transaction.commit();
        }
    } catch (Exception e) {
        rollbackTransaction();
        throw new ServiceException("Can't commit transaction", e);
    }
}

From source file:org.apache.ranger.audit.destination.DBAuditDestination.java

private boolean beginTransaction() {
    EntityTransaction trx = getTransaction();

    if (trx != null && !trx.isActive()) {
        trx.begin();/*  w  w  w .  j a v a  2  s.  c  o  m*/
    }

    if (trx == null) {
        logger.warn("DBAuditDestination.beginTransaction(): trx is null");
    }

    return trx != null;
}

From source file:org.apache.james.sieve.jpa.JPASieveRepository.java

private void rollbackTransactionIfActive(EntityTransaction transaction) {
    if (transaction.isActive()) {
        transaction.rollback();
    }
}

From source file:org.easy.criteria.BaseDAO.java

/**
 * {@link javax.persistence.EntityTransaction#isActive())}
 *  {@link javax.persistence.EntityTransaction#commit())}
 *//*from   w  w w . jav  a 2  s .  c o m*/
public void commitTransaction(EntityTransaction transaction) {
    if (transaction.isActive())
        transaction.commit();
}

From source file:org.easy.criteria.BaseDAO.java

/**
 * {@link javax.persistence.EntityTransaction#isActive())}
 * {@link javax.persistence.EntityTransaction#rollback())}
 *///from w  ww  .j  a va2 s.  c  om
public void rollbackTransaction(EntityTransaction transaction) {
    if (transaction.isActive())
        transaction.rollback();
}