Search in sources :

Example 6 with HSQLDialect

use of org.hibernate.dialect.HSQLDialect 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();
}
Also used : HSQLDialect(org.hibernate.dialect.HSQLDialect) SAPDBDialect(org.hibernate.dialect.SAPDBDialect) MySQLDialect(org.hibernate.dialect.MySQLDialect) Serializable(java.io.Serializable) TimesTenDialect(org.hibernate.dialect.TimesTenDialect) PointbaseDialect(org.hibernate.dialect.PointbaseDialect) Session(org.hibernate.Session) Test(org.junit.Test)

Example 7 with HSQLDialect

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

the class FooBarTest method testAutoFlush.

@Test
public void testAutoFlush() throws Exception {
    Session s = openSession();
    Transaction txn = s.beginTransaction();
    FooProxy foo = new Foo();
    s.save(foo);
    assertTrue("autoflush create", s.createQuery("from Foo foo").list().size() == 1);
    foo.setChar('X');
    assertTrue("autoflush update", s.createQuery("from Foo foo where foo.char='X'").list().size() == 1);
    txn.commit();
    s.close();
    s = openSession();
    txn = s.beginTransaction();
    foo = (FooProxy) s.load(Foo.class, foo.getKey());
    //assertTrue( s.find("from Foo foo where not foo.char='X'").size()==1, "autoflush update" );
    if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && !(getDialect() instanceof PointbaseDialect)) {
        foo.setBytes("osama".getBytes());
        assertTrue("autoflush collection update", s.createQuery("from Foo foo where 111 in elements(foo.bytes)").list().size() == 1);
        foo.getBytes()[0] = 69;
        assertTrue("autoflush collection update", s.createQuery("from Foo foo where 69 in elements(foo.bytes)").list().size() == 1);
    }
    s.delete(foo);
    assertTrue("autoflush delete", s.createQuery("from Foo foo").list().size() == 0);
    txn.commit();
    s.close();
}
Also used : HSQLDialect(org.hibernate.dialect.HSQLDialect) MySQLDialect(org.hibernate.dialect.MySQLDialect) Transaction(org.hibernate.Transaction) PointbaseDialect(org.hibernate.dialect.PointbaseDialect) Session(org.hibernate.Session) Test(org.junit.Test)

Example 8 with HSQLDialect

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

the class FooBarTest method testScrollableIterator.

@Test
public void testScrollableIterator() throws Exception {
    // skip if not one of these named dialects
    boolean match = getDialect() instanceof DB2Dialect || getDialect() instanceof SybaseDialect || getDialect() instanceof HSQLDialect || // 9i/10g too because of inheritence...
    getDialect() instanceof Oracle8iDialect;
    if (!match) {
        return;
    }
    Session s = openSession();
    Transaction txn = s.beginTransaction();
    s.save(new Foo());
    s.save(new Foo());
    s.save(new Foo());
    s.save(new Bar());
    Query query = s.createQuery("select f, f.integer from Foo f");
    assertTrue(query.getReturnTypes().length == 2);
    ScrollableResults iter = query.scroll();
    assertTrue(iter.next());
    assertTrue(iter.scroll(1));
    FooProxy f2 = (FooProxy) iter.get()[0];
    assertTrue(f2 != null);
    assertTrue(iter.scroll(-1));
    Object f1 = iter.get(0);
    iter.next();
    assertTrue(f1 != null && iter.get(0) == f2);
    iter.getInteger(1);
    assertTrue(!iter.scroll(100));
    assertTrue(iter.first());
    assertTrue(iter.scroll(3));
    Object f4 = iter.get(0);
    assertTrue(f4 != null);
    assertTrue(!iter.next());
    assertTrue(iter.first());
    assertTrue(iter.get(0) == f1);
    assertTrue(iter.last());
    assertTrue(iter.get(0) == f4);
    assertTrue(iter.previous());
    txn.commit();
    s.close();
    s = openSession();
    txn = s.beginTransaction();
    query = s.createQuery("select f, f.integer from Foo f");
    assertTrue(query.getReturnTypes().length == 2);
    iter = query.scroll();
    assertTrue(iter.next());
    assertTrue(iter.scroll(1));
    f2 = (FooProxy) iter.get()[0];
    assertTrue(f2 != null);
    assertTrue(f2.getString() != null && f2.getComponent().getImportantDates().length > 0);
    assertTrue(iter.scroll(-1));
    f1 = iter.get(0);
    iter.next();
    assertTrue(f1 != null && iter.get(0) == f2);
    iter.getInteger(1);
    assertTrue(!iter.scroll(100));
    assertTrue(iter.first());
    assertTrue(iter.scroll(3));
    f4 = iter.get(0);
    assertTrue(f4 != null);
    assertTrue(!iter.next());
    assertTrue(iter.first());
    assertTrue(iter.get(0) == f1);
    assertTrue(iter.last());
    assertTrue(iter.get(0) == f4);
    assertTrue(iter.previous());
    int i = 0;
    for (Object entity : s.createQuery("from Foo").list()) {
        i++;
        s.delete(entity);
    }
    assertEquals(4, i);
    s.flush();
    assertTrue(s.createQuery("from java.lang.Object").list().size() == 0);
    txn.commit();
    s.close();
}
Also used : HSQLDialect(org.hibernate.dialect.HSQLDialect) Query(org.hibernate.Query) SybaseDialect(org.hibernate.dialect.SybaseDialect) DB2Dialect(org.hibernate.dialect.DB2Dialect) Oracle8iDialect(org.hibernate.dialect.Oracle8iDialect) Transaction(org.hibernate.Transaction) ScrollableResults(org.hibernate.ScrollableResults) Session(org.hibernate.Session) Test(org.junit.Test)

Example 9 with HSQLDialect

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

the class ABCProxyTest method testDiscriminatorFiltering.

@Test
public void testDiscriminatorFiltering() throws Exception {
    if ((getDialect() instanceof HSQLDialect))
        return;
    Session s = openSession();
    Transaction t = s.beginTransaction();
    s.createQuery("from C1 c1 left join c1.c2s c2").list();
    s.createCriteria(C1.class).createCriteria("c2s").list();
    t.commit();
    s.close();
}
Also used : HSQLDialect(org.hibernate.dialect.HSQLDialect) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Example 10 with HSQLDialect

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

the class FooBarTest method testManyToManyBag.

@Test
public void testManyToManyBag() throws Exception {
    Session s = openSession();
    s.beginTransaction();
    Baz baz = new Baz();
    Serializable id = s.save(baz);
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    baz = (Baz) s.load(Baz.class, id);
    baz.getFooBag().add(new Foo());
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    baz = (Baz) s.load(Baz.class, id);
    assertTrue(!Hibernate.isInitialized(baz.getFooBag()));
    assertTrue(baz.getFooBag().size() == 1);
    if (!(getDialect() instanceof HSQLDialect))
        assertTrue(Hibernate.isInitialized(baz.getFooBag().iterator().next()));
    s.delete(baz);
    s.getTransaction().commit();
    s.close();
}
Also used : HSQLDialect(org.hibernate.dialect.HSQLDialect) Serializable(java.io.Serializable) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

HSQLDialect (org.hibernate.dialect.HSQLDialect)24 Session (org.hibernate.Session)22 Test (org.junit.Test)22 Transaction (org.hibernate.Transaction)15 MySQLDialect (org.hibernate.dialect.MySQLDialect)15 Iterator (java.util.Iterator)9 List (java.util.List)9 DB2Dialect (org.hibernate.dialect.DB2Dialect)8 ArrayList (java.util.ArrayList)7 PointbaseDialect (org.hibernate.dialect.PointbaseDialect)7 SAPDBDialect (org.hibernate.dialect.SAPDBDialect)6 Serializable (java.io.Serializable)4 Query (org.hibernate.Query)4 DerbyDialect (org.hibernate.dialect.DerbyDialect)4 MckoiDialect (org.hibernate.dialect.MckoiDialect)4 PostgreSQL81Dialect (org.hibernate.dialect.PostgreSQL81Dialect)4 SybaseDialect (org.hibernate.dialect.SybaseDialect)4 TimesTenDialect (org.hibernate.dialect.TimesTenDialect)4 ScrollableResults (org.hibernate.ScrollableResults)3 Oracle8iDialect (org.hibernate.dialect.Oracle8iDialect)3