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");
relationshipPartnerAttributeNameMapping.setSetMethodName("setRelationshipPartnerAttributeName");
relationshipPartnerAttributeNameMapping.setXPath(getPrimaryNamespaceXPath() + "bidirectional-target-attribute/text()");
descriptor.addMapping(relationshipPartnerAttributeNameMapping);
XMLDirectMapping usesBatchReadingMapping = new XMLDirectMapping();
usesBatchReadingMapping.setAttributeName("usesBatchReading");
usesBatchReadingMapping.setGetMethodName("shouldUseBatchReading");
usesBatchReadingMapping.setSetMethodName("setUsesBatchReading");
usesBatchReadingMapping.setXPath(getPrimaryNamespaceXPath() + "batch-reading/text()");
usesBatchReadingMapping.setNullValue(Boolean.FALSE);
descriptor.addMapping(usesBatchReadingMapping);
XMLCompositeObjectMapping containerPolicyMapping = new XMLCompositeObjectMapping();
containerPolicyMapping.setAttributeName("collectionPolicy");
containerPolicyMapping.setGetMethodName("getContainerPolicy");
containerPolicyMapping.setSetMethodName("setContainerPolicy");
containerPolicyMapping.setReferenceClass(ContainerPolicy.class);
containerPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "container");
descriptor.addMapping(containerPolicyMapping);
XMLCompositeObjectMapping indirectionPolicyMapping = new XMLCompositeObjectMapping();
indirectionPolicyMapping.setReferenceClass(IndirectionPolicy.class);
// Handle translation of NoIndirectionPolicy -> null.
indirectionPolicyMapping.setAttributeAccessor(new AttributeAccessor() {
public Object getAttributeValueFromObject(Object object) {
IndirectionPolicy policy = ((ForeignReferenceMapping)object).getIndirectionPolicy();
if (policy instanceof NoIndirectionPolicy) {
return null;
}