예제 #1
0
  private void doPathExpression(String token, QueryTranslatorImpl q) throws QueryException {

    preprocess(token, q);

    StringTokenizer tokens = new StringTokenizer(token, ".", true);
    pathExpressionParser.start(q);
    while (tokens.hasMoreTokens()) {
      pathExpressionParser.token(tokens.nextToken(), q);
    }
    pathExpressionParser.end(q);
    if (pathExpressionParser.isCollectionValued()) {
      openExpression(q, "");
      appendToken(q, pathExpressionParser.getCollectionSubquery(q.getEnabledFilters()));
      closeExpression(q, "");
      // this is ugly here, but needed because its a subquery
      q.addQuerySpaces(
          q.getCollectionPersister(pathExpressionParser.getCollectionRole()).getCollectionSpaces());
    } else {
      if (pathExpressionParser.isExpectingCollectionIndex()) {
        expectingIndex++;
      } else {
        addJoin(pathExpressionParser.getWhereJoin(), q);
        appendToken(q, pathExpressionParser.getWhereColumn());
      }
    }
  }
예제 #2
0
 private void preprocess(String token, QueryTranslatorImpl q) throws QueryException {
   // ugly hack for cases like "elements(foo.bar.collection)"
   // (multi-part path expression ending in elements or indices)
   String[] tokens = StringHelper.split(".", token, true);
   if (tokens.length > 5
       && (CollectionPropertyNames.COLLECTION_ELEMENTS.equals(tokens[tokens.length - 1])
           || CollectionPropertyNames.COLLECTION_INDICES.equals(tokens[tokens.length - 1]))) {
     pathExpressionParser.start(q);
     for (int i = 0; i < tokens.length - 3; i++) {
       pathExpressionParser.token(tokens[i], q);
     }
     pathExpressionParser.token(null, q);
     pathExpressionParser.end(q);
     addJoin(pathExpressionParser.getWhereJoin(), q);
     pathExpressionParser.ignoreInitialJoin();
   }
 }