/**
  * INTERNAL: Rebuild myself against the base, with the values of parameters supplied by the
  * context expression. This is used for transforming a standalone expression (e.g. the join
  * criteria of a mapping) into part of some larger expression. You normally would not call this
  * directly, instead calling twist See the comment there for more details"
  */
 public Expression twistedForBaseAndContext(Expression newBase, Expression context) {
   Expression twistedBase = getBaseExpression().twistedForBaseAndContext(newBase, context);
   QueryKeyExpression result = (QueryKeyExpression) twistedBase.get(getName());
   if (shouldUseOuterJoin) {
     result.doUseOuterJoin();
   }
   if (shouldQueryToManyRelationship) {
     result.doQueryToManyRelationship();
   }
   return result;
 }
 /**
  * PUBLIC: Return an expression representing traversal of a 1:many or many:many relationship. This
  * allows you to query whether any of the "many" side of the relationship satisfies the remaining
  * criteria.
  *
  * <p>Example:
  *
  * <pre><blockquote>
  *     Expression: employee.anyOf("managedEmployees").get("firstName").equal("Bob")
  *     Java: no direct equivalent
  *     SQL: SELECT DISTINCT ... WHERE (t2.MGR_ID = t1.ID) AND (t2.F_NAME = 'Bob')
  * </pre>
  *
  * </blockquote>
  *
  * @parameter shouldJoinBeIndependent indicates whether a new expression should be created.
  */
 @Override
 public Expression anyOf(String attributeName, boolean shouldJoinBeIndependent) {
   QueryKeyExpression queryKey;
   if (shouldJoinBeIndependent) {
     queryKey = newDerivedExpressionNamed(attributeName);
   } else {
     queryKey = derivedExpressionNamed(attributeName);
   }
   queryKey.doQueryToManyRelationship();
   return queryKey;
 }
  /**
   * INTERNAL: This expression is built on a different base than the one we want. Rebuild it and
   * return the root of the new tree
   */
  public Expression rebuildOn(Expression newBase) {
    Expression newLocalBase = getBaseExpression().rebuildOn(newBase);
    QueryKeyExpression result = null;

    // For bug 3096634 rebuild outer joins correctly from the start.
    if (shouldUseOuterJoin) {
      result = (QueryKeyExpression) newLocalBase.getAllowingNull(getName());
    } else {
      result = (QueryKeyExpression) newLocalBase.get(getName());
    }
    if (shouldQueryToManyRelationship) {
      result.doQueryToManyRelationship();
    }
    result.setSelectIfOrderedBy(selectIfOrderedBy());
    return result;
  }