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