class AuditDBHelper {

  public boolean update(Set<Tuple> tupleSet) {

    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 false;
    }
    LOG.info("Connected to DB");

    boolean isUpdate = false, isInsert = false;
    ResultSet rs = null;
    String selectstatement = getSelectStmtForUpdation();
    String insertStatement = getInsertStmtForUpdation();
    String updateStatement = getUpdateStmtForUpdation();
    PreparedStatement selectPreparedStatement = null, insertPreparedStatement = null, updatePreparedStatement = null;
    try {
      selectPreparedStatement = connection.prepareStatement(selectstatement);
      insertPreparedStatement = connection.prepareStatement(insertStatement);
      updatePreparedStatement = connection.prepareStatement(updateStatement);
      for (Tuple tuple : tupleSet) {
        rs = executeSelectStmtUpdation(selectPreparedStatement, tuple);
        if (rs.next()) {
          if (!addToUpdateStatementBatch(updatePreparedStatement, tuple, rs))
            return false;
          isUpdate = true;
        } else {
          if (!addToInsertStatementBatch(insertPreparedStatement, tuple))
            return false;
          isInsert = true;
        }
      }
      if (isUpdate)
        updatePreparedStatement.executeBatch();
      if (isInsert)
        insertPreparedStatement.executeBatch();
      connection.commit();
    } catch (SQLException e) {
      logNextException("SQLException while updating daily table", e);
      return false;
    } finally {
      try {
        if (rs != null) {
          rs.close();
        }
        selectPreparedStatement.close();
        insertPreparedStatement.close();
        updatePreparedStatement.close();
        connection.close();
      } catch (SQLException e) {
        logNextException("Exception while closing ", e);
      }
    }
    return true;
  }

  public  AuditDBHelper(ClientConfig config);

}