Java Code Examples for javax.persistence.EntityManager#contains()

The following examples show how to use javax.persistence.EntityManager#contains() . 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
Source File: JPALink.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public void save() {
  EntityManager em = context.getEntityManager();
  ODataJPATransaction tx = context.getODataJPATransaction();
  boolean isLocalTransaction = false;
  if (!tx.isActive()) {
    tx.begin();
    isLocalTransaction = true;
  }
  if (sourceJPAEntity != null) {
    em.persist(sourceJPAEntity);
  }
  if (targetJPAEntity != null) {
    em.persist(targetJPAEntity);
  }
  if (isLocalTransaction
      && ((sourceJPAEntity != null && em.contains(sourceJPAEntity)) || (targetJPAEntity != null && em
          .contains(targetJPAEntity)))) {
    tx.commit();
  }
}
 
Example 2
Source File: JPAWorkItemHandler.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
private void doDelete(EntityManager em,
                      Object entity,
                      Object id) {
    // detached entity
    if (!em.contains(entity)) {
        entity = doGet(em,
                       entity.getClass().getName(),
                       id);
    }
    if (entity == null) {
        throw new IllegalArgumentException("Can't load the entity to remove. Provide an attached entity or the id to load it.");
    }
    em.remove(entity);
}
 
Example 3
Source File: PersistenceServletFilter.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void testEntityManagerFactory() {
    Assert.assertNotNull(entityMgrFactory);

    Address a = new Address();
    EntityManager em = entityMgrFactory.createEntityManager();
    em.contains(a);
}
 
Example 4
Source File: PersistenceServlet.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void testEntityManagerFactory() {
    Assert.assertNotNull(entityMgrFactory);

    Address a = new Address();
    EntityManager em = entityMgrFactory.createEntityManager();
    em.contains(a);
}
 
Example 5
Source File: AbstractJpaStorage.java    From apiman with Apache License 2.0 5 votes vote down vote up
/**
 * @param bean the bean to update
 * @throws StorageException if a storage problem occurs while storing a bean
 */
public <T> void update(T bean) throws StorageException {
    EntityManager entityManager = getActiveEntityManager();
    try {
        if (!entityManager.contains(bean)) {
            entityManager.merge(bean);
        }
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
        throw new StorageException(t);
    }
}
 
Example 6
Source File: AbstractJpaOperations.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void persist(EntityManager em, Object entity) {
    if (!em.contains(entity)) {
        em.persist(entity);
    }
}