File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java | File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/persister/collection/BasicCollectionPersister.java | |||
Method name: void insertRows(PersistentCollection, Serializable, SessionImplementor)
|
Method name: int doUpdateRows(Serializable, PersistentCollection, SessionImplementor)
|
|||
Number of AST nodes: 38 | Number of AST nodes: 36 | |||
1 | try {↵ | 1 | try {↵ | |
2 | //insert all the new entries↵ | 2 | ↵ | |
3 | collection.preInsert( this );↵ | |||
4 | Iterator entries = collection.entries( this );↵ | 3 | PreparedStatement st = null;↵ | |
5 | Expectation expectation = Expectations.appropriateExpectation( getInsertCheckStyle() );↵ | 4 | Expectation expectation = Expectations.appropriateExpectation( getUpdateCheckStyle() );↵ | |
6 | boolean callable = isInsertCallable();↵ | 5 | boolean callable = isUpdateCallable();↵ | |
7 | boolean useBatch = expectation.canBeBatched();↵ | 6 | boolean useBatch = expectation.canBeBatched();↵ | |
8 | ↵ | 7 | Iterator entries = collection.entries( this );↵ | |
9 | String sql = getSQLInsertRowString();↵ | 8 | String sql = getSQLUpdateRowString();↵ | |
10 | int i = 0;↵ | 9 | int i = 0;↵ | |
11 | int count = 0;↵ | 10 | int count = 0;↵ | |
12 | while ( entries.hasNext() ) {↵ | 11 | while ( entries.hasNext() ) {↵ | |
13 | int offset = 1;↵ | 12 | ↵ | |
14 | Object entry = entries.next();↵ | 13 | Object entry = entries.next();↵ | |
15 | PreparedStatement st = null;↵ | 14 | ↵ | |
16 | if ( collection.needsInserting( entry, i, elementType ) ) {↵ | 15 | if ( collection.needsUpdating( entry, i, elementType ) ) {↵ | |
17 | ↵ | 16 | int offset = 1;↵ | |
18 | if ( useBatch ) {↵ | 17 | if ( useBatch ) {↵ | |
19 | if ( st == null ) {↵ | 18 | if ( st == null ) {↵ | |
20 | if ( callable ) {↵ | 19 | if ( callable ) {↵ | |
21 | st = session.getBatcher().prepareBatchCallableStatement( sql );↵ | 20 | st = session.getBatcher().prepareBatchCallableStatement( sql );↵ | |
22 | }↵ | 21 | }↵ | |
23 | else {↵ | 22 | else {↵ | |
24 | st = session.getBatcher().prepareBatchStatement( sql );↵ | 23 | st = session.getBatcher().prepareBatchStatement( sql );↵ | |
25 | }↵ | 24 | }↵ | |
26 | }↵ | 25 | }↵ | |
27 | }↵ | 26 | }↵ | |
28 | else {↵ | 27 | else {↵ | |
29 | if ( callable ) {↵ | 28 | if ( callable ) {↵ | |
30 | st = session.getBatcher().prepareCallableStatement( sql );↵ | 29 | st = session.getBatcher().prepareCallableStatement( sql );↵ | |
31 | }↵ | 30 | }↵ | |
32 | else {↵ | 31 | else {↵ | |
33 | st = session.getBatcher().prepareStatement( sql );↵ | 32 | st = session.getBatcher().prepareStatement( sql );↵ | |
34 | }↵ | 33 | }↵ | |
35 | }↵ | 34 | }↵ | |
36 | try {↵ | 35 | try {↵ | |
37 | offset += expectation.prepare( st );↵ | 36 | offset+= expectation.prepare( st );↵ | |
38 | //TODO: copy/paste from recreate()↵ | 37 | ↵ | |
39 | offset = writeKey( st, id, offset, session );↵ | 38 | int loc = writeElement( st, collection.getElement( entry ), offset, session );↵ | |
40 | if ( hasIdentifier ) {↵ | 39 | if ( hasIdentifier ) {↵ | |
41 | offset = writeIdentifier( st, collection.getIdentifier(entry, i), offset, session );↵ | 40 | writeIdentifier( st, collection.getIdentifier( entry, i ), loc, session );↵ | |
42 | }↵ | 41 | }↵ | |
42 | else {↵ | |||
43 | loc = writeKey( st, id, loc, session );↵ | |||
43 | if ( hasIndex /*&& !indexIsFormula*/ ) {↵ | 44 | if ( hasIndex && !indexContainsFormula ) {↵ | |
44 | offset = writeIndex( st, collection.getIndex(entry, i, this), offset, session );↵ | 45 | writeIndexToWhere( st, collection.getIndex( entry, i, this ), loc, session );↵ | |
45 | }↵ | 46 | }↵ | |
46 | ↵ | 47 | else {↵ | |
47 | writeElement(st, collection.getElement(entry), offset, session );↵ | 48 | writeElementToWhere( st, collection.getSnapshotElement( entry, i ), loc, session );↵ | |
48 | ↵ | 49 | }↵ | |
50 | }↵ | |||
49 | if ( useBatch ) {↵ | 51 | if ( useBatch ) {↵ | |
50 | session.getBatcher().addToBatch( expectation );↵ | 52 | session.getBatcher().addToBatch( expectation );↵ | |
51 | }↵ | 53 | }↵ | |
52 | else {↵ | 54 | else {↵ | |
53 | expectation.verifyOutcome( st.executeUpdate(), st, -1 );↵ | 55 | expectation.verifyOutcome( st.executeUpdate(), st, -1 );↵ | |
54 | }↵ | 56 | }↵ | |
55 | collection.afterRowInsert( this, entry, i );↵ | 57 | ↵ | |
56 | count++;↵ | |||
57 | }↵ | 58 | }↵ | |
58 | catch ( SQLException sqle ) {↵ | 59 | catch ( SQLException sqle ) {↵ | |
59 | if ( useBatch ) {↵ | 60 | if ( useBatch ) {↵ | |
60 | session.getBatcher().abortBatch( sqle );↵ | 61 | session.getBatcher().abortBatch( sqle );↵ | |
61 | }↵ | 62 | }↵ | |
62 | throw sqle;↵ | 63 | throw sqle;↵ | |
63 | }↵ | 64 | }↵ | |
64 | finally {↵ | 65 | finally {↵ | |
65 | if ( !useBatch ) {↵ | 66 | if ( !useBatch ) {↵ | |
66 | session.getBatcher().closeStatement( st );↵ | 67 | session.getBatcher().closeStatement( st );↵ | |
67 | }↵ | 68 | }↵ | |
68 | }↵ | 69 | }↵ | |
69 | }↵ | 70 | ↵ | |
70 | i++;↵ | 71 | count++;↵ | |
71 | }↵ | 72 | }↵ | |
72 | if ( log.isDebugEnabled() ) {↵ | 73 | i↵ | |
73 | log.debug( "done inserting rows: " + count + " inserted" );↵ | |||
74 | }↵ | |||
75 | ↵ | 74 | ++;↵ | |
75 | }↵ | |||
76 | return count;↵ | |||
76 | }↵ | 77 | }↵ | |
77 | catch ( SQLException sqle ) {↵ | 78 | catch ( SQLException sqle ) {↵ | |
78 | throw JDBCExceptionHelper.convert(↵ | 79 | throw JDBCExceptionHelper.convert(↵ | |
79 | sqlExceptionConverter,↵ | 80 | getSQLExceptionConverter(),↵ | |
80 | sqle,↵ | 81 | sqle,↵ | |
81 | "could not insert collection rows: " + ↵ | 82 | "could not update collection rows: " + ↵ | |
82 | MessageHelper.collectionInfoString( this, id, getFactory() ),↵ | 83 | MessageHelper.collectionInfoString( this, id, getFactory() ),↵ | |
83 | getSQLInsertRowString()↵ | 84 | getSQLUpdateRowString()↵ | |
84 | );↵ | 85 | );↵ | |
85 | } | 86 | } | |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 2 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 2 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 4.7 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 189 |
Number of mapped statements | 18 |
Number of unmapped statements in the first code fragment | 20 |
Number of unmapped statements in the second code fragment | 18 |
Time elapsed for statement mapping (ms) | 123.9 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4 | try |
| 3 | try | ||||||||||||||||
| 4 | PreparedStatement st = null; | ||||||||||||||||||
5 | collection.preInsert(this); |
| | |||||||||||||||||
6 | Iterator entries = collection.entries(this); | 8 | Iterator entries = collection.entries(this); | |||||||||||||||||
7 | Expectation expectation = Expectations.appropriateExpectation(getInsertCheckStyle()); |
| 5 | Expectation expectation = Expectations.appropriateExpectation(getUpdateCheckStyle()); | ||||||||||||||||
8 | boolean callable = isInsertCallable(); |
| 6 | boolean callable = isUpdateCallable(); | ||||||||||||||||
9 | boolean useBatch = expectation.canBeBatched(); | 7 | boolean useBatch = expectation.canBeBatched(); | |||||||||||||||||
10 | String sql = getSQLInsertRowString(); |
| 9 | String sql = getSQLUpdateRowString(); | ||||||||||||||||
11 | int i = 0; | 10 | int i = 0; | |||||||||||||||||
12 | int count = 0; | 11 | int count = 0; | |||||||||||||||||
13 | while (entries.hasNext()) | 12 | while (entries.hasNext()) | |||||||||||||||||
14 | int offset = 1; |
| | |||||||||||||||||
15 | Object entry = entries.next(); | 13 | Object entry = entries.next(); | |||||||||||||||||
16 | PreparedStatement st = null; |
| | |||||||||||||||||
17 | if (collection.needsInserting(entry, i, elementType)) |
| 14 | if (collection.needsUpdating(entry, i, elementType)) | ||||||||||||||||
| 15 | int offset = 1; | ||||||||||||||||||
18 | if (useBatch) | 16 | if (useBatch) | |||||||||||||||||
19 | if (st == null) | 17 | if (st == null) | |||||||||||||||||
20 | if (callable) | 18 | if (callable) | |||||||||||||||||
21 | st = session.getBatcher().prepareBatchCallableStatement(sql); | 19 | st = session.getBatcher().prepareBatchCallableStatement(sql); | |||||||||||||||||
else | | |||||||||||||||||||
|
| 20 | st = session.getBatcher().prepareBatchStatement(sql); | |||||||||||||||||
22 | st = session.getBatcher().prepareBatchStatement(sql); |
| | |||||||||||||||||
else | else | |||||||||||||||||||
23 | if (callable) | 21 | if (callable) | |||||||||||||||||
24 | st = session.getBatcher().prepareCallableStatement(sql); | 22 | st = session.getBatcher().prepareCallableStatement(sql); | |||||||||||||||||
else | | |||||||||||||||||||
|
| 23 | st = session.getBatcher().prepareStatement(sql); | |||||||||||||||||
25 | st = session.getBatcher().prepareStatement(sql); |
| | |||||||||||||||||
|
| 24 | try | |||||||||||||||||
|
| 25 | offset += expectation.prepare(st); | |||||||||||||||||
|
| 26 | int loc = writeElement(st, collection.getElement(entry), offset, session); | |||||||||||||||||
| 27 | if (hasIdentifier) | ||||||||||||||||||
|
| 28 | writeIdentifier(st, collection.getIdentifier(entry, i), loc, session); | |||||||||||||||||
| else | |||||||||||||||||||
|
| 29 | loc = writeKey(st, id, loc, session); | |||||||||||||||||
| 30 | if (hasIndex && !indexContainsFormula) | ||||||||||||||||||
|
| 31 | writeIndexToWhere(st, collection.getIndex(entry, i, this), loc, session); | |||||||||||||||||
| else | |||||||||||||||||||
|
| 32 | writeElementToWhere(st, collection.getSnapshotElement(entry, i), loc, session); | |||||||||||||||||
|
| 33 | if (useBatch) | |||||||||||||||||
|
| 34 | session.getBatcher().addToBatch(expectation); | |||||||||||||||||
| else | |||||||||||||||||||
|
| 35 | expectation.verifyOutcome(st.executeUpdate(), st, -1); | |||||||||||||||||
26 | try |
| | |||||||||||||||||
27 | offset += expectation.prepare(st); |
| | |||||||||||||||||
28 | offset = writeKey(st, id, offset, session); |
| | |||||||||||||||||
29 | if (hasIdentifier) | | ||||||||||||||||||
30 | offset = writeIdentifier(st, collection.getIdentifier(entry, i), offset, session); |
| | |||||||||||||||||
31 | if (hasIndex) | | ||||||||||||||||||
32 | offset = writeIndex(st, collection.getIndex(entry, i, this), offset, session); |
| | |||||||||||||||||
33 | writeElement(st, collection.getElement(entry), offset, session); |
| | |||||||||||||||||
34 | if (useBatch) |
| | |||||||||||||||||
35 | session.getBatcher().addToBatch(expectation); |
| | |||||||||||||||||
else | | |||||||||||||||||||
36 | expectation.verifyOutcome(st.executeUpdate(), st, -1); |
| | |||||||||||||||||
37 | collection.afterRowInsert(this, entry, i); |
| | |||||||||||||||||
38 | count++; |
| | |||||||||||||||||
|
| 36 | count++; | |||||||||||||||||
39 | i++; | 37 | i++; | |||||||||||||||||
|
| 38 | return count; | |||||||||||||||||
40 | if (log.isDebugEnabled()) | | ||||||||||||||||||
41 | log.debug("done inserting rows: " + count + " inserted"); |
| |
Row | Violation |
---|---|
1 | Unmatched statement collection.preInsert(this); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
2 | Unmatched statement int offset=1; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
3 | Unmatched statement PreparedStatement st=null; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
4 | Expression collection.needsInserting(entry,i,elementType) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
5 | Expression collection.needsUpdating(entry,i,elementType) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
6 | Unmatched statement st=session.getBatcher().prepareBatchStatement(sql); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
7 | Unmatched statement st=session.getBatcher().prepareBatchStatement(sql); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
8 | Unmatched statement st=session.getBatcher().prepareBatchStatement(sql); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
9 | Unmatched statement st=session.getBatcher().prepareBatchStatement(sql); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
10 | Unmatched statement st=session.getBatcher().prepareStatement(sql); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
11 | Unmatched statement st=session.getBatcher().prepareStatement(sql); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
12 | Unmatched statement st=session.getBatcher().prepareStatement(sql); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
13 | Unmatched statement st=session.getBatcher().prepareStatement(sql); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
14 | Unmatched statement try cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
15 | Unmatched statement offset+=expectation.prepare(st); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
16 | Unmatched statement offset+=expectation.prepare(st); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
17 | Unmatched statement int loc=writeElement(st,collection.getElement(entry),offset,session); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
18 | Unmatched statement int loc=writeElement(st,collection.getElement(entry),offset,session); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
19 | Unmatched statement writeIdentifier(st,collection.getIdentifier(entry,i),loc,session); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
20 | Unmatched statement loc=writeKey(st,id,loc,session); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
21 | Unmatched statement writeIndexToWhere(st,collection.getIndex(entry,i,this),loc,session); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
22 | Unmatched statement writeElementToWhere(st,collection.getSnapshotElement(entry,i),loc,session); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
23 | Unmatched statement if(useBatch) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
24 | Unmatched statement session.getBatcher().addToBatch(expectation); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
25 | Unmatched statement expectation.verifyOutcome(st.executeUpdate(),st,-1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
26 | Unmatched statement try cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
27 | Unmatched statement offset+=expectation.prepare(st); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
28 | Unmatched statement offset+=expectation.prepare(st); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
29 | Unmatched statement offset=writeKey(st,id,offset,session); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
30 | Unmatched statement offset=writeKey(st,id,offset,session); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
31 | Unmatched statement offset=writeIdentifier(st,collection.getIdentifier(entry,i),offset,session); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
32 | Unmatched statement offset=writeIndex(st,collection.getIndex(entry,i,this),offset,session); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
33 | Unmatched statement writeElement(st,collection.getElement(entry),offset,session); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
34 | Unmatched statement writeElement(st,collection.getElement(entry),offset,session); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
35 | Unmatched statement if(useBatch) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
36 | Unmatched statement session.getBatcher().addToBatch(expectation); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
37 | Unmatched statement expectation.verifyOutcome(st.executeUpdate(),st,-1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
38 | Unmatched statement collection.afterRowInsert(this,entry,i); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
39 | Unmatched statement collection.afterRowInsert(this,entry,i); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
40 | Unmatched statement count++; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
41 | Unmatched statement count++; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
42 | Unmatched statement return count; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
43 | Unmatched return count; |
44 | Unmatched statement log.debug("done inserting rows: " + count + " inserted"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
45 | Clone fragment #1 returns variables useBatch, st, expectation, i, entry, count , while Clone fragment #2 returns variables useBatch, st, expectation, entry, i, count |
Number of mapped statements | 1 |
Number of unmapped statements in the first code fragment | 5 |
Number of unmapped statements in the second code fragment | 2 |
Time elapsed for statement mapping (ms) | 4.6 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
27 | offset += expectation.prepare(st); | | ||||||||||||
28 | offset = writeKey(st, id, offset, session); |
| | |||||||||||
33 | writeElement(st, collection.getElement(entry), offset, session); |
| | |||||||||||
34 | if (useBatch) |
| 18 | if (callable) | ||||||||||
|
| 19 | st = session.getBatcher().prepareBatchCallableStatement(sql); | |||||||||||
35 | session.getBatcher().addToBatch(expectation); |
| | |||||||||||
else | | |||||||||||||
|
| 20 | st = session.getBatcher().prepareBatchStatement(sql); | |||||||||||
36 | expectation.verifyOutcome(st.executeUpdate(), st, -1); |
| |
Row | Violation |
---|---|
1 | Unmatched statement offset=writeKey(st,id,offset,session); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
2 | Unmatched statement writeElement(st,collection.getElement(entry),offset,session); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
3 | Unmatched statement st=session.getBatcher().prepareBatchCallableStatement(sql); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
4 | Unmatched statement st=session.getBatcher().prepareBatchCallableStatement(sql); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
5 | Unmatched statement session.getBatcher().addToBatch(expectation); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
6 | Unmatched statement session.getBatcher().addToBatch(expectation); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
7 | Unmatched statement st=session.getBatcher().prepareBatchStatement(sql); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
8 | Unmatched statement st=session.getBatcher().prepareBatchStatement(sql); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
9 | Unmatched statement expectation.verifyOutcome(st.executeUpdate(),st,-1); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
10 | The refactoring of the clones is infeasible, because the number of macthed statements is equal to zero |