Add a EXISTS clause with a sub-query inside of parenthesis.

<p>
<b>NOTE:</b> The sub-query will be prepared at the same time that the outside query is.
</p>
3289
public Where<T, ID> exists(QueryBuilder<?, ?> subQueryBuilder) {
		// we do this to turn off the automatic addition of the ID column in the select column list
		subQueryBuilder.enableInnerQuery();
		addClause(new Exists(new InternalQueryBuilderWrapper(subQueryBuilder)));
		return this;
	}
1109588
private void appendExistsCriteria(ExistsCriteria c, StringBuffer buf)
    {
        Query subQuery = (Query) c.getValue();

        buf.append(c.getClause());
        appendSubQuery(subQuery, buf);
    }
264346
public void configureEventSubscriptionQuery(EventSubscriptionQueryImpl query) {
    configureQuery(query);
    CompositePermissionCheck permissionCheck = new PermissionCheckBuilder()
            .disjunctive()
            .atomicCheck(PROCESS_INSTANCE, "RES.PROC_INST_ID_", READ)
            .atomicCheck(PROCESS_DEFINITION, "PROCDEF.KEY_", READ_INSTANCE)
            .build();
    addPermissionCheck(query.getAuthCheck(), permissionCheck);
  }
968841
def add_assignment_clause(self, clause):
        
        if not isinstance(clause, AssignmentClause):
            raise StatementException("only instances of AssignmentClause can be added to statements")
        clause.set_context_id(self.context_counter)
        self.context_counter += clause.get_context_size()
        self.assignments.append(clause)
242523
public void addQueryParam( String paramName, String value )
    {
        if ( _queryString == null )
        {
            _queryString = new InternalStringBuilder( "?" );
        }
        else
        {
            _queryString.append( '&' );
        }
        
        _queryString.append( paramName );
        
        if ( value != null )
        {
            _queryString.append( '=' ).append( value );
        }
    }
892351
public @NotNull QueryBuilder append(@NotNull String sql, @NotNull Collection<?> args) {
        query.append(requireNonNull(sql));
        addArguments(args);
        return this;
    }
1322817
public SqlBuilder where(final Condition... cons) {
    if (isNotEmpty(statement)) throw new RuntimeException("cannot add condition to a exists statement");
    return where(Arrays.asList(cons));
  }
745780
public void setQuery(String query) {

        if (CmsStringUtil.isEmptyOrWhitespaceOnly(query)) {
            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_VALIDATE_SEARCH_QUERY_0));
        }
        m_query = query;
    }
284589
def add_clause(self, clause, no_return=True):
        

        if self.maplesat:
            res = pysolvers.maplesat_add_cl(self.maplesat, clause)

            if res == False:
                self.status = False

            if not no_return:
                return res
917091
protected void appendClause(StringBuffer clause, Criteria crit, StringBuffer stmt)
    {
        /**
         * MBAIRD
         * when generating the "WHERE/HAVING" clause we need to append the criteria for multi-mapped
         * tables. We only need to do this for the root classdescriptor and not for joined tables
         * because we assume you cannot make a relation of the wrong type upon insertion. Of course,
         * you COULD mess the data up manually and this would cause a problem.
         */

        if (clause != null)
        {
            stmt.append(clause.toString());
        }
        if (crit != null)
        {
            if (clause == null)
            {
                stmt.append(asSQLStatement(crit));
            }
            else
            {
                stmt.append(" AND (");
                stmt.append(asSQLStatement(crit));
                stmt.append(")");
            }

        }
    }
1241138
public void appendQuerytoSQL(Collection<Match> matches, StringBuilder sb, List<Object> params) {

        // 如果query为空，则直接返回
        if (matches == null || matches.size() == 0) {
            return;
        }

        sb.append(" where ");
        appendMatches(matches, sb, params);
    }
804787
public void addBasicSentence(MtasCQLParserBasicSentenceCondition s)
      throws ParseException {
    if (!simplified) {
      List<MtasCQLParserBasicSentencePartCondition> newWordList = s
          .getPartList();
      partList.addAll(newWordList);
    } else {
      throw new ParseException("already simplified");
    }
  }
582465
private void addSubQuery(BoolQueryBuilder boolQuery, Where where, QueryBuilder subQuery) {
        if(where instanceof Condition){
            Condition condition = (Condition) where;

			if (condition.isNested()) {
				boolean isNestedQuery = subQuery instanceof NestedQueryBuilder;
				InnerHitBuilder ihb = null;
				if (condition.getInnerHits() != null) {
                    try (JsonXContentParser parser = new JsonXContentParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, new JsonFactory().createParser(condition.getInnerHits()))) {
                        ihb = InnerHitBuilder.fromXContent(parser);
                    } catch (IOException e) {
                        throw new IllegalArgumentException("couldn't parse inner_hits: " + e.getMessage(), e);
                    }
                }

                // bugfix #628
                if ("missing".equalsIgnoreCase(String.valueOf(condition.getValue())) && (condition.getOpear() == Condition.OPEAR.IS || condition.getOpear() == Condition.OPEAR.EQ)) {
                    NestedQueryBuilder q = isNestedQuery ? (NestedQueryBuilder) subQuery : QueryBuilders.nestedQuery(condition.getNestedPath(), QueryBuilders.boolQuery().mustNot(subQuery), ScoreMode.None);
					if (ihb != null) {
						q.innerHit(ihb);
                    }
                    boolQuery.mustNot(q);
                    return;
                }

                if (!isNestedQuery) {
					subQuery = QueryBuilders.nestedQuery(condition.getNestedPath(), subQuery, ScoreMode.None);
				}
                if (ihb != null) {
                    ((NestedQueryBuilder) subQuery).innerHit(ihb);
                }
            } else if(condition.isChildren()) {
            	subQuery = JoinQueryBuilders.hasChildQuery(condition.getChildType(), subQuery, ScoreMode.None);
            }
        }

		//zhongshu-comment 将subQuery对象纳入到boolQuery中，即boolQuery是上一级，subQuery是下一级
		if (where.getConn() == CONN.AND) {
			boolQuery.must(subQuery);
		} else {
			boolQuery.should(subQuery);
		}
	}
838376
private MtasSpanQuery createQuery(
      List<MtasCQLParserSentenceCondition> sentenceSequence)
      throws ParseException {
    if (sentenceSequence.size() == 1) {
      if (maximumOccurence > 1) {
        return new MtasSpanRecurrenceQuery(sentenceSequence.get(0).getQuery(),
            minimumOccurence, maximumOccurence, ignore, maximumIgnoreLength);
      } else {
        return sentenceSequence.get(0).getQuery();
      }
    } else {
      List<MtasSpanSequenceItem> clauses = new ArrayList<MtasSpanSequenceItem>();
      for (MtasCQLParserSentenceCondition sentence : sentenceSequence) {
        clauses.add(
            new MtasSpanSequenceItem(sentence.getQuery(), sentence.optional));
      }
      if (maximumOccurence > 1) {
        return new MtasSpanRecurrenceQuery(
            new MtasSpanSequenceQuery(clauses, ignore, maximumIgnoreLength),
            minimumOccurence, maximumOccurence, ignore, maximumIgnoreLength);
      } else {
        return new MtasSpanSequenceQuery(clauses, ignore, maximumIgnoreLength);
      }
    }
  }
343479
public void addSubMetricQuery(final String metric_query, 
                                final int sub_query_index,
                                final int param_index) {
    if (metric_query == null || metric_query.isEmpty()) {
      throw new IllegalArgumentException("Metric query cannot be null or empty");
    }
    if (sub_query_index < 0) {
      throw new IllegalArgumentException("Sub query index must be 0 or greater");
    }
    if (param_index < 0) {
      throw new IllegalArgumentException("Parameter index must be 0 or greater");
    }
    if (sub_metric_queries == null) {
      sub_metric_queries = Maps.newHashMap();
    }
    sub_metric_queries.put(sub_query_index, metric_query);
    parameter_index.put(param_index, Parameter.METRIC_QUERY);
  }
593945
protected void appendSQLClause(SelectionCriteria c, StringBuffer buf)
    {
        // BRJ : handle SqlCriteria
        if (c instanceof SqlCriteria)
        {
            buf.append(c.getAttribute());
            return;
        }
        
        // BRJ : criteria attribute is a query
        if (c.getAttribute() instanceof Query)
        {
            Query q = (Query) c.getAttribute();
            buf.append("(");
            buf.append(getSubQuerySQL(q));
            buf.append(")");
            buf.append(c.getClause());
            appendParameter(c.getValue(), buf);
            return;
        }

		AttributeInfo attrInfo = getAttributeInfo((String) c.getAttribute(), false, c.getUserAlias(), c.getPathClasses());
        TableAlias alias = attrInfo.tableAlias;

        if (alias != null)
        {
            boolean hasExtents = alias.hasExtents();

            if (hasExtents)
            {
                // BRJ : surround with braces if alias has extents
                buf.append("(");
                appendCriteria(alias, attrInfo.pathInfo, c, buf);

                c.setNumberOfExtentsToBind(alias.extents.size());
                Iterator iter = alias.iterateExtents();
                while (iter.hasNext())
                {
                    TableAlias tableAlias = (TableAlias) iter.next();
                    buf.append(" OR ");
                    appendCriteria(tableAlias, attrInfo.pathInfo, c, buf);
                }
                buf.append(")");
            }
            else
            {
                // no extents
                appendCriteria(alias, attrInfo.pathInfo, c, buf);
            }
        }
        else
        {
            // alias null
            appendCriteria(alias, attrInfo.pathInfo, c, buf);
        }

    }
850810
private SelectSubqueryExpression parseSubqueryExpression(VoltXMLElement exprNode) {
        assert(exprNode.children.size() == 1);
        VoltXMLElement subqueryElmt = exprNode.children.get(0);
        AbstractParsedStmt subqueryStmt = parseSubquery(subqueryElmt);
        // add table to the query cache
        String withoutAlias = null;
        StmtSubqueryScan stmtSubqueryScan =
                addSubqueryToStmtCache(subqueryStmt, withoutAlias);
        // Set to the default SELECT_SUBQUERY. May be overridden depending on the context
        return new SelectSubqueryExpression(ExpressionType.SELECT_SUBQUERY, stmtSubqueryScan);
    }