else if ( associationType == AssociationType.ASSOCIATION_TABLE_TO_ENTITY ) {
String[] elementColumnNames = getElementColumnNames();
Object[] elementColumnValues = LogicalPhysicalConverterHelper.getColumnValuesFromResultset( tuple, elementColumnNames );
Serializable entityId = (Serializable) gridTypeOfAssociatedId.nullSafeGet( tuple, getElementColumnNames(), session, null );
AssociationPersister associationPersister = new AssociationPersister(
getElementPersister().getMappedClass()
)
.gridDialect( gridDialect )
.keyColumnValues( elementColumnValues )
.session( session )
.associationKeyMetadata( associationKeyMetadataFromElement )
.collectionPersister( this )
.key( entityId )
.inverse();
// TODO what happens when a row should be *updated* ?: I suspect ADD works OK as it's a put()
if ( action == Action.ADD ) {
// FIXME build the key
Tuple assocTuple = associationPersister.createAndPutAssociationTuple( rowKey );
for ( String columnName : tuple.getColumnNames() ) {
assocTuple.put( columnName, tuple.get( columnName ) );
}
associationPersister.getAssociation().put( rowKey, assocTuple );
}
else if ( action == Action.REMOVE ) {
// we try and match the whole tuple as it should be on both sides of the navigation
if ( rowKey == null ) {
throw new AssertionFailure( "Deleting a collection tuple that is not present: " + "table {"
+ getTableName() + "} key column names {" + Arrays.toString( elementColumnNames )
+ "} key column values {" + Arrays.toString( elementColumnValues ) + "}" );
}
associationPersister.getAssociation().remove( rowKey );
}
else {
throw new AssertionFailure( "Unknown action type: " + action );
}
if ( associationPersister.hostingEntityRequiresReadAfterUpdate() && entity == null ) {
entity = session.getPersistenceContext().getEntity( session.generateEntityKey( entityId, getElementPersister() ) );
}
associationPersister.hostingEntity( entity );
associationPersister.flushToCache();
}
}