/** * INTERNAL: * Maintain for backward compatibility. * This is 'public' so StoredProcedureGenerator * does not have to use the custom query expressions. */ public Map getTargetForeignKeyToSourceKeys() { return this.getTargetForeignKeysToSourceKeys(); }
private void addForeignKeyFieldToSourceTargetTable(OneToManyMapping mapping) { addForeignMappingFkConstraint(mapping.getTargetForeignKeysToSourceKeys()); }
/** * INTERNAL: * Clone the appropriate attributes. */ public Object clone() { OneToManyMapping clone = (OneToManyMapping)super.clone(); clone.setTargetForeignKeysToSourceKeys(new HashMap(this.getTargetForeignKeysToSourceKeys())); return clone; }
/** * The selection criteria are created with target foreign keys and source "primary" keys. * These criteria are then used to read the target records from the table. * These criteria are also used as the default "delete all" criteria. * * CR#3922 - This method is almost the same as buildSelectionCriteria() the difference * is that TargetForeignKeysToSourceKeys contains more information after login then SourceKeyFields * contains before login. */ protected Expression buildDefaultSelectionCriteria() { Expression selectionCriteria = null; Expression builder = new ExpressionBuilder(); for (Iterator keys = this.getTargetForeignKeysToSourceKeys().keySet().iterator(); keys.hasNext();) { DatabaseField targetForeignKey = (DatabaseField)keys.next(); DatabaseField sourceKey = (DatabaseField)this.getTargetForeignKeysToSourceKeys().get(targetForeignKey); Expression partialSelectionCriteria = builder.getField(targetForeignKey).equal(builder.getParameter(sourceKey)); selectionCriteria = partialSelectionCriteria.and(selectionCriteria); } return selectionCriteria; }
/** * Extract the key field values from the specified row. * Used for batch reading. Keep the fields in the same order * as in the targetForeignKeysToSourceKeys hashtable. */ protected Vector extractKeyFromRow(AbstractRecord row, AbstractSession session) { Vector key = new Vector(this.getTargetForeignKeysToSourceKeys().size()); for (Iterator stream = this.getTargetForeignKeysToSourceKeys().values().iterator(); stream.hasNext();) { DatabaseField field = (DatabaseField)stream.next(); Object value = row.get(field); // Must ensure the classification to get a cache hit. try { value = session.getDatasourcePlatform().convertObject(value, getDescriptor().getObjectBuilder().getFieldClassification(field)); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } key.addElement(value); } return key; }
/** * Extract the foreign key value from the reference object. * Used for batch reading. Keep the fields in the same order * as in the targetForeignKeysToSourceKeys hashtable. */ protected Vector extractForeignKeyFromReferenceObject(Object object, AbstractSession session) { Vector foreignKey = new Vector(this.getTargetForeignKeysToSourceKeys().size()); for (Iterator stream = this.getTargetForeignKeysToSourceKeys().entrySet().iterator(); stream.hasNext();) { Map.Entry entry = (Map.Entry)stream.next(); DatabaseField targetField = (DatabaseField)entry.getKey(); DatabaseField sourceField = (DatabaseField)entry.getValue(); if (object == null) { foreignKey.addElement(null); } else { Object value = this.getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(object, targetField, session); //CR:somenewsgroupbug need to ensure source and target types match. try { value = session.getDatasourcePlatform().convertObject(value, getDescriptor().getObjectBuilder().getFieldClassification(sourceField)); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } foreignKey.addElement(value); } } return foreignKey; }
DatabaseField targetForeignKey = targetForeignKeys.nextElement(); DatabaseField sourcePrimaryKey = sourceKeys.nextElement(); this.getTargetForeignKeysToSourceKeys().put(targetForeignKey, sourcePrimaryKey); this.getSourceKeysToTargetForeignKeys().put(sourcePrimaryKey, targetForeignKey);