Creates a new {@link SqlQuery} consisting of given SQL statement and arguments.
'?' characters act as placeholders for arguments in the query.
436554
public static @NotNull SqlQuery query(@NotNull @SQL String sql, Object... args) {
        return new SqlQuery(sql, asList(args));
    }
494027
@Override
    public Statement createStatement() throws SQLException
    {
        checkClosed();
        try
        {
            return new JDBC4Statement(this);
        }
        catch(Exception x)
        {
            throw SQLError.get(x);
        }
    }
689770
public @NotNull QueryBuilder appendPlaceholders(int count) {
        if (count <= 0) throw new IllegalArgumentException("count must be positive, but was: " + count);

        query.append('?');
        for (int i = 1; i < count; i++)
            query.append(",?");

        return this;
    }

    /**
     * Adds placeholders for all elements of collection and then adds then values
     * of collection itself.
     */
    public @NotNull QueryBuilder appendPlaceholders(@NotNull Collection<?> args) {
        appendPlaceholders(args.size());
        addArguments(args);

        return this;
    }

    /**
     * Is the query string empty?
     */
    public boolean isEmpty() {
       return query.length() == 0;
    }

    /**
     * Does this query have any arguments?
     */
    public boolean hasArguments() {
        return !arguments.isEmpty();
    }

    /**
     * Adds an argument to this query.
     */
    public @NotNull QueryBuilder addArgument(@Nullable Object argument) {
        arguments.add(argument);
        return this;
    }

    /**
     * Adds given arguments to this query.
     */
    public @NotNull QueryBuilder addArguments(Object... args) {
        return addArguments(asList(args));
    }

    /**
     * Adds given arguments to this query.
     */
    public @NotNull QueryBuilder addArguments(@NotNull Collection<?> args) {
        arguments.addAll(args);
        return this;
    }

    /**
     * Builds an SQL query from the current state of this builder.
     *
     * @throws IllegalStateException if the builder is empty
     */
    public @NotNull SqlQuery build() {
        if (query.length() == 0)
            throw new IllegalStateException("empty query");

        return SqlQuery.query(query.toString(), new ArrayList<>(arguments));
    }
}
874597
public <T> T querySingleTypedResult(String sql, String[] args, int column) {
		return db.querySingleTypedResult(sql, args, column);
	}
81881
@Override
  public ResultSet executeQuery(String sql) throws SQLException
  {
    raiseSQLExceptionIfStatementIsClosed();
    return executeQueryInternal(sql, null);
  }
150208
public List<Object> querySingleColumnResults(String sql, String[] args,
			int column) {
		return db.querySingleColumnResults(sql, args, column);
	}
338892
public static Sql getSql(String query, Map<String, Object> parameters) {
		SqlBuilder builder = new SqlBuilder();
		String sql = builder.replaceVariables(query, parameters);
		return new Sql(sql, parameters);
	}
442513
private QueryImpl makeQuery(Session session) throws InvalidQueryException, RepositoryException
   {
      StatementContext context = new StatementContext();
      context.statement = new StringBuilder("SELECT * FROM ");
      context.statement.append(JCROrganizationServiceImpl.JOS_USERS_NODETYPE);

      if (query.getUserName() != null)
      {
         addStringStatement(context, UserProperties.JOS_USER_NAME, query.getUserName());
      }

      if (query.getFirstName() != null)
      {
         addStringStatement(context, UserProperties.JOS_FIRST_NAME, query.getFirstName());
      }

      if (query.getLastName() != null)
      {
         addStringStatement(context, UserProperties.JOS_LAST_NAME, query.getLastName());
      }

      if (query.getEmail() != null)
      {
         addStringStatement(context, UserProperties.JOS_EMAIL, query.getEmail());
      }

      if (query.getFromLoginDate() != null)
      {
         addDateStatement(context, UserProperties.JOS_LAST_LOGIN_TIME, ">=", query.getFromLoginDate());
      }

      if (query.getToLoginDate() != null)
      {
         addDateStatement(context, UserProperties.JOS_LAST_LOGIN_TIME, "<=", query.getToLoginDate());
      }

      if (status != UserStatus.ANY)
      {
         context.statement.append(" AND ").append(JCROrganizationServiceImpl.JOS_DISABLED);
         if (status == UserStatus.ENABLED)
            context.statement.append(" IS NULL");
         else
            context.statement.append(" IS NOT NULL");
      }

      return (QueryImpl)session.getWorkspace().getQueryManager().createQuery(context.statement.toString(), Query.SQL);
   }
1167742
protected String constructInStringsQuery(String query, Set<String> values) {
        String replace = "IN (?)";
        assert query.lastIndexOf(replace) == query.indexOf(replace);
        String sql = query.replace("IN (?)", "IN (%s)");

        StringBuffer list = new StringBuffer();
        for (String value : values) {
            if (list.length() > 0) {
                list.append(",");
            }
            value = String.format("'%s'", StringEscapeUtils.escapeSql(value));
            list.append(value);
        }

        return String.format(sql, list.toString());
    }
796448
public static Map<String, Object> queryForMap(String sql, Object... args) {
		Map<String, Object> result = new HashMap<String, Object>();
		List<Map<String, Object>> list = queryForList(sql, args);
		if (list.size() > 0) {
			result = list.get(0);
		}
		return result;
	}
26423
public static SqlBuilder sql(final String queryStr) {
    SqlBuilder sqlQuery = new SqlBuilder();
    sqlQuery.statement = queryStr;
    return sqlQuery;
  }
871532
public <T> List<List<T>> queryTypedResults(String sql, String[] args) {
		@SuppressWarnings("unchecked")
		List<List<T>> result = (List<List<T>>) (Object) queryResults(sql, args);
		return result;
	}
180530
public Sql[] generateSql(CreateSynonymStatement statement, Database database, SqlGeneratorChain chain) {
		StringBuilder sql = new StringBuilder("CREATE ");
		if (statement.isReplace() != null && statement.isReplace()) {
			sql.append("OR REPLACE ");
		}

		if (statement.isPublic() != null && statement.isPublic()) {
			sql.append("PUBLIC ");
		}

		sql.append("SYNONYM ");

		if (statement.getSynonymSchemaName() != null) {
			sql.append(statement.getSynonymSchemaName()).append(".");
		}

		sql.append(statement.getSynonymName());
		sql.append(" FOR ");

		if (statement.getObjectSchemaName() != null) {
			sql.append(statement.getObjectSchemaName()).append(".");
		}

		sql.append(statement.getObjectName());

		return new Sql[] { new UnparsedSql(sql.toString()) };
	}
215714
@Deprecated
	public static ResultSet query(String sql, Object... args) {
		ResultSet result = null;
		Connection con = getconnnection();
		PreparedStatement ps = null;
		try {
			ps = con.prepareStatement(sql);
			if (args != null) {
				for (int i = 0; i < args.length; i++) {
					ps.setObject((i + 1), args[i]);
				}
			}
			result = ps.executeQuery();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result;
	}
1077305
public static String compile(String sql, final Object... param) {
		for (final Object element : param) {
			sql = sql.replaceFirst("\\?", element.toString());
		}
		return sql;
	}
125620
public static <T> T queryColumn(String sql, Object... paras) {
		return MAIN.queryColumn(sql, paras);
	}
905491
@Override
    public final Query createQuery(String query)
    {
        checkClosed();
        checkTransactionNeeded();
        return getPersistenceDelegator().createQuery(query);
    }