Search in sources :

Example 41 with HQLQueryPlan

use of org.hibernate.engine.query.spi.HQLQueryPlan in project jbosstools-hibernate by jbosstools.

the class ServiceImpl method newHQLQueryPlan.

@Override
public IHQLQueryPlan newHQLQueryPlan(String query, boolean shallow, ISessionFactory sessionFactory) {
    SessionFactoryImpl factory = (SessionFactoryImpl) ((IFacade) sessionFactory).getTarget();
    Map<String, Filter> enabledFilters = Collections.emptyMap();
    HQLQueryPlan queryPlan = new HQLQueryPlan(query, shallow, enabledFilters, factory);
    return facadeFactory.createHQLQueryPlan(queryPlan);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) Filter(org.hibernate.Filter) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl)

Example 42 with HQLQueryPlan

use of org.hibernate.engine.query.spi.HQLQueryPlan in project jbosstools-hibernate by jbosstools.

the class ServiceImpl method newHQLQueryPlan.

@Override
public IHQLQueryPlan newHQLQueryPlan(String query, boolean shallow, ISessionFactory sessionFactory) {
    assert sessionFactory instanceof IFacade;
    SessionFactoryImpl factory = (SessionFactoryImpl) ((IFacade) sessionFactory).getTarget();
    Map<String, Filter> enabledFilters = Collections.emptyMap();
    HQLQueryPlan queryPlan = new HQLQueryPlan(query, shallow, enabledFilters, factory);
    return facadeFactory.createHQLQueryPlan(queryPlan);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) Filter(org.hibernate.Filter) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl)

Example 43 with HQLQueryPlan

use of org.hibernate.engine.query.spi.HQLQueryPlan 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(AvailableSettings.DIALECT, TestDialect.class.getName());
    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);
        }
    });
    SessionFactoryBuilder sfb = new SessionFactoryBuilderImpl(wrapper);
    SessionFactoryImpl sfi = (SessionFactoryImpl) sfb.build();
    Map<String, Filter> filters = Collections.emptyMap();
    HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, filters, sfi);
    IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
    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) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) 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) 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.jupiter.api.Test)

Example 44 with HQLQueryPlan

use of org.hibernate.engine.query.spi.HQLQueryPlan in project jbosstools-hibernate by jbosstools.

the class ServiceImplTest method testNewHQLQueryPlan.

@Test
public void testNewHQLQueryPlan() throws Exception {
    IConfiguration configuration = service.newDefaultConfiguration();
    configuration.setProperty(AvailableSettings.DIALECT, TestDialect.class.getName());
    File testFile = File.createTempFile("test", "tmp");
    testFile.deleteOnExit();
    FileWriter fileWriter = new FileWriter(testFile);
    fileWriter.write(TEST_HBM_STRING);
    fileWriter.close();
    configuration.addFile(testFile);
    ISessionFactory sfi = configuration.buildSessionFactory();
    IHQLQueryPlan queryPlan = service.newHQLQueryPlan("from ServiceImplTest$Foo", true, sfi);
    assertNotNull(queryPlan);
    Object target = ((IFacade) queryPlan).getTarget();
    assertNotNull(target);
    assertTrue(target instanceof HQLQueryPlan);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) FileWriter(java.io.FileWriter) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 45 with HQLQueryPlan

use of org.hibernate.engine.query.spi.HQLQueryPlan in project jbosstools-hibernate by jbosstools.

the class ServiceImplTest method testNewHQLQueryPlan.

@Test
public void testNewHQLQueryPlan() throws Exception {
    IConfiguration configuration = service.newDefaultConfiguration();
    configuration.setProperty(AvailableSettings.DIALECT, TestDialect.class.getName());
    File testFile = File.createTempFile("test", "tmp");
    testFile.deleteOnExit();
    FileWriter fileWriter = new FileWriter(testFile);
    fileWriter.write(TEST_HBM_STRING);
    fileWriter.close();
    configuration.addFile(testFile);
    ISessionFactory sfi = configuration.buildSessionFactory();
    IHQLQueryPlan queryPlan = service.newHQLQueryPlan("from ServiceImplTest$Foo", true, sfi);
    assertNotNull(queryPlan);
    Object target = ((IFacade) queryPlan).getTarget();
    assertNotNull(target);
    assertTrue(target instanceof HQLQueryPlan);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) FileWriter(java.io.FileWriter) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

HQLQueryPlan (org.hibernate.engine.query.spi.HQLQueryPlan)46 IHQLQueryPlan (org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan)27 Filter (org.hibernate.Filter)18 TableFilter (org.hibernate.cfg.reveng.TableFilter)18 ITableFilter (org.jboss.tools.hibernate.runtime.spi.ITableFilter)18 Test (org.junit.jupiter.api.Test)18 SessionFactoryImpl (org.hibernate.internal.SessionFactoryImpl)16 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)11 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)11 File (java.io.File)9 FileWriter (java.io.FileWriter)9 Column (org.hibernate.mapping.Column)9 PrimaryKey (org.hibernate.mapping.PrimaryKey)9 RootClass (org.hibernate.mapping.RootClass)9 SimpleValue (org.hibernate.mapping.SimpleValue)9 Table (org.hibernate.mapping.Table)9 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)9 IPrimaryKey (org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)9 ISessionFactory (org.jboss.tools.hibernate.runtime.spi.ISessionFactory)9 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)9