if ( ArrayHelper.isAllFalse(elementColumnIsSettable) ) return 0;
try {
PreparedStatement st = null;
Expectation expectation = Expectations.appropriateExpectation( getUpdateCheckStyle() );
boolean callable = isUpdateCallable();
boolean useBatch = expectation.canBeBatched();
Iterator entries = collection.entries( this );
String sql = getSQLUpdateRowString();
int i = 0;
int count = 0;
while ( entries.hasNext() ) {
Object entry = entries.next();
if ( collection.needsUpdating( entry, i, elementType ) ) {
int offset = 1;
if ( useBatch ) {
if ( updateBatchKey == null ) {
updateBatchKey = new BasicBatchKey(
getRole() + "#UPDATE",
expectation
);
}
st = session.getTransactionCoordinator()
.getJdbcCoordinator()
.getBatch( updateBatchKey )
.getBatchStatement( sql, callable );
}
else {
st = session.getTransactionCoordinator()
.getJdbcCoordinator()
.getStatementPreparer()
.prepareStatement( sql, callable );
}
try {
offset+= expectation.prepare( st );
int loc = writeElement( st, collection.getElement( entry ), offset, session );
if ( hasIdentifier ) {
writeIdentifier( st, collection.getIdentifier( entry, i ), loc, session );
}
else {
loc = writeKey( st, id, loc, session );
if ( hasIndex && !indexContainsFormula ) {
writeIndexToWhere( st, collection.getIndex( entry, i, this ), loc, session );
}
else {
writeElementToWhere( st, collection.getSnapshotElement( entry, i ), loc, session );
}
}
if ( useBatch ) {
session.getTransactionCoordinator()
.getJdbcCoordinator()
.getBatch( updateBatchKey )
.addToBatch();
}
else {
expectation.verifyOutcome( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 );
}
}
catch ( SQLException sqle ) {
if ( useBatch ) {
session.getTransactionCoordinator().getJdbcCoordinator().abortBatch();