File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java | |||
Method name: void testDialectSQLFunctions()
|
Method name: void testDialectSQLFunctions()
|
|||
Number of AST nodes: 35 | Number of AST nodes: 35 | |||
1 | Session s = openSession(); ↵ | 1 | Session s = openSession();↵ | |
2 | Transaction t = s.beginTransaction();↵ | 2 | Transaction t = s.beginTransaction();↵ | |
3 | ↵ | |||
4 | Iterator iter = s.iterate("select max(s.count) from Simple s");↵ | 3 | Iterator iter = s.iterate("select max(s.count) from Simple s");↵ | |
5 | ↵ | |||
6 | if ( getDialect() instanceof MySQLDialect ) assertTrue( iter.hasNext() && iter.next()==null );↵ | 4 | if ( getDialect() instanceof MySQLDialect ) assertTrue( iter.hasNext() && iter.next()==null );↵ | |
7 | ↵ | |||
8 | Simple simple = new Simple(); ↵ | 5 | Simple simple = new Simple();↵ | |
9 | simple.setName("Simple Dialect Function Test"); ↵ | 6 | simple.setName("Simple Dialect Function Test");↵ | |
10 | simple.setAddress("Simple Address"); ↵ | 7 | simple.setAddress("Simple Address");↵ | |
11 | simple.setPay(new Float(45.8)); ↵ | 8 | simple.setPay(new Float(45.8));↵ | |
12 | simple.setCount(2); ↵ | 9 | simple.setCount(2);↵ | |
13 | s.save(simple, new Long(10) );↵ | 10 | s.save(simple, new Long(10) );↵ | |
14 | ↵ | |||
15 | // Test to make sure allocating an specified object operates correctly. ↵ | 11 | // Test to make sure allocating an specified object operates correctly.↵ | |
16 | assertTrue( ↵ | 12 | assertTrue(↵ | |
17 | s.find("select new org.hibernate.test.legacy.S(s.count, s.address) from Simple s").size() == 1 ↵ | 13 | s.find("select new org.hibernate.test.legacy.S(s.count, s.address) from Simple s").size() == 1↵ | |
18 | );↵ | 14 | );↵ | |
19 | ↵ | |||
20 | // Quick check the base dialect functions operate correctly ↵ | 15 | // Quick check the base dialect functions operate correctly↵ | |
21 | assertTrue( ↵ | 16 | assertTrue(↵ | |
22 | s.find("select max(s.count) from Simple s").size() == 1 ↵ | 17 | s.find("select max(s.count) from Simple s").size() == 1↵ | |
23 | ); ↵ | 18 | );↵ | |
24 | assertTrue( ↵ | 19 | assertTrue(↵ | |
25 | s.find("select count(*) from Simple s").size() == 1 ↵ | 20 | s.find("select count(*) from Simple s").size() == 1↵ | |
26 | );↵ | 21 | );↵ | |
27 | ↵ | |||
28 | if ( getDialect() instanceof Cache71Dialect) { ↵ | 22 | if ( getDialect() instanceof Oracle9iDialect ) {↵ | |
29 | // Check Oracle Dialect mix of dialect functions - no args (no parenthesis and single arg functions ↵ | 23 | // Check Oracle Dialect mix of dialect functions - no args (no parenthesis and single arg functions↵ | |
30 | java.util.List rset = s.find("select s.name, sysdate, floor(s.pay), round(s.pay,0) from Simple s"); ↵ | 24 | java.util.List rset = s.find("select s.name, sysdate(), trunc(s.pay), round(s.pay) from Simple s");↵ | |
31 | assertNotNull("Name string should have been returned",(((Object[])rset.get(0))[0])); ↵ | 25 | assertNotNull("Name string should have been returned",(((Object[])rset.get(0))[0]));↵ | |
32 | assertNotNull("Todays Date should have been returned",(((Object[])rset.get(0))[1])); ↵ | 26 | assertNotNull("Todays Date should have been returned",(((Object[])rset.get(0))[1]));↵ | |
33 | assertEquals("floor(45.8) result was incorrect ", new Integer(45), ( (Object[]) rset.get(0) )[2] ); ↵ | 27 | assertEquals("trunc(45.8) result was incorrect ", new Float(45), ( (Object[]) rset.get(0) )[2] );↵ | |
34 | assertEquals("round(45.8) result was incorrect ", new Float(46), ( (Object[]) rset.get(0) )[3] );↵ | 28 | assertEquals("round(45.8) result was incorrect ", new Float(46), ( (Object[]) rset.get(0) )[3] );↵ | |
35 | ↵ | |||
36 | simple.setPay(new Float(-45.8)); ↵ | 29 | simple.setPay(new Float(-45.8));↵ | |
37 | s.update(simple);↵ | 30 | s.update(simple);↵ | |
38 | ↵ | |||
39 | // Test type conversions while using nested functions (Float to Int). ↵ | 31 | // Test type conversions while using nested functions (Float to Int).↵ | |
40 | rset = s.find("select abs(round(s.pay,0)) from Simple s"); ↵ | 32 | rset = s.find("select abs(round(s.pay)) from Simple s");↵ | |
41 | assertEquals("abs(round(-45.8)) result was incorrect ", new Float(46), rset.get(0));↵ | 33 | assertEquals("abs(round(-45.8)) result was incorrect ", new Float(46), rset.get(0));↵ | |
42 | ↵ | |||
43 | // Test a larger depth 3 function example - Not a useful combo other than for testing ↵ | 34 | // Test a larger depth 3 function example - Not a useful combo other than for testing↵ | |
44 | assertTrue( ↵ | 35 | assertTrue(↵ | |
45 | s.find("select floor(round(sysdate,1)) from Simple s").size() == 1 ↵ | 36 | s.find("select trunc(round(sysdate())) from Simple s").size() == 1↵ | |
46 | );↵ | 37 | );↵ | |
47 | ↵ | |||
48 | // Test the oracle standard NVL funtion as a test of multi-param functions... ↵ | 38 | // Test the oracle standard NVL funtion as a test of multi-param functions...↵ | |
49 | simple.setPay(null); ↵ | 39 | simple.setPay(null);↵ | |
50 | s.update(simple); ↵ | 40 | s.update(simple);↵ | |
51 | Double value = (Double) s.createQuery("select mod( nvl(s.pay, 5000), 2 ) from Simple as s where s.id = 10").list().get(0); ↵ | 41 | Integer value = (Integer) s.find("select MOD( NVL(s.pay, 5000), 2 ) from Simple as s where s.id = 10").get(0);↵ | |
52 | assertTrue( 0 == value.intValue() ); ↵ | 42 | assertTrue( 0 == value.intValue() );↵ | |
53 | }↵ | 43 | }↵ | |
54 | ↵ | |||
55 | if ( (getDialect() instanceof Cache71Dialect) ) { ↵ | 44 | if ( (getDialect() instanceof HSQLDialect) ) {↵ | |
56 | // Test the hsql standard MOD funtion as a test of multi-param functions... ↵ | 45 | // Test the hsql standard MOD funtion as a test of multi-param functions...↵ | |
57 | Double value = (Double) s.find("select MOD(s.count, 2) from Simple as s where s.id = 10" ).get(0); ↵ | 46 | Integer value = (Integer) s.find("select MOD(s.count, 2) from Simple as s where s.id = 10" ).get(0);↵ | |
58 | assertTrue( 0 == value.intValue() );↵ | 47 | assertTrue( 0 == value.intValue() );↵ | |
59 | }↵ | |||
60 | /*↵ | |||
61 | if ( (getDialect() instanceof Cache71Dialect) ) {↵ | |||
62 | // Test the hsql standard MOD funtion as a test of multi-param functions...↵ | |||
63 | Date value = (Date) s.find("select sysdate from Simple as s where nvl(cast(null as date), sysdate)=sysdate" ).get(0);↵ | |||
64 | assertTrue( value.equals(new java.sql.Date(System.currentTimeMillis())));↵ | |||
65 | }↵ | |||
66 | */↵ | |||
67 | ↵ | |||
48 | }↵ | |||
68 | s.delete(simple); ↵ | 49 | s.delete(simple);↵ | |
69 | t.commit(); ↵ | 50 | t.commit();↵ | |
70 | s.close(); | 51 |
| |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.6 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 443 |
Number of mapped statements | 34 |
Number of unmapped statements in the first code fragment | 1 |
Number of unmapped statements in the second code fragment | 1 |
Time elapsed for statement mapping (ms) | 38.1 |
Clone type | Type 2 |
ID | Statement | ID | Statement | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Session s = openSession(); | 1 | Session s = openSession(); | |||||||||||||||||||
2 | Transaction t = s.beginTransaction(); | 2 | Transaction t = s.beginTransaction(); | |||||||||||||||||||
3 | Iterator iter = s.iterate("select max(s.count) from Simple s"); | 3 | Iterator iter = s.iterate("select max(s.count) from Simple s"); | |||||||||||||||||||
4 | if (getDialect() instanceof MySQLDialect) | 4 | if (getDialect() instanceof MySQLDialect) | |||||||||||||||||||
5 | assertTrue(iter.hasNext() && iter.next() == null); | 5 | assertTrue(iter.hasNext() && iter.next() == null); | |||||||||||||||||||
6 | Simple simple = new Simple(); | 6 | Simple simple = new Simple(); | |||||||||||||||||||
7 | simple.setName("Simple Dialect Function Test"); | 7 | simple.setName("Simple Dialect Function Test"); | |||||||||||||||||||
8 | simple.setAddress("Simple Address"); | 8 | simple.setAddress("Simple Address"); | |||||||||||||||||||
9 | simple.setPay(new Float(45.8)); | 9 | simple.setPay(new Float(45.8)); | |||||||||||||||||||
10 | simple.setCount(2); | 10 | simple.setCount(2); | |||||||||||||||||||
11 | s.save(simple, new Long(10)); | 11 | s.save(simple, new Long(10)); | |||||||||||||||||||
12 | assertTrue(s.find("select new org.hibernate.test.legacy.S(s.count, s.address) from Simple s").size() == 1); | 12 | assertTrue(s.find("select new org.hibernate.test.legacy.S(s.count, s.address) from Simple s").size() == 1); | |||||||||||||||||||
13 | assertTrue(s.find("select max(s.count) from Simple s").size() == 1); | 13 | assertTrue(s.find("select max(s.count) from Simple s").size() == 1); | |||||||||||||||||||
14 | assertTrue(s.find("select count(*) from Simple s").size() == 1); | 14 | assertTrue(s.find("select count(*) from Simple s").size() == 1); | |||||||||||||||||||
15 | if (getDialect() instanceof Cache71Dialect) |
| 15 | if (getDialect() instanceof Oracle9iDialect) | ||||||||||||||||||
16 | java.util.List rset = s.find("select s.name, sysdate, floor(s.pay), round(s.pay,0) from Simple s"); |
| 16 | java.util.List rset = s.find("select s.name, sysdate(), trunc(s.pay), round(s.pay) from Simple s"); | ||||||||||||||||||
17 | assertNotNull("Name string should have been returned", (((Object[])rset.get(0))[0])); | 17 | assertNotNull("Name string should have been returned", (((Object[])rset.get(0))[0])); | |||||||||||||||||||
18 | assertNotNull("Todays Date should have been returned", (((Object[])rset.get(0))[1])); | 18 | assertNotNull("Todays Date should have been returned", (((Object[])rset.get(0))[1])); | |||||||||||||||||||
19 | assertEquals("floor(45.8) result was incorrect ", new Integer(45), ((Object[])rset.get(0))[2]); |
| 19 | assertEquals("trunc(45.8) result was incorrect ", new Float(45), ((Object[])rset.get(0))[2]); | ||||||||||||||||||
20 | assertEquals("round(45.8) result was incorrect ", new Float(46), ((Object[])rset.get(0))[3]); | 20 | assertEquals("round(45.8) result was incorrect ", new Float(46), ((Object[])rset.get(0))[3]); | |||||||||||||||||||
21 | simple.setPay(new Float(-45.8)); | 21 | simple.setPay(new Float(-45.8)); | |||||||||||||||||||
22 | s.update(simple); | 22 | s.update(simple); | |||||||||||||||||||
23 | rset = s.find("select abs(round(s.pay,0)) from Simple s"); |
| 23 | rset = s.find("select abs(round(s.pay)) from Simple s"); | ||||||||||||||||||
24 | assertEquals("abs(round(-45.8)) result was incorrect ", new Float(46), rset.get(0)); | 24 | assertEquals("abs(round(-45.8)) result was incorrect ", new Float(46), rset.get(0)); | |||||||||||||||||||
25 | assertTrue(s.find("select floor(round(sysdate,1)) from Simple s").size() == 1); |
| 25 | assertTrue(s.find("select trunc(round(sysdate())) from Simple s").size() == 1); | ||||||||||||||||||
26 | simple.setPay(null); | 26 | simple.setPay(null); | |||||||||||||||||||
27 | s.update(simple); | 27 | s.update(simple); | |||||||||||||||||||
|
| 28 | Integer value = (Integer)s.find("select MOD( NVL(s.pay, 5000), 2 ) from Simple as s where s.id = 10").get(0); | |||||||||||||||||||
28 | Double value = (Double)s.createQuery("select mod( nvl(s.pay, 5000), 2 ) from Simple as s where s.id = 10").list().get(0); |
| | |||||||||||||||||||
29 | assertTrue(0 == value.intValue()); |
| 29 | assertTrue(0 == value.intValue()); | ||||||||||||||||||
30 | if ((getDialect() instanceof Cache71Dialect)) |
| 30 | if ((getDialect() instanceof HSQLDialect)) | ||||||||||||||||||
31 | Double value = (Double)s.find("select MOD(s.count, 2) from Simple as s where s.id = 10").get(0); |
| 31 | Integer value = (Integer)s.find("select MOD(s.count, 2) from Simple as s where s.id = 10").get(0); | ||||||||||||||||||
32 | assertTrue(0 == value.intValue()); |
| 32 | assertTrue(0 == value.intValue()); | ||||||||||||||||||
33 | s.delete(simple); | 33 | s.delete(simple); | |||||||||||||||||||
34 | t.commit(); | 34 | t.commit(); | |||||||||||||||||||
35 | s.close(); | 35 | s.close(); |
Row | Violation |
---|---|
1 | Unmatched statement Integer value=(Integer)s.find("select MOD( NVL(s.pay, 5000), 2 ) from Simple as s where s.id = 10").get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
2 | Unmatched statement Double value=(Double)s.createQuery("select mod( nvl(s.pay, 5000), 2 ) from Simple as s where s.id = 10").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
3 | Expression (Double)s.find("select MOD(s.count, 2) from Simple as s where s.id = 10").get(0) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
4 | Expression (Integer)s.find("select MOD(s.count, 2) from Simple as s where s.id = 10").get(0) cannot be parameterized, because it has dependencies to/from statements that will be extracted |