Пример #1
0
 public void resolveCollectionProperty(AST expr) throws SemanticException {
   String propertyName = CollectionProperties.getNormalizedPropertyName(getMethodName());
   if (expr instanceof FromReferenceNode) {
     FromReferenceNode collectionNode = (FromReferenceNode) expr;
     // If this is 'elements' then create a new FROM element.
     if (CollectionPropertyNames.COLLECTION_ELEMENTS.equals(propertyName)) {
       handleElements(collectionNode, propertyName);
     } else {
       // Not elements(x)
       fromElement = collectionNode.getFromElement();
       setDataType(fromElement.getPropertyType(propertyName, propertyName));
       selectColumns = fromElement.toColumns(fromElement.getTableAlias(), propertyName, inSelect);
     }
     if (collectionNode instanceof DotNode) {
       prepareAnyImplicitJoins((DotNode) collectionNode);
     }
     if (!inSelect) {
       fromElement.setText("");
       fromElement.setUseWhereFragment(false);
     }
     prepareSelectColumns(selectColumns);
     setText(selectColumns[0]);
     setType(SqlTokenTypes.SQL_TOKEN);
   } else {
     throw new SemanticException(
         "Unexpected expression " + expr + " found for collection function " + propertyName);
   }
 }
Пример #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();
   }
 }