Example usage for org.hibernate SessionFactory isClosed

List of usage examples for org.hibernate SessionFactory isClosed

Introduction

In this page you can find the example usage for org.hibernate SessionFactory isClosed.

Prototype

boolean isClosed();

Source Link

Document

Is this factory already closed?

Usage

From source file:net.krotscheck.jersey2.hibernate.factory.HibernateSessionFactoryFactoryTest.java

License:Apache License

/**
 * Test the application binder.//from   www  .  java 2  s  .co m
 */
@Test
public void testBinder() {

    // Create a fake application.
    SessionFactory factoryFactory = locator.getService(SessionFactory.class);
    Assert.assertNotNull(factoryFactory);

    // Make sure it's reading from the same place.
    Assert.assertFalse(factoryFactory.isClosed());

    // Make sure it's a singleton...
    SessionFactory factoryFactory2 = handler.getServiceLocator().getService(SessionFactory.class);
    Assert.assertSame(factoryFactory, factoryFactory2);
}

From source file:org.jboss.jpa.deployers.test.jbjpa6.PersistenceUnitJNDIBindingsTestCase.java

License:Open Source License

@Test
public void testSF() throws Exception {
    InitialContext ctx = new InitialContext();
    SessionFactory sf = null;
    try {// w  ww.  j  ava  2s  . co  m
        sf = (SessionFactory) ctx.lookup(SF_PATH);
    } catch (Exception e) {
        fail("SessionFactory binding failed");
    }
    try {
        sf.isClosed();
    } catch (Exception e) {
        fail("SessionFactory test invocation failed");
    }

}

From source file:org.jbpm.jbpm2605.JBPM2605Test.java

License:Open Source License

public void testExternalSessionFactory() {
    SessionFactory sessionFactory = new MockSessionFactory();

    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseResource("jbpm.cfg.xml");
    try {//from  ww  w.j a va2s  . co m
        JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
        jbpmContext.setSessionFactory(sessionFactory);
    } finally {
        jbpmConfiguration.close();
    }

    assert !sessionFactory.isClosed() : "expected external session factory to remain open";
}

From source file:org.jbpm.JbpmConfigurationTest.java

License:Open Source License

public void testJbpmConfigurationClose() {
    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
    SessionFactory sessionFactory;
    try {/*from   w  w  w . j  a  va 2  s .co  m*/
        sessionFactory = jbpmContext.getSessionFactory();
    } finally {
        jbpmContext.close();
    }
    jbpmConfiguration.close();

    assertTrue("expected " + sessionFactory + " to be closed", sessionFactory.isClosed());
}

From source file:org.springframework.orm.hibernate3.HibernateSessionFactoryConfigurationTests.java

License:Apache License

@Test
public void builtSessionFactoryIsDisposableBeanProxy() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
            AnnotationSessionFactoryConfig.class);
    SessionFactory sessionFactory = ctx.getBean(SessionFactory.class);
    assertThat(sessionFactory, instanceOf(DisposableBean.class));
    assertThat(sessionFactory.toString(), startsWith("DisposableBean proxy for SessionFactory"));
    ctx.close();/* w ww. j  ava2s  . c om*/
    assertTrue("SessionFactory was not closed as expected", sessionFactory.isClosed());
}

From source file:org.wso2.appserver.hibernate.jndi.sample.listener.HibernateSessionFactoryListener.java

License:Open Source License

public void contextDestroyed(ServletContextEvent servletContextEvent) {
    SessionFactory sessionFactory = (SessionFactory) servletContextEvent.getServletContext()
            .getAttribute("SessionFactory");
    if (sessionFactory != null && !sessionFactory.isClosed()) {
        logger.info("Closing sessionFactory");
        sessionFactory.close();//from   ww  w .  j  a v  a2s.  co m
    }
    logger.info("Released Hibernate sessionFactory resource");
}