}
return query;
}
public final QueryByCriteria selectQuery() throws RecognitionException, TokenStreamException {
QueryByCriteria query = null;
try { // for error handling
Class clazz = null;
Criteria criteria = new Criteria();
String[] projectionAttrs;
boolean distinct = false;
match(LITERAL_select);
{
if ((LA(1)==LITERAL_distinct)) {
match(LITERAL_distinct);
distinct = true;
}
else if ((LA(1)==TOK_STAR||LA(1)==Identifier)) {
}
else {
throw new NoViableAltException(LT(1), getFilename());
}
}
projectionAttrs=projectionAttributes();
match(LITERAL_from);
clazz=fromClause();
{
if ((LA(1)==LITERAL_where)) {
match(LITERAL_where);
whereClause(criteria);
}
else if ((_tokenSet_1.member(LA(1)))) {
}
else {
throw new NoViableAltException(LT(1), getFilename());
}
}
if (clazz != null)
{
if (projectionAttrs[0].indexOf('.') < 0)
{
query = QueryFactory.newQuery(clazz, criteria, distinct);
}
else
{
ClassDescriptor cld = MetadataManager.getInstance().getRepository().getDescriptorFor(clazz);
for (int i = 0; i < projectionAttrs.length; i++)
{
projectionAttrs[i] = projectionAttrs[i].substring(projectionAttrs[i].indexOf('.') + 1);
}
ArrayList descs = cld.getAttributeDescriptorsForPath(projectionAttrs[0]);
int pathLen = descs.size();
if ((pathLen > 0) && (descs.get(pathLen - 1) instanceof ObjectReferenceDescriptor))
{
ObjectReferenceDescriptor ord =
((ObjectReferenceDescriptor) descs.get(pathLen - 1));
query = QueryFactory.newQuery(clazz, criteria, distinct);
query.setObjectProjectionAttribute(projectionAttrs[0],
ord.getItemClass());
}
else
{
query = QueryFactory.newReportQuery(clazz, projectionAttrs, criteria, distinct);