DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader) {
if (valueToApply.equals(QueryType.DEFAULT)) {
return query;
}
// Allows an query type, or a custom query class.
DatabaseQuery newQuery = query;
if (valueToApply.equals(QueryType.ReadAll)) {
newQuery = new ReadAllQuery();
} else if (valueToApply.equals(QueryType.ReadObject)) {
newQuery = new ReadObjectQuery();
} else if (valueToApply.equals(QueryType.Report)) {
newQuery = new ReportQuery();
if (query.isObjectLevelReadQuery()) {
((ReportQuery)newQuery).addAttribute("root", ((ReportQuery)newQuery).getExpressionBuilder());
}
} else if (valueToApply.equals(QueryType.ResultSetMapping)) {
newQuery = new ResultSetMappingQuery();
} else if (valueToApply.equals(QueryType.UpdateAll)) {
newQuery = new UpdateAllQuery();
} else if (valueToApply.equals(QueryType.DeleteAll)) {
newQuery = new DeleteAllQuery();
} else if (valueToApply.equals(QueryType.DataModify)) {
newQuery = new DataModifyQuery();
} else if (valueToApply.equals(QueryType.DataRead)) {
newQuery = new DataReadQuery();
} else if (valueToApply.equals(QueryType.DirectRead)) {
newQuery = new DirectReadQuery();
} else if (valueToApply.equals(QueryType.ValueRead)) {
newQuery = new ValueReadQuery();
} else {
Class queryClass = loadClass((String)valueToApply, query, loader);
newQuery = (DatabaseQuery)newInstance(queryClass, query, QueryHints.QUERY_TYPE);
}
newQuery.copyFromQuery(query);
return newQuery;
}