/** * INTERNAL: * Extract the key value from the reference object. */ protected Vector extractKeyFromReferenceObject(Object object, AbstractSession session) { Vector key = new Vector(); Iterator sourceKeyIterator = getSourceToTargetKeyFields().keySet().iterator(); while (sourceKeyIterator.hasNext()) { DatabaseField field = (DatabaseField)sourceKeyIterator.next(); if (object == null) { key.addElement(null); } else { key.addElement(getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(object, field, session)); } } return key; }
/** * INTERNAL: * Return the primary key for the reference object (i.e. the object * object referenced by domainObject and specified by mapping). * This key will be used by a RemoteValueHolder. */ public Vector extractPrimaryKeysForReferenceObjectFromRow(AbstractRecord row) { List primaryKeyFields = getReferenceDescriptor().getPrimaryKeyFields(); Vector result = new Vector(primaryKeyFields.size()); for (int index = 0; index < primaryKeyFields.size(); index++) { DatabaseField targetKeyField = (DatabaseField)primaryKeyFields.get(index); DatabaseField sourceKeyField = (DatabaseField)getTargetToSourceKeyFields().get(targetKeyField); if (sourceKeyField == null) { return new Vector(1); } result.addElement(row.get(sourceKeyField)); } return result; }
/** * INTERNAL: * The foreign keys primary keys are stored as database fields in the hashtable. */ protected void initializeForeignKeys(AbstractSession session) { HashMap newSourceToTargetKeyFields = new HashMap(getSourceToTargetKeyFields().size()); HashMap newTargetToSourceKeyFields = new HashMap(getTargetToSourceKeyFields().size()); Iterator iterator = getSourceToTargetKeyFields().entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry)iterator.next(); DatabaseField sourceField = (DatabaseField)entry.getKey(); DatabaseField targetField = (DatabaseField)entry.getValue(); sourceField = getDescriptor().buildField(sourceField); targetField = getReferenceDescriptor().buildField(targetField); newSourceToTargetKeyFields.put(sourceField, targetField); newTargetToSourceKeyFields.put(targetField, sourceField); } setSourceToTargetKeyFields(newSourceToTargetKeyFields); setTargetToSourceKeyFields(newTargetToSourceKeyFields); }
/** * INTERNAL: * The foreign keys primary keys are stored as database fields in the hashtable. */ protected void initializeForeignKeys(AbstractSession session) { HashMap newSourceToTargetKeyFields = new HashMap(getSourceToTargetKeyFields().size()); HashMap newTargetToSourceKeyFields = new HashMap(getTargetToSourceKeyFields().size()); Iterator iterator = getSourceToTargetKeyFields().entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry)iterator.next(); DatabaseField sourceField = (DatabaseField)entry.getKey(); DatabaseField targetField = (DatabaseField)entry.getValue(); sourceField = getDescriptor().buildField(sourceField); targetField = getReferenceDescriptor().buildField(targetField); newSourceToTargetKeyFields.put(sourceField, targetField); newTargetToSourceKeyFields.put(targetField, sourceField); } setSourceToTargetKeyFields(newSourceToTargetKeyFields); setTargetToSourceKeyFields(newTargetToSourceKeyFields); }
/** * INTERNAL: * The foreign keys primary keys are stored as database fields in the hashtable. */ protected void initializeForeignKeys(AbstractSession session) { HashMap newSourceToTargetKeyFields = new HashMap(getSourceToTargetKeyFields().size()); HashMap newTargetToSourceKeyFields = new HashMap(getTargetToSourceKeyFields().size()); Iterator iterator = getSourceToTargetKeyFields().entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry)iterator.next(); DatabaseField sourceField = (DatabaseField)entry.getKey(); DatabaseField targetField = (DatabaseField)entry.getValue(); sourceField = getDescriptor().buildField(sourceField); targetField = getReferenceDescriptor().buildField(targetField); newSourceToTargetKeyFields.put(sourceField, targetField); newTargetToSourceKeyFields.put(targetField, sourceField); } setSourceToTargetKeyFields(newSourceToTargetKeyFields); setTargetToSourceKeyFields(newTargetToSourceKeyFields); }
/** * INTERNAL: * Return the primary key for the reference object (i.e. the object * object referenced by domainObject and specified by mapping). * This key will be used by a RemoteValueHolder. */ @Override public Object extractPrimaryKeysForReferenceObjectFromRow(AbstractRecord row) { List primaryKeyFields = getReferenceDescriptor().getPrimaryKeyFields(); Object[] result = new Object[primaryKeyFields.size()]; for (int index = 0; index < primaryKeyFields.size(); index++) { DatabaseField targetKeyField = (DatabaseField)primaryKeyFields.get(index); DatabaseField sourceKeyField = getTargetToSourceKeyFields().get(targetKeyField); if (sourceKeyField == null) { return null; } result[index] = row.get(sourceKeyField); if (getReferenceDescriptor().getCachePolicy().getCacheKeyType() == CacheKeyType.ID_VALUE) { return result[index]; } } return new CacheId(result); }
/** * INTERNAL: * Return the primary key for the reference object (i.e. the object * object referenced by domainObject and specified by mapping). * This key will be used by a RemoteValueHolder. */ @Override public Object extractPrimaryKeysForReferenceObjectFromRow(AbstractRecord row) { List primaryKeyFields = getReferenceDescriptor().getPrimaryKeyFields(); Object[] result = new Object[primaryKeyFields.size()]; for (int index = 0; index < primaryKeyFields.size(); index++) { DatabaseField targetKeyField = (DatabaseField)primaryKeyFields.get(index); DatabaseField sourceKeyField = getTargetToSourceKeyFields().get(targetKeyField); if (sourceKeyField == null) { return null; } result[index] = row.get(sourceKeyField); if (getReferenceDescriptor().getCachePolicy().getCacheKeyType() == CacheKeyType.ID_VALUE) { return result[index]; } } return new CacheId(result); }
/** * INTERNAL: * Return the classifiction for the field contained in the mapping. * This is used to convert the row value to a consistent java value. */ public Class getFieldClassification(DatabaseField fieldToClassify) throws DescriptorException { DatabaseField fieldInTarget = (DatabaseField)getSourceToTargetKeyFields().get(fieldToClassify); if (fieldInTarget == null) { return null;// Can be registered as multiple table secondary field mapping } DatabaseMapping mapping = getReferenceDescriptor().getObjectBuilder().getMappingForField(fieldInTarget); if (mapping == null) { return null;// Means that the mapping is read-only } return mapping.getFieldClassification(fieldInTarget); }
/** * INTERNAL: * Return the classifiction for the field contained in the mapping. * This is used to convert the row value to a consistent java value. */ @Override public Class getFieldClassification(DatabaseField fieldToClassify) throws DescriptorException { DatabaseField fieldInTarget = getSourceToTargetKeyFields().get(fieldToClassify); if (fieldInTarget == null) { return null;// Can be registered as multiple table secondary field mapping } DatabaseMapping mapping = getReferenceDescriptor().getObjectBuilder().getMappingForField(fieldInTarget); if (mapping == null) { return null;// Means that the mapping is read-only } return mapping.getFieldClassification(fieldInTarget); }
/** * INTERNAL: * Return the classifiction for the field contained in the mapping. * This is used to convert the row value to a consistent java value. */ @Override public Class getFieldClassification(DatabaseField fieldToClassify) throws DescriptorException { DatabaseField fieldInTarget = getSourceToTargetKeyFields().get(fieldToClassify); if (fieldInTarget == null) { return null;// Can be registered as multiple table secondary field mapping } DatabaseMapping mapping = getReferenceDescriptor().getObjectBuilder().getMappingForField(fieldInTarget); if (mapping == null) { return null;// Means that the mapping is read-only } return mapping.getFieldClassification(fieldInTarget); }
/** * INTERNAL: * Get a value from the object and set that in the respective field of the row. */ public void writeFromObjectIntoRow(Object object, AbstractRecord Record, AbstractSession session) { if (isReadOnly() || (!isForeignKeyRelationship())) { return; } AbstractRecord referenceRow = getIndirectionPolicy().extractReferenceRow(getAttributeValueFromObject(object)); if (referenceRow == null) { // Extract from object. Object referenceObject = getRealAttributeValueFromObject(object, session); for (int i = 0; i < getForeignKeyFields().size(); i++) { DatabaseField sourceKey = getForeignKeyFields().get(i); DatabaseField targetKey = (DatabaseField)getSourceToTargetKeyFields().get(sourceKey); Object referenceValue = null; // If privately owned part is null then method cannot be invoked. if (referenceObject != null) { referenceValue = getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(referenceObject, targetKey, session); } Record.add(sourceKey, referenceValue); } } else { for (int i = 0; i < getForeignKeyFields().size(); i++) { DatabaseField sourceKey = getForeignKeyFields().get(i); Record.add(sourceKey, referenceRow.get(sourceKey)); } } }
/** * INTERNAL: * Get a value from the object and set that in the respective field of the row. */ @Override public void writeFromObjectIntoRow(Object object, AbstractRecord Record, AbstractSession session, WriteType writeType) { if (isReadOnly() || (!isForeignKeyRelationship())) { return; } AbstractRecord referenceRow = getIndirectionPolicy().extractReferenceRow(getAttributeValueFromObject(object)); if (referenceRow == null) { // Extract from object. Object referenceObject = getRealAttributeValueFromObject(object, session); for (int i = 0; i < getForeignKeyFields().size(); i++) { DatabaseField sourceKey = getForeignKeyFields().get(i); DatabaseField targetKey = getSourceToTargetKeyFields().get(sourceKey); Object referenceValue = null; // If privately owned part is null then method cannot be invoked. if (referenceObject != null) { referenceValue = getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(referenceObject, targetKey, session); } Record.add(sourceKey, referenceValue); } } else { for (int i = 0; i < getForeignKeyFields().size(); i++) { DatabaseField sourceKey = getForeignKeyFields().get(i); Record.add(sourceKey, referenceRow.get(sourceKey)); } } }
/** * INTERNAL: * Get a value from the object and set that in the respective field of the row. */ @Override public void writeFromObjectIntoRow(Object object, AbstractRecord Record, AbstractSession session, WriteType writeType) { if (isReadOnly() || (!isForeignKeyRelationship())) { return; } AbstractRecord referenceRow = getIndirectionPolicy().extractReferenceRow(getAttributeValueFromObject(object)); if (referenceRow == null) { // Extract from object. Object referenceObject = getRealAttributeValueFromObject(object, session); for (int i = 0; i < getForeignKeyFields().size(); i++) { DatabaseField sourceKey = getForeignKeyFields().get(i); DatabaseField targetKey = getSourceToTargetKeyFields().get(sourceKey); Object referenceValue = null; // If privately owned part is null then method cannot be invoked. if (referenceObject != null) { referenceValue = getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(referenceObject, targetKey, session); } Record.add(sourceKey, referenceValue); } } else { for (int i = 0; i < getForeignKeyFields().size(); i++) { DatabaseField sourceKey = getForeignKeyFields().get(i); Record.add(sourceKey, referenceRow.get(sourceKey)); } } }