// How did we get here? An exception should have been
// thrown in ModelMapping.parseRelationship
throw new JDOFatalUserException(I18N.msg("E_collection_no_source"));
}
Selector selector = new Selector
(columnToUse.getTable(),
new SimpleCondition(columnToUse, Operator.EQUAL, ownerPKey));
if (mapping.getFilter() != null) {
logger.fine("Filter: " + mapping.getFilter());
logger.fine("Imports: " + mapping.getImports());
logger.fine("Parameters: " + mapping.getParameters());
logger.fine("Variables: " + mapping.getVariables());
if (mapping.getParameters() != null &&
!mapping.getParameters().equals("") &&
(args == null || args.length == 0)) {
throw new NullPointerException(I18N.msg("E_missing_arguments"));
}
//logger.fine("Class Mapping Table: " + classMapping.getTable().getName());
Class filterTargetClass = classMapping.getMappedClass();
//logger.fine("Filter Target Class: " + filterTargetClass.getName());
QueryImpl query = new QueryImpl(mgr);
query.setClass(filterTargetClass);
query.setFilter(mapping.getFilter());
// We support the implicit "owner" parameter in filters.
// The owner refers to the object instance off which the
// collection field getter is being called. We need to add
// it to the parameters that we set on the query.
String parameters = mapping.getParameters();
ClassMapping ownerClassMapping = owner.getClassMapping();
Class ownerClass = ownerClassMapping.getMappedClass();
String ownerClassName = ownerClass.getName();
//ownerClassName = ownerClassName.substring(ownerClassName.lastIndexOf('.') + 1);
//logger.fine("OwnerClassName: " + ownerClassName);
if (mapping.getImports() != null) {
query.declareImports(mapping.getImports());
}
if (parameters == null || parameters.equals("")) {
// No parameters, just this owner param
parameters = ownerClassName + " owner";
}
else {
// Append this owner param to the existing parameters
parameters += ", " + ownerClassName + " owner";
}
logger.fine("Modified Parameters: " + parameters);
query.declareParameters(parameters);
if (mapping.getVariables() != null) {
query.declareVariables(mapping.getVariables());
}
if (mapping.getOrdering() != null) {
query.setOrdering(mapping.getOrdering());
}
query.compile();
//logger.fine("Filter Query: " + query);
BoundExpression bound = query.getBoundExpression();
int paramCount = 0;
if (args != null) {
while (paramCount < args.length) {
bound.bindParameter(paramCount, args[paramCount]);
++paramCount;
}
}
// Always bind the implicit "owner" parameter
bound.bindParameter(paramCount++, owner.getProxy());
//logger.fine(paramCount + " parameter(s) bound");
/*
logger.info("Main Selector Table Before: " +
selector.getTable().getName());
logger.info("Main Selector Before: " + selector);
*/
Selector filterSelector = bound.getSelector();
/*
logger.info("Filter Selector Table: " +
filterSelector.getTable().getName());
logger.info("Filter Selector: " + filterSelector);