public AssignmentSpecification(AST eq, Queryable persister) {
    if (eq.getType() != HqlSqlTokenTypes.EQ) {
      throw new QueryException("assignment in set-clause not associated with equals");
    }

    this.eq = eq;
    this.factory = persister.getFactory();

    // Needed to bump this up to DotNode, because that is the only thing which currently
    // knows about the property-ref path in the correct format; it is either this, or
    // recurse over the DotNodes constructing the property path just like DotNode does
    // internally
    final PathSeparatorNode lhs = (PathSeparatorNode) eq.getFirstChild();
    final SqlNode rhs = (SqlNode) lhs.getNextSibling();

    validateLhs(lhs);

    final String propertyPath = lhs.getPropertyPath();
    Set<String> temp = new HashSet<String>();
    // yuck!
    if (persister instanceof UnionSubclassEntityPersister) {
      final String[] tables = persister.getConstraintOrderedTableNameClosure();
      Collections.addAll(temp, tables);
    } else {
      temp.add(
          persister.getSubclassTableName(persister.getSubclassPropertyTableNumber(propertyPath)));
    }
    this.tableNames = Collections.unmodifiableSet(temp);

    if (rhs == null) {
      hqlParameters = new ParameterSpecification[0];
    } else if (isParam(rhs)) {
      hqlParameters =
          new ParameterSpecification[] {((ParameterNode) rhs).getHqlParameterSpecification()};
    } else {
      List parameterList =
          ASTUtil.collectChildren(
              rhs,
              new ASTUtil.IncludePredicate() {
                public boolean include(AST node) {
                  return isParam(node);
                }
              });
      hqlParameters = new ParameterSpecification[parameterList.size()];
      Iterator itr = parameterList.iterator();
      int i = 0;
      while (itr.hasNext()) {
        hqlParameters[i++] = ((ParameterNode) itr.next()).getHqlParameterSpecification();
      }
    }
  }
 private AST createFromElement(String text) {
   AST ast =
       ASTUtil.create(
           fromClause.getASTFactory(),
           implied
               ? IMPLIED_FROM
               : FROM_FRAGMENT, // This causes the factory to instantiate the desired class.
           text);
   // Reset the node type, because the rest of the system is expecting FROM_FRAGMENT, all we wanted
   // was
   // for the factory to create the right sub-class.  This might get reset again later on anyway to
   // make the
   // SQL generation simpler.
   ast.setType(FROM_FRAGMENT);
   return ast;
 }
示例#3
0
  @Test
  public void testEjb3PositionalParameters() throws Exception {
    QueryTranslatorImpl qt = compile("from Animal a where a.bodyWeight = ?1");
    AST ast = (AST) qt.getSqlAST();

    // make certain that the ejb3-positional param got recognized as a named param
    List namedParams =
        ASTUtil.collectChildren(
            ast,
            new ASTUtil.FilterPredicate() {
              public boolean exclude(AST n) {
                return n.getType() != HqlSqlTokenTypes.NAMED_PARAM;
              }
            });
    assertTrue("ejb3 positional param not recognized as a named param", namedParams.size() > 0);
  }