Search in sources :

Example 6 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();
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    CollectionMetadata collectionMetadata = sessionFactory.getCollectionMetadata("org.jboss.tools.hibernate.runtime.v_3_6.internal.test.Foo.bars");
    Assert.assertSame(collectionMetadata, ((IFacade) sessionFactoryFacade.getCollectionMetadata("org.jboss.tools.hibernate.runtime.v_3_6.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) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) Test(org.junit.Test)

Example 7 with ISessionFactory

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

the class FacadeFactoryTest method testCreateSessionFactory.

@Test
public void testCreateSessionFactory() {
    SessionFactory sessionFactory = (SessionFactory) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { SessionFactory.class }, new TestInvocationHandler());
    ISessionFactory facade = facadeFactory.createSessionFactory(sessionFactory);
    Assert.assertSame(sessionFactory, ((IFacade) facade).getTarget());
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) PersistentClass(org.hibernate.mapping.PersistentClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) POJOClass(org.hibernate.tool.hbm2x.pojo.POJOClass) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) Test(org.junit.Test)

Example 8 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();
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry();
    SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    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) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) ServiceRegistry(org.hibernate.service.ServiceRegistry) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) Session(org.hibernate.Session) ISession(org.jboss.tools.hibernate.runtime.spi.ISession) Test(org.junit.Test)

Example 9 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);
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry();
    SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    ClassMetadata classMetadata = sessionFactory.getClassMetadata(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_4_0.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) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) ServiceRegistry(org.hibernate.service.ServiceRegistry) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) Test(org.junit.Test)

Example 10 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)

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