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/AbstractCollectionPersister.java | |||
Method name: void recreate(PersistentCollection, Serializable, SessionImplementor)
|
Method name: void insertRows(PersistentCollection, Serializable, SessionImplementor)
|
|||
Number of AST nodes: 43 | Number of AST nodes: 41 | |||
1 | if ( !isInverse && isRowInsertEnabled() ) {↵ | 1 | if ( !isInverse && isRowInsertEnabled() ) {↵ | |
2 | if ( log.isDebugEnabled() ) {↵ | 2 | if ( log.isDebugEnabled() ) {↵ | |
3 | log.debug( ↵ | 3 | log.debug( ↵ | |
4 | "Inserting collection: " + ↵ | 4 | "Inserting rows of collection: " + ↵ | |
5 | MessageHelper.collectionInfoString( this, id, getFactory() ) ↵ | 5 | MessageHelper.collectionInfoString( this, id, getFactory() ) ↵ | |
6 | );↵ | 6 | );↵ | |
7 | }↵ | 7 | }↵ | |
8 | try {↵ | 8 | try {↵ | |
9 | //create all the new entries↵ | 9 | //insert all the new entries↵ | |
10 | Iterator entries = collection.entries(this);↵ | 10 | ↵ | |
11 | if ( entries.hasNext() ) {↵ | |||
12 | collection.preInsert( this );↵ | |||
13 | int i = 0;↵ | |||
14 | int count = 0;↵ | |||
15 | while ( entries.hasNext() ) {↵ | |||
16 | final Object entry = entries.next();↵ | |||
17 | if (↵ | 11 | collection.preInsert( this );↵ | |
18 | collection.entryExists( entry, i ) ) {↵ | 12 | Iterator entries = collection.entr↵ | |
19 | int offset = 1;↵ | |||
20 | PreparedStatement st = null;↵ | |||
21 | ↵ | 13 | ies( this );↵ | |
22 | Expectation expectation = Expectations.appropriateExpectation( getInsertCheckStyle() );↵ | 14 | Expectation expectation = Expectations.appropriateExpectation( getInsertCheckStyle() );↵ | |
23 | boolean callable = isInsertCallable();↵ | 15 | boolean callable = isInsertCallable();↵ | |
24 | boolean useBatch = expectation.canBeBatched();↵ | 16 | boolean useBatch = expectation.canBeBatched();↵ | |
25 | String sql = getSQLInsertRowString();↵ | 17 | String sql = getSQLInsertRowString();↵ | |
26 | if ( useBatch↵ | 18 | int i = 0;↵ | |
19 | int count = 0;↵ | |||
20 | while ( entries.hasNext() ) {↵ | |||
21 | int offset = 1;↵ | |||
22 | Object entry = entries.next();↵ | |||
23 | PreparedStatement st = null;↵ | |||
24 | if ( collection.needsInserting( entry, i, elementType ) ) {↵ | |||
25 | if ( useBatch ) {↵ | |||
27 | ) {↵ | 26 | if ( st == null ) {↵ | |
28 | if ( callable ) {↵ | 27 | if ( callable ) {↵ | |
29 | st = session.getBatcher().prepareBatchCallableStatement( sql );↵ | 28 | st = session.getBatcher().prepareBatchCallableStatement( sql );↵ | |
30 | }↵ | 29 | }↵ | |
31 | else {↵ | 30 | else {↵ | |
32 | st = session.getBatcher().prepareBatchStatement( sql );↵ | 31 | st = session.getBatcher().prepareBatchStatement( sql );↵ | |
33 | }↵ | 32 | }↵ | |
34 | }↵ | 33 | }↵ | |
35 | ↵ | 34 | }↵ | |
36 | else {↵ | 35 | else {↵ | |
37 | if ( callable ) {↵ | 36 | if ( callable ) {↵ | |
38 | st = session.getBatcher().prepareCallableStatement( sql );↵ | 37 | st = session.getBatcher().prepareCallableStatement( sql );↵ | |
39 | }↵ | 38 | }↵ | |
40 | else {↵ | 39 | else {↵ | |
41 | st = session.getBatcher().prepareStatement( sql );↵ | 40 | st = session.getBatcher().prepareStatement( sql );↵ | |
42 | }↵ | 41 | }↵ | |
43 | }↵ | 42 | ↵ | |
43 | }↵ | |||
44 | try {↵ | 44 | try {↵ | |
45 | offset+= expectation.prepare( st );↵ | 45 | offset += expectation.prepare( st );↵ | |
46 | //TODO: copy/paste from insertRows()↵ | 46 | //TODO: copy/paste from recreate()↵ | |
47 | int loc = writeKey( st, id, offset, session );↵ | 47 | offset = writeKey( st, id, offset, session );↵ | |
48 | if ( hasIdentifier ) {↵ | 48 | if ( hasIdentifier ) {↵ | |
49 | loc = writeIdentifier( st, collection.getIdentifier(entry, i), loc, session );↵ | 49 | offset = writeIdentifier( st, collection.getIdentifier(entry, i), offset, session );↵ | |
50 | }↵ | 50 | }↵ | |
51 | if ( hasIndex /*&& !indexIsFormula*/ ) {↵ | 51 | if ( hasIndex /*&& !indexIsFormula*/ ) {↵ | |
52 | loc = writeIndex( st, collection.getIndex(entry, i, this), loc, session );↵ | 52 | offset = writeIndex( st, collection.getIndex(entry, i, this), offset, session );↵ | |
53 | }↵ | 53 | }↵ | |
54 | loc = writeElement(st, collection.getElement(entry), loc, session );↵ | 54 | writeElement(st, collection.getElement(entry), offset, session );↵ | |
55 | if ( useBatch ) {↵ | 55 | if ( useBatch ) {↵ | |
56 | session.getBatcher().addToBatch( expectation );↵ | 56 | session.getBatcher().addToBatch( expectation );↵ | |
57 | }↵ | 57 | }↵ | |
58 | else {↵ | 58 | else {↵ | |
59 | expectation.verifyOutcome( st.executeUpdate(), st, -1 );↵ | 59 | expectation.verifyOutcome( st.executeUpdate(), st, -1 );↵ | |
60 | }↵ | 60 | }↵ | |
61 | collection.afterRowInsert( this, entry, i );↵ | 61 | collection.afterRowInsert( this, entry, i );↵ | |
62 | count++;↵ | 62 | count++;↵ | |
63 | }↵ | 63 | }↵ | |
64 | catch ( SQLException sqle ) {↵ | 64 | catch ( SQLException sqle ) {↵ | |
65 | if ( useBatch ) {↵ | 65 | if ( useBatch ) {↵ | |
66 | session.getBatcher().abortBatch( sqle );↵ | 66 | session.getBatcher().abortBatch( sqle );↵ | |
67 | }↵ | 67 | }↵ | |
68 | throw sqle;↵ | 68 | throw sqle;↵ | |
69 | }↵ | 69 | }↵ | |
70 | finally {↵ | 70 | finally {↵ | |
71 | if ( !useBatch ) {↵ | 71 | if ( !useBatch ) {↵ | |
72 | session.getBatcher().closeStatement( st );↵ | 72 | session.getBatcher().closeStatement( st );↵ | |
73 | }↵ | 73 | }↵ | |
74 | }↵ | 74 | ↵ | |
75 | }↵ | |||
75 | }↵ | 76 | }↵ | |
76 | i++;↵ | 77 | i++;↵ | |
77 | }↵ | 78 | }↵ | |
78 | if ( log.isDebugEnabled() ) {↵ | 79 | if ( log.isDebugEnabled() ) {↵ | |
79 | log.debug( "done inserting collection: " + count + " rows inserted" );↵ | 80 | log.debug( "done inserting rows: " + count + " inserted" );↵ | |
80 | }↵ | 81 | ↵ | |
81 | }↵ | |||
82 | else {↵ | |||
83 | if ( log.isDebugEnabled() ) {↵ | |||
84 | log.debug( "collection was empty" );↵ | |||
85 | }↵ | |||
86 | }↵ | 82 | }↵ | |
87 | }↵ | 83 | }↵ | |
88 | catch ( SQLException sqle ) {↵ | 84 | catch ( SQLException sqle ) {↵ | |
89 | throw JDBCExceptionHelper.convert(↵ | 85 | throw JDBCExceptionHelper.convert(↵ | |
90 | sqlExceptionConverter,↵ | 86 | sqlExceptionConverter,↵ | |
91 | sqle,↵ | 87 | sqle,↵ | |
92 | "could not insert collection: " + ↵ | 88 | "could not insert collection rows: " + ↵ | |
93 | MessageHelper.collectionInfoString( this, id, getFactory() ),↵ | 89 | MessageHelper.collectionInfoString( this, id, getFactory() ),↵ | |
94 | getSQLInsertRowString()↵ | 90 | getSQLInsertRowString()↵ | |
95 | );↵ | 91 | );↵ | |
96 | }↵ | 92 | }↵ | |
97 | } | 93 |
| |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 4 |
Number of refactorable cases | 2 |
Number of non-refactorable cases | 2 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 150.2 |
Clones location | Clones are declared in the same class |
Number of node comparisons | 170 |
Number of mapped statements | 3 |
Number of unmapped statements in the first code fragment | 0 |
Number of unmapped statements in the second code fragment | 0 |
Time elapsed for statement mapping (ms) | 258.7 |
Clone type | Type 1 |
ID | Statement | ID | Statement | |
---|---|---|---|---|
20 | if (callable) | 20 | if (callable) | |
21 | st = session.getBatcher().prepareBatchCallableStatement(sql); | 21 | st = session.getBatcher().prepareBatchCallableStatement(sql); | |
else | else | |||
22 | st = session.getBatcher().prepareBatchStatement(sql); | 22 | st = session.getBatcher().prepareBatchStatement(sql); |
Row | Violation |
---|
Number of mapped statements | 3 |
Number of unmapped statements in the first code fragment | 0 |
Number of unmapped statements in the second code fragment | 0 |
Time elapsed for statement mapping (ms) | 39.4 |
Clone type | Type 2 |
ID | Statement | ID | Statement | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
23 | if (callable) | 20 | if (callable) | |||||||||||
24 | st = session.getBatcher().prepareCallableStatement(sql); |
| 21 | st = session.getBatcher().prepareBatchCallableStatement(sql); | ||||||||||
else | else | |||||||||||||
25 | st = session.getBatcher().prepareStatement(sql); |
| 22 | st = session.getBatcher().prepareBatchStatement(sql); |
Row | Violation |
---|
Number of mapped statements | 19 |
Number of unmapped statements in the first code fragment | 16 |
Number of unmapped statements in the second code fragment | 18 |
Time elapsed for statement mapping (ms) | 88.7 |
Clone type | Type 3 |
ID | Statement | ID | Statement | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7 | collection.preInsert(this); | 5 | collection.preInsert(this); | ||||||||||||||||||
8 | int i = 0; | 11 | int i = 0; | ||||||||||||||||||
9 | int count = 0; | 12 | int count = 0; | ||||||||||||||||||
10 | while (entries.hasNext()) | 13 | while (entries.hasNext()) | ||||||||||||||||||
11 | final Object entry = entries.next(); |
| | ||||||||||||||||||
|
| 14 | int offset = 1; | ||||||||||||||||||
|
| 15 | Object entry = entries.next(); | ||||||||||||||||||
|
| 16 | PreparedStatement st = null; | ||||||||||||||||||
12 | if (collection.entryExists(entry, i)) |
| 17 | if (collection.needsInserting(entry, i, elementType)) | |||||||||||||||||
13 | int offset = 1; |
| | ||||||||||||||||||
14 | PreparedStatement st = null; |
| | ||||||||||||||||||
15 | Expectation expectation = Expectations.appropriateExpectation(getInsertCheckStyle()); |
| | ||||||||||||||||||
16 | boolean callable = isInsertCallable(); |
| | ||||||||||||||||||
17 | boolean useBatch = expectation.canBeBatched(); |
| | ||||||||||||||||||
| 18 | if (useBatch) | |||||||||||||||||||
| 19 | if (st == null) | |||||||||||||||||||
| 20 | if (callable) | |||||||||||||||||||
|
| 21 | st = session.getBatcher().prepareBatchCallableStatement(sql); | ||||||||||||||||||
| else | ||||||||||||||||||||
|
| 22 | st = session.getBatcher().prepareBatchStatement(sql); | ||||||||||||||||||
| 23 | if (callable) | |||||||||||||||||||
|
| 24 | st = session.getBatcher().prepareCallableStatement(sql); | ||||||||||||||||||
| else | ||||||||||||||||||||
|
| 25 | st = session.getBatcher().prepareStatement(sql); | ||||||||||||||||||
18 | String sql = getSQLInsertRowString(); |
| | ||||||||||||||||||
19 | if (useBatch) | | |||||||||||||||||||
20 | if (callable) | | |||||||||||||||||||
21 | st = session.getBatcher().prepareBatchCallableStatement(sql); |
| | ||||||||||||||||||
else | | ||||||||||||||||||||
22 | st = session.getBatcher().prepareBatchStatement(sql); |
| | ||||||||||||||||||
23 | if (callable) | | |||||||||||||||||||
24 | st = session.getBatcher().prepareCallableStatement(sql); |
| | ||||||||||||||||||
else | | ||||||||||||||||||||
25 | st = session.getBatcher().prepareStatement(sql); |
| | ||||||||||||||||||
26 | try | 26 | try | ||||||||||||||||||
27 | offset += expectation.prepare(st); | 27 | offset += expectation.prepare(st); | ||||||||||||||||||
|
| 28 | offset = writeKey(st, id, offset, session); | ||||||||||||||||||
28 | int loc = writeKey(st, id, offset, session); |
| | ||||||||||||||||||
29 | if (hasIdentifier) | 29 | if (hasIdentifier) | ||||||||||||||||||
30 | loc = writeIdentifier(st, collection.getIdentifier(entry, i), loc, session); |
| 30 | offset = writeIdentifier(st, collection.getIdentifier(entry, i), offset, session); | |||||||||||||||||
31 | if (hasIndex) | 31 | if (hasIndex) | ||||||||||||||||||
32 | loc = writeIndex(st, collection.getIndex(entry, i, this), loc, session); |
| 32 | offset = writeIndex(st, collection.getIndex(entry, i, this), offset, session); | |||||||||||||||||
|
| 33 | writeElement(st, collection.getElement(entry), offset, session); | ||||||||||||||||||
33 | loc = writeElement(st, collection.getElement(entry), loc, session); |
| | ||||||||||||||||||
34 | if (useBatch) | 34 | if (useBatch) | ||||||||||||||||||
35 | session.getBatcher().addToBatch(expectation); | 35 | session.getBatcher().addToBatch(expectation); | ||||||||||||||||||
else | else | ||||||||||||||||||||
36 | expectation.verifyOutcome(st.executeUpdate(), st, -1); | 36 | expectation.verifyOutcome(st.executeUpdate(), st, -1); | ||||||||||||||||||
37 | collection.afterRowInsert(this, entry, i); | 37 | collection.afterRowInsert(this, entry, i); | ||||||||||||||||||
38 | count++; | 38 | count++; | ||||||||||||||||||
39 | i++; | 39 | i++; | ||||||||||||||||||
40 | if (log.isDebugEnabled()) | 40 | if (log.isDebugEnabled()) | ||||||||||||||||||
41 | log.debug("done inserting collection: " + count + " rows inserted"); |
| 41 | log.debug("done inserting rows: " + count + " inserted"); |
Row | Violation |
---|---|
1 | Unmatched statement final Object entry=entries.next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements 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 Object entry=entries.next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
4 | 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 |
5 | Expression collection.entryExists(entry,i) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
6 | Expression collection.needsInserting(entry,i,elementType) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
7 | Expression collection.entryExists(entry,i) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
8 | Expression collection.needsInserting(entry,i,elementType) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
9 | 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 |
10 | 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 |
11 | Unmatched statement Expectation expectation=Expectations.appropriateExpectation(getInsertCheckStyle()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
12 | Unmatched statement boolean callable=isInsertCallable(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
13 | Unmatched statement boolean useBatch=expectation.canBeBatched(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
14 | Unmatched statement st=session.getBatcher().prepareBatchCallableStatement(sql); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
15 | 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 |
16 | Unmatched statement st=session.getBatcher().prepareCallableStatement(sql); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
17 | 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 |
18 | Unmatched statement String sql=getSQLInsertRowString(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
19 | Unmatched statement st=session.getBatcher().prepareBatchCallableStatement(sql); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
20 | 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 |
21 | Unmatched statement st=session.getBatcher().prepareCallableStatement(sql); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
22 | 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 |
23 | 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 |
24 | 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 |
25 | Unmatched statement int loc=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 |
26 | Unmatched statement int loc=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 |
27 | Expression loc cannot be parameterized, because it has dependencies to/from statements that will be extracted |
28 | Expression offset cannot be parameterized, because it has dependencies to/from statements that will be extracted |
29 | Expression loc cannot be parameterized, because it has dependencies to/from statements that will be extracted |
30 | Expression offset cannot be parameterized, because it has dependencies to/from statements that will be extracted |
31 | 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 |
32 | 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 |
33 | Unmatched statement loc=writeElement(st,collection.getElement(entry),loc,session); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
34 | Unmatched statement loc=writeElement(st,collection.getElement(entry),loc,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 | Clone fragment #1 returns variables offset, loc , while Clone fragment #2 returns variables offset |
Number of mapped statements | 1 |
Number of unmapped statements in the first code fragment | 1 |
Number of unmapped statements in the second code fragment | 2 |
Time elapsed for statement mapping (ms) | 2.1 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
42 | if (log.isDebugEnabled()) |
| 20 | if (callable) | ||||||||||
|
| 21 | st = session.getBatcher().prepareBatchCallableStatement(sql); | |||||||||||
| else | |||||||||||||
|
| 22 | st = session.getBatcher().prepareBatchStatement(sql); | |||||||||||
43 | log.debug("collection was empty"); | |
Row | Violation |
---|---|
1 | Unmatched statement st=session.getBatcher().prepareBatchCallableStatement(sql); cannot be moved, because it updates a variable modified in other unmapped statements |
2 | Unmatched statement st=session.getBatcher().prepareBatchStatement(sql); cannot be moved, because it updates a variable modified in other unmapped statements |