use of org.hibernate.dialect.TimesTenDialect in project hibernate-orm by hibernate.
the class FooBarTest method testQueryCollectionOfValues.
@Test
public void testQueryCollectionOfValues() throws Exception {
Session s = openSession();
s.beginTransaction();
Baz baz = new Baz();
baz.setDefaults();
s.save(baz);
Glarch g = new Glarch();
Serializable gid = s.save(g);
if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && /*&& !(dialect instanceof MckoiDialect)*/
!(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof PointbaseDialect) && !(getDialect() instanceof TimesTenDialect)) {
s.createFilter(baz.getFooArray(), "where size(this.bytes) > 0").list();
s.createFilter(baz.getFooArray(), "where 0 in elements(this.bytes)").list();
}
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
s.createQuery("from Baz baz join baz.fooSet foo join foo.foo.foo foo2 where foo2.string = 'foo'").list();
s.createQuery("from Baz baz join baz.fooArray foo join foo.foo.foo foo2 where foo2.string = 'foo'").list();
s.createQuery("from Baz baz join baz.stringDateMap date where index(date) = 'foo'").list();
s.createQuery("from Baz baz join baz.topGlarchez g where index(g) = 'A'").list();
s.createQuery("select index(g) from Baz baz join baz.topGlarchez g").list();
assertTrue(s.createQuery("from Baz baz left join baz.stringSet").list().size() == 3);
baz = (Baz) s.createQuery("from Baz baz join baz.stringSet str where str='foo'").list().get(0);
assertTrue(!Hibernate.isInitialized(baz.getStringSet()));
baz = (Baz) s.createQuery("from Baz baz left join fetch baz.stringSet").list().get(0);
assertTrue(Hibernate.isInitialized(baz.getStringSet()));
assertTrue(s.createQuery("from Baz baz join baz.stringSet string where string='foo'").list().size() == 1);
assertTrue(s.createQuery("from Baz baz inner join baz.components comp where comp.name='foo'").list().size() == 1);
//List bss = s.find("select baz, ss from Baz baz inner join baz.stringSet ss");
s.createQuery("from Glarch g inner join g.fooComponents comp where comp.fee is not null").list();
s.createQuery("from Glarch g inner join g.fooComponents comp join comp.fee fee where fee.count > 0").list();
s.createQuery("from Glarch g inner join g.fooComponents comp where comp.fee.count is not null").list();
s.delete(baz);
s.delete(s.get(Glarch.class, gid));
s.getTransaction().commit();
s.close();
}
use of org.hibernate.dialect.TimesTenDialect in project hibernate-orm by hibernate.
the class SQLFunctionsTest method testSQLFunctions.
@Test
public void testSQLFunctions() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
Simple simple = new Simple(Long.valueOf(10));
simple.setName("Simple 1");
s.save(simple);
if (getDialect() instanceof DB2Dialect && !(getDialect() instanceof DerbyDialect)) {
s.createQuery("from Simple s where repeat('foo', 3) = 'foofoofoo'").list();
s.createQuery("from Simple s where repeat(s.name, 3) = 'foofoofoo'").list();
s.createQuery("from Simple s where repeat( lower(s.name), 3 + (1-1) / 2) = 'foofoofoo'").list();
}
assertTrue(s.createQuery("from Simple s where upper( s.name ) ='SIMPLE 1'").list().size() == 1);
if (!(getDialect() instanceof HSQLDialect)) {
assertTrue(s.createQuery("from Simple s where not( upper( s.name ) ='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar' )").list().size() == 1);
}
if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof SybaseDialect) && !(getDialect() instanceof SQLServerDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof InterbaseDialect) && !(getDialect() instanceof TimesTenDialect)) {
//My SQL has a funny concatenation operator
assertTrue(s.createQuery("from Simple s where lower( s.name || ' foo' ) ='simple 1 foo'").list().size() == 1);
}
if ((getDialect() instanceof SybaseDialect)) {
assertTrue(s.createQuery("from Simple s where lower( s.name + ' foo' ) ='simple 1 foo'").list().size() == 1);
}
if ((getDialect() instanceof MckoiDialect) || (getDialect() instanceof TimesTenDialect)) {
assertTrue(s.createQuery("from Simple s where lower( concat(s.name, ' foo') ) ='simple 1 foo'").list().size() == 1);
}
Simple other = new Simple(Long.valueOf(20));
other.setName("Simple 2");
other.setCount(12);
simple.setOther(other);
s.save(other);
//s.find("from Simple s where s.name ## 'cat|rat|bag'");
assertTrue(s.createQuery("from Simple s where upper( s.other.name ) ='SIMPLE 2'").list().size() == 1);
assertTrue(s.createQuery("from Simple s where not ( upper( s.other.name ) ='SIMPLE 2' )").list().size() == 0);
assertTrue(s.createQuery("select distinct s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2").list().size() == 1);
assertTrue(s.createQuery("select s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2 order by s.other.count").list().size() == 1);
Simple min = new Simple(Long.valueOf(30));
min.setCount(-1);
s.save(min);
if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect)) {
//My SQL has no subqueries
assertTrue(s.createQuery("from Simple s where s.count > ( select min(sim.count) from Simple sim )").list().size() == 2);
t.commit();
t = s.beginTransaction();
assertTrue(s.createQuery("from Simple s where s = some( select sim from Simple sim where sim.count>=0 ) and s.count >= 0").list().size() == 2);
assertTrue(s.createQuery("from Simple s where s = some( select sim from Simple sim where sim.other.count=s.other.count ) and s.other.count > 0").list().size() == 1);
}
Iterator iter = s.createQuery("select sum(s.count) from Simple s group by s.count having sum(s.count) > 10").iterate();
assertTrue(iter.hasNext());
assertEquals(Long.valueOf(12), iter.next());
assertTrue(!iter.hasNext());
if (!(getDialect() instanceof MySQLDialect)) {
iter = s.createQuery("select s.count from Simple s group by s.count having s.count = 12").iterate();
assertTrue(iter.hasNext());
}
s.createQuery("select s.id, s.count, count(t), max(t.date) from Simple s, Simple t where s.count = t.count group by s.id, s.count order by s.count").iterate();
Query q = s.createQuery("from Simple s");
q.setMaxResults(10);
assertTrue(q.list().size() == 3);
q = s.createQuery("from Simple s");
q.setMaxResults(1);
assertTrue(q.list().size() == 1);
q = s.createQuery("from Simple s");
assertTrue(q.list().size() == 3);
q = s.createQuery("from Simple s where s.name = ?");
q.setString(0, "Simple 1");
assertTrue(q.list().size() == 1);
q = s.createQuery("from Simple s where s.name = ? and upper(s.name) = ?");
q.setString(1, "SIMPLE 1");
q.setString(0, "Simple 1");
q.setFirstResult(0);
assertTrue(q.iterate().hasNext());
q = s.createQuery("from Simple s where s.name = :foo and upper(s.name) = :bar or s.count=:count or s.count=:count + 1");
q.setParameter("bar", "SIMPLE 1");
q.setString("foo", "Simple 1");
q.setInteger("count", 69);
q.setFirstResult(0);
assertTrue(q.iterate().hasNext());
q = s.createQuery("select s.id from Simple s");
q.setFirstResult(1);
q.setMaxResults(2);
iter = q.iterate();
int i = 0;
while (iter.hasNext()) {
assertTrue(iter.next() instanceof Long);
i++;
}
assertTrue(i == 2);
q = s.createQuery("select all s, s.other from Simple s where s = :s");
q.setParameter("s", simple);
assertTrue(q.list().size() == 1);
q = s.createQuery("from Simple s where s.name in (:name_list) and s.count > :count");
HashSet set = new HashSet();
set.add("Simple 1");
set.add("foo");
q.setParameterList("name_list", set);
q.setParameter("count", Integer.valueOf(-1));
assertTrue(q.list().size() == 1);
ScrollableResults sr = s.createQuery("from Simple s").scroll();
sr.next();
sr.get(0);
sr.close();
s.delete(other);
s.delete(simple);
s.delete(min);
t.commit();
s.close();
}
use of org.hibernate.dialect.TimesTenDialect in project hibernate-orm by hibernate.
the class SQLLoaderTest method testEscapedJDBC.
@Test
@SkipForDialect({ HSQLDialect.class, PostgreSQL81Dialect.class, PostgreSQLDialect.class })
public void testEscapedJDBC() throws HibernateException, SQLException {
Session session = openSession();
session.beginTransaction();
for (Object entity : session.createQuery("from A").list()) {
session.delete(entity);
}
A savedA = new A();
savedA.setName("Max");
session.save(savedA);
B savedB = new B();
session.save(savedB);
session.flush();
int count = session.createQuery("from A").list().size();
session.getTransaction().commit();
session.close();
session = openSession();
session.beginTransaction();
Query query;
if (getDialect() instanceof TimesTenDialect) {
// TimesTen does not permit general expressions (like UPPER) in the second part of a LIKE expression,
// so we execute a similar test
query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA where {fn ucase(name)} like 'MAX'").addEntity("a", A.class);
} else {
query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA where {fn ucase(name)} like {fn ucase('max')}").addEntity("a", A.class);
}
List list = query.list();
assertNotNull(list);
assertEquals(1, list.size());
session.getTransaction().commit();
session.close();
}
use of org.hibernate.dialect.TimesTenDialect in project hibernate-orm by hibernate.
the class FooBarTest method testQuery.
@Test
public void testQuery() throws Exception {
Session s = openSession();
Transaction txn = s.beginTransaction();
Foo foo = new Foo();
s.save(foo);
Foo foo2 = new Foo();
s.save(foo2);
foo.setFoo(foo2);
List list = s.createQuery("from Foo foo inner join fetch foo.foo").list();
Foo foof = (Foo) list.get(0);
assertTrue(Hibernate.isInitialized(foof.getFoo()));
s.createQuery("from Baz baz left outer join fetch baz.fooToGlarch").list();
list = s.createQuery("select foo, bar from Foo foo left outer join foo.foo bar where foo = ?").setParameter(0, foo, s.getTypeHelper().entity(Foo.class)).list();
Object[] row1 = (Object[]) list.get(0);
assertTrue(row1[0] == foo && row1[1] == foo2);
s.createQuery("select foo.foo.foo.string from Foo foo where foo.foo = 'bar'").list();
s.createQuery("select foo.foo.foo.foo.string from Foo foo where foo.foo = 'bar'").list();
s.createQuery("select foo from Foo foo where foo.foo.foo = 'bar'").list();
s.createQuery("select foo.foo.foo.foo.string from Foo foo where foo.foo.foo = 'bar'").list();
s.createQuery("select foo.foo.foo.string from Foo foo where foo.foo.foo.foo.string = 'bar'").list();
if (!(getDialect() instanceof HSQLDialect))
s.createQuery("select foo.string from Foo foo where foo.foo.foo.foo = foo.foo.foo").list();
s.createQuery("select foo.string from Foo foo where foo.foo.foo = 'bar' and foo.foo.foo.foo = 'baz'").list();
s.createQuery("select foo.string from Foo foo where foo.foo.foo.foo.string = 'a' and foo.foo.string = 'b'").list();
s.createQuery("from Bar bar, foo in elements(bar.baz.fooArray)").list();
if ((getDialect() instanceof DB2Dialect) && !(getDialect() instanceof DerbyDialect)) {
s.createQuery("from Foo foo where lower( foo.foo.string ) = 'foo'").list();
s.createQuery("from Foo foo where lower( (foo.foo.string || 'foo') || 'bar' ) = 'foo'").list();
s.createQuery("from Foo foo where repeat( (foo.foo.string || 'foo') || 'bar', 2 ) = 'foo'").list();
s.createQuery("from Bar foo where foo.foo.integer is not null and repeat( (foo.foo.string || 'foo') || 'bar', (5+5)/2 ) = 'foo'").list();
s.createQuery("from Bar foo where foo.foo.integer is not null or repeat( (foo.foo.string || 'foo') || 'bar', (5+5)/2 ) = 'foo'").list();
}
if (getDialect() instanceof SybaseDialect) {
s.createQuery("select baz from Baz as baz join baz.fooArray foo group by baz order by sum(foo.float)").iterate();
}
s.createQuery("from Foo as foo where foo.component.glarch.name is not null").list();
s.createQuery("from Foo as foo left outer join foo.component.glarch as glarch where glarch.name = 'foo'").list();
list = s.createQuery("from Foo").list();
assertTrue(list.size() == 2 && list.get(0) instanceof FooProxy);
list = s.createQuery("from Foo foo left outer join foo.foo").list();
assertTrue(list.size() == 2 && ((Object[]) list.get(0))[0] instanceof FooProxy);
s.createQuery("from Bar, Bar").list();
s.createQuery("from Foo, Bar").list();
s.createQuery("from Baz baz left join baz.fooToGlarch, Bar bar join bar.foo").list();
s.createQuery("from Baz baz left join baz.fooToGlarch join baz.fooSet").list();
s.createQuery("from Baz baz left join baz.fooToGlarch join fetch baz.fooSet foo left join fetch foo.foo").list();
list = s.createQuery("from Foo foo where foo.string='osama bin laden' and foo.boolean = true order by foo.string asc, foo.component.count desc").list();
assertTrue("empty query", list.size() == 0);
Iterator iter = s.createQuery("from Foo foo where foo.string='osama bin laden' order by foo.string asc, foo.component.count desc").iterate();
assertTrue("empty iterator", !iter.hasNext());
list = s.createQuery("select foo.foo from Foo foo").list();
assertTrue("query", list.size() == 1);
assertTrue("returned object", list.get(0) == foo.getFoo());
foo.getFoo().setFoo(foo);
foo.setString("fizard");
//The following test is disabled for databases with no subselects...also for Interbase (not sure why).
if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof PointbaseDialect) && !(getDialect() instanceof DerbyDialect)) {
// && !db.equals("weblogic") {
if (!(getDialect() instanceof InterbaseDialect)) {
list = s.createQuery("from Foo foo where ? = some elements(foo.component.importantDates)").setParameter(0, foo.getTimestamp(), StandardBasicTypes.DATE).list();
assertTrue("component query", list.size() == 2);
}
if (!(getDialect() instanceof TimesTenDialect)) {
//WAS: 4
list = s.createQuery("from Foo foo where size(foo.component.importantDates) = 3").list();
assertTrue("component query", list.size() == 2);
list = s.createQuery("from Foo foo where 0 = size(foo.component.importantDates)").list();
assertTrue("component query", list.size() == 0);
}
list = s.createQuery("from Foo foo where exists elements(foo.component.importantDates)").list();
assertTrue("component query", list.size() == 2);
s.createQuery("from Foo foo where not exists (from Bar bar where bar.id = foo.id)").list();
s.createQuery("select foo.foo from Foo foo where foo = some(select x from Foo x where x.long > foo.foo.long)").list();
s.createQuery("select foo.foo from Foo foo where foo = some(from Foo x where (x.long > foo.foo.long))").list();
if (!(getDialect() instanceof TimesTenDialect)) {
s.createQuery("select foo.foo from Foo foo where foo.long = some( select max(x.long) from Foo x where (x.long > foo.foo.long) group by x.foo )").list();
}
s.createQuery("from Foo foo where foo = some(select x from Foo x where x.long > foo.foo.long) and foo.foo.string='baz'").list();
s.createQuery("from Foo foo where foo.foo.string='baz' and foo = some(select x from Foo x where x.long > foo.foo.long)").list();
s.createQuery("from Foo foo where foo = some(select x from Foo x where x.long > foo.foo.long)").list();
s.createQuery("select foo.string, foo.date, foo.foo.string, foo.id from Foo foo, Baz baz where foo in elements(baz.fooArray) and foo.string like 'foo'").iterate();
}
list = s.createQuery("from Foo foo where foo.component.count is null order by foo.component.count").list();
assertTrue("component query", list.size() == 0);
list = s.createQuery("from Foo foo where foo.component.name='foo'").list();
assertTrue("component query", list.size() == 2);
list = s.createQuery("select distinct foo.component.name, foo.component.name from Foo foo where foo.component.name='foo'").list();
assertTrue("component query", list.size() == 1);
list = s.createQuery("select distinct foo.component.name, foo.id from Foo foo where foo.component.name='foo'").list();
assertTrue("component query", list.size() == 2);
list = s.createQuery("select foo.foo from Foo foo").list();
assertTrue("query", list.size() == 2);
list = s.createQuery("from Foo foo where foo.id=?").setParameter(0, foo.getKey(), StandardBasicTypes.STRING).list();
assertTrue("id query", list.size() == 1);
list = s.createQuery("from Foo foo where foo.key=?").setParameter(0, foo.getKey(), StandardBasicTypes.STRING).list();
assertTrue("named id query", list.size() == 1);
assertTrue("id query", list.get(0) == foo);
list = s.createQuery("select foo.foo from Foo foo where foo.string='fizard'").list();
assertTrue("query", list.size() == 1);
assertTrue("returned object", list.get(0) == foo.getFoo());
list = s.createQuery("from Foo foo where foo.component.subcomponent.name='bar'").list();
assertTrue("components of components", list.size() == 2);
list = s.createQuery("select foo.foo from Foo foo where foo.foo.id=?").setParameter(0, foo.getFoo().getKey(), StandardBasicTypes.STRING).list();
assertTrue("by id query", list.size() == 1);
assertTrue("by id returned object", list.get(0) == foo.getFoo());
s.createQuery("from Foo foo where foo.foo = ?").setParameter(0, foo.getFoo(), s.getTypeHelper().entity(Foo.class)).list();
assertTrue(!s.createQuery("from Bar bar where bar.string='a string' or bar.string='a string'").iterate().hasNext());
iter = s.createQuery("select foo.component.name, elements(foo.component.importantDates) from Foo foo where foo.foo.id=?").setParameter(0, foo.getFoo().getKey(), StandardBasicTypes.STRING).iterate();
int i = 0;
while (iter.hasNext()) {
i++;
Object[] row = (Object[]) iter.next();
assertTrue(row[0] instanceof String && (row[1] == null || row[1] instanceof Date));
}
//WAS: 4
assertTrue(i == 3);
iter = s.createQuery("select max( elements(foo.component.importantDates) ) from Foo foo group by foo.id").iterate();
assertTrue(iter.next() instanceof Date);
list = s.createQuery("select foo.foo.foo.foo from Foo foo, Foo foo2 where" + " foo = foo2.foo and not not ( not foo.string='fizard' )" + " and foo2.string between 'a' and (foo.foo.string)" + ((getDialect() instanceof HSQLDialect || getDialect() instanceof InterbaseDialect || getDialect() instanceof TimesTenDialect || getDialect() instanceof TeradataDialect) ? " and ( foo2.string in ( 'fiz', 'blah') or 1=1 )" : " and ( foo2.string in ( 'fiz', 'blah', foo.foo.string, foo.string, foo2.string ) )")).list();
assertTrue("complex query", list.size() == 1);
assertTrue("returned object", list.get(0) == foo);
foo.setString("from BoogieDown -tinsel town =!@#$^&*())");
list = s.createQuery("from Foo foo where foo.string='from BoogieDown -tinsel town =!@#$^&*())'").list();
assertTrue("single quotes", list.size() == 1);
list = s.createQuery("from Foo foo where not foo.string='foo''bar'").list();
assertTrue("single quotes", list.size() == 2);
list = s.createQuery("from Foo foo where foo.component.glarch.next is null").list();
assertTrue("query association in component", list.size() == 2);
Bar bar = new Bar();
Baz baz = new Baz();
baz.setDefaults();
bar.setBaz(baz);
baz.setManyToAny(new ArrayList());
baz.getManyToAny().add(bar);
baz.getManyToAny().add(foo);
s.save(bar);
s.save(baz);
list = s.createQuery(" from Bar bar where bar.baz.count=667 and bar.baz.count!=123 and not bar.baz.name='1-E-1'").list();
assertTrue("query many-to-one", list.size() == 1);
list = s.createQuery(" from Bar i where i.baz.name='Bazza'").list();
assertTrue("query many-to-one", list.size() == 1);
Iterator rs = s.createQuery("select count(distinct foo.foo) from Foo foo").iterate();
assertTrue("count", ((Long) rs.next()).longValue() == 2);
assertTrue(!rs.hasNext());
rs = s.createQuery("select count(foo.foo.boolean) from Foo foo").iterate();
assertTrue("count", ((Long) rs.next()).longValue() == 2);
assertTrue(!rs.hasNext());
rs = s.createQuery("select count(*), foo.int from Foo foo group by foo.int").iterate();
assertTrue("count(*) group by", ((Object[]) rs.next())[0].equals(new Long(3)));
assertTrue(!rs.hasNext());
rs = s.createQuery("select sum(foo.foo.int) from Foo foo").iterate();
assertTrue("sum", ((Long) rs.next()).longValue() == 4);
assertTrue(!rs.hasNext());
rs = s.createQuery("select count(foo) from Foo foo where foo.id=?").setParameter(0, foo.getKey(), StandardBasicTypes.STRING).iterate();
assertTrue("id query count", ((Long) rs.next()).longValue() == 1);
assertTrue(!rs.hasNext());
s.createQuery("from Foo foo where foo.boolean = ?").setParameter(0, new Boolean(true), StandardBasicTypes.BOOLEAN).list();
s.createQuery("select new Foo(fo.x) from Fo fo").list();
s.createQuery("select new Foo(fo.integer) from Foo fo").list();
list = s.createQuery("select new Foo(fo.x) from Foo fo").setCacheable(true).list();
assertTrue(list.size() == 3);
list = s.createQuery("select new Foo(fo.x) from Foo fo").setCacheable(true).list();
assertTrue(list.size() == 3);
rs = s.createQuery("select new Foo(fo.x) from Foo fo").iterate();
assertTrue("projection iterate (results)", rs.hasNext());
assertTrue("projection iterate (return check)", Foo.class.isAssignableFrom(rs.next().getClass()));
ScrollableResults sr = s.createQuery("select new Foo(fo.x) from Foo fo").scroll();
assertTrue("projection scroll (results)", sr.next());
assertTrue("projection scroll (return check)", Foo.class.isAssignableFrom(sr.get(0).getClass()));
list = s.createQuery("select foo.long, foo.component.name, foo, foo.foo from Foo foo").list();
rs = list.iterator();
int count = 0;
while (rs.hasNext()) {
count++;
Object[] row = (Object[]) rs.next();
assertTrue(row[0] instanceof Long);
assertTrue(row[1] instanceof String);
assertTrue(row[2] instanceof Foo);
assertTrue(row[3] instanceof Foo);
}
assertTrue(count != 0);
list = s.createQuery("select avg(foo.float), max(foo.component.name), count(distinct foo.id) from Foo foo").list();
rs = list.iterator();
count = 0;
while (rs.hasNext()) {
count++;
Object[] row = (Object[]) rs.next();
assertTrue(row[0] instanceof Double);
assertTrue(row[1] instanceof String);
assertTrue(row[2] instanceof Long);
}
assertTrue(count != 0);
list = s.createQuery("select foo.long, foo.component, foo, foo.foo from Foo foo").list();
rs = list.iterator();
count = 0;
while (rs.hasNext()) {
count++;
Object[] row = (Object[]) rs.next();
assertTrue(row[0] instanceof Long);
assertTrue(row[1] instanceof FooComponent);
assertTrue(row[2] instanceof Foo);
assertTrue(row[3] instanceof Foo);
}
assertTrue(count != 0);
s.save(new Holder("ice T"));
s.save(new Holder("ice cube"));
assertTrue(s.createQuery("from java.lang.Object as o").list().size() == 15);
assertTrue(s.createQuery("from Named").list().size() == 7);
assertTrue(s.createQuery("from Named n where n.name is not null").list().size() == 4);
iter = s.createQuery("from Named n").iterate();
while (iter.hasNext()) {
assertTrue(iter.next() instanceof Named);
}
s.save(new Holder("bar"));
iter = s.createQuery("from Named n0, Named n1 where n0.name = n1.name").iterate();
int cnt = 0;
while (iter.hasNext()) {
Object[] row = (Object[]) iter.next();
if (row[0] != row[1])
cnt++;
}
if (!(getDialect() instanceof HSQLDialect)) {
assertTrue(cnt == 2);
assertTrue(s.createQuery("from Named n0, Named n1 where n0.name = n1.name").list().size() == 7);
}
Query qu = s.createQuery("from Named n where n.name = :name");
qu.getReturnTypes();
qu.getNamedParameters();
iter = s.createQuery("from java.lang.Object").iterate();
int c = 0;
while (iter.hasNext()) {
iter.next();
c++;
}
assertTrue(c == 16);
s.createQuery("select baz.code, min(baz.count) from Baz baz group by baz.code").iterate();
iter = s.createQuery("selecT baz from Baz baz where baz.stringDateMap['foo'] is not null or baz.stringDateMap['bar'] = ?").setParameter(0, new Date(), StandardBasicTypes.DATE).iterate();
assertFalse(iter.hasNext());
list = s.createQuery("select baz from Baz baz where baz.stringDateMap['now'] is not null").list();
assertTrue(list.size() == 1);
list = s.createQuery("select baz from Baz baz where baz.stringDateMap['now'] is not null and baz.stringDateMap['big bang'] < baz.stringDateMap['now']").list();
assertTrue(list.size() == 1);
list = s.createQuery("select index(date) from Baz baz join baz.stringDateMap date").list();
System.out.println(list);
assertTrue(list.size() == 2);
s.createQuery("from Foo foo where foo.integer not between 1 and 5 and foo.string not in ('cde', 'abc') and foo.string is not null and foo.integer<=3").list();
s.createQuery("from Baz baz inner join baz.collectionComponent.nested.foos foo where foo.string is null").list();
if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof PointbaseDialect)) {
s.createQuery("from Baz baz inner join baz.fooSet where '1' in (from baz.fooSet foo where foo.string is not null)").list();
s.createQuery("from Baz baz where 'a' in elements(baz.collectionComponent.nested.foos) and 1.0 in elements(baz.collectionComponent.nested.floats)").list();
s.createQuery("from Baz baz where 'b' in elements(baz.collectionComponent.nested.foos) and 1.0 in elements(baz.collectionComponent.nested.floats)").list();
}
s.createQuery("from Foo foo join foo.foo where foo.foo in ('1','2','3')").list();
if (!(getDialect() instanceof HSQLDialect))
s.createQuery("from Foo foo left join foo.foo where foo.foo in ('1','2','3')").list();
s.createQuery("select foo.foo from Foo foo where foo.foo in ('1','2','3')").list();
s.createQuery("select foo.foo.string from Foo foo where foo.foo in ('1','2','3')").list();
s.createQuery("select foo.foo.string from Foo foo where foo.foo.string in ('1','2','3')").list();
s.createQuery("select foo.foo.long from Foo foo where foo.foo.string in ('1','2','3')").list();
s.createQuery("select count(*) from Foo foo where foo.foo.string in ('1','2','3') or foo.foo.long in (1,2,3)").list();
s.createQuery("select count(*) from Foo foo where foo.foo.string in ('1','2','3') group by foo.foo.long").list();
s.createQuery("from Foo foo1 left join foo1.foo foo2 left join foo2.foo where foo1.string is not null").list();
s.createQuery("from Foo foo1 left join foo1.foo.foo where foo1.string is not null").list();
s.createQuery("from Foo foo1 left join foo1.foo foo2 left join foo1.foo.foo foo3 where foo1.string is not null").list();
s.createQuery("select foo.formula from Foo foo where foo.formula > 0").list();
int len = s.createQuery("from Foo as foo join foo.foo as foo2 where foo2.id >'a' or foo2.id <'a'").list().size();
assertTrue(len == 2);
for (Object entity : s.createQuery("from Holder").list()) {
s.delete(entity);
}
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
baz = (Baz) s.createQuery("from Baz baz left outer join fetch baz.manyToAny").uniqueResult();
assertTrue(Hibernate.isInitialized(baz.getManyToAny()));
assertTrue(baz.getManyToAny().size() == 2);
BarProxy barp = (BarProxy) baz.getManyToAny().get(0);
s.createQuery("from Baz baz join baz.manyToAny").list();
assertTrue(s.createQuery("select baz from Baz baz join baz.manyToAny a where index(a) = 0").list().size() == 1);
FooProxy foop = (FooProxy) s.get(Foo.class, foo.getKey());
assertTrue(foop == baz.getManyToAny().get(1));
barp.setBaz(baz);
assertTrue(s.createQuery("select bar from Bar bar where bar.baz.stringDateMap['now'] is not null").list().size() == 1);
assertTrue(s.createQuery("select bar from Bar bar join bar.baz b where b.stringDateMap['big bang'] < b.stringDateMap['now'] and b.stringDateMap['now'] is not null").list().size() == 1);
assertTrue(s.createQuery("select bar from Bar bar where bar.baz.stringDateMap['big bang'] < bar.baz.stringDateMap['now'] and bar.baz.stringDateMap['now'] is not null").list().size() == 1);
list = s.createQuery("select foo.string, foo.component, foo.id from Bar foo").list();
assertTrue(((FooComponent) ((Object[]) list.get(0))[1]).getName().equals("foo"));
list = s.createQuery("select elements(baz.components) from Baz baz").list();
assertTrue(list.size() == 2);
list = s.createQuery("select bc.name from Baz baz join baz.components bc").list();
assertTrue(list.size() == 2);
//list = s.find("select bc from Baz baz join baz.components bc");
s.createQuery("from Foo foo where foo.integer < 10 order by foo.string").setMaxResults(12).list();
s.delete(barp);
s.delete(baz);
s.delete(foop.getFoo());
s.delete(foop);
txn.commit();
s.close();
}
use of org.hibernate.dialect.TimesTenDialect in project hibernate-orm by hibernate.
the class FumTest method testCompositeKeyPathExpressions.
@Test
@SkipForDialect(value = SybaseASE15Dialect.class, jiraKey = "HHH-3690")
public void testCompositeKeyPathExpressions() throws Exception {
Session s = openSession();
s.beginTransaction();
s.createQuery("select fum1.fo from Fum fum1 where fum1.fo.fum is not null").list();
s.createQuery("from Fum fum1 where fum1.fo.fum is not null order by fum1.fo.fum").list();
if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof PointbaseDialect)) {
s.createQuery("from Fum fum1 where exists elements(fum1.friends)").list();
if (!(getDialect() instanceof TimesTenDialect)) {
// can't execute because TimesTen can't do subqueries combined with aggreations
s.createQuery("from Fum fum1 where size(fum1.friends) = 0").list();
}
}
s.createQuery("select elements(fum1.friends) from Fum fum1").list();
s.createQuery("from Fum fum1, fr in elements( fum1.friends )").list();
s.getTransaction().commit();
s.close();
}
Aggregations