Search in sources :

Example 11 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 12 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 13 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 14 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 15 with ISession

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

the class AbstractFacadeFactory method createFullTextSession.

@Override
public IFullTextSession createFullTextSession(ISessionFactory sessionFactory) {
    ISession session = sessionFactory.openSession();
    Object targetSession = ((IFacade) session).getTarget();
    Object targetFullTextSession = Util.invokeMethod(getSearchClass(), "getFullTextSession", new Class[] { getSessionClass() }, new Object[] { targetSession });
    return new AbstractFullTextSessionFacade(this, targetFullTextSession) {
    };
}
Also used : ISession(org.jboss.tools.hibernate.runtime.spi.ISession) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade)

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