use of org.hibernate.dialect.SAPDBDialect in project hibernate-orm by hibernate.
the class FooBarTest method testPersistCollections.
@Test
public void testPersistCollections() throws Exception {
Session s = openSession();
Transaction txn = s.beginTransaction();
assertEquals(0l, s.createQuery("select count(*) from Bar").iterate().next());
assertEquals(0l, s.createQuery("select count(*) from Bar b").iterate().next());
assertFalse(s.createQuery("from Glarch g").iterate().hasNext());
Baz baz = new Baz();
s.save(baz);
baz.setDefaults();
baz.setStringArray(new String[] { "stuff" });
Set bars = new HashSet();
bars.add(new Bar());
baz.setCascadingBars(bars);
HashMap sgm = new HashMap();
sgm.put("a", new Glarch());
sgm.put("b", new Glarch());
baz.setStringGlarchMap(sgm);
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
assertEquals(1L, ((Long) s.createQuery("select count(*) from Bar").iterate().next()).longValue());
baz = (Baz) ((Object[]) s.createQuery("select baz, baz from Baz baz").list().get(0))[1];
assertTrue(baz.getCascadingBars().size() == 1);
//System.out.println( s.print(baz) );
Foo foo = new Foo();
s.save(foo);
Foo foo2 = new Foo();
s.save(foo2);
baz.setFooArray(new Foo[] { foo, foo, null, foo2 });
baz.getFooSet().add(foo);
baz.getCustoms().add(new String[] { "new", "custom" });
baz.setStringArray(null);
baz.getStringList().set(0, "new value");
baz.setStringSet(new TreeSet());
Time time = new java.sql.Time(12345);
baz.getTimeArray()[2] = time;
//System.out.println(time);
assertTrue(baz.getStringGlarchMap().size() == 1);
//The following test is disabled databases with no subselects
if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && !(getDialect() instanceof PointbaseDialect)) {
List list = s.createQuery("select foo from Foo foo, Baz baz where foo in elements(baz.fooArray) and 3 = some elements(baz.intArray) and 4 > all indices(baz.intArray)").list();
assertTrue("collection.elements find", list.size() == 2);
}
if (!(getDialect() instanceof SAPDBDialect)) {
// SAPDB doesn't like distinct with binary type
List list = s.createQuery("select distinct foo from Baz baz join baz.fooArray foo").list();
assertTrue("collection.elements find", list.size() == 2);
}
List list = s.createQuery("select foo from Baz baz join baz.fooSet foo").list();
assertTrue("association.elements find", list.size() == 1);
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
assertEquals(1, ((Long) s.createQuery("select count(*) from Bar").iterate().next()).longValue());
baz = (Baz) s.createQuery("select baz from Baz baz order by baz").list().get(0);
assertTrue("collection of custom types - added element", baz.getCustoms().size() == 4 && baz.getCustoms().get(0) != null);
assertTrue("component of component in collection", baz.getComponents()[1].getSubcomponent() != null);
assertTrue(baz.getComponents()[1].getBaz() == baz);
assertTrue("set of objects", ((FooProxy) baz.getFooSet().iterator().next()).getKey().equals(foo.getKey()));
assertTrue("collection removed", baz.getStringArray().length == 0);
assertTrue("changed element", baz.getStringList().get(0).equals("new value"));
assertTrue("replaced set", baz.getStringSet().size() == 0);
assertTrue("array element change", baz.getTimeArray()[2] != null);
assertTrue(baz.getCascadingBars().size() == 1);
//System.out.println( s.print(baz) );
baz.getStringSet().add("two");
baz.getStringSet().add("one");
baz.getBag().add("three");
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
baz = (Baz) s.createQuery("select baz from Baz baz order by baz").list().get(0);
assertTrue(baz.getStringSet().size() == 2);
assertTrue(baz.getStringSet().first().equals("one"));
assertTrue(baz.getStringSet().last().equals("two"));
assertTrue(baz.getBag().size() == 5);
baz.getStringSet().remove("two");
baz.getBag().remove("duplicate");
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
assertEquals(1, ((Long) s.createQuery("select count(*) from Bar").iterate().next()).longValue());
baz = (Baz) s.load(Baz.class, baz.getCode());
assertTrue(baz.getCascadingBars().size() == 1);
Bar bar = new Bar();
Bar bar2 = new Bar();
s.save(bar);
s.save(bar2);
baz.setTopFoos(new HashSet());
baz.getTopFoos().add(bar);
baz.getTopFoos().add(bar2);
assertTrue(baz.getCascadingBars().size() == 1);
baz.setTopGlarchez(new TreeMap());
GlarchProxy g = new Glarch();
s.save(g);
baz.getTopGlarchez().put('G', g);
HashMap map = new HashMap();
map.put(bar, g);
map.put(bar2, g);
baz.setFooToGlarch(map);
map = new HashMap();
map.put(new FooComponent("name", 123, null, null), bar);
map.put(new FooComponent("nameName", 12, null, null), bar);
baz.setFooComponentToFoo(map);
map = new HashMap();
map.put(bar, g);
baz.setGlarchToFoo(map);
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
baz = (Baz) s.createQuery("select baz from Baz baz order by baz").list().get(0);
assertTrue(baz.getCascadingBars().size() == 1);
Session s2 = openSession();
Transaction txn2 = s2.beginTransaction();
assertEquals(3, ((Long) s2.createQuery("select count(*) from Bar").iterate().next()).longValue());
Baz baz2 = (Baz) s2.createQuery("select baz from Baz baz order by baz").list().get(0);
Object o = baz2.getFooComponentToFoo().get(new FooComponent("name", 123, null, null));
assertTrue(o == baz2.getFooComponentToFoo().get(new FooComponent("nameName", 12, null, null)) && o != null);
txn2.commit();
s2.close();
assertTrue(Hibernate.isInitialized(baz.getFooToGlarch()));
assertTrue(baz.getTopFoos().size() == 2);
assertTrue(baz.getTopGlarchez().size() == 1);
assertTrue(baz.getTopFoos().iterator().next() != null);
assertTrue(baz.getStringSet().size() == 1);
assertTrue(baz.getBag().size() == 4);
assertTrue(baz.getFooToGlarch().size() == 2);
assertTrue(baz.getFooComponentToFoo().size() == 2);
assertTrue(baz.getGlarchToFoo().size() == 1);
Iterator iter = baz.getFooToGlarch().keySet().iterator();
for (int i = 0; i < 2; i++) assertTrue(iter.next() instanceof BarProxy);
FooComponent fooComp = (FooComponent) baz.getFooComponentToFoo().keySet().iterator().next();
assertTrue(((fooComp.getCount() == 123 && fooComp.getName().equals("name")) || (fooComp.getCount() == 12 && fooComp.getName().equals("nameName"))) && (baz.getFooComponentToFoo().get(fooComp) instanceof BarProxy));
Glarch g2 = new Glarch();
s.save(g2);
g = (GlarchProxy) baz.getTopGlarchez().get('G');
baz.getTopGlarchez().put('H', g);
baz.getTopGlarchez().put('G', g2);
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
baz = (Baz) s.load(Baz.class, baz.getCode());
assertTrue(baz.getTopGlarchez().size() == 2);
assertTrue(baz.getCascadingBars().size() == 1);
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
assertEquals(3, ((Long) s.createQuery("select count(*) from Bar").iterate().next()).longValue());
baz = (Baz) s.createQuery("select baz from Baz baz order by baz").list().get(0);
assertTrue(baz.getTopGlarchez().size() == 2);
assertTrue(baz.getCascadingBars().size() == 1);
txn.commit();
final Session s3 = (Session) SerializationHelper.deserialize(SerializationHelper.serialize(s));
s.close();
txn2 = s3.beginTransaction();
baz = (Baz) s3.load(Baz.class, baz.getCode());
assertEquals(3, ((Long) s3.createQuery("select count(*) from Bar").iterate().next()).longValue());
s3.delete(baz);
s3.delete(baz.getTopGlarchez().get('G'));
s3.delete(baz.getTopGlarchez().get('H'));
int rows = s3.doReturningWork(new AbstractReturningWork<Integer>() {
@Override
public Integer execute(Connection connection) throws SQLException {
final String sql = "update " + getDialect().openQuote() + "glarchez" + getDialect().closeQuote() + " set baz_map_id=null where baz_map_index='a'";
Statement st = connection.createStatement();
return st.executeUpdate(sql);
}
});
assertTrue(rows == 1);
assertEquals(2, doDelete(s3, "from Bar bar"));
FooProxy[] arr = baz.getFooArray();
assertTrue("new array of objects", arr.length == 4 && arr[1].getKey().equals(foo.getKey()));
for (int i = 1; i < arr.length; i++) {
if (arr[i] != null)
s3.delete(arr[i]);
}
//nonexistent
s3.load(Qux.class, new Long(666));
assertEquals(1, doDelete(s3, "from Glarch g"));
txn2.commit();
s3.disconnect();
Session s4 = (Session) SerializationHelper.deserialize(SerializationHelper.serialize(s3));
s3.close();
//s3.reconnect();
//nonexistent
assertTrue(s4.load(Qux.class, new Long(666)) != null);
//s3.disconnect();
s4.close();
}
use of org.hibernate.dialect.SAPDBDialect 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.SAPDBDialect in project hibernate-orm by hibernate.
the class MasterDetailTest method testCollectionQuery.
@Test
public void testCollectionQuery() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof MckoiDialect)) {
s.createQuery("FROM Master m WHERE NOT EXISTS ( FROM m.details d WHERE NOT d.i=5 )").iterate();
s.createQuery("FROM Master m WHERE NOT 5 IN ( SELECT d.i FROM m.details AS d )").iterate();
}
s.createQuery("SELECT m FROM Master m JOIN m.details d WHERE d.i=5").iterate();
s.createQuery("SELECT m FROM Master m JOIN m.details d WHERE d.i=5").list();
s.createQuery("SELECT m.id FROM Master AS m JOIN m.details AS d WHERE d.i=5").list();
t.commit();
s.close();
}
use of org.hibernate.dialect.SAPDBDialect in project hibernate-orm by hibernate.
the class MasterDetailTest method testMasterDetail.
@Test
public void testMasterDetail() throws Exception {
if (getDialect() instanceof HSQLDialect)
return;
Session s = openSession();
Transaction t = s.beginTransaction();
Master master = new Master();
assertTrue("save returned native id", s.save(master) != null);
Serializable mid = s.getIdentifier(master);
Detail d1 = new Detail();
d1.setMaster(master);
Serializable did = s.save(d1);
Detail d2 = new Detail();
d2.setI(12);
d2.setMaster(master);
assertTrue("generated id returned", s.save(d2) != null);
master.addDetail(d1);
master.addDetail(d2);
if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof org.hibernate.dialect.TimesTenDialect)) {
assertTrue("query", s.createQuery("from Detail d, Master m where m = d.master and size(m.outgoing) = 0 and size(m.incoming) = 0").list().size() == 2);
}
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
master = new Master();
s.load(master, mid);
assertTrue(master.getDetails().size() == 2);
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
master = (Master) s.load(Master.class, mid);
Iterator iter = master.getDetails().iterator();
int i = 0;
while (iter.hasNext()) {
Detail d = (Detail) iter.next();
assertTrue("master-detail", d.getMaster() == master);
i++;
}
assertTrue("master-detail", i == 2);
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
assertTrue(s.createQuery("select elements(master.details) from Master master").list().size() == 2);
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
List list = s.createQuery("from Master m left join fetch m.details").list();
Master m = (Master) list.get(0);
assertTrue(Hibernate.isInitialized(m.getDetails()));
assertTrue(m.getDetails().size() == 2);
list = s.createQuery("from Detail d inner join fetch d.master").list();
Detail dt = (Detail) list.get(0);
Serializable dtid = s.getIdentifier(dt);
assertTrue(dt.getMaster() == m);
//assertTrue(m.getAllDetails().size()==2);
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
list = s.createQuery("select m from Master m1, Master m left join fetch m.details where m.name=m1.name").list();
assertTrue(Hibernate.isInitialized(((Master) list.get(0)).getDetails()));
dt = (Detail) s.load(Detail.class, dtid);
assertTrue(((Master) list.get(0)).getDetails().contains(dt));
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
list = s.createQuery("select m, m1.name from Master m1, Master m left join fetch m.details where m.name=m1.name").list();
assertTrue(Hibernate.isInitialized(((Master) ((Object[]) list.get(0))[0]).getDetails()));
dt = (Detail) s.load(Detail.class, dtid);
assertTrue(((Master) ((Object[]) list.get(0))[0]).getDetails().contains(dt));
//list = s.find("select m from Master m, Master m2 left join fetch m.details");
// depracted syntax
// list = s.find("select m.id from Master m inner join fetch m.details");
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
Detail dd = (Detail) s.load(Detail.class, did);
master = dd.getMaster();
assertTrue("detail-master", master.getDetails().contains(dd));
assertTrue(s.createFilter(master.getDetails(), "order by this.i desc").list().size() == 2);
assertTrue(s.createFilter(master.getDetails(), "select this where this.id > -1").list().size() == 2);
Query q = s.createFilter(master.getDetails(), "where this.id > :id");
q.setInteger("id", -1);
assertTrue(q.list().size() == 2);
q = s.createFilter(master.getDetails(), "where this.id > :id1 and this.id < :id2");
q.setInteger("id1", -1);
q.setInteger("id2", 99999999);
assertTrue(q.list().size() == 2);
q.setInteger("id2", -1);
assertTrue(q.list().size() == 0);
q = s.createFilter(master.getDetails(), "where this.id in (:ids)");
list = new ArrayList();
list.add(did);
list.add(new Long(-1));
q.setParameterList("ids", list);
assertTrue(q.list().size() == 1);
assertTrue(q.iterate().hasNext());
assertTrue(s.createFilter(master.getDetails(), "where this.id > -1").list().size() == 2);
assertTrue(s.createFilter(master.getDetails(), "select this.master where this.id > -1").list().size() == 2);
assertTrue(s.createFilter(master.getDetails(), "select m from Master m where this.id > -1 and this.master=m").list().size() == 2);
assertTrue(s.createFilter(master.getIncoming(), "where this.id > -1 and this.name is not null").list().size() == 0);
assertTrue(s.createFilter(master.getDetails(), "select max(this.i)").iterate().next() instanceof Integer);
assertTrue(s.createFilter(master.getDetails(), "select max(this.i) group by this.id").iterate().next() instanceof Integer);
assertTrue(s.createFilter(master.getDetails(), "select count(*)").iterate().next() instanceof Long);
assertTrue(s.createFilter(master.getDetails(), "select this.master").list().size() == 2);
assertTrue(s.createFilter(master.getMoreDetails(), "").list().size() == 0);
assertTrue(s.createFilter(master.getIncoming(), "").list().size() == 0);
Query f = s.createFilter(master.getDetails(), "select max(this.i) where this.i < :top and this.i>=:bottom");
f.setInteger("top", 100);
f.setInteger("bottom", 0);
assertEquals(f.iterate().next(), new Integer(12));
f.setInteger("top", 2);
assertEquals(f.iterate().next(), new Integer(0));
f = s.createFilter(master.getDetails(), "select max(this.i) where this.i not in (:list)");
Collection coll = new ArrayList();
coll.add(new Integer(-666));
coll.add(new Integer(22));
coll.add(new Integer(0));
f.setParameterList("list", coll);
assertEquals(f.iterate().next(), new Integer(12));
f = s.createFilter(master.getDetails(), "select max(this.i) where this.i not in (:list) and this.master.name = :listy2");
f.setParameterList("list", coll);
f.setParameter("listy2", master.getName());
assertEquals(f.iterate().next(), new Integer(12));
iter = master.getDetails().iterator();
i = 0;
while (iter.hasNext()) {
Detail d = (Detail) iter.next();
assertTrue("master-detail", d.getMaster() == master);
s.delete(d);
i++;
}
assertTrue("master-detail", i == 2);
s.delete(master);
t.commit();
s.close();
}
use of org.hibernate.dialect.SAPDBDialect in project hibernate-orm by hibernate.
the class FooBarTest method testCollectionsInSelect.
@Test
public void testCollectionsInSelect() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
Foo[] foos = new Foo[] { null, new Foo() };
s.save(foos[1]);
Baz baz = new Baz();
baz.setDefaults();
baz.setFooArray(foos);
s.save(baz);
Baz baz2 = new Baz();
baz2.setDefaults();
s.save(baz2);
Bar bar = new Bar();
bar.setBaz(baz);
s.save(bar);
List list = s.createQuery("select new Result(foo.string, foo.long, foo.integer) from Foo foo").list();
assertTrue(list.size() == 2 && (list.get(0) instanceof Result) && (list.get(1) instanceof Result));
/*list = s.find("select new Result( baz.name, foo.long, count(elements(baz.fooArray)) ) from Baz baz join baz.fooArray foo group by baz.name, foo.long");
assertTrue( list.size()==1 && ( list.get(0) instanceof Result ) );
Result r = ((Result) list.get(0) );
assertEquals( r.getName(), baz.getName() );
assertEquals( r.getCount(), 1 );
assertEquals( r.getAmount(), foos[1].getLong().longValue() );*/
list = s.createQuery("select new Result( baz.name, max(foo.long), count(foo) ) from Baz baz join baz.fooArray foo group by baz.name").list();
assertTrue(list.size() == 1 && (list.get(0) instanceof Result));
Result r = ((Result) list.get(0));
assertEquals(r.getName(), baz.getName());
assertEquals(r.getCount(), 1);
assertTrue(r.getAmount() > 696969696969696000l);
//The following test is disabled for databases with no subselects...also for Interbase (not sure why).
if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && /*&& !(dialect instanceof MckoiDialect)*/
!(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof PointbaseDialect)) {
s.createQuery("select count(*) from Baz as baz where 1 in indices(baz.fooArray)").list();
s.createQuery("select count(*) from Bar as bar where 'abc' in elements(bar.baz.fooArray)").list();
s.createQuery("select count(*) from Bar as bar where 1 in indices(bar.baz.fooArray)").list();
if (!(getDialect() instanceof DB2Dialect) && !(getDialect() instanceof Oracle8iDialect) && !(getDialect() instanceof SybaseDialect) && !(getDialect() instanceof Sybase11Dialect) && !(getDialect() instanceof SybaseASE15Dialect) && !(getDialect() instanceof PostgreSQLDialect) && !(getDialect() instanceof PostgreSQL81Dialect) && !(getDialect() instanceof AbstractHANADialect)) {
// SybaseAnywhereDialect supports implicit conversions from strings to ints
s.createQuery("select count(*) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)").list();
s.createQuery("select max( elements(bar.baz.fooArray) ) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)").list();
}
s.createQuery("select count(*) from Bar as bar where '1' in (from bar.component.glarch.proxyArray g where g.name='foo')").list();
s.createQuery("select count(*) from Bar as bar where '1' in (from bar.component.glarch.proxyArray g where g.name='foo')").list();
s.createQuery("select count(*) from Bar as bar left outer join bar.component.glarch.proxyArray as pg where '1' in (from bar.component.glarch.proxyArray)").list();
}
list = s.createQuery("from Baz baz left join baz.fooToGlarch join fetch baz.fooArray foo left join fetch foo.foo").list();
assertTrue(list.size() == 1 && ((Object[]) list.get(0)).length == 2);
s.createQuery("select baz.name from Bar bar inner join bar.baz baz inner join baz.fooSet foo where baz.name = bar.string").list();
s.createQuery("SELECT baz.name FROM Bar AS bar INNER JOIN bar.baz AS baz INNER JOIN baz.fooSet AS foo WHERE baz.name = bar.string").list();
if (!(getDialect() instanceof HSQLDialect))
s.createQuery("select baz.name from Bar bar join bar.baz baz left outer join baz.fooSet foo where baz.name = bar.string").list();
s.createQuery("select baz.name from Bar bar join bar.baz baz join baz.fooSet foo where baz.name = bar.string").list();
s.createQuery("SELECT baz.name FROM Bar AS bar JOIN bar.baz AS baz JOIN baz.fooSet AS foo WHERE baz.name = bar.string").list();
if (!(getDialect() instanceof HSQLDialect)) {
s.createQuery("select baz.name from Bar bar left join bar.baz baz left join baz.fooSet foo where baz.name = bar.string").list();
s.createQuery("select foo.string from Bar bar left join bar.baz.fooSet foo where bar.string = foo.string").list();
}
s.createQuery("select baz.name from Bar bar left join bar.baz baz left join baz.fooArray foo where baz.name = bar.string").list();
s.createQuery("select foo.string from Bar bar left join bar.baz.fooArray foo where bar.string = foo.string").list();
s.createQuery("select bar.string, foo.string from Bar bar inner join bar.baz as baz inner join baz.fooSet as foo where baz.name = 'name'").list();
s.createQuery("select foo from Bar bar inner join bar.baz as baz inner join baz.fooSet as foo").list();
s.createQuery("select foo from Bar bar inner join bar.baz.fooSet as foo").list();
s.createQuery("select bar.string, foo.string from Bar bar join bar.baz as baz join baz.fooSet as foo where baz.name = 'name'").list();
s.createQuery("select foo from Bar bar join bar.baz as baz join baz.fooSet as foo").list();
s.createQuery("select foo from Bar bar join bar.baz.fooSet as foo").list();
assertTrue(s.createQuery("from Bar bar join bar.baz.fooArray foo").list().size() == 1);
assertTrue(s.createQuery("from Bar bar join bar.baz.fooSet foo").list().size() == 0);
assertTrue(s.createQuery("from Bar bar join bar.baz.fooArray foo").list().size() == 1);
s.delete(bar);
if (getDialect() instanceof DB2Dialect || getDialect() instanceof PostgreSQLDialect || getDialect() instanceof PostgreSQL81Dialect) {
s.createQuery("select one from One one join one.manies many group by one order by count(many)").iterate();
s.createQuery("select one from One one join one.manies many group by one having count(many) < 5").iterate();
}
s.createQuery("from One one join one.manies many where one.id = 1 and many.id = 1").list();
s.createQuery("select one.id, elements(one.manies) from One one").iterate();
s.createQuery("select max( elements(one.manies) ) from One one").iterate();
s.createQuery("select one, elements(one.manies) from One one").list();
Iterator iter = s.createQuery("select elements(baz.fooArray) from Baz baz where baz.id=?").setParameter(0, baz.getCode(), StandardBasicTypes.STRING).iterate();
assertTrue(iter.next() == foos[1] && !iter.hasNext());
list = s.createQuery("select elements(baz.fooArray) from Baz baz where baz.id=?").setParameter(0, baz.getCode(), StandardBasicTypes.STRING).list();
assertEquals(1, list.size());
iter = s.createQuery("select indices(baz.fooArray) from Baz baz where baz.id=?").setParameter(0, baz.getCode(), StandardBasicTypes.STRING).iterate();
assertTrue(iter.next().equals(new Integer(1)) && !iter.hasNext());
iter = s.createQuery("select size(baz.stringSet) from Baz baz where baz.id=?").setParameter(0, baz.getCode(), StandardBasicTypes.STRING).iterate();
assertEquals(new Integer(3), iter.next());
s.createQuery("from Foo foo where foo.component.glarch.id is not null").list();
iter = s.createQuery("select baz, size(baz.stringSet), count( distinct elements(baz.stringSet) ), max( elements(baz.stringSet) ) from Baz baz group by baz").iterate();
while (iter.hasNext()) {
Object[] arr = (Object[]) iter.next();
log.info(arr[0] + " " + arr[1] + " " + arr[2] + " " + arr[3]);
}
s.delete(baz);
s.delete(baz2);
s.delete(foos[1]);
t.commit();
s.close();
}
Aggregations