/** * PUBLIC: * Add a field name translation that maps from a field name in the * source table to a field name in the aggregate descriptor. */ public void addFieldNameTranslation(String sourceFieldName, String aggregateFieldName) { String unQualifiedAggregateFieldName = aggregateFieldName.substring(aggregateFieldName.lastIndexOf('.') + 1);// -1 is returned for no ".". getAggregateToSourceFieldNames().put(unQualifiedAggregateFieldName, sourceFieldName); }
/** * INTERNAL: * Return a collection of the aggregate to source field name associations. */ public Vector<Association> getAggregateToSourceFieldNameAssociations() { Vector<Association> associations = new Vector(getAggregateToSourceFieldNames().size()); Iterator aggregateEnum = getAggregateToSourceFieldNames().keySet().iterator(); Iterator sourceEnum = getAggregateToSourceFieldNames().values().iterator(); while (aggregateEnum.hasNext()) { associations.addElement(new Association(aggregateEnum.next(), sourceEnum.next())); } return associations; }
/** * INTERNAL: * If field names are different in the source and aggregate objects then the translation * is done here. The aggregate field name is converted to source field name from the * field name mappings stored. */ protected void translateFields(ClassDescriptor clonedDescriptor, AbstractSession session) { for (Enumeration entry = clonedDescriptor.getFields().elements(); entry.hasMoreElements();) { DatabaseField field = (DatabaseField)entry.nextElement(); String nameInAggregate = field.getName(); String nameInSource = (String)getAggregateToSourceFieldNames().get(nameInAggregate); // Do not modify non-translated fields. if (nameInSource != null) { DatabaseField fieldInSource = new DatabaseField(nameInSource); // Check if the translated field specified a table qualifier. if (fieldInSource.getName().equals(nameInSource)) { // No table so just set the field name. field.setName(nameInSource); } else { // There is a table, so set the name and table. field.setName(fieldInSource.getName()); field.setTable(clonedDescriptor.getTable(fieldInSource.getTable().getName())); } } } clonedDescriptor.rehashFieldDependancies(session); }