protected ClassDescriptor buildRelationalDescriptorDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(RelationalDescriptor.class);
descriptor.getInheritancePolicy().setParentClass(ClassDescriptor.class);
XMLCompositeCollectionMapping tablesMapping = new XMLCompositeCollectionMapping();
tablesMapping.useCollectionClass(NonSynchronizedVector.class);
tablesMapping.setAttributeName("tables/table");
tablesMapping.setGetMethodName("getTables");
tablesMapping.setSetMethodName("setTables");
tablesMapping.setXPath(getPrimaryNamespaceXPath() + "tables/" + getPrimaryNamespaceXPath() + "table");
tablesMapping.setReferenceClass(DatabaseTable.class);
descriptor.addMapping(tablesMapping);
XMLCompositeCollectionMapping multipleTablesPrimaryKey = new XMLCompositeCollectionMapping();
multipleTablesPrimaryKey.setAttributeAccessor(new AttributeAccessor() {
public Object getAttributeValueFromObject(Object object) {
ClassDescriptor mapping = (ClassDescriptor)object;
Vector associations = mapping.getMultipleTablePrimaryKeyAssociations();
for (int index = 0; index < associations.size(); index++) {
Association association = (Association)associations.get(index);
association.setKey(new DatabaseField((String)association.getKey()));
association.setValue(new DatabaseField((String)association.getValue()));
}
return associations;
}
public void setAttributeValueInObject(Object object, Object value) {
ClassDescriptor mapping = (ClassDescriptor)object;
Vector associations = (Vector)value;
for (int index = 0; index < associations.size(); index++) {
Association association = (Association)associations.get(index);
association.setKey(((DatabaseField)association.getKey()).getQualifiedName());
association.setValue(((DatabaseField)association.getValue()).getQualifiedName());
}
mapping.setForeignKeyFieldNamesForMultipleTable(associations);
}
});
multipleTablesPrimaryKey.setAttributeName("multipleTablesPrimaryKeys");
multipleTablesPrimaryKey.setReferenceClass(Association.class);
multipleTablesPrimaryKey.setXPath(getPrimaryNamespaceXPath() + "multiple-table-primary-keys/" + getSecondaryNamespaceXPath() + "field-reference");
descriptor.addMapping(multipleTablesPrimaryKey);
XMLCompositeCollectionMapping multipleTables = new XMLCompositeCollectionMapping();
multipleTables.setReferenceClass(Association.class);
multipleTables.setXPath(getPrimaryNamespaceXPath() + "multiple-table-foreign-keys/" + getSecondaryNamespaceXPath() + "field-reference");
multipleTables.setAttributeAccessor(new AttributeAccessor() {
public Object getAttributeValueFromObject(Object object) {
ClassDescriptor mapping = (ClassDescriptor)object;
Vector associations = mapping.getMultipleTableForeignKeyAssociations();
for (int index = 0; index < associations.size(); index++) {
Association association = (Association)associations.get(index);
association.setKey(new DatabaseField((String)association.getKey()));
association.setValue(new DatabaseField((String)association.getValue()));
}
return associations;
}
public void setAttributeValueInObject(Object object, Object value) {
ClassDescriptor mapping = (ClassDescriptor)object;
Vector associations = (Vector)value;
for (int index = 0; index < associations.size(); index++) {
Association association = (Association)associations.get(index);
association.setKey(((DatabaseField)association.getKey()).getQualifiedName());
association.setValue(((DatabaseField)association.getValue()).getQualifiedName());
}
mapping.setForeignKeyFieldNamesForMultipleTable(associations);
}
});
multipleTables.setAttributeName("multipleTablesForeignKeys");
descriptor.addMapping(multipleTables);
return descriptor;
}