if ( !supportsBulkInsertIdGeneration( IntegerVersioned.class ) ) { reportSkip( "bulk id generation not supported", "test bulk inserts with generated id and generated timestamp"); return; } Session s = openSession(); Transaction t = s.beginTransaction(); IntegerVersioned entity = new IntegerVersioned( "int-vers" ); s.save( entity ); s.createQuery( "select id, name, version from IntegerVersioned" ).list(); t.commit(); s.close(); Long initialId = entity.getId(); int initialVersion = entity.getVersion(); s = openSession(); t = s.beginTransaction(); int count = s.createQuery( "insert into IntegerVersioned ( name ) select name from IntegerVersioned" ).executeUpdate(); t.commit(); s.close(); assertEquals( "unexpected insertion count", 1, count ); s = openSession(); t = s.beginTransaction(); IntegerVersioned created = ( IntegerVersioned ) s.createQuery( "from IntegerVersioned where id <> :initialId" ) .setLong( "initialId", initialId.longValue() ) .uniqueResult(); t.commit(); s.close(); assertEquals( "version was not seeded", initialVersion, created.getVersion() ); s = openSession(); t = s.beginTransaction(); s.createQuery( "delete IntegerVersioned" ).executeUpdate(); t.commit(); s.close();
if ( !supportsBulkInsertIdGeneration( TimestampVersioned.class ) ) { reportSkip( "bulk id generation not supported", "test bulk inserts with generated id and generated timestamp"); return; } // dialects which do not allow a parameter in the select portion of an INSERT ... SELECT statement // will also be problematic for this test because the timestamp here is vm-based as opposed to // db-based. if ( ! getDialect().supportsParametersInInsertSelect() ) { reportSkip( "dialect does not support parameter in INSERT ... SELECT", "test bulk inserts with generated id and generated timestamp"); return; } Session s = openSession(); Transaction t = s.beginTransaction(); TimestampVersioned entity = new TimestampVersioned( "int-vers" ); s.save( entity ); s.createQuery( "select id, name, version from TimestampVersioned" ).list(); t.commit(); s.close(); Long initialId = entity.getId(); //Date initialVersion = entity.getVersion(); s = openSession(); t = s.beginTransaction(); int count = s.createQuery( "insert into TimestampVersioned ( name ) select name from TimestampVersioned" ).executeUpdate(); t.commit(); s.close(); assertEquals( "unexpected insertion count", 1, count ); s = openSession(); t = s.beginTransaction(); TimestampVersioned created = ( TimestampVersioned ) s.createQuery( "from TimestampVersioned where id <> :initialId" ) .setLong( "initialId", initialId.longValue() ) .uniqueResult(); t.commit(); s.close(); assertNotNull( created.getVersion() ); //assertEquals( "version was not seeded", initialVersion, created.getVersion() ); s = openSession(); t = s.beginTransaction(); s.createQuery( "delete TimestampVersioned" ).executeUpdate(); 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/hql/BulkManipulationTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java
Method name: void testInsertWithGeneratedVersionAndId() Method name: void testInsertWithGeneratedTimestampVersion()
Number of AST nodes: 29 Number of AST nodes: 31
1
if ( !supportsBulkInsertIdGeneration( IntegerVersioned.class ) ) {
1
if ( !supportsBulkInsertIdGeneration( TimestampVersioned.class ) ) {
2
			reportSkip( "bulk id generation not supported", "test bulk inserts with generated id and generated timestamp");
2
			reportSkip( "bulk id generation not supported", "test bulk inserts with generated id and generated timestamp");
3
			return;
3
			return;
4
		}
4
		}
5
		// dialects which do not allow a parameter in the select portion of an INSERT ... SELECT statement
6
		// will also be problematic for this test because the timestamp here is vm-based as opposed to
7
		// db-based.
8
		if ( ! getDialect().supportsParametersInInsertSelect() ) {
9
			reportSkip( "dialect does not support parameter in INSERT ... SELECT",
10
				"test bulk inserts with generated id and generated timestamp");
11
			return;
12
		}
5
		Session s = openSession();
13
		Session s = openSession();
6
		Transaction t = s.beginTransaction();
14
		Transaction t = s.beginTransaction();
7
		IntegerVersioned entity = new IntegerVersioned( "int-vers" );
15
		TimestampVersioned entity = new TimestampVersioned( "int-vers" );
8
		s.save( entity );
16
		s.save( entity );
9
		s.createQuery( "select id, name, version from IntegerVersioned" ).list();
17
		s.createQuery( "select id, name, version from TimestampVersioned" ).list();
10
		t.commit();
18
		t.commit();
11
		s.close();
19
		s.close();
12
		Long initialId = entity.getId();
20
		Long initialId = entity.getId();
13
		int initialVersion = entity.getVersion();
21
		//Date initialVersion = entity.getVersion();
14
		s = openSession();
22
		s = openSession();
15
		t = s.beginTransaction();
23
		t = s.beginTransaction();
16
		int count = s.createQuery( "insert into IntegerVersioned ( name ) select name from IntegerVersioned" ).executeUpdate();
24
		int count = s.createQuery( "insert into TimestampVersioned ( name ) select name from TimestampVersioned" ).executeUpdate();
17
		t.commit();
25
		t.commit();
18
		s.close();
26
		s.close();
19
		assertEquals( "unexpected insertion count", 1, count );
27
		assertEquals( "unexpected insertion count", 1, count );
20
		s = openSession();
28
		s = openSession();
21
		t = s.beginTransaction();
29
		t = s.beginTransaction();
22
		IntegerVersioned created = ( IntegerVersioned ) s.createQuery( "from IntegerVersioned where id <> :initialId" )
30
		TimestampVersioned created = ( TimestampVersioned ) s.createQuery( "from TimestampVersioned where id <> :initialId" )
23
				.setLong( "initialId", initialId.longValue() )
31
				.setLong( "initialId", initialId.longValue() )
24
				.uniqueResult();
32
				.uniqueResult();
25
		t.commit();
33
		t.commit();
26
		s.close();
34
		s.close();
27
		
35
		assertNotNull( created.getVersion() );
28
assertEquals( "version was not seeded", initialVersion, created.getVersion() );
36
		//assertEquals( "version was not seeded", initialVersion, created.getVersion() );
29
		s = openSession();
37
		s = openSession();
30
		t = s.beginTransaction();
38
		t = s.beginTransaction();
31
		s.createQuery( "delete IntegerVersioned" ).executeUpdate();
39
		s.createQuery( "delete TimestampVersioned" ).executeUpdate();
32
		t.commit();
40
		t.commit();
33
		s.close();
41
		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.5
Clones locationClones are declared in the same class
Number of node comparisons184
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements26
    Number of unmapped statements in the first code fragment3
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)44.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    if (!supportsBulkInsertIdGeneration(IntegerVersioned.class))
    1
    if (!supportsBulkInsertIdGeneration(IntegerVersioned.class))
    1
    if (!supportsBulkInsertIdGeneration(TimestampVersioned.class))
    Differences
    Expression1Expression2Difference
    IntegerVersioned.classTimestampVersioned.classLITERAL_VALUE_MISMATCH
    1
    if (!supportsBulkInsertIdGeneration(TimestampVersioned.class))
    2
    reportSkip("bulk id generation not supported", "test bulk inserts with generated id and generated timestamp");
    2
    reportSkip("bulk id generation not supported", "test bulk inserts with generated id and generated timestamp");
    3
    return;
    3
    return;
    3
    return;
    Preondition Violations
    Conditional return;
    3
    return;
    4
    Session s = openSession();
    7
    Session s = openSession();
    5
    Transaction t = s.beginTransaction();
    8
    Transaction t = s.beginTransaction();
    6
    IntegerVersioned entity = new IntegerVersioned("int-vers");
    6
    IntegerVersioned entity = new IntegerVersioned("int-vers");
    Preondition Violations
    Unmatched statement IntegerVersioned entity=new IntegerVersioned("int-vers"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                                            
                                                                                                                                    
    9
    TimestampVersioned entity = new TimestampVersioned("int-vers");
    Preondition Violations
    Unmatched statement TimestampVersioned entity=new TimestampVersioned("int-vers"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    9
    TimestampVersioned entity = new TimestampVersioned("int-vers");
    7
    s.save(entity);
    7
    s.save(entity);
    10
    s.save(entity);
    Differences
    Expression1Expression2Difference
    org.hibernate.test.hql.IntegerVersionedorg.hibernate.test.hql.TimestampVersionedVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.hql.IntegerVersioned of variable entity does not match with type org.hibernate.test.hql.TimestampVersioned of variable entity
    • Make classes org.hibernate.test.hql.IntegerVersioned and org.hibernate.test.hql.TimestampVersioned extend a common superclass
    10
    s.save(entity);
    8
    s.createQuery("select id, name, version from IntegerVersioned").list();
    8
    s.createQuery("select id, name, version from IntegerVersioned").list();
    11
    s.createQuery("select id, name, version from TimestampVersioned").list();
    Differences
    Expression1Expression2Difference
    "select id, name, version from IntegerVersioned""select id, name, version from TimestampVersioned"LITERAL_VALUE_MISMATCH
    11
    s.createQuery("select id, name, version from TimestampVersioned").list();
    9
    t.commit();
    12
    t.commit();
    10
    s.close();
    13
    s.close();
    11
    Long initialId = entity.getId();
    11
    Long initialId = entity.getId();
    14
    Long initialId = entity.getId();
    Differences
    Expression1Expression2Difference
    org.hibernate.test.hql.IntegerVersionedorg.hibernate.test.hql.TimestampVersionedVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.hql.IntegerVersioned of variable entity does not match with type org.hibernate.test.hql.TimestampVersioned of variable entity
    • Make classes org.hibernate.test.hql.IntegerVersioned and org.hibernate.test.hql.TimestampVersioned extend a common superclass
    14
    Long initialId = entity.getId();
    12
    int initialVersion = entity.getVersion();
                                                                                          
    13
    s = openSession();
    15
    s = openSession();
    14
    t = s.beginTransaction();
    16
    t = s.beginTransaction();
    15
    int count = s.createQuery("insert into IntegerVersioned ( name ) select name from IntegerVersioned").executeUpdate();
    15
    int count = s.createQuery("insert into IntegerVersioned ( name ) select name from IntegerVersioned").executeUpdate();
    17
    int count = s.createQuery("insert into TimestampVersioned ( name ) select name from TimestampVersioned").executeUpdate();
    Differences
    Expression1Expression2Difference
    "insert into IntegerVersioned ( name ) select name from IntegerVersioned""insert into TimestampVersioned ( name ) select name from TimestampVersioned"LITERAL_VALUE_MISMATCH
    17
    int count = s.createQuery("insert into TimestampVersioned ( name ) select name from TimestampVersioned").executeUpdate();
    16
    t.commit();
    18
    t.commit();
    17
    s.close();
    19
    s.close();
    18
    assertEquals("unexpected insertion count", 1, count);
    20
    assertEquals("unexpected insertion count", 1, count);
    19
    s = openSession();
    21
    s = openSession();
    20
    t = s.beginTransaction();
    22
    t = s.beginTransaction();
    21
    IntegerVersioned created = (IntegerVersioned)s.createQuery("from IntegerVersioned where id <> :initialId").setLong("initialId", initialId.longValue()).uniqueResult();
    21
    IntegerVersioned created = (IntegerVersioned)s.createQuery("from IntegerVersioned where id <> :initialId").setLong("initialId", initialId.longValue()).uniqueResult();
    Preondition Violations
    Unmatched statement IntegerVersioned created=(IntegerVersioned)s.createQuery("from IntegerVersioned where id <> :initialId").setLong("initialId",initialId.longValue()).uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                              
    23
    TimestampVersioned created = (TimestampVersioned)s.createQuery("from TimestampVersioned where id <> :initialId").setLong("initialId", initialId.longValue()).uniqueResult();
    Preondition Violations
    Unmatched statement TimestampVersioned created=(TimestampVersioned)s.createQuery("from TimestampVersioned where id <> :initialId").setLong("initialId",initialId.longValue()).uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    23
    TimestampVersioned created = (TimestampVersioned)s.createQuery("from TimestampVersioned where id <> :initialId").setLong("initialId", initialId.longValue()).uniqueResult();
    22
    t.commit();
    24
    t.commit();
    23
    s.close();
    25
    s.close();
    24
    assertEquals("version was not seeded", initialVersion, created.getVersion());
    24
    assertEquals("version was not seeded", initialVersion, created.getVersion());
    26
    assertNotNull(created.getVersion());
    Differences
    Expression1Expression2Difference
    assertEqualsassertNotNullMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals("version was not seeded",initialVersion,created.getVersion())assertNotNull(created.getVersion())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals("version was not seeded",initialVersion,created.getVersion()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNotNull(created.getVersion()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("version was not seeded",initialVersion,created.getVersion()) is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(created.getVersion()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals("version was not seeded",initialVersion,created.getVersion()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNotNull(created.getVersion()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("version was not seeded",initialVersion,created.getVersion()) is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(created.getVersion()) is a void method call, and thus it cannot be parameterized
    26
    assertNotNull(created.getVersion());
    25
    s = openSession();
    27
    s = openSession();
    26
    t = s.beginTransaction();
    28
    t = s.beginTransaction();
    27
    s.createQuery("delete IntegerVersioned").executeUpdate();
    27
    s.createQuery("delete IntegerVersioned").executeUpdate();
    29
    s.createQuery("delete TimestampVersioned").executeUpdate();
    Differences
    Expression1Expression2Difference
    "delete IntegerVersioned""delete TimestampVersioned"LITERAL_VALUE_MISMATCH
    29
    s.createQuery("delete TimestampVersioned").executeUpdate();
    28
    t.commit();
    30
    t.commit();
    29
    s.close();
    31
    s.close();
    Precondition Violations (16)
    Row Violation
    1Conditional return;
    2Unmatched statement IntegerVersioned entity=new IntegerVersioned("int-vers"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement TimestampVersioned entity=new TimestampVersioned("int-vers"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Type org.hibernate.test.hql.IntegerVersioned of variable entity does not match with type org.hibernate.test.hql.TimestampVersioned of variable entity
    5Type org.hibernate.test.hql.IntegerVersioned of variable entity does not match with type org.hibernate.test.hql.TimestampVersioned of variable entity
    6Unmatched statement IntegerVersioned created=(IntegerVersioned)s.createQuery("from IntegerVersioned where id <> :initialId").setLong("initialId",initialId.longValue()).uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Unmatched statement TimestampVersioned created=(TimestampVersioned)s.createQuery("from TimestampVersioned where id <> :initialId").setLong("initialId",initialId.longValue()).uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Expression assertEquals("version was not seeded",initialVersion,created.getVersion()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression assertNotNull(created.getVersion()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression assertEquals("version was not seeded",initialVersion,created.getVersion()) is a void method call, and thus it cannot be parameterized
    11Expression assertNotNull(created.getVersion()) is a void method call, and thus it cannot be parameterized
    12Expression assertEquals("version was not seeded",initialVersion,created.getVersion()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression assertNotNull(created.getVersion()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression assertEquals("version was not seeded",initialVersion,created.getVersion()) is a void method call, and thus it cannot be parameterized
    15Expression assertNotNull(created.getVersion()) is a void method call, and thus it cannot be parameterized
    16Clone fragment #1 returns variables initialId, s , while Clone fragment #2 returns variables initialId, s