File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/immutable/ImmutableTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/immutable/ImmutableTest.java | |||
Method name: void testImmutableChildEntityWithUpdate()
|
Method name: void testImmutableCollectionWithUpdate()
|
|||
Number of AST nodes: 32 | Number of AST nodes: 31 | |||
1 | Contract c = new Contract("gavin", "phone");↵ | 1 | Contract c = new Contract("gavin", "phone");↵ | |
2 | ContractVariation cv1 = new ContractVariation(1, c);↵ | 2 | ContractVariation cv1 = new ContractVariation(1, c);↵ | |
3 | cv1.setText("expensive");↵ | 3 | cv1.setText("expensive");↵ | |
4 | ContractVariation cv2 = new ContractVariation(2, c);↵ | 4 | ContractVariation cv2 = new ContractVariation(2, c);↵ | |
5 | cv2.setText("more expensive");↵ | 5 | cv2.setText("more expensive");↵ | |
6 | Session s = openSession();↵ | 6 | Session s = openSession();↵ | |
7 | Transaction t = s.beginTransaction();↵ | 7 | Transaction t = s.beginTransaction();↵ | |
8 | s.persist(c);↵ | 8 | s.persist(c);↵ | |
9 | t.commit();↵ | 9 | t.commit();↵ | |
10 | s.close();↵ | 10 | s.close();↵ | |
11 | s = openSession();↵ | 11 | s = openSession();↵ | |
12 | t = s.beginTransaction();↵ | 12 | t = s.beginTransaction();↵ | |
13 | cv1 = (ContractVariation) c.getVariations().iterator().next();↵ | 13 | c↵ | |
14 | cv1.setText("blah blah");↵ | |||
15 | s.update( c );↵ | |||
16 | t.commit↵ | 14 | .getVariations().add( new ContractVariation(3, c) );↵ | |
15 | try {↵ | |||
16 | s.update( c );↵ | |||
17 | fail( "should have failed because reassociated object has a dirty collection");↵ | |||
18 | }↵ | |||
19 | catch ( HibernateException ex ) {↵ | |||
20 | // expected↵ | |||
21 | }↵ | |||
22 | finally {↵ | |||
17 | ();↵ | 23 | t.rollback();↵ | |
18 | s.close();↵ | 24 | s.close();↵ | |
25 | }↵ | |||
19 | s = openSession();↵ | 26 | s = openSession();↵ | |
20 | t = s.beginTransaction();↵ | 27 | t = s.beginTransaction();↵ | |
21 | c = (Contract) s.createCriteria(Contract.class).uniqueResult();↵ | 28 | c = (Contract) s.createCriteria(Contract.class).uniqueResult();↵ | |
22 | assertEquals( c.getCustomerName(), "gavin" );↵ | 29 | assertEquals( c.getCustomerName(), "gavin" );↵ | |
23 | assertEquals( c.getVariations().size(), 2 );↵ | 30 | assertEquals( c.getVariations().size(), 2 );↵ | |
24 | Iterator it = c.getVariations().iterator();↵ | 31 | Iterator it = c.getVariations().iterator();↵ | |
25 | cv1 = (ContractVariation) it.next();↵ | 32 | cv1 = (ContractVariation) it.next();↵ | |
26 | assertEquals( cv1.getText(), "expensive" );↵ | 33 | assertEquals( cv1.getText(), "expensive" );↵ | |
27 | cv2 = (ContractVariation) it.next();↵ | 34 | cv2 = (ContractVariation) it.next();↵ | |
28 | assertEquals( cv2.getText(), "more expensive" );↵ | 35 | assertEquals( cv2.getText(), "more expensive" );↵ | |
29 | s.delete(c);↵ | 36 | s.delete(c);↵ | |
30 | assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );↵ | 37 | assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );↵ | |
31 | assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );↵ | 38 | assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );↵ | |
32 | t.commit();↵ | 39 | t.commit();↵ | |
33 | s.close(); | 40 |
| |
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.0 |
Clones location | Clones are declared in the same class |
Number of node comparisons | 313 |
Number of mapped statements | 27 |
Number of unmapped statements in the first code fragment | 5 |
Number of unmapped statements in the second code fragment | 1 |
Time elapsed for statement mapping (ms) | 0.0 |
Clone type | Type 3 |
ID | Statement | ID | Statement | ||||
---|---|---|---|---|---|---|---|
1 | Contract c = new Contract("gavin", "phone"); | 1 | Contract c = new Contract("gavin", "phone"); | ||||
2 | ContractVariation cv1 = new ContractVariation(1, c); | 2 | ContractVariation cv1 = new ContractVariation(1, c); | ||||
3 | cv1.setText("expensive"); | 3 | cv1.setText("expensive"); | ||||
4 | ContractVariation cv2 = new ContractVariation(2, c); | 4 | ContractVariation cv2 = new ContractVariation(2, c); | ||||
5 | cv2.setText("more expensive"); | 5 | cv2.setText("more expensive"); | ||||
6 | Session s = openSession(); | 6 | Session s = openSession(); | ||||
7 | Transaction t = s.beginTransaction(); | 7 | Transaction t = s.beginTransaction(); | ||||
8 | s.persist(c); | 8 | s.persist(c); | ||||
9 | t.commit(); | 9 | t.commit(); | ||||
10 | s.close(); | 10 | s.close(); | ||||
11 | s = openSession(); | 11 | s = openSession(); | ||||
12 | t = s.beginTransaction(); | 12 | t = s.beginTransaction(); | ||||
|
| 13 | c.getVariations().add(new ContractVariation(3, c)); | ||||
13 | cv1 = (ContractVariation)c.getVariations().iterator().next(); |
| | ||||
14 | cv1.setText("blah blah"); |
| | ||||
15 | s.update(c); |
| | ||||
16 | t.commit(); | 30 | t.commit(); | ||||
17 | s.close(); |
| | ||||
18 | s = openSession(); | 17 | s = openSession(); | ||||
19 | t = s.beginTransaction(); | 18 | t = s.beginTransaction(); | ||||
20 | c = (Contract)s.createCriteria(Contract.class).uniqueResult(); | 19 | c = (Contract)s.createCriteria(Contract.class).uniqueResult(); | ||||
21 | assertEquals(c.getCustomerName(), "gavin"); | 20 | assertEquals(c.getCustomerName(), "gavin"); | ||||
22 | assertEquals(c.getVariations().size(), 2); | 21 | assertEquals(c.getVariations().size(), 2); | ||||
23 | Iterator it = c.getVariations().iterator(); | 22 | Iterator it = c.getVariations().iterator(); | ||||
24 | cv1 = (ContractVariation)it.next(); | 23 | cv1 = (ContractVariation)it.next(); | ||||
25 | assertEquals(cv1.getText(), "expensive"); | 24 | assertEquals(cv1.getText(), "expensive"); | ||||
26 | cv2 = (ContractVariation)it.next(); | 25 | cv2 = (ContractVariation)it.next(); | ||||
27 | assertEquals(cv2.getText(), "more expensive"); | 26 | assertEquals(cv2.getText(), "more expensive"); | ||||
28 | s.delete(c); | 27 | s.delete(c); | ||||
29 | assertEquals(s.createCriteria(Contract.class).setProjection(Projections.rowCount()).uniqueResult(), new Integer(0)); | 28 | assertEquals(s.createCriteria(Contract.class).setProjection(Projections.rowCount()).uniqueResult(), new Integer(0)); | ||||
30 | assertEquals(s.createCriteria(ContractVariation.class).setProjection(Projections.rowCount()).uniqueResult(), new Integer(0)); | 29 | assertEquals(s.createCriteria(ContractVariation.class).setProjection(Projections.rowCount()).uniqueResult(), new Integer(0)); | ||||
31 | t.commit(); |
| | ||||
32 | s.close(); | 31 | s.close(); |
Row | Violation |
---|---|
1 | Unmatched statement c.getVariations().add(new ContractVariation(3,c)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
2 | Unmatched statement cv1=(ContractVariation)c.getVariations().iterator().next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
3 | Unmatched statement cv1.setText("blah blah"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
4 | Unmatched statement s.update(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
5 | Unmatched statement s.close(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
6 | Unmatched statement t.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
7 | Clone fragment #1 returns variables , while Clone fragment #2 returns variables s, t, c |