public void testBroken() throws Exception { if (getDialect() instanceof Oracle9Dialect) return; Session s = openSession(); Transaction t = s.beginTransaction(); Broken b = new Fixed(); b.setId( new Long(123)); b.setOtherId("foobar"); s.save(b); s.flush(); b.setTimestamp( new Date() ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); s.update(b); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); b = (Broken) s.load( Broken.class, b ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); s.delete(b); t.commit(); s.close(); }
public void testTS() throws Exception { if (getDialect() instanceof Oracle9Dialect) return; Session session = openSession(); Transaction txn = session.beginTransaction(); Simple sim = new Simple(); sim.setDate( new Date() ); session.save( sim, new Long(1) ); Query q = session.createSQLQuery("select {sim.*} from Simple {sim} where {sim}.date_ = ?", "sim", Simple.class); q.setTimestamp( 0, sim.getDate() ); assertTrue ( q.list().size()==1 ); session.delete(sim); txn.commit(); session.close(); }
public void testCompositeUserType() { Session s = openSession(); org.hibernate.Transaction t = s.beginTransaction(); Transaction tran = new Transaction(); tran.setDescription("a small transaction"); tran.setValue( new MonetoryAmount( new BigDecimal(1.5), Currency.getInstance("USD") ) ); s.persist(tran); List result = s.createQuery("from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'USD'").list(); assertEquals( result.size(), 1 ); tran.getValue().setCurrency( Currency.getInstance("AUD") ); result = s.createQuery("from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'AUD'").list(); assertEquals( result.size(), 1 ); if ( !(getDialect() instanceof HSQLDialect) && ! (getDialect() instanceof Oracle9Dialect) ) { result = s.createQuery("from Transaction txn where txn.value = (1.5, 'AUD')").list(); assertEquals( result.size(), 1 ); result = s.createQuery("from Transaction where value = (1.5, 'AUD')").list(); assertEquals( result.size(), 1 ); } s.delete(tran); t.commit(); s.close(); }
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 '123%' or str(an.bodyWeight) like '1.23%'").uniqueResult(); if ( getDialect() instanceof DB2Dialect ) { assertTrue( str.startsWith("1.234") ); } else if ( getDialect() instanceof SQLServerDialect ) { // no assertion as SQLServer always returns nulls here; even trying directly against the // database, it seems to have problems with str() in the where clause... } else { assertTrue( str.startsWith("123.4") ); } if ( ! ( getDialect() instanceof SybaseDialect ) ) { // 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 Oracle9Dialect || 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(); }
public void testGroupByFunction() { if ( getDialect() instanceof Oracle9Dialect ) return; if ( getDialect() instanceof Oracle8iDialect ) return; // the new hiearchy... if ( getDialect() instanceof PostgreSQLDialect ) return; assertTranslation( "select count(*) from Human h group by year(h.birthdate)" ); assertTranslation( "select count(*) from Human h group by trunc( sqrt(h.bodyWeight*4)/2 )" ); assertTranslation( "select count(*) from Human h group by year(sysdate)" ); }
public void testClassProperty() throws Exception { // This test causes failures on theta-join dialects because the SQL is different. // The queries are semantically the same however. if ( getDialect() instanceof Oracle9Dialect ) return; if ( getDialect() instanceof Oracle8iDialect ) return; assertTranslation( "from Animal a where a.mother.class = Reptile" ); }
public void testDuplicateImplicitJoinInSelect() { // This test causes failures on theta-join dialects because the SQL is different. The old parser // duplicates the condition, whereas the new parser does not. The queries are semantically the // same however. if ( getDialect() instanceof Oracle9Dialect ) return; if ( getDialect() instanceof Oracle8iDialect ) return; assertTranslation( "select an.mother.bodyWeight from Animal an join an.mother m where an.mother.bodyWeight > 10" ); assertTranslation( "select an.mother.bodyWeight from Animal an where an.mother.bodyWeight > 10" ); //assertTranslation("select an.mother from Animal an where an.mother.bodyWeight is not null"); assertTranslation( "select an.mother.bodyWeight from Animal an order by an.mother.bodyWeight" ); }
public boolean appliesTo(Dialect dialect) { // currently have only defined triggers for oracle... // TODO : add more triggers for dialects which allow mods in triggers... return ( dialect instanceof Oracle9Dialect ); }
public boolean appliesTo(Dialect dialect) { return dialect instanceof Oracle9Dialect; }
public boolean appliesTo(Dialect dialect) { return ( dialect instanceof Oracle9Dialect ); }
public boolean appliesTo(Dialect dialect) { // the DataDirect driver for Oracle known to not support // JDBC3 getGeneratedKeys... return ( dialect instanceof Oracle9Dialect ) && ( ! ( dialect instanceof DataDirectOracle9Dialect ) ) ; }
public boolean appliesTo(Dialect dialect) { return ( dialect instanceof Oracle9Dialect ) && !( dialect instanceof DataDirectOracle9Dialect ); }