Search in sources :

Example 1 with SessionFactoryOptionsBuilder

use of org.hibernate.boot.internal.SessionFactoryOptionsBuilder 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);
        }
    });
    SessionFactoryImpl sfi = new SessionFactoryImpl(wrapper, new SessionFactoryOptionsBuilder(serviceRegistry));
    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 : RootClass(org.hibernate.mapping.RootClass) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryOptionsBuilder(org.hibernate.boot.internal.SessionFactoryOptionsBuilder) 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) Method(java.lang.reflect.Method) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) 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) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Column(org.hibernate.mapping.Column) 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) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Aggregations

InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Filter (org.hibernate.Filter)1 MetadataSources (org.hibernate.boot.MetadataSources)1 SessionFactoryOptionsBuilder (org.hibernate.boot.internal.SessionFactoryOptionsBuilder)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)1 TableFilter (org.hibernate.cfg.reveng.TableFilter)1 HQLQueryPlan (org.hibernate.engine.query.spi.HQLQueryPlan)1 SessionFactoryImpl (org.hibernate.internal.SessionFactoryImpl)1 Column (org.hibernate.mapping.Column)1 PersistentClass (org.hibernate.mapping.PersistentClass)1 PrimaryKey (org.hibernate.mapping.PrimaryKey)1 RootClass (org.hibernate.mapping.RootClass)1 SimpleValue (org.hibernate.mapping.SimpleValue)1 Table (org.hibernate.mapping.Table)1 POJOClass (org.hibernate.tool.hbm2x.pojo.POJOClass)1 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)1