RelationshipMapping.Endpoint target = new RelationshipMapping.Endpoint();
target.setCollectionType(target.SET);
relationship.setTarget(target);
Table table = null;
Iterator i = root.getExtensions().iterator();
String sourceStr = null;
String targetStr = null;
String indexStr = null;
// Added support for filtered collections (Dan Checkoway, 6/26/03)
String filterStr = null;
String parametersStr = null;
String variablesStr = null;
String importsStr = null;
while (i.hasNext()) {
JDOExtension element = (JDOExtension) i.next();
if (XORM_VENDOR_NAME.equals(element.getVendorName())) {
String key = element.getKey();
String value = element.getValue();
boolean redefined = false;
if ("table".equals(key)) {
redefined = table != null;
table = getTable(value);
if (table == null) {
throw new JDOFatalUserException(I18N.msg("E_unknown_table", value));
}
} else if (ATTR_SOURCE.equals(key)) {
redefined = sourceStr != null;
sourceStr = value;
} else if (ATTR_TARGET.equals(key)) {
redefined = targetStr != null;
targetStr = value;
} else if (ATTR_ORDER_BY.equals(key)) {
redefined = relationship.getOrderBy() != null;
relationship.setOrderBy(value);
} else if (ATTR_INDEX.equals(key)) {
redefined = indexStr != null;
indexStr = value;
} else if (ATTR_FILTER.equals(key)) {
// Filtered collection query
redefined = filterStr != null;
filterStr = value;
} else if (ATTR_PARAMETERS.equals(key)) {
// Filtered collection query parameters
redefined = parametersStr != null;
parametersStr = value;
} else if (ATTR_VARIABLES.equals(key)) {
// Filtered collection query variables
redefined = variablesStr != null;
variablesStr = value;
} else if (ATTR_ORDERING.equals(key)) {
// JDO-style ordering
redefined = relationship.getOrdering() != null;
relationship.setOrdering(value);
} else if (ATTR_IMPORTS.equals(key)) {
redefined = importsStr != null;
importsStr = value;
}
if (redefined) {
throw new JDOFatalUserException(I18N.msg("E_collection_redefinition", key, field.getName(), jdoClass.getName()));
}
}
} // for each "extension" element
if (sourceStr == null && filterStr == null) {
if (useDefaultMapping) {
sourceStr = "source_" + ownerClass.getName();
} else {
// You have to specify either a source or a filter or both.
throw new JDOFatalUserException(I18N.msg("E_collection_no_source", field.getName(), jdoClass.getName()));
}
}
if (table == null) {
// The table wasn't explicitly specified. We can safely
// assume that if a collection is specified without an explicit
// table, then the table is the collection element type's table.
ClassMapping mapping = getClassMapping(elementClass);
if ((table = mapping.getTable()) == null) {
// Not much we can do about this. I don't think it will ever
// happen, but just in case...
throw new JDOFatalUserException(I18N.msg("E_collection_no_table", field.getName(), jdoClass.getName()));
}
logger.fine("No table specified for collection field \"" +
field.getName() +
"\"...assuming element type table: " +
table.getName());
}
if (relationship.getOrderBy() != null &&
relationship.getOrdering() != null) {
// Don't even bother trying to interpret precedence
throw new JDOFatalUserException(I18N.msg("E_collection_order_by_and_ordering"));
}
if (relationship.getOrdering() != null && filterStr == null) {
throw new JDOFatalUserException(I18N.msg("E_collection_ordering_without_filter", field.getName(), jdoClass.getName()));
}
if (sourceStr != null) {
source.setColumn(table.getColumnByName(sourceStr));
}
if (targetStr == null) {
target.setColumn(table.getPrimaryKey());
} else {
// It's many-to-many. We used to set the target's elementClass
// to signify this, but that seemed like a hack to me. And since
// the target's elementClass was set to the owner class, which
// didn't seem to apply (if anything the target element class
// would be the collection's element class, not the owner's class),
// I added this boolean setter/getter instead.
relationship.setMToN(true);
target.setColumn(table.getColumnByName(targetStr));
}
if (indexStr != null) {
Column c = table.getColumnByName(indexStr);
// Set the column to managed mode; we don't want
// indices to be included in Row.equals() operations
c.setManaged(true);
relationship.setIndexColumn(c);
}