Session s = openSession(); Transaction t = s.beginTransaction(); 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() ); } if ( (getDialect() instanceof Cache71Dialect) ) { // Test the hsql standard MOD funtion as a test of multi-param functions... Double value = (Double) s.find("select MOD(s.count, 2) from Simple as s where s.id = 10" ).get(0); assertTrue( 0 == value.intValue() ); } /* if ( (getDialect() instanceof Cache71Dialect) ) { // Test the hsql standard MOD funtion as a test of multi-param functions... Date value = (Date) s.find("select sysdate from Simple as s where nvl(cast(null as date), sysdate)=sysdate" ).get(0); assertTrue( value.equals(new java.sql.Date(System.currentTimeMillis()))); } */ s.delete(simple); t.commit(); s.close();
Session s = openSession(); Transaction t = s.beginTransaction(); 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 Oracle9iDialect ) { // 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(), trunc(s.pay), round(s.pay) 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("trunc(45.8) result was incorrect ", new Float(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)) 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 trunc(round(sysdate())) from Simple s").size() == 1 ); // Test the oracle standard NVL funtion as a test of multi-param functions... simple.setPay(null); s.update(simple); Integer value = (Integer) s.find("select MOD( NVL(s.pay, 5000), 2 ) from Simple as s where s.id = 10").get(0); assertTrue( 0 == value.intValue() ); } if ( (getDialect() instanceof HSQLDialect) ) { // Test the hsql standard MOD funtion as a test of multi-param functions... Integer value = (Integer) s.find("select MOD(s.count, 2) from Simple as s where s.id = 10" ).get(0); assertTrue( 0 == value.intValue() ); } s.delete(simple); t.commit(); s.close();
Clone fragments detected by clone detection tool
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
		s.close();
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.6
Clones locationClones are in different classes having the same super class
Number of node comparisons443
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements34
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)38.1
    Clone typeType 2
    Mapped Statements
    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 Cache71Dialect)
    15
    if (getDialect() instanceof Oracle9iDialect)
    Differences
    Expression1Expression2Difference
    org.hibernate.dialect.Cache71Dialectorg.hibernate.dialect.Oracle9iDialectSUBCLASS_TYPE_MISMATCH
    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, 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");
    Differences
    Expression1Expression2Difference
    "select s.name, sysdate, floor(s.pay), round(s.pay,0) from Simple s""select s.name, sysdate(), trunc(s.pay), round(s.pay) from Simple s"LITERAL_VALUE_MISMATCH
    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("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]);
    Differences
    Expression1Expression2Difference
    "floor(45.8) result was incorrect ""trunc(45.8) result was incorrect "LITERAL_VALUE_MISMATCH
    java.lang.Integerjava.lang.FloatSUBCLASS_TYPE_MISMATCH
    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,0)) from Simple s");
    23
    rset = s.find("select abs(round(s.pay)) from Simple s");
    Differences
    Expression1Expression2Difference
    "select abs(round(s.pay,0)) from Simple s""select abs(round(s.pay)) from Simple s"LITERAL_VALUE_MISMATCH
    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 floor(round(sysdate,1)) from Simple s").size() == 1);
    25
    assertTrue(s.find("select trunc(round(sysdate())) from Simple s").size() == 1);
    Differences
    Expression1Expression2Difference
    "select floor(round(sysdate,1)) from Simple s""select trunc(round(sysdate())) from Simple s"LITERAL_VALUE_MISMATCH
    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);
    Preondition Violations
    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
    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);
    28
    Double value = (Double)s.createQuery("select mod( nvl(s.pay, 5000), 2 ) from Simple as s where s.id = 10").list().get(0);
    Preondition Violations
    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
                                                                                                                                                                                                                                                          
    29
    assertTrue(0 == value.intValue());
    29
    assertTrue(0 == value.intValue());
    29
    assertTrue(0 == value.intValue());
    Differences
    Expression1Expression2Difference
    java.lang.Doublejava.lang.IntegerSUBCLASS_TYPE_MISMATCH
    29
    assertTrue(0 == value.intValue());
    30
    if ((getDialect() instanceof Cache71Dialect))
    30
    if ((getDialect() instanceof Cache71Dialect))
    30
    if ((getDialect() instanceof HSQLDialect))
    Differences
    Expression1Expression2Difference
    org.hibernate.dialect.Cache71Dialectorg.hibernate.dialect.HSQLDialectSUBCLASS_TYPE_MISMATCH
    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
    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);
    Differences
    Expression1Expression2Difference
    java.lang.Doublejava.lang.IntegerSUBCLASS_TYPE_MISMATCH
    java.lang.Doublejava.lang.IntegerSUBCLASS_TYPE_MISMATCH
    java.lang.Doublejava.lang.IntegerSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    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
    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
    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());
    32
    assertTrue(0 == value.intValue());
    Differences
    Expression1Expression2Difference
    java.lang.Doublejava.lang.IntegerSUBCLASS_TYPE_MISMATCH
    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();
    Precondition Violations (4)
    Row Violation
    1Unmatched 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
    2Unmatched 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
    3Expression (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
    4Expression (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