/** * 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; }
this.getDescriptor().buildField((DatabaseField)keys.nextElement());
/** * INTERNAL: * Initialize the mapping. */ public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); if (!this.isSourceKeySpecified()) { // sourceKeyFields will be empty when #setTargetForeignKeyFieldName() is used this.setSourceKeyFields(oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(getDescriptor().getPrimaryKeyFields())); } this.initializeTargetForeignKeysToSourceKeys(); if (this.shouldInitializeSelectionCriteria()) { this.setSelectionCriteria(this.buildDefaultSelectionCriteria()); } this.initializeDeleteAllQuery(); }