throws HibernateException {
if ( ArrayHelper.isAllFalse( elementColumnIsSettable ) ) return 0;
int count = 0;
int i = 0;
Iterator entries = collection.entries( this );
PropertyMetadataProvider metadataProvider = new PropertyMetadataProvider()
.gridManager( gridManager )
.tableName( getTableName() )
.key( key )
.keyColumnNames( getKeyColumnNames() )
.keyGridType( getKeyGridType() )
.session( session );
while ( entries.hasNext() ) {
Object entry = entries.next();
if ( collection.needsUpdating( entry, i, elementType ) ) {
//get the tuple Key
Map<String, Object> tupleKey = getTupleKeyForUpdate( key, collection, session, i, entry );
//find the matching element
Map<String, Object> matchingTuple = metadataProvider.findMatchingTuple( tupleKey );
if ( matchingTuple == null ) {
throw new AssertionFailure( "Updating a collection tuple that is not present: " +
"table {" + getTableName() + "} collectionKey {" + key + "} entry {" + entry + "}" );
}
//update the matching element
//FIXME update the associated entity key data
updateAssociatedEntityTableIfNeeded( session, matchingTuple, Action.REMOVE );
getElementGridType().nullSafeSet( matchingTuple, collection.getElement( entry ), getElementColumnNames(), session );
updateAssociatedEntityTableIfNeeded( session, matchingTuple, Action.ADD );
count++;
}
i++;
}
//need to put the data back in the cache
metadataProvider.flushToCache();
return count;
}