super(QueryHints.BATCH, "");
}
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader) {
if (query.isReadAllQuery() && !query.isReportQuery()) {
ReadAllQuery raq = (ReadAllQuery)query;
StringTokenizer tokenizer = new StringTokenizer((String)valueToApply, ".");
if (tokenizer.countTokens() < 2){
throw QueryException.queryHintDidNotContainEnoughTokens(query, QueryHints.BATCH, valueToApply);
}
// ignore the first token since we are assuming read all query
// e.g. In e.phoneNumbers we will assume "e" refers to the base of the query
String previousToken = tokenizer.nextToken();
ClassDescriptor descriptor = raq.getDescriptor();
Expression expression = raq.getExpressionBuilder();
while (tokenizer.hasMoreTokens()){
String token = tokenizer.nextToken();
ForeignReferenceMapping frMapping = null;
DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForAttributeName(token);
if (mapping == null){
throw QueryException.queryHintNavigatedNonExistantRelationship(query, QueryHints.BATCH, valueToApply, previousToken + "." + token);
} else if (!mapping.isForeignReferenceMapping()){
throw QueryException.queryHintNavigatedIllegalRelationship(query, QueryHints.BATCH, valueToApply, previousToken + "." + token);
} else {
frMapping = (ForeignReferenceMapping)mapping;
}
descriptor = frMapping.getReferenceDescriptor();
if (frMapping.isCollectionMapping()){
expression = expression.anyOf(token);
} else {
expression = expression.get(token);
}
previousToken = token;
}
raq.addBatchReadAttribute(expression);
} else {
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)}));
}
return query;
}