javax.persistence.EntityManager#isOpen ( )源码实例Demo

下面列出了javax.persistence.EntityManager#isOpen ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jasperreports   文件: EjbqlApp.java
/**
 *
 */
public void fill() throws JRException
{
	long start = System.currentTimeMillis();
	// create entity manager factory for connection with database
	EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu1", new HashMap<Object, Object>());
	EntityManager em = emf.createEntityManager();

	try
	{
		Map<String, Object> parameters = getParameters(em);
		
		JasperFillManager.fillReportToFile("build/reports/JRMDbReport.jasper", parameters);

		em.close();
		
		System.err.println("Filling time : " + (System.currentTimeMillis() - start));
	}
	finally
	{
		if (em.isOpen())
			em.close();
		if (emf.isOpen())
			emf.close();
	}
}
 
源代码2 项目: crushpaper   文件: JpaDb.java
/**
 * Returns an entity manager and creates it if needed. Also recreates it if
 * it has been spontaneously closed which is a real thing that can happen.
 * 
 * @return
 */
private EntityManager getOrCreateEntityManager() {
	buildEntityManagerFactory();

	EntityManager entityManager = entityManagerThreadLocal.get();
	if (entityManager == null) {
		entityManager = createEntityManager();
	}

	if (!entityManager.isOpen()) {
		entityManager = createEntityManager();
	}

	EntityTransaction transaction = entityManager.getTransaction();
	if (!transaction.isActive())
		transaction.begin();

	return entityManager;
}
 
源代码3 项目: deltaspike   文件: Resources.java
public void dispose(@Disposes @Default EntityManager entityManager)
{
    if (entityManager.isOpen())
    {
        entityManager.close();
    }
}
 
源代码4 项目: james-project   文件: EntityManagerUtils.java
/**
 * Safely close an EntityManager by rolling back any active transaction and then closing it. That is needed to prevent memory leaks.
 * @param entityManager the entity manager to close
 */
public static void safelyClose(EntityManager entityManager) {

    if (entityManager == null) {
        return;
    }

    if (entityManager.isOpen()) {
        if (entityManager.getTransaction().isActive()) {
            entityManager.getTransaction().rollback();
        }
        entityManager.close();
    }

}
 
源代码5 项目: deltaspike   文件: TestEntityManagerProducer.java
protected void closeSecondEntityManager(@Disposes @Second EntityManager entityManager)
{
    if (entityManager.isOpen())
    {
        entityManager.close();
    }
    closeEntityManagerCountSecondEntityManager++;
}
 
源代码6 项目: deltaspike   文件: TestEntityManagerProducer.java
protected void closeFirstEntityManager(@Disposes @First EntityManager entityManager)
{
    if (entityManager.isOpen())
    {
        entityManager.close();
    }
    closeEntityManagerCountFirstEntityManager++;
}
 
源代码7 项目: deltaspike   文件: TestEntityManagerProducer.java
protected void closeDefaultEntityManager(@Disposes @Default EntityManager entityManager)
{
    if (entityManager.isOpen())
    {
        entityManager.close();
    }
    closeEntityManagerCountDefaultEntityManager++;
}
 
源代码8 项目: deltaspike   文件: TestEntityManagerProducer.java
protected void closeFirstEntityManager(@Disposes @First EntityManager entityManager)
{
    if (entityManager.isOpen())
    {
        entityManager.close();
    }
    closeEntityManagerCountFirstEntityManager++;
}
 
public void close(@Disposes EntityManager em) {
    if (em.isOpen()) {
        em.close();
    }
}
 
源代码10 项目: ranger   文件: DbAuditProvider.java
private boolean isDbConnected() {
	EntityManager em = getEntityManager();
	
	return em != null && em.isOpen();
}
 
源代码11 项目: tomee   文件: PersonProducer.java
public void closeEntityManager(@Disposes EntityManager manager) {
    if (manager.isOpen()) {
        manager.close();
    }
}
 
源代码12 项目: jersey-jwt   文件: EntityManagerProducer.java
public void closeEntityManager(@Disposes EntityManager entityManager) {
    if (entityManager.isOpen()) {
        entityManager.close();
    }
}
 
源代码13 项目: Knowage-Server   文件: JPAPersistenceManager.java
@Override
public void updateRecord(JSONObject aRecord, RegistryConfiguration registryConf) {

	EntityTransaction entityTransaction = null;

	logger.debug("IN");
	EntityManager entityManager = null;
	try {
		Assert.assertNotNull(aRecord, "Input parameter [record] cannot be null");
		Assert.assertNotNull(aRecord, "Input parameter [registryConf] cannot be null");

		logger.debug("New record: " + aRecord.toString(3));
		logger.debug("Target entity: " + registryConf.getEntity());

		entityManager = dataSource.getEntityManager();
		Assert.assertNotNull(entityManager, "entityManager cannot be null");

		entityTransaction = entityManager.getTransaction();

		EntityType targetEntity = getTargetEntity(registryConf, entityManager);
		String keyAttributeName = getKeyAttributeName(targetEntity);
		logger.debug("Key attribute name is equal to " + keyAttributeName);

		Iterator it = aRecord.keys();

		Object keyColumnValue = aRecord.get(keyAttributeName);
		logger.debug("Key of new record is equal to " + keyColumnValue);
		logger.debug("Key column java type equal to [" + targetEntity.getJavaType() + "]");
		Attribute a = targetEntity.getAttribute(keyAttributeName);
		Object obj = entityManager.find(targetEntity.getJavaType(), this.convertValue(keyColumnValue, a));
		logger.debug("Key column class is equal to [" + obj.getClass().getName() + "]");

		while (it.hasNext()) {
			String attributeName = (String) it.next();
			logger.debug("Processing column [" + attributeName + "] ...");

			if (keyAttributeName.equals(attributeName)) {
				logger.debug("Skip column [" + attributeName + "] because it is the key of the table");
				continue;
			}
			Column column = registryConf.getColumnConfiguration(attributeName);
			if (!column.isEditable()) {
				logger.debug("Skip column [" + attributeName + "] because it is not editable");
				continue;
			}
			List columnDepends = new ArrayList();
			if (column.getDependences() != null && !"".equals(column.getDependences())) {
				String[] dependences = column.getDependences().split(",");
				for (int i = 0; i < dependences.length; i++) {
					// get dependences informations
					Column dependenceColumns = getDependenceColumns(registryConf.getColumns(), dependences[i]);
					if (dependenceColumns != null)
						columnDepends.add(dependenceColumns);
				}
			}

			// if column is info column do not update
			if (!column.isInfoColumn()) {
				if (column.getSubEntity() != null) {
					logger.debug("Column [" + attributeName + "] is a foreign key");
					manageForeignKey(targetEntity, column, obj, attributeName, aRecord, columnDepends, entityManager, registryConf.getColumns());
				} else {
					logger.debug("Column [" + attributeName + "] is a normal column");
					manageProperty(targetEntity, obj, attributeName, aRecord);
				}
			}
		}

		if (!entityTransaction.isActive()) {
			entityTransaction.begin();
		}

		entityManager.persist(obj);
		entityManager.flush();
		entityTransaction.commit();

	} catch (Throwable t) {
		if (entityTransaction != null && entityTransaction.isActive()) {
			entityTransaction.rollback();
		}
		logger.error(t);
		throw new SpagoBIRuntimeException("Error saving entity", t);
	} finally {
		if (entityManager != null) {
			if (entityManager.isOpen()) {
				entityManager.close();
			}
		}
		logger.debug("OUT");
	}

}
 
源代码14 项目: hammock   文件: EntityManagerProducer.java
public void closeEM(@Disposes @Any EntityManager entityManager) {
   if(entityManager.isOpen()) {
      entityManager.close();
   }
}
 
源代码15 项目: jpa-unit   文件: EntityManagerProducer.java
public void close(@Disposes final EntityManager em) {
    if (em.isOpen()) {
        em.close();
    }
}
 
源代码16 项目: tomee   文件: EntityManagerProducer.java
public void dispose(@Disposes @Default EntityManager entityManager) {
    if (entityManager.isOpen()) {
        entityManager.close();
    }
}
 
源代码17 项目: jpa-unit   文件: EntityManagerProducer.java
public void close(@Disposes final EntityManager em) {
    if (em.isOpen()) {
        em.close();
    }
}
 
源代码18 项目: ranger   文件: DBAuditDestination.java
private boolean isDbConnected() {
	EntityManager em = getEntityManager();
	return em != null && em.isOpen();
}
 
源代码19 项目: ranger   文件: RangerKMSDB.java
private boolean isDbConnected() {
	EntityManager em = getEntityManager();
	
	return em != null && em.isOpen();
}
 
源代码20 项目: kumuluzee   文件: TxScopedEntityManagerWrapper.java
@Override
public void close() {

    EntityManager nonTxEm = nonTxEmHolder.getEntityManager();

    if (nonTxEm != null && nonTxEm.isOpen()) {

        nonTxEm.close();

        nonTxEmHolder.setEntityManager(null);
    }
}