Beispiel #1
0
  private Query getQueryFromMap(Map<String, Object> map) {
    if (map == null || map.size() == 0) {
      return null;
    }

    String query = (String) map.get("query");
    long startTime = (Long) map.get("start_time");
    int state = (Integer) map.get("state");

    Query q = new Query(startTime, query, state);

    Object endTime = map.get("finish_time");
    Object result = map.get("result");
    if (endTime != null) {
      q.setEndTime((Long) endTime);
    }

    if (result != null) {
      q.setResult((String) result);
    }

    return q;
  }
Beispiel #2
0
  /**
   * Update the query.
   *
   * @param id
   * @param query
   * @return
   */
  public int updateQuery(long id, Query query) {
    String sql = "update `query` set `finish_time`=?, `state`=?, `result`=? where `id`=? ";

    QueryRunner qr = this.createQueryRunner();
    Connection conn = null;
    int affectedRows = 0;

    try {
      conn = this.getDBConnection(true);
      affectedRows =
          qr.update(conn, sql, query.getEndTime(), query.getState(), query.getResult(), id);

    } catch (IOException e) {
      logger.error(e.getMessage());

    } catch (SQLException e) {
      logger.error(e.getMessage());

    } finally {
      DbUtils.closeQuietly(conn);
    }

    return affectedRows;
  }