relationTableMapping.setGetMethodName("getRelationTableQualifiedName");
relationTableMapping.setSetMethodName("setRelationTableName");
relationTableMapping.setXPath(getSecondaryNamespaceXPath() + "relation-table/text()");
descriptor.addMapping(relationTableMapping);
XMLCompositeCollectionMapping sourceToRelationKeyFieldAssociationsMapping = new XMLCompositeCollectionMapping();
sourceToRelationKeyFieldAssociationsMapping.setReferenceClass(Association.class);
// Handle translation of foreign key associations to hashtables.
sourceToRelationKeyFieldAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {
public Object getAttributeValueFromObject(Object object) {
List sourceFields = ((ManyToManyMapping)object).getSourceKeyFields();
List relationFields = ((ManyToManyMapping)object).getSourceRelationKeyFields();
List associations = new ArrayList(sourceFields.size());
for (int index = 0; index < sourceFields.size(); index++) {
associations.add(new Association(relationFields.get(index), sourceFields.get(index)));
}
return associations;
}
public void setAttributeValueInObject(Object object, Object value) {
ManyToManyMapping mapping = (ManyToManyMapping)object;
List associations = (List)value;
mapping.setSourceKeyFields(NonSynchronizedVector.newInstance(associations.size()));
mapping.setSourceRelationKeyFields(NonSynchronizedVector.newInstance(associations.size()));
Iterator iterator = associations.iterator();
while (iterator.hasNext()) {
Association association = (Association)iterator.next();
mapping.getSourceKeyFields().add((DatabaseField)association.getValue());
mapping.getSourceRelationKeyFields().add((DatabaseField)association.getKey());
}
}
});
sourceToRelationKeyFieldAssociationsMapping.setAttributeName("sourceToRelationKeyFieldAssociationsMapping");
sourceToRelationKeyFieldAssociationsMapping.setXPath(getSecondaryNamespaceXPath() + "source-relation-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
descriptor.addMapping(sourceToRelationKeyFieldAssociationsMapping);
XMLCompositeCollectionMapping targetToRelationKeyFieldAssociationsMapping = new XMLCompositeCollectionMapping();
targetToRelationKeyFieldAssociationsMapping.setReferenceClass(Association.class);
// Handle translation of foreign key associations to hashtables.
targetToRelationKeyFieldAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {
public Object getAttributeValueFromObject(Object object) {
List targetFields = ((ManyToManyMapping)object).getTargetKeyFields();
List relationFields = ((ManyToManyMapping)object).getTargetRelationKeyFields();
List associations = new ArrayList(targetFields.size());
for (int index = 0; index < targetFields.size(); index++) {
associations.add(new Association(relationFields.get(index), targetFields.get(index)));
}
return associations;
}
public void setAttributeValueInObject(Object object, Object value) {
ManyToManyMapping mapping = (ManyToManyMapping)object;
List associations = (List)value;
mapping.setTargetKeyFields(NonSynchronizedVector.newInstance(associations.size()));
mapping.setTargetRelationKeyFields(NonSynchronizedVector.newInstance(associations.size()));
Iterator iterator = associations.iterator();
while (iterator.hasNext()) {
Association association = (Association)iterator.next();
mapping.getTargetKeyFields().add((DatabaseField)association.getValue());
mapping.getTargetRelationKeyFields().add((DatabaseField)association.getKey());
}
}
});
targetToRelationKeyFieldAssociationsMapping.setAttributeName("targetToRelationKeyFieldAssociations");
targetToRelationKeyFieldAssociationsMapping.setXPath(getSecondaryNamespaceXPath() + "target-relation-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
descriptor.addMapping(targetToRelationKeyFieldAssociationsMapping);
XMLDirectMapping relationshipPartnerAttributeNameMapping = new XMLDirectMapping();
relationshipPartnerAttributeNameMapping.setAttributeName("relationshipPartnerAttributeName");
relationshipPartnerAttributeNameMapping.setGetMethodName("getRelationshipPartnerAttributeName");