@Override
public boolean update( Connection c, MetaClass mc, ObjectMappingDB omdb,
Object o, Collection<MetaField> fields, Collection<MetaField> keys,
MetaField dirtyField, Object dirtyValue ) throws SQLException {
Expression exp = null;
// Check if there is table inheritence going on, and if so delete the super table first
BaseDef base = omdb.getDBDef();
if ( base instanceof TableDef ) {
TableDef table = (TableDef) base;
InheritenceDef inheritence = table.getInheritence();
if ( inheritence != null ) {
ObjectMappingDB smom = (ObjectMappingDB) omdb.getSuperMapping();
// Setup the key
MetaField rf = omdb.getField( inheritence.getRefColumn() );
Collection<MetaField> pkeys = new ArrayList<MetaField>();
pkeys.add( rf );
// Create the super classes table entry
if ( !update( c, mc, smom, o, fields, pkeys, dirtyField, dirtyValue )) {
return false;
// throw new SQLException( "Super table entry could not be updated for mapping [" + smom + "]" );
}
// Set the mapping field
MetaField f = omdb.getField( inheritence.getColumnName() );
// Set the expression to delete
exp = new Expression( f.getName(), rf.getObject( o ));
// Can only have dirty fields on the highest level of inheritence
dirtyField = null;
dirtyValue = null;
}
}
// If there wasn't inheritence, then generate the delete where clause
if ( exp == null ) {
// Generate the keys expression
for( MetaField mf : keys ) {
//if ( omdb.isInThisMap( mf )) {
Expression e = new Expression( mf.getName(), mf.getObject( o ));
if ( exp == null ) exp = e;
else exp = exp.and( e );
//}
}
}
// Add the dirty field expression
if ( dirtyField != null ) {
Expression e = new Expression( dirtyField.getName(), dirtyValue );
if ( exp == null ) exp = e;
else exp = exp.and( e );
}
//setAutoFields( c, mc, omdb, fields, o, ObjectManager.UPDATE );