Java Code Examples for javax.persistence.EntityManagerFactory#isOpen()

The following examples show how to use javax.persistence.EntityManagerFactory#isOpen() . 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: EntityManagerContainerFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void close() throws Exception {
	try {
		if (instance != null) {
			for (EntityManagerFactory emf : instance.entityManagerFactoryMap.values()) {
				if (emf.isOpen()) {
					emf.close();
				}
			}
			instance.entityManagerFactoryMap.clear();
			instance.checkPersistFieldMap.clear();
			instance.checkRemoveFieldMap.clear();
		}
		/* 注销驱动程序 */
		Enumeration<Driver> drivers = DriverManager.getDrivers();
		while (drivers.hasMoreElements()) {
			Driver driver = drivers.nextElement();
			DriverManager.deregisterDriver(driver);
		}
		/* 由于可能重新载入 */
		instance = null;
	} catch (Exception e) {
		throw new Exception("close error.", e);
	}
}
 
Example 2
Source File: EjbqlApp.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
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();
	}
}
 
Example 3
Source File: AbstractEntityManagerTest.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setUp() throws Exception {
  super.setUp();
  final EntityManagerFactory emf = getEntityManagerFactory();
  if (emf == null || !emf.isOpen() || lastTestClass != getClass()) {
    setEntityManagerFactory(createEntityManagerFactory());
    lastTestClass = getClass();
  }
}