Search in sources :

Example 21 with ISession

use of org.jboss.tools.hibernate.runtime.spi.ISession 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 22 with ISession

use of org.jboss.tools.hibernate.runtime.spi.ISession 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 23 with ISession

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

the class ClassMetadataFacadeTest method testGetIdentifier.

@Test
public void testGetIdentifier() {
    ClassLoader cl = FACADE_FACTORY.getClassLoader();
    final SessionImplementor sessionTarget = (SessionImplementor) Proxy.newProxyInstance(cl, new Class[] { SessionImplementor.class }, new TestInvocationHandler());
    ISession session = (ISession) Proxy.newProxyInstance(cl, new Class[] { ISession.class, IFacade.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return sessionTarget;
        }
    });
    Object object = Integer.MAX_VALUE;
    Assert.assertSame(object, classMetadata.getIdentifier(object, session));
    Assert.assertEquals("getIdentifier", methodName);
    Assert.assertArrayEquals(new Object[] { object, sessionTarget }, arguments);
}
Also used : ISession(org.jboss.tools.hibernate.runtime.spi.ISession) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) RootClass(org.hibernate.mapping.RootClass) PersistentClass(org.hibernate.mapping.PersistentClass) Method(java.lang.reflect.Method) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) InvocationHandler(java.lang.reflect.InvocationHandler) Test(org.junit.Test)

Example 24 with ISession

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

the class ClassMetadataFacadeTest method testGetIdentifier.

@Test
public void testGetIdentifier() {
    ClassLoader cl = FACADE_FACTORY.getClassLoader();
    final SessionImplementor sessionTarget = (SessionImplementor) Proxy.newProxyInstance(cl, new Class[] { SessionImplementor.class }, new TestInvocationHandler());
    ISession session = (ISession) Proxy.newProxyInstance(cl, new Class[] { ISession.class, IFacade.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return sessionTarget;
        }
    });
    Object object = Integer.MAX_VALUE;
    Assert.assertSame(object, classMetadata.getIdentifier(object, session));
    Assert.assertEquals("getIdentifier", methodName);
    Assert.assertArrayEquals(new Object[] { object, sessionTarget }, arguments);
}
Also used : ISession(org.jboss.tools.hibernate.runtime.spi.ISession) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) RootClass(org.hibernate.mapping.RootClass) PersistentClass(org.hibernate.mapping.PersistentClass) Method(java.lang.reflect.Method) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) InvocationHandler(java.lang.reflect.InvocationHandler) Test(org.junit.Test)

Example 25 with ISession

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

the class FacadeFactoryTest method testCreateSession.

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

Aggregations

ISession (org.jboss.tools.hibernate.runtime.spi.ISession)27 Test (org.junit.Test)24 Session (org.hibernate.Session)16 PersistentClass (org.hibernate.mapping.PersistentClass)16 RootClass (org.hibernate.mapping.RootClass)16 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)9 InvocationHandler (java.lang.reflect.InvocationHandler)8 Method (java.lang.reflect.Method)8 SessionFactory (org.hibernate.SessionFactory)8 Configuration (org.hibernate.cfg.Configuration)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 ISessionFactory (org.jboss.tools.hibernate.runtime.spi.ISessionFactory)8 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)6 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)5 QueryPage (org.hibernate.console.QueryPage)2 Command (org.hibernate.console.execution.ExecutionContext.Command)2 SessionImplementor (org.hibernate.engine.SessionImplementor)2 ServiceRegistry (org.hibernate.service.ServiceRegistry)1