This method produces a ParameterStateManager to pass to HSQL so that VoltDB
can track the parameters it created when parsing the current statement.
486002
public static HSQLInterface.ParameterStateManager getParamStateManager() {
        return new ParameterStateManager() {
            @Override
            public int getNextParamIndex() {
                return ParameterizationInfo.getNextParamIndex();
            }

            @Override
            public void resetCurrentParamIndex() {
                ParameterizationInfo.resetCurrentParamIndex();
            }
        };
    }
182884
public static void javaMethodParam2WhereConditions(MethodSpec.Builder methodBuilder, SQLiteModelMethod method,
			String methodParamName, String paramName, TypeName paramType) {
		if (method.hasAdapterForParam(methodParamName)) {
			
			checkTypeAdapterForParam(method, methodParamName, BindSqlParam.class);
			
			methodBuilder.addCode(
					AbstractSQLTransform.PRE_TYPE_ADAPTER_TO_STRING + "$L" + AbstractSQLTransform.POST_TYPE_ADAPTER,
					SQLTypeAdapterUtils.class, method.getAdapterForParam(methodParamName), paramName);
		} else {
			SQLTransform transform = lookup(paramType);

			AssertKripton.assertTrueOrUnsupportedFieldTypeException(transform != null, paramType);
			transform.generateWriteParam2WhereCondition(methodBuilder, method, paramName, paramType);
		}
	}
1212932
public static Sql getPreperSQL(String query, Map<String, Object> parameters) {
		SqlBuilder builder = new SqlBuilder();
		return builder.getPreperSQLWithParameters(query, parameters);
	}
419985
public static void generateDynamicPartOfQuery(final SQLiteModelMethod method, MethodSpec.Builder methodBuilder, SplittedSql splittedSql, boolean countQuery) {
		final JQL jql = method.jql;
		if (StringUtils.hasText(splittedSql.sqlGroupStatement)) {
			methodBuilder.addCode("\n// manage GROUP BY statement\n");
			methodBuilder.addStatement("String _sqlGroupByStatement=$S", splittedSql.sqlGroupStatement);
			methodBuilder.addStatement("_sqlBuilder.append($L)", "_sqlGroupByStatement");
		}

		if (StringUtils.hasText(splittedSql.sqlHavingStatement)) {
			methodBuilder.addCode("\n// manage HAVING statement\n");
			methodBuilder.addStatement("String _sqlHavingStatement=$S", splittedSql.sqlHavingStatement);
			methodBuilder.addStatement("_sqlBuilder.append($L)", "_sqlHavingStatement");
		}

		// add order by when the query is not a total count query
		if (countQuery == false) {

			if (jql.isOrderBy()) {
				methodBuilder.addComment("generation order - BEGIN");
				String value = splittedSql.sqlOrderByStatement;
				String valueToReplace = jql.dynamicReplace.get(JQLDynamicStatementType.DYNAMIC_ORDER_BY);

				if (jql.isStaticOrderBy() && !jql.isDynamicOrderBy()) {
					// case static statement and NO dynamic

					methodBuilder.addStatement("String _sqlOrderByStatement=$S", value);
				} else if (jql.isStaticOrderBy() && jql.isDynamicOrderBy()) {
					methodBuilder.addStatement("String _sqlOrderByStatement=$S+$T.ifNotEmptyAppend($L, \", \")", value.replace(valueToReplace, ""), StringUtils.class, "_sortOrder");
				} else if (!jql.isStaticOrderBy() && jql.isDynamicOrderBy()) {
					methodBuilder.addStatement("String _sqlOrderByStatement=$T.ifNotEmptyAppend($L,\" $L \")", StringUtils.class, "_sortOrder", JQLKeywords.ORDER_BY_KEYWORD);
				}

				methodBuilder.addStatement("_sqlBuilder.append($L)", "_sqlOrderByStatement");
				methodBuilder.addComment("generation order - END");
				methodBuilder.addCode("\n");
			}

			if (jql.dynamicReplace.containsKey(JQLDynamicStatementType.DYNAMIC_PAGE_SIZE) || jql.annotatedPageSize) {
				methodBuilder.addComment("generation limit - BEGIN");
				if (SelectBuilderUtility.detectSelectType(method) != SelectType.PAGED_RESULT && !method.isPagedLiveData()) {
					methodBuilder.addStatement("String _sqlLimitStatement=$S", splittedSql.sqlLimitStatement);
				} else if (jql.annotatedPageSize || method.isPagedLiveData()) {
					methodBuilder.addStatement("String _sqlLimitStatement=\" LIMIT \"+$L", "paginatedResult.getPageSize()");
				} else if (jql.hasParamPageSize()) {
					methodBuilder.addStatement("String _sqlLimitStatement=$T.printIf($L>0, \" LIMIT \"+$L)", SqlUtils.class, "paginatedResult.getPageSize()", "paginatedResult.getPageSize()");
				}
				methodBuilder.addStatement("_sqlBuilder.append($L)", "_sqlLimitStatement");
				methodBuilder.addComment("generation limit - END");
				methodBuilder.addCode("\n");
			}

			if (jql.dynamicReplace.containsKey(JQLDynamicStatementType.DYNAMIC_PAGE_OFFSET) && (SelectBuilderUtility.detectSelectType(method) == SelectType.PAGED_RESULT || method.isPagedLiveData())) {
				methodBuilder.addComment("generation offset - BEGIN");
				if (jql.annotatedPageSize || method.isPagedLiveData()) {
					methodBuilder.addStatement("String _sqlOffsetStatement=\" OFFSET \"+paginatedResult.getOffset()", SqlUtils.class);
				} else if (jql.hasParamPageSize()) {
					methodBuilder.addStatement("String _sqlOffsetStatement=$T.printIf($L>0 && paginatedResult.getOffset()>0, \" OFFSET \"+paginatedResult.getOffset())", SqlUtils.class,
							jql.paramPageSize);
				}

				methodBuilder.addStatement("_sqlBuilder.append($L)", "_sqlOffsetStatement");
				methodBuilder.addComment("generation offset - END");
				methodBuilder.addCode("\n");
			}
		}
	}
111042
@Inline(value = "VMCommandLine.saveVMParameters((($1) != null) ? ($1).getCanonicalName() : null, ($2))",
			imported = {VMCommandLine.class}, statementExpression = true)
	public static void saveVMParameters(Class<?> classToLaunch, String... parameters) {
 		saveVMParameters(
 				(classToLaunch != null)
 				? classToLaunch.getCanonicalName()
 				: null, parameters);
	}
364822
public Sql getSQLByNameWithParameters(String name, Object parameters) {
		if (name == null) {
			return null;
		}

		Map<String, Object> parameterMap = buildParameters(parameters);

		SqlObject sqlObj = this.sqlMap.get(name);
		if (sqlObj != null) {

			if (sqlObj.isPrepare() == false || (this.varMap.containsKey("prepare") == false && "false".equalsIgnoreCase(this.varMap.get("prepare")))) {
				String sql = replaceSQL(sqlObj, parameterMap);
				return new Sql(sql, parameterMap);
			} else {
				String sql = replaceChoose(sqlObj, parameterMap);
				if (sqlObj instanceof ProcedureObject) {
					ProcedureObject procedureObj = (ProcedureObject)sqlObj;
					List<Out> outList = procedureObj.getOut();
					for (Out out : outList) {
						parameterMap.put(out.getName(), out);
					}
				}
				return getPreperSQLWithParameters(sql, parameterMap);
			}
		} else {
			return null;
		}
	}
381214
static Flowable<Integer> createWithZeroOutParameters(Single<Connection> connection, String sql,
            Flowable<List<Object>> parameterGroups, List<ParameterPlaceholder> parameterPlaceholders) {
        return connection.toFlowable()
                .flatMap(con -> Call.<Integer>createWithParameters(con, sql, parameterGroups, parameterPlaceholders,
                        (stmt, parameters) -> createWithZeroOutParameters(stmt, parameters, parameterPlaceholders)))
                .dematerialize();
    }
1156780
@Deprecated
    void execute(String sql, Object... parameters) {
        if (N.isNullOrEmpty(parameters)) {
            sqliteDB.execSQL(sql);
        } else {
            final NamedSQL namedSQL = parseSQL(sql);
            final Object[] args = prepareArguments(namedSQL, parameters);
            sqliteDB.execSQL(namedSQL.getPureSQL(), args);
        }
    }
354417
protected Collection<String> getParameters(final CreateSpatialIndexStatement statement) {
      final Collection<String> parameters = new ArrayList<String>();
      if (StringUtils.trimToNull(statement.getGeometryType()) != null) {
         final String gType = getGtype(statement.getGeometryType().trim());
         if (gType != null) {
            parameters.add("layer_gtype=" + gType);
         }
      }
      if (StringUtils.trimToNull(statement.getTablespace()) != null) {
         parameters.add("tablespace=" + statement.getTablespace().trim());
      }
      return parameters;
   }
176566
protected <L extends JqlBaseListener> void analyzeVariableStatementInternal(JQLContext jqlContext, final String jql, L listener) {
		walker.walk(listener, prepareVariableStatement(jqlContext, jql).value0);
	}
53241
private PreparedStatement buildPreparedStatement(Connection connection, QueryModel queryModel)
            throws SQLException {
        PreparedStatement preparedStatement = connection.prepareStatement(buildSelectString(queryModel));

        int parameterLocation = 1;
        for (Condition condition : queryModel.getConditions()) {
            JDBCConstraint jdbcConstraint = (JDBCConstraint) condition.getConstraint();

            if (jdbcConstraint.getParameter1() != null) {
                preparedStatement.setObject(parameterLocation++, jdbcConstraint.getParameter1());
            }

            if (jdbcConstraint.getParameter2() != null) {
                preparedStatement.setObject(parameterLocation++, jdbcConstraint.getParameter2());
            }
        }

        return preparedStatement;
    }
881352
function BaseStatement(
    statementOptions, context, services, connectionConfig)
{
  // call super
  EventEmitter.call(this);

  // validate input
  Errors.assertInternal(Util.isObject(statementOptions));
  Errors.assertInternal(Util.isObject(context));

  context.services         = services;
  context.connectionConfig = connectionConfig;
  context.isFetchingResult = true;

  // TODO: add the parameters map to the statement context

  var statement = this;

  /**
   * Returns this statement's SQL text.
   *
   * @returns {String}
   */
  this.getSqlText = function()
  {
    return context.sqlText;
  };

  /**
   * Returns the current status of this statement.
   *
   * @returns {String}
   */
  this.getStatus = function()
  {
    return context.isFetchingResult ? states.FETCHING : states.COMPLETE;
  };

  /**
   * Returns the columns produced by this statement.
   *
   * @returns {Object[]}
   */
  this.getColumns = function()
  {
    return context.result ? context.result.getColumns() : undefined;
  };

  /**
   * Given a column identifier, returns the corresponding column. The column
   * identifier can be either the column name (String) or the column index
   * (Number). If a column is specified and there is more than one column with
   * that name, the first column with the specified name will be returned.
   *
   * @param {String | Number} columnIdentifier
   *
   * @returns {Object}
   */
  this.getColumn = function(columnIdentifier)
  {
    return context.result ? context.result.getColumn(columnIdentifier) :
        undefined;
  };

  /**
   * Returns the number of rows returned by this statement.
   *
   * @returns {Number}
   */
  this.getNumRows = function()
  {
    return context.result ? context.result.getReturnedRows() : undefined;
  };

  /**
   * Returns the number of rows updated by this statement.
   *
   * @returns {Number}
   */
  this.getNumUpdatedRows = function()
  {
    return context.result ? context.result.getNumUpdatedRows() : undefined;
  };

  /**
   * Returns an object that contains information about the values of the
   * current warehouse, current database, etc., when this statement finished
   * executing.
   *
   * @returns {Object}
   */
  this.getSessionState = function()
  {
    return context.result ? context.result.getSessionState() : undefined;
  };

  /**
   * Returns the request id that was used when the statement was issued.
   *
   * @returns {String}
   */
  this.getRequestId = function()
  {
    return context.requestId;
  };

  /**
   * Returns the statement id generated by the server for this statement.
   * If the statement is still executing and we don't know the statement id
   * yet, this method will return undefined.
   *
   * @returns {String}
   */
  this.getStatementId = function()
  {
    return context.statementId;
  };

  /**
   * Cancels this statement if possible.
   *
   * @param {Function} [callback]
   */
  this.cancel = function(callback)
  {
    sendCancelStatement(context, statement, callback);
  };

  /**
   * Issues a request to get the statement result again.
   *
   * @param {Function} callback
   */
  context.refresh = function(callback)
  {
    // pick the appropriate function to get the result based on whether we
    // have the statement id or request id (we should have at least one)
    var sendRequestFn = context.statementId ?
        sendRequestPostExec : sendRequestPreExec;

    // the current result error might be transient,
    // so issue a request to get the result again
    sendRequestFn(context, function(err, body)
    {
      // refresh the result
      context.onStatementRequestComp(err, body);

      // if a callback was specified, invoke it
      if (Util.isFunction(callback))
      {
        callback(context);
      }
    });
  };

  /**
   * Called when the statement request is complete.
   *
   * @param err
   * @param body
   */
  context.onStatementRequestComp = function(err, body)
  {
    // if we already have a result or a result error, we invoked the complete
    // callback once, so don't invoke it again
    var suppressComplete = context.result || context.resultError;

    // clear the previous result error
    context.resultError = null;

    // if there was no error, call the success function
    if (!err)
    {
      context.onStatementRequestSucc(body);
    }
    else
    {
      // save the error
      context.resultError = err;

      // if we don't have a statement id and we got a response from GS, extract
      // the statement id from the data
      if (!context.statementId &&
          Errors.isOperationFailedError(err) && err.data)
      {
        context.statementId = err.data.queryId;
      }
    }

    // we're no longer fetching the result
    context.isFetchingResult = false;

    if (!suppressComplete)
    {
      // emit a complete event
      context.emit('statement-complete', Errors.externalize(err), statement);

      // if a complete function was specified, invoke it
      if (Util.exists(context.complete))
      {
        invokeStatementComplete(statement, context);
      }
    }
    else
    {
      Logger.getInstance().debug('refreshed result of statement with %s',
          context.requestId ?
              Util.format('request id = %s', context.requestId) :
              Util.format('statement id = %s', context.statementId));
    }
  };

  /**
   * Called when the statement request is successful. Subclasses must provide
   * their own implementation.
   *
   * @param {Object} body
   */
  context.onStatementRequestSucc = function(body){};
}
1284121
private static ProcessedInput processSqlStatement(final String sql) {
        Map<String, String> parsedSqlResult = new HashMap<String, String>();

        Set<String> namedParameters = new HashSet<String>();
        String sqlToUse = sql;
        List<ParameterHolder> parameterList = new ArrayList<ParameterHolder>();

        char[] statement = sql.toCharArray();
        int namedParameterCount = 0;
        int unnamedParameterCount = 0;
        int totalParameterCount = 0;

        int escapes = 0;
        int i = 0;
        while (i < statement.length) {
            int skipToPosition = i;
            while (i < statement.length) {
                skipToPosition = skipCommentsAndQuotes(statement, i);
                if (i == skipToPosition) {
                    break;
                } else {
                    i = skipToPosition;
                }
            }
            if (i >= statement.length) {
                break;
            }
            char c = statement[i];
            if (c == ':' || c == '&') {
                int j = i + 1;
                if (j < statement.length && statement[j] == ':' && c == ':') {
                    // Postgres-style "::" casting operator - to be skipped.
                    i = i + 2;
                    continue;
                }
                String parameter = null;
                if (j < statement.length && c == ':' && statement[j] == '{') {
                    // :{x} style parameter
                    while (j < statement.length && !('}' == statement[j])) {
                        j++;
                        if (':' == statement[j] || '{' == statement[j]) {
                            throw new IllegalArgumentException("Parameter name contains invalid character '"
                                    + statement[j] + "' at position " + i + " in statement " + sql);
                        }
                    }
                    if (j >= statement.length) {
                        throw new IllegalArgumentException("Non-terminated named parameter declaration at position "
                                + i + " in statement " + sql);
                    }
                    if (j - i > 3) {
                        parameter = sql.substring(i + 2, j);
                        namedParameterCount = addNewNamedParameter(namedParameters, namedParameterCount, parameter);
                        totalParameterCount = addNamedParameter(parameterList, totalParameterCount, escapes, i, j + 1, parameter);
                    }
                    j++;
                } else {
                    while (j < statement.length && !isParameterSeparator(statement[j])) {
                        j++;
                    }
                    if (j - i > 1) {
                        parameter = sql.substring(i + 1, j);
                        namedParameterCount = addNewNamedParameter(namedParameters, namedParameterCount, parameter);
                        totalParameterCount = addNamedParameter(parameterList, totalParameterCount, escapes, i, j, parameter);
                    }
                }
                i = j - 1;
            } else {
                if (c == '\\') {
                    int j = i + 1;
                    if (j < statement.length && statement[j] == ':') {
                        // this is an escaped : and should be skipped
                        sqlToUse = sqlToUse.substring(0, i - escapes) + sqlToUse.substring(i - escapes + 1);
                        escapes++;
                        i = i + 2;
                        continue;
                    }
                }
                if (c == '?') {
                    unnamedParameterCount++;
                    totalParameterCount++;
                }
            }
            i++;
        }
        ProcessedInput processedInput = new ProcessedInput(sql);

        for (ParameterHolder ph : parameterList) {
            processedInput.addParameter(ph.getParameterName(), ph.getStartIndex(), ph.getEndIndex());
        }

        return processedInput;
    }
305583
private boolean setCallableStatement(Object[] args) {

        // CallableStatement vs. PreparedStatement
        if (args != null && args.length == 1 && args[0] != null) {
            Class argClass = args[0].getClass();
            if (argClass.isArray() && JdbcControl.SQLParameter.class.isAssignableFrom(argClass.getComponentType())) {
                return true;
            }
        }
        return false;
    }
1374431
void loadSchema(Reader reader, Database db, DdlProceduresToLoad whichProcs)
            throws VoltCompiler.VoltCompilerException {
        int currLineNo = 1;

        DDLStatement stmt = getNextStatement(reader, m_compiler, currLineNo);
        while (stmt != null) {
            // Some statements are processed by VoltDB and the rest are handled by HSQL.
            processVoltDBStatements(db, whichProcs, stmt);
            stmt = getNextStatement(reader, m_compiler, stmt.endLineNo);
        }

        try {
            reader.close();
        } catch (IOException e) {
            throw m_compiler.new VoltCompilerException("Error closing schema file");
        }

        // process extra classes
        m_tracker.addExtraClasses(m_classMatcher.getMatchedClassList());
        // possibly save some memory
        m_classMatcher.clear();
    }
345329
@PublicEvolving
	public QueryableStateStream<KEY, T> asQueryableState(
			String queryableStateName,
			ValueStateDescriptor<T> stateDescriptor) {

		transform("Queryable state: " + queryableStateName,
				getType(),
				new QueryableValueStateOperator<>(queryableStateName, stateDescriptor));

		stateDescriptor.initializeSerializerUnlessSet(getExecutionConfig());

		return new QueryableStateStream<>(
				queryableStateName,
				stateDescriptor,
				getKeyType().createSerializer(getExecutionConfig()));
	}
36692
public static void checkReflectionParameters(SqlFragmentContainer statement, MethodDeclaration methodDecl) {

        ArrayList<ParameterDeclaration> params =
                new ArrayList<ParameterDeclaration>(methodDecl.getParameters());
        HashMap<String, ParameterDeclaration> paramMap = new HashMap<String, ParameterDeclaration>();

        // don't run these checks if this is a compiled class file (method names replaced with arg0, arg1, etc)
        if (params.size() > 0 && params.get(0).getSimpleName().equals("arg0")) {
            return;
        }

        for (int i = 0; i < params.size(); i++) {
            paramMap.put(params.get(i).getSimpleName(), params.get(i));
        }

        doCheck(statement, paramMap, methodDecl);
    }