/** * INTERNAL: * If a user does not specify the source key then the primary keys of the source table are used. */ protected void initializeSourceKeysWithDefaults(AbstractSession session) { List<DatabaseField> primaryKeyFields = getDescriptor().getPrimaryKeyFields(); for (int index = 0; index < primaryKeyFields.size(); index++) { getSourceKeyFields().addElement(primaryKeyFields.get(index)); } }
/** * INTERNAL: * All the source key field names are converted to DatabaseField and stored. */ protected void initializeSourceKeys(AbstractSession session) { for (Enumeration sourceEnum = getSourceKeyFields().elements(); sourceEnum.hasMoreElements();) { getDescriptor().buildField((DatabaseField)sourceEnum.nextElement()); } }
/** * INTERNAL: * The translation row may require additional fields than the primary key if the mapping in not on the primary key. */ protected void prepareTranslationRow(AbstractRecord translationRow, Object object, AbstractSession session) { // Make sure that each source key field is in the translation row. for (Enumeration sourceFieldsEnum = getSourceKeyFields().elements(); sourceFieldsEnum.hasMoreElements();) { DatabaseField sourceKey = (DatabaseField)sourceFieldsEnum.nextElement(); if (!translationRow.containsKey(sourceKey)) { Object value = getDescriptor().getObjectBuilder().extractValueFromObjectForField(object, sourceKey, session); translationRow.put(sourceKey, value); } } }
/** * INTERNAL: * Extract the primary key value from the source row. * Used for batch reading, most following same order and fields as in the mapping. */ protected Vector extractPrimaryKeyFromRow(AbstractRecord row, AbstractSession session) { Vector key = new Vector(getSourceKeyFields().size()); for (Enumeration fieldEnum = getSourceKeyFields().elements(); fieldEnum.hasMoreElements();) { DatabaseField field = (DatabaseField)fieldEnum.nextElement(); Object value = row.get(field); // Must ensure the classificatin to get a cache hit. try { value = session.getDatasourcePlatform().getConversionManager().convertObject(value, getDescriptor().getObjectBuilder().getFieldClassification(field)); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } key.addElement(value); } return key; }
/** * INTERNAL: * Extract the source primary key value from the relation row. * Used for batch reading, most following same order and fields as in the mapping. */ protected Vector extractKeyFromRelationRow(AbstractRecord row, AbstractSession session) { Vector key = new Vector(getSourceRelationKeyFields().size()); for (int index = 0; index < getSourceRelationKeyFields().size(); index++) { DatabaseField relationField = (DatabaseField)getSourceRelationKeyFields().elementAt(index); DatabaseField sourceField = (DatabaseField)getSourceKeyFields().elementAt(index); Object value = row.get(relationField); // Must ensure the classificatin to get a cache hit. try { value = session.getDatasourcePlatform().getConversionManager().convertObject(value, getDescriptor().getObjectBuilder().getFieldClassification(sourceField)); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } key.addElement(value); } return key; }