Search in sources :

Example 66 with ISessionFactory

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

the class SessionFactoryFacadeTest method testGetCollectionMetadata.

@Test
public void testGetCollectionMetadata() {
    Configuration configuration = new Configuration();
    configuration.addClass(Foo.class);
    SessionFactory sessionFactory = configuration.buildSessionFactory(new StandardServiceRegistryBuilder().build());
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Metamodel metamodel = ((EntityManagerFactory) sessionFactory).getMetamodel();
    CollectionMetadata collectionMetadata = (CollectionMetadata) ((MetamodelImplementor) metamodel).collectionPersister("org.jboss.tools.hibernate.runtime.v_5_3.internal.test.Foo.bars");
    Assert.assertSame(collectionMetadata, ((IFacade) sessionFactoryFacade.getCollectionMetadata("org.jboss.tools.hibernate.runtime.v_5_3.internal.test.Foo.bars")).getTarget());
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) CollectionMetadata(org.hibernate.metadata.CollectionMetadata) ICollectionMetadata(org.jboss.tools.hibernate.runtime.spi.ICollectionMetadata) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) EntityManagerFactory(javax.persistence.EntityManagerFactory) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) Metamodel(javax.persistence.metamodel.Metamodel) Test(org.junit.Test)

Example 67 with ISessionFactory

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

the class SessionFactoryFacadeTest method testGetClassMetadata.

@Test
public void testGetClassMetadata() {
    Configuration configuration = new Configuration();
    configuration.addClass(Foo.class);
    SessionFactory sessionFactory = configuration.buildSessionFactory(new StandardServiceRegistryBuilder().build());
    Metamodel metamodel = ((EntityManagerFactory) sessionFactory).getMetamodel();
    ClassMetadata classMetadata = (ClassMetadata) ((MetamodelImplementor) metamodel).entityPersister(Foo.class);
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Assert.assertSame(classMetadata, ((IFacade) sessionFactoryFacade.getClassMetadata(Foo.class)).getTarget());
    Assert.assertSame(classMetadata, ((IFacade) sessionFactoryFacade.getClassMetadata("org.jboss.tools.hibernate.runtime.v_5_3.internal.test.Foo")).getTarget());
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) ClassMetadata(org.hibernate.metadata.ClassMetadata) IClassMetadata(org.jboss.tools.hibernate.runtime.spi.IClassMetadata) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) EntityManagerFactory(javax.persistence.EntityManagerFactory) Foo(org.jboss.tools.hibernate.runtime.v_5_3.internal.test.Foo) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) Metamodel(javax.persistence.metamodel.Metamodel) Test(org.junit.Test)

Example 68 with ISessionFactory

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

the class SessionFactoryFacadeTest method testGetAllClassMetadata.

@Test
public void testGetAllClassMetadata() throws Exception {
    Configuration configuration = new Configuration();
    SessionFactory sessionFactory = configuration.buildSessionFactory(new StandardServiceRegistryBuilder().build());
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Assert.assertTrue(sessionFactoryFacade.getAllClassMetadata().isEmpty());
    sessionFactory.close();
    configuration.addClass(Foo.class);
    sessionFactory = configuration.buildSessionFactory(new StandardServiceRegistryBuilder().build());
    sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Map<String, IClassMetadata> allClassMetaData = sessionFactoryFacade.getAllClassMetadata();
    Assert.assertNotNull(allClassMetaData.get("org.jboss.tools.hibernate.runtime.v_5_3.internal.test.Foo"));
}
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) IClassMetadata(org.jboss.tools.hibernate.runtime.spi.IClassMetadata) Test(org.junit.Test)

Example 69 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_5_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 70 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