Search in sources :

Example 1 with TeradataDialect

use of org.hibernate.dialect.TeradataDialect in project hibernate-orm by hibernate.

the class ASTParserLoadingTest method testStr.

@Test
public void testStr() {
    Session session = openSession();
    Transaction txn = session.beginTransaction();
    Animal an = new Animal();
    an.setBodyWeight(123.45f);
    session.persist(an);
    String str = (String) session.createQuery("select str(an.bodyWeight) from Animal an where str(an.bodyWeight) like '%1%'").uniqueResult();
    if ((getDialect() instanceof DB2Dialect || getDialect() instanceof TeradataDialect) && !(getDialect() instanceof DerbyDialect)) {
        assertTrue(str.startsWith("1.234"));
    } else //noinspection deprecation
    if (getDialect() instanceof SybaseDialect || getDialect() instanceof Sybase11Dialect || getDialect() instanceof SybaseASE15Dialect || getDialect() instanceof SybaseAnywhereDialect || getDialect() instanceof SQLServerDialect) {
        // str(val) on sybase assumes a default of 10 characters with no decimal point or decimal values
        // str(val) on sybase result is right-justified
        assertEquals(str.length(), 10);
        assertTrue(str.endsWith("123"));
        str = (String) session.createQuery("select str(an.bodyWeight, 8, 3) from Animal an where str(an.bodyWeight, 8, 3) like '%1%'").uniqueResult();
        assertEquals(str.length(), 8);
        assertTrue(str.endsWith("123.450"));
    } else {
        assertTrue(str.startsWith("123.4"));
    }
    //noinspection deprecation
    if (!(getDialect() instanceof SybaseDialect) && !(getDialect() instanceof Sybase11Dialect) && !(getDialect() instanceof SybaseASE15Dialect) && !(getDialect() instanceof SybaseAnywhereDialect) && !(getDialect() instanceof SQLServerDialect || getDialect() instanceof TeradataDialect)) {
        // In TransactSQL (the variant spoken by Sybase and SQLServer), the str() function
        // is explicitly intended for numeric values only...
        String dateStr1 = (String) session.createQuery("select str(current_date) from Animal").uniqueResult();
        String dateStr2 = (String) session.createQuery("select str(year(current_date))||'-'||str(month(current_date))||'-'||str(day(current_date)) from Animal").uniqueResult();
        System.out.println(dateStr1 + '=' + dateStr2);
        if (!(getDialect() instanceof Oracle8iDialect)) {
            //Oracle renders the name of the month :(
            String[] dp1 = StringHelper.split("-", dateStr1);
            String[] dp2 = StringHelper.split("-", dateStr2);
            for (int i = 0; i < 3; i++) {
                if (dp1[i].startsWith("0")) {
                    dp1[i] = dp1[i].substring(1);
                }
                assertEquals(dp1[i], dp2[i]);
            }
        }
    }
    session.delete(an);
    txn.commit();
    session.close();
}
Also used : DerbyDialect(org.hibernate.dialect.DerbyDialect) SybaseASE15Dialect(org.hibernate.dialect.SybaseASE15Dialect) SQLServerDialect(org.hibernate.dialect.SQLServerDialect) SybaseDialect(org.hibernate.dialect.SybaseDialect) DB2Dialect(org.hibernate.dialect.DB2Dialect) Oracle8iDialect(org.hibernate.dialect.Oracle8iDialect) SybaseAnywhereDialect(org.hibernate.dialect.SybaseAnywhereDialect) Transaction(org.hibernate.Transaction) TeradataDialect(org.hibernate.dialect.TeradataDialect) Sybase11Dialect(org.hibernate.dialect.Sybase11Dialect) Session(org.hibernate.Session) Test(org.junit.Test)

Example 2 with TeradataDialect

use of org.hibernate.dialect.TeradataDialect in project hibernate-orm by hibernate.

the class SQLFunctionsTest method testBlobClob.

@Test
public void testBlobClob() throws Exception {
    // Sybase does not support ResultSet.getBlob(String)
    if (getDialect() instanceof SybaseDialect || getDialect() instanceof Sybase11Dialect || getDialect() instanceof SybaseASE15Dialect || getDialect() instanceof SybaseAnywhereDialect || getDialect() instanceof TeradataDialect) {
        return;
    }
    Session s = openSession();
    s.beginTransaction();
    Blobber b = new Blobber();
    b.setBlob(s.getLobHelper().createBlob("foo/bar/baz".getBytes()));
    b.setClob(s.getLobHelper().createClob("foo/bar/baz"));
    s.save(b);
    //s.refresh(b);
    //assertTrue( b.getClob() instanceof ClobImpl );
    s.flush();
    s.refresh(b);
    //b.getBlob().setBytes( 2, "abc".getBytes() );
    b.getClob().getSubString(2, 3);
    //b.getClob().setString(2, "abc");
    s.flush();
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    b = (Blobber) s.load(Blobber.class, new Integer(b.getId()));
    Blobber b2 = new Blobber();
    s.save(b2);
    b2.setBlob(b.getBlob());
    b.setBlob(null);
    //assertTrue( b.getClob().getSubString(1, 3).equals("fab") );
    b.getClob().getSubString(1, 6);
    //b.getClob().setString(1, "qwerty");
    s.flush();
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    b = (Blobber) s.load(Blobber.class, new Integer(b.getId()));
    b.setClob(s.getLobHelper().createClob("xcvfxvc xcvbx cvbx cvbx cvbxcvbxcvbxcvb"));
    s.flush();
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    b = (Blobber) s.load(Blobber.class, new Integer(b.getId()));
    assertTrue(b.getClob().getSubString(1, 7).equals("xcvfxvc"));
    //b.getClob().setString(5, "1234567890");
    s.flush();
    s.getTransaction().commit();
    s.close();
}
Also used : SybaseAnywhereDialect(org.hibernate.dialect.SybaseAnywhereDialect) SybaseASE15Dialect(org.hibernate.dialect.SybaseASE15Dialect) TeradataDialect(org.hibernate.dialect.TeradataDialect) Sybase11Dialect(org.hibernate.dialect.Sybase11Dialect) SybaseDialect(org.hibernate.dialect.SybaseDialect) Session(org.hibernate.Session) Test(org.junit.Test)

Example 3 with TeradataDialect

use of org.hibernate.dialect.TeradataDialect in project hibernate-orm by hibernate.

the class ParentChildTest method testLoadAfterNonExists.

@Test
public void testLoadAfterNonExists() throws HibernateException, SQLException {
    Session session = openSession();
    if ((getDialect() instanceof MySQLDialect) || (getDialect() instanceof IngresDialect)) {
        session.doWork(new AbstractWork() {

            @Override
            public void execute(Connection connection) throws SQLException {
                connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
            }
        });
    }
    session.getTransaction().begin();
    // First, prime the fixture session to think the entity does not exist
    try {
        session.load(Simple.class, new Long(-1));
        fail();
    } catch (ObjectNotFoundException onfe) {
        if (getDialect() instanceof TeradataDialect) {
            session.getTransaction().rollback();
            session.getTransaction().begin();
        }
    // this is correct
    }
    // Next, lets create that entity "under the covers"
    Session anotherSession = sessionFactory().openSession();
    anotherSession.beginTransaction();
    Simple myNewSimple = new Simple(Long.valueOf(-1));
    myNewSimple.setName("My under the radar Simple entity");
    myNewSimple.setAddress("SessionCacheTest.testLoadAfterNonExists");
    myNewSimple.setCount(1);
    myNewSimple.setDate(new Date());
    myNewSimple.setPay(Float.valueOf(100000000));
    anotherSession.save(myNewSimple);
    anotherSession.getTransaction().commit();
    anotherSession.close();
    // Now, lets make sure the original session can see the created row...
    session.clear();
    try {
        Simple dummy = (Simple) session.get(Simple.class, Long.valueOf(-1));
        assertNotNull("Unable to locate entity Simple with id = -1", dummy);
        session.delete(dummy);
    } catch (ObjectNotFoundException onfe) {
        fail("Unable to locate entity Simple with id = -1");
    }
    session.getTransaction().commit();
    session.close();
}
Also used : MySQLDialect(org.hibernate.dialect.MySQLDialect) SQLException(java.sql.SQLException) AbstractWork(org.hibernate.jdbc.AbstractWork) IngresDialect(org.hibernate.dialect.IngresDialect) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) Connection(java.sql.Connection) TeradataDialect(org.hibernate.dialect.TeradataDialect) Date(java.util.Date) Session(org.hibernate.Session) Test(org.junit.Test)

Example 4 with TeradataDialect

use of org.hibernate.dialect.TeradataDialect 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();
}
Also used : TimesTenDialect(org.hibernate.dialect.TimesTenDialect) Query(org.hibernate.Query) ArrayList(java.util.ArrayList) SybaseDialect(org.hibernate.dialect.SybaseDialect) MySQLDialect(org.hibernate.dialect.MySQLDialect) JoinedIterator(org.hibernate.internal.util.collections.JoinedIterator) Iterator(java.util.Iterator) TeradataDialect(org.hibernate.dialect.TeradataDialect) List(java.util.List) ArrayList(java.util.ArrayList) ScrollableResults(org.hibernate.ScrollableResults) HSQLDialect(org.hibernate.dialect.HSQLDialect) MckoiDialect(org.hibernate.dialect.MckoiDialect) DerbyDialect(org.hibernate.dialect.DerbyDialect) InterbaseDialect(org.hibernate.dialect.InterbaseDialect) PointbaseDialect(org.hibernate.dialect.PointbaseDialect) DB2Dialect(org.hibernate.dialect.DB2Dialect) Date(java.util.Date) SAPDBDialect(org.hibernate.dialect.SAPDBDialect) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Session (org.hibernate.Session)4 TeradataDialect (org.hibernate.dialect.TeradataDialect)4 Test (org.junit.Test)4 SybaseDialect (org.hibernate.dialect.SybaseDialect)3 Date (java.util.Date)2 Transaction (org.hibernate.Transaction)2 DB2Dialect (org.hibernate.dialect.DB2Dialect)2 DerbyDialect (org.hibernate.dialect.DerbyDialect)2 MySQLDialect (org.hibernate.dialect.MySQLDialect)2 Sybase11Dialect (org.hibernate.dialect.Sybase11Dialect)2 SybaseASE15Dialect (org.hibernate.dialect.SybaseASE15Dialect)2 SybaseAnywhereDialect (org.hibernate.dialect.SybaseAnywhereDialect)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)1 Query (org.hibernate.Query)1 ScrollableResults (org.hibernate.ScrollableResults)1