Search in sources :

Example 56 with ISessionFactory

use of org.jboss.tools.hibernate.runtime.spi.ISessionFactory in project jbosstools-hibernate by jbosstools.

the class SessionFactoryFacadeTest method testOpenSession.

@Test
public void testOpenSession() {
    Configuration configuration = new Configuration();
    SessionFactory sessionFactory = configuration.buildSessionFactory(new StandardServiceRegistryBuilder().build());
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    ISession sessionFacade = sessionFactoryFacade.openSession();
    Session session = (Session) ((IFacade) sessionFacade).getTarget();
    Assert.assertSame(sessionFactory, session.getSessionFactory());
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) ISession(org.jboss.tools.hibernate.runtime.spi.ISession) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) Session(org.hibernate.Session) ISession(org.jboss.tools.hibernate.runtime.spi.ISession) Test(org.junit.Test)

Example 57 with ISessionFactory

use of org.jboss.tools.hibernate.runtime.spi.ISessionFactory in project jbosstools-hibernate by jbosstools.

the class SessionFactoryFacadeTest method testGetAllCollectionMetadata.

@Test
public void testGetAllCollectionMetadata() {
    Configuration configuration = new Configuration();
    SessionFactory sessionFactory = configuration.buildSessionFactory(new StandardServiceRegistryBuilder().build());
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Assert.assertTrue(sessionFactoryFacade.getAllCollectionMetadata().isEmpty());
    sessionFactory.close();
    configuration.addClass(Foo.class);
    sessionFactory = configuration.buildSessionFactory(new StandardServiceRegistryBuilder().build());
    sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Map<String, ICollectionMetadata> allCollectionMetaData = sessionFactoryFacade.getAllCollectionMetadata();
    Assert.assertNotNull(allCollectionMetaData.get("org.jboss.tools.hibernate.runtime.v_4_3.internal.test.Foo.bars"));
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) ICollectionMetadata(org.jboss.tools.hibernate.runtime.spi.ICollectionMetadata) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) Test(org.junit.Test)

Example 58 with ISessionFactory

use of org.jboss.tools.hibernate.runtime.spi.ISessionFactory in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testBuildSessionFactory.

@Test
public void testBuildSessionFactory() throws Throwable {
    ISessionFactory sessionFactoryFacade = configurationFacade.buildSessionFactory();
    Assert.assertNotNull(sessionFactoryFacade);
    Object sessionFactory = ((IFacade) sessionFactoryFacade).getTarget();
    Assert.assertNotNull(sessionFactory);
    Assert.assertTrue(sessionFactory instanceof SessionFactory);
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) Test(org.junit.Test)

Example 59 with ISessionFactory

use of org.jboss.tools.hibernate.runtime.spi.ISessionFactory in project jbosstools-hibernate by jbosstools.

the class ServiceImplTest method testNewHQLQueryPlan.

@Test
public void testNewHQLQueryPlan() throws Exception {
    IConfiguration configuration = service.newDefaultConfiguration();
    File testFile = File.createTempFile("test", "tmp");
    testFile.deleteOnExit();
    FileWriter fileWriter = new FileWriter(testFile);
    fileWriter.write(TEST_HBM_STRING);
    fileWriter.close();
    configuration.addFile(testFile);
    ISessionFactory sfi = configuration.buildSessionFactory();
    IHQLQueryPlan queryPlan = service.newHQLQueryPlan("from ServiceImplTest$Foo", true, sfi);
    Assert.assertNotNull(queryPlan);
    Object target = ((IFacade) queryPlan).getTarget();
    Assert.assertNotNull(target);
    Assert.assertTrue(target instanceof HQLQueryPlan);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) FileWriter(java.io.FileWriter) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) File(java.io.File) Test(org.junit.Test)

Example 60 with ISessionFactory

use of org.jboss.tools.hibernate.runtime.spi.ISessionFactory in project jbosstools-hibernate by jbosstools.

the class SessionFactoryFacadeTest method testClose.

@Test
public void testClose() {
    Configuration configuration = new Configuration();
    SessionFactory sessionFactory = configuration.buildSessionFactory(new StandardServiceRegistryBuilder().build());
    sessionFactory.openSession();
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Assert.assertFalse(sessionFactory.isClosed());
    sessionFactoryFacade.close();
    Assert.assertTrue(sessionFactory.isClosed());
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) Test(org.junit.Test)

Aggregations

ISessionFactory (org.jboss.tools.hibernate.runtime.spi.ISessionFactory)70 Test (org.junit.Test)68 SessionFactory (org.hibernate.SessionFactory)64 Configuration (org.hibernate.cfg.Configuration)48 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)30 IClassMetadata (org.jboss.tools.hibernate.runtime.spi.IClassMetadata)16 ICollectionMetadata (org.jboss.tools.hibernate.runtime.spi.ICollectionMetadata)16 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)12 Session (org.hibernate.Session)8 PersistentClass (org.hibernate.mapping.PersistentClass)8 RootClass (org.hibernate.mapping.RootClass)8 ClassMetadata (org.hibernate.metadata.ClassMetadata)8 CollectionMetadata (org.hibernate.metadata.CollectionMetadata)8 POJOClass (org.hibernate.tool.hbm2x.pojo.POJOClass)8 IPOJOClass (org.jboss.tools.hibernate.runtime.spi.IPOJOClass)8 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)8 ISession (org.jboss.tools.hibernate.runtime.spi.ISession)8 ServiceRegistryBuilder (org.hibernate.service.ServiceRegistryBuilder)6 ServiceRegistry (org.hibernate.service.ServiceRegistry)5 File (java.io.File)4