class AuditDBHelper {

  public Set<Tuple> retrieve(Date toDate, Date fromDate, Filter filter,
      GroupBy groupBy) {
    LOG.debug("Retrieving from db  from-time :" + fromDate + " to-date :" + ":"
        + toDate + " filter :" + filter.toString());
    Set<Tuple> tupleSet = new HashSet<Tuple>();

    LOG.info("Connecting to DB ...");
    Connection connection = getConnection(
        config.getString(AuditDBConstants.JDBC_DRIVER_CLASS_NAME),
        config.getString(AuditDBConstants.DB_URL),
        config.getString(AuditDBConstants.DB_USERNAME),
        config.getString(AuditDBConstants.DB_PASSWORD));
    if (connection == null) {
      LOG.error("Connection not initialized returning ...");
      return null;
    }
    LOG.info("Connected to DB");
    ResultSet rs = null;
    String statement = getSelectStmtForRetrieve(filter, groupBy);
    LOG.debug("Select statement :" + statement);
    PreparedStatement preparedstatement = null;
    try {
      preparedstatement = connection.prepareStatement(statement);
      int index = 1;
      preparedstatement.setLong(index++, fromDate.getTime());
      preparedstatement.setLong(index++, toDate.getTime());
      if (filter.getFilters() != null) {
        for (Column column : Column.values()) {
          List<String> values = filter.getFilters().get(column);
          if (values != null && !values.isEmpty()) {
            for (String value : values) {
              preparedstatement.setString(index++, value);
            }
          }
        }
      }
      LOG.debug("Prepared statement is " + preparedstatement.toString());
      rs = preparedstatement.executeQuery();
      while (rs.next()) {
        Tuple tuple = createNewTuple(rs, groupBy);
         if (tuple == null) {
          LOG.error("Returned null tuple..returning");
          return null;
        }
        tupleSet.add(tuple);
      }
      connection.commit();
    } catch (SQLException e) {
      logNextException("SQLException encountered", e);
    } finally {
      try {
        if (rs != null)
          rs.close();
        if (preparedstatement != null)
          preparedstatement.close();
        connection.close();
      } catch (SQLException e) {
        logNextException("Exception while closing ", e);
      }
    }
    return tupleSet;
  }

  public  AuditDBHelper(ClientConfig config);

}