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: 40 | Number of AST nodes: 38 | |||
1 | try {↵ | 1 | try {↵ | |
2 | //create all the new entries↵ | 2 | //insert all the new entries↵ | |
3 | Iterator entries = collection.entries(this);↵ | 3 | ↵ | |
4 | if ( entries.hasNext() ) {↵ | |||
5 | collection.preInsert( this );↵ | |||
6 | int i = 0;↵ | |||
7 | int count = 0;↵ | |||
8 | while ( entries.hasNext() ) {↵ | |||
9 | final Object entry = entries.next();↵ | |||
10 | if (↵ | 4 | collection.preInsert( this );↵ | |
11 | collection.entryExists( entry, i ) ) {↵ | 5 | Iterator entries = collection.entr↵ | |
12 | int offset = 1;↵ | |||
13 | PreparedStatement st = null;↵ | |||
14 | ↵ | 6 | ies( this );↵ | |
15 | Expectation expectation = Expectations.appropriateExpectation( getInsertCheckStyle() );↵ | 7 | Expectation expectation = Expectations.appropriateExpectation( getInsertCheckStyle() );↵ | |
16 | boolean callable = isInsertCallable();↵ | 8 | boolean callable = isInsertCallable();↵ | |
17 | boolean useBatch = expectation.canBeBatched();↵ | 9 | boolean useBatch = expectation.canBeBatched();↵ | |
18 | String sql = getSQLInsertRowString();↵ | 10 | String sql = getSQLInsertRowString();↵ | |
19 | if ( useBatch↵ | 11 | int i = 0;↵ | |
12 | int count = 0;↵ | |||
13 | while ( entries.hasNext() ) {↵ | |||
14 | int offset = 1;↵ | |||
15 | Object entry = entries.next();↵ | |||
16 | PreparedStatement st = null;↵ | |||
17 | if ( collection.needsInserting( entry, i, elementType ) ) {↵ | |||
18 | if ( useBatch ) {↵ | |||
20 | ) {↵ | 19 | if ( st == null ) {↵ | |
21 | if ( callable ) {↵ | 20 | if ( callable ) {↵ | |
22 | st = session.getBatcher().prepareBatchCallableStatement( sql );↵ | 21 | st = session.getBatcher().prepareBatchCallableStatement( sql );↵ | |
23 | }↵ | 22 | }↵ | |
24 | else {↵ | 23 | else {↵ | |
25 | st = session.getBatcher().prepareBatchStatement( sql );↵ | 24 | st = session.getBatcher().prepareBatchStatement( sql );↵ | |
26 | }↵ | 25 | }↵ | |
27 | }↵ | 26 | }↵ | |
28 | ↵ | 27 | }↵ | |
29 | else {↵ | 28 | else {↵ | |
30 | if ( callable ) {↵ | 29 | if ( callable ) {↵ | |
31 | st = session.getBatcher().prepareCallableStatement( sql );↵ | 30 | st = session.getBatcher().prepareCallableStatement( sql );↵ | |
32 | }↵ | 31 | }↵ | |
33 | else {↵ | 32 | else {↵ | |
34 | st = session.getBatcher().prepareStatement( sql );↵ | 33 | st = session.getBatcher().prepareStatement( sql );↵ | |
35 | }↵ | 34 | }↵ | |
36 | }↵ | 35 | }↵ | |
37 | try {↵ | 36 | try {↵ | |
38 | offset+= expectation.prepare( st );↵ | 37 | offset += expectation.prepare( st );↵ | |
39 | //TODO: copy/paste from insertRows()↵ | 38 | //TODO: copy/paste from recreate()↵ | |
40 | int loc = writeKey( st, id, offset, session );↵ | 39 | offset = writeKey( st, id, offset, session );↵ | |
41 | if ( hasIdentifier ) {↵ | 40 | if ( hasIdentifier ) {↵ | |
42 | loc = writeIdentifier( st, collection.getIdentifier(entry, i), loc, session );↵ | 41 | offset = writeIdentifier( st, collection.getIdentifier(entry, i), offset, session );↵ | |
43 | }↵ | 42 | }↵ | |
44 | if ( hasIndex /*&& !indexIsFormula*/ ) {↵ | 43 | if ( hasIndex /*&& !indexIsFormula*/ ) {↵ | |
45 | loc = writeIndex( st, collection.getIndex(entry, i, this), loc, session );↵ | 44 | offset = writeIndex( st, collection.getIndex(entry, i, this), offset, session );↵ | |
46 | }↵ | 45 | }↵ | |
47 | loc = writeElement(st, collection.getElement(entry), loc, session );↵ | 46 | writeElement(st, collection.getElement(entry), offset, session );↵ | |
48 | if ( useBatch ) {↵ | 47 | if ( useBatch ) {↵ | |
49 | session.getBatcher().addToBatch( expectation );↵ | 48 | session.getBatcher().addToBatch( expectation );↵ | |
50 | }↵ | 49 | }↵ | |
51 | else {↵ | 50 | else {↵ | |
52 | expectation.verifyOutcome( st.executeUpdate(), st, -1 );↵ | 51 | expectation.verifyOutcome( st.executeUpdate(), st, -1 );↵ | |
53 | }↵ | 52 | ↵ | |
53 | }↵ | |||
54 | collection.afterRowInsert( this, entry, i );↵ | 54 | collection.afterRowInsert( this, entry, i );↵ | |
55 | count++;↵ | 55 | count++;↵ | |
56 | }↵ | 56 | }↵ | |
57 | catch ( SQLException sqle ) {↵ | 57 | catch ( SQLException sqle ) {↵ | |
58 | if ( useBatch ) {↵ | 58 | if ( useBatch ) {↵ | |
59 | session.getBatcher().abortBatch( sqle );↵ | 59 | session.getBatcher().abortBatch( sqle );↵ | |
60 | }↵ | 60 | }↵ | |
61 | throw sqle;↵ | 61 | throw sqle;↵ | |
62 | }↵ | 62 | }↵ | |
63 | finally {↵ | 63 | finally {↵ | |
64 | if ( !useBatch ) {↵ | 64 | if ( !useBatch ) {↵ | |
65 | session.getBatcher().closeStatement( st );↵ | 65 | session.getBatcher().closeStatement( st );↵ | |
66 | }↵ | 66 | }↵ | |
67 | }↵ | 67 | }↵ | |
68 | }↵ | 68 | }↵ | |
69 | i++;↵ | 69 | i++;↵ | |
70 | }↵ | 70 | ↵ | |
71 | }↵ | |||
71 | if ( log.isDebugEnabled() ) {↵ | 72 | if ( log.isDebugEnabled() ) {↵ | |
72 | log.debug( "done inserting collection: " + count + " rows inserted" );↵ | 73 | log.debug( "done inserting rows: " + count + " inserted" );↵ | |
73 | }↵ | 74 | ↵ | |
74 | }↵ | |||
75 | else {↵ | |||
76 | if ( log.isDebugEnabled() ) {↵ | |||
77 | log.debug( "collection was empty" );↵ | |||
78 | }↵ | |||
79 | }↵ | 75 | }↵ | |
80 | }↵ | 76 | }↵ | |
81 | catch ( SQLException sqle ) {↵ | 77 | catch ( SQLException sqle ) {↵ | |
82 | throw JDBCExceptionHelper.convert(↵ | 78 | throw JDBCExceptionHelper.convert(↵ | |
83 | sqlExceptionConverter,↵ | 79 | sqlExceptionConverter,↵ | |
84 | sqle,↵ | 80 | sqle,↵ | |
85 | "could not insert collection: " + ↵ | 81 | "could not insert collection rows: " + ↵ | |
86 | MessageHelper.collectionInfoString( this, id, getFactory() ),↵ | 82 | MessageHelper.collectionInfoString( this, id, getFactory() ),↵ | |
87 | getSQLInsertRowString()↵ | 83 | getSQLInsertRowString()↵ | |
88 | );↵ | 84 | );↵ | |
89 | } | 85 |
| |
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) | 2.8 |
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) | 2.6 |
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) | 2.6 |
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) | 21.9 |
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) | 1.2 |
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 |