Search in sources :

Example 1 with SessionFactoryOptions

use of org.hibernate.boot.spi.SessionFactoryOptions in project hibernate-orm by hibernate.

the class JCacheRegionAccessStrategy method putFromLoad.

@Override
public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version) throws CacheException {
    final SessionFactoryOptions options = region.getSessionFactoryOptions();
    final boolean minimalPutOverride = options != null && options.isMinimalPutsEnabled();
    return putFromLoad(session, key, value, txTimestamp, version, minimalPutOverride);
}
Also used : SessionFactoryOptions(org.hibernate.boot.spi.SessionFactoryOptions)

Example 2 with SessionFactoryOptions

use of org.hibernate.boot.spi.SessionFactoryOptions in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateHQLQueryPlan.

@Test
public void testCreateHQLQueryPlan() {
    final Collection<PersistentClass> entityBindings = new ArrayList<PersistentClass>();
    final StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
    standardServiceRegistryBuilder.applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    final StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    Table t = new Table("FOO");
    Column c = new Column("foo");
    t.addColumn(c);
    PrimaryKey key = new PrimaryKey(t);
    key.addColumn(c);
    t.setPrimaryKey(key);
    SimpleValue sv = new SimpleValue(metadata);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.setTable(t);
    sv.addColumn(c);
    final RootClass rc = new RootClass(null);
    rc.setEntityName("foo");
    rc.setJpaEntityName("foo");
    rc.setIdentifier(sv);
    rc.setTable(t);
    entityBindings.add(rc);
    MetadataImplementor wrapper = (MetadataImplementor) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { MetadataImplementor.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            if ("getEntityBinding".equals(method.getName()) && args != null && args.length == 1 && "foo".equals(args[0])) {
                return rc;
            } else if ("getEntityBindings".equals(method.getName())) {
                return entityBindings;
            }
            return method.invoke(metadata, args);
        }
    });
    SessionFactoryBuilderImpl sessionFactoryBuilder = (SessionFactoryBuilderImpl) metadata.getSessionFactoryBuilder();
    SessionFactoryOptions sessionFactoryOptions = new SessionFactoryOptionsImpl(sessionFactoryBuilder);
    SessionFactoryImpl sfi = new SessionFactoryImpl(wrapper, sessionFactoryOptions);
    Map<String, Filter> filters = Collections.emptyMap();
    HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, filters, sfi);
    IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
    Assert.assertSame(hqlQueryPlan, ((IFacade) facade).getTarget());
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ArrayList(java.util.ArrayList) MetadataSources(org.hibernate.boot.MetadataSources) PrimaryKey(org.hibernate.mapping.PrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Column(org.hibernate.mapping.Column) SessionFactoryOptions(org.hibernate.boot.spi.SessionFactoryOptions) SessionFactoryBuilderImpl(org.hibernate.boot.internal.SessionFactoryBuilderImpl) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) RootClass(org.hibernate.mapping.RootClass) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) SessionFactoryOptionsImpl(org.hibernate.boot.internal.SessionFactoryOptionsImpl) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) SimpleValue(org.hibernate.mapping.SimpleValue) HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) Filter(org.hibernate.Filter) 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) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) Test(org.junit.Test)

Example 3 with SessionFactoryOptions

use of org.hibernate.boot.spi.SessionFactoryOptions in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateHQLQueryPlan.

@Test
public void testCreateHQLQueryPlan() {
    final Collection<PersistentClass> entityBindings = new ArrayList<PersistentClass>();
    final StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
    standardServiceRegistryBuilder.applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    final StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    Table t = new Table("FOO");
    Column c = new Column("foo");
    t.addColumn(c);
    PrimaryKey key = new PrimaryKey(t);
    key.addColumn(c);
    t.setPrimaryKey(key);
    SimpleValue sv = new SimpleValue(metadata);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.setTable(t);
    sv.addColumn(c);
    final RootClass rc = new RootClass(null);
    rc.setEntityName("foo");
    rc.setJpaEntityName("foo");
    rc.setIdentifier(sv);
    rc.setTable(t);
    entityBindings.add(rc);
    MetadataImplementor wrapper = (MetadataImplementor) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { MetadataImplementor.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            if ("getEntityBinding".equals(method.getName()) && args != null && args.length == 1 && "foo".equals(args[0])) {
                return rc;
            } else if ("getEntityBindings".equals(method.getName())) {
                return entityBindings;
            }
            return method.invoke(metadata, args);
        }
    });
    SessionFactoryBuilderImpl sessionFactoryBuilder = (SessionFactoryBuilderImpl) metadata.getSessionFactoryBuilder();
    SessionFactoryOptions sessionFactoryOptions = new SessionFactoryOptionsImpl(sessionFactoryBuilder);
    SessionFactoryImpl sfi = new SessionFactoryImpl(wrapper, sessionFactoryOptions);
    Map<String, Filter> filters = Collections.emptyMap();
    HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, filters, sfi);
    IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
    Assert.assertSame(hqlQueryPlan, ((IFacade) facade).getTarget());
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ArrayList(java.util.ArrayList) MetadataSources(org.hibernate.boot.MetadataSources) PrimaryKey(org.hibernate.mapping.PrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Column(org.hibernate.mapping.Column) SessionFactoryOptions(org.hibernate.boot.spi.SessionFactoryOptions) SessionFactoryBuilderImpl(org.hibernate.boot.internal.SessionFactoryBuilderImpl) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) RootClass(org.hibernate.mapping.RootClass) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) SessionFactoryOptionsImpl(org.hibernate.boot.internal.SessionFactoryOptionsImpl) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) SimpleValue(org.hibernate.mapping.SimpleValue) HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) Filter(org.hibernate.Filter) 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) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) Test(org.junit.Test)

Example 4 with SessionFactoryOptions

use of org.hibernate.boot.spi.SessionFactoryOptions in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateHQLQueryPlan.

@Test
public void testCreateHQLQueryPlan() {
    final Collection<PersistentClass> entityBindings = new ArrayList<PersistentClass>();
    final StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
    standardServiceRegistryBuilder.applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    final StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    Table t = new Table("FOO");
    Column c = new Column("foo");
    t.addColumn(c);
    PrimaryKey key = new PrimaryKey(t);
    key.addColumn(c);
    t.setPrimaryKey(key);
    SimpleValue sv = new SimpleValue(metadata);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.setTable(t);
    sv.addColumn(c);
    final RootClass rc = new RootClass(null);
    rc.setEntityName("foo");
    rc.setJpaEntityName("foo");
    rc.setIdentifier(sv);
    rc.setTable(t);
    entityBindings.add(rc);
    MetadataImplementor wrapper = (MetadataImplementor) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { MetadataImplementor.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            if ("getEntityBinding".equals(method.getName()) && args != null && args.length == 1 && "foo".equals(args[0])) {
                return rc;
            } else if ("getEntityBindings".equals(method.getName())) {
                return entityBindings;
            }
            return method.invoke(metadata, args);
        }
    });
    SessionFactoryBuilderImpl sessionFactoryBuilder = (SessionFactoryBuilderImpl) metadata.getSessionFactoryBuilder();
    SessionFactoryOptions sessionFactoryOptions = new SessionFactoryOptionsImpl(sessionFactoryBuilder);
    SessionFactoryImpl sfi = new SessionFactoryImpl(wrapper, sessionFactoryOptions);
    Map<String, Filter> filters = Collections.emptyMap();
    HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, filters, sfi);
    IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
    Assert.assertSame(hqlQueryPlan, ((IFacade) facade).getTarget());
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ArrayList(java.util.ArrayList) MetadataSources(org.hibernate.boot.MetadataSources) PrimaryKey(org.hibernate.mapping.PrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Column(org.hibernate.mapping.Column) SessionFactoryOptions(org.hibernate.boot.spi.SessionFactoryOptions) SessionFactoryBuilderImpl(org.hibernate.boot.internal.SessionFactoryBuilderImpl) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) RootClass(org.hibernate.mapping.RootClass) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) SessionFactoryOptionsImpl(org.hibernate.boot.internal.SessionFactoryOptionsImpl) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) SimpleValue(org.hibernate.mapping.SimpleValue) HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) Filter(org.hibernate.Filter) 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) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) Test(org.junit.Test)

Aggregations

SessionFactoryOptions (org.hibernate.boot.spi.SessionFactoryOptions)4 InvocationHandler (java.lang.reflect.InvocationHandler)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 Filter (org.hibernate.Filter)3 MetadataSources (org.hibernate.boot.MetadataSources)3 SessionFactoryBuilderImpl (org.hibernate.boot.internal.SessionFactoryBuilderImpl)3 SessionFactoryOptionsImpl (org.hibernate.boot.internal.SessionFactoryOptionsImpl)3 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)3 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)3 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)3 TableFilter (org.hibernate.cfg.reveng.TableFilter)3 HQLQueryPlan (org.hibernate.engine.query.spi.HQLQueryPlan)3 SessionFactoryImpl (org.hibernate.internal.SessionFactoryImpl)3 Column (org.hibernate.mapping.Column)3 PersistentClass (org.hibernate.mapping.PersistentClass)3 PrimaryKey (org.hibernate.mapping.PrimaryKey)3 RootClass (org.hibernate.mapping.RootClass)3 SimpleValue (org.hibernate.mapping.SimpleValue)3 Table (org.hibernate.mapping.Table)3