use of org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan 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);
}
use of org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateHQLQueryPlan.
@Test
public void testCreateHQLQueryPlan() {
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
Mappings mappings = configuration.createMappings();
Table t = new Table("FOO");
Column c = new Column("foo");
t.addColumn(c);
PrimaryKey key = new PrimaryKey();
key.addColumn(c);
t.setPrimaryKey(key);
SimpleValue sv = new SimpleValue();
sv.setNullValue("null");
sv.setTypeName(Integer.class.getName());
sv.setTable(t);
sv.addColumn(c);
RootClass rc = new RootClass();
rc.setEntityName("foo");
rc.setIdentifier(sv);
rc.setTable(t);
mappings.addClass(rc);
SessionFactoryImplementor sfi = new SessionFactoryImpl(configuration, null, configuration.buildSettings(), null, null);
HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, Collections.emptyMap(), sfi);
IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
Assert.assertSame(hqlQueryPlan, ((IFacade) facade).getTarget());
}
use of org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan 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());
}
use of org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan 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());
}
use of org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan 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());
}
Aggregations