Example #1
0
    void setConfiguredQueries(Map<String, String> replacements, JsonValue queriesConfig) {
      configured.clear();
      for (String queryName : queriesConfig.keys()) {
        String rawQuery = queriesConfig.get(queryName).required().asString();

        TokenHandler tokenHandler = new TokenHandler();
        // Replace the table name tokens.
        String tempQueryString = tokenHandler.replaceSomeTokens(rawQuery, replacements);

        // Convert to ? for prepared statement, populate token replacement info
        List<String> tokenNames = tokenHandler.extractTokens(tempQueryString);
        String queryString = tokenHandler.replaceTokens(tempQueryString, "?", PREFIX_LIST);

        QueryInfo queryInfo = new QueryInfo(queryString, tokenNames);
        configured.put(queryName, queryInfo);
        logger.info(
            "Configured query converted to JDBC query {} and tokens {}", queryString, tokenNames);
      }
    }
Example #2
0
  /**
   * Resolves a query filter.
   *
   * @param con The db connection
   * @param filter the query filter to parse
   * @return A resolved statement
   */
  PreparedStatement parseQueryFilter(Connection con, QueryFilter filter, Map<String, Object> params)
      throws SQLException, ResourceException {
    Map<String, Object> replacementTokens = new LinkedHashMap<String, Object>();

    String rawQuery = tableHandler.renderQueryFilter(filter, replacementTokens, params);

    Map<String, String> replacements = new LinkedHashMap<String, String>();
    replacements.put("_mainTable", mainTableName);
    replacements.put("_propTable", propTableName);
    replacements.put("_dbSchema", dbSchemaName);

    TokenHandler tokenHandler = new TokenHandler();
    // Replace the table name tokens.
    String tempQueryString = tokenHandler.replaceSomeTokens(rawQuery, replacements);

    logger.debug("Tokenized statement: {} with replacementTokens: {}", rawQuery, replacementTokens);

    // Convert to ? for prepared statement, populate token replacement info
    List<String> tokenNames = tokenHandler.extractTokens(tempQueryString);
    String queryString = tokenHandler.replaceTokens(tempQueryString, "?", PREFIX_LIST);

    QueryInfo queryInfo = new QueryInfo(queryString, tokenNames);
    return resolveQuery(queryInfo, con, replacementTokens);
  }