Iterator iter = s.iterate("select max(s.count) from Simple s");
if ( getDialect() instanceof MySQLDialect ) assertTrue( iter.hasNext() && iter.next()==null );
Simple simple = new Simple();
simple.setName("Simple Dialect Function Test");
simple.setAddress("Simple Address");
simple.setPay(new Float(45.8));
simple.setCount(2);
s.save(simple, new Long(10) );
// Test to make sure allocating an specified object operates correctly.
assertTrue(
s.find("select new org.hibernate.test.legacy.S(s.count, s.address) from Simple s").size() == 1
);
// Quick check the base dialect functions operate correctly
assertTrue(
s.find("select max(s.count) from Simple s").size() == 1
);
assertTrue(
s.find("select count(*) from Simple s").size() == 1
);
if ( getDialect() instanceof Cache71Dialect) {
// Check Oracle Dialect mix of dialect functions - no args (no parenthesis and single arg functions
java.util.List rset = s.find("select s.name, sysdate, floor(s.pay), round(s.pay,0) from Simple s");
assertNotNull("Name string should have been returned",(((Object[])rset.get(0))[0]));
assertNotNull("Todays Date should have been returned",(((Object[])rset.get(0))[1]));
assertEquals("floor(45.8) result was incorrect ", new Integer(45), ( (Object[]) rset.get(0) )[2] );
assertEquals("round(45.8) result was incorrect ", new Float(46), ( (Object[]) rset.get(0) )[3] );
simple.setPay(new Float(-45.8));
s.update(simple);
// Test type conversions while using nested functions (Float to Int).
rset = s.find("select abs(round(s.pay,0)) from Simple s");
assertEquals("abs(round(-45.8)) result was incorrect ", new Float(46), rset.get(0));
// Test a larger depth 3 function example - Not a useful combo other than for testing
assertTrue(
s.find("select floor(round(sysdate,1)) from Simple s").size() == 1
);
// Test the oracle standard NVL funtion as a test of multi-param functions...
simple.setPay(null);
s.update(simple);
Double value = (Double) s.createQuery("select mod( nvl(s.pay, 5000), 2 ) from Simple as s where s.id = 10").list().get(0);
assertTrue( 0 == value.intValue() );
}