class DBQueries {

    public static <K, O> boolean contains(final K objectKey, final Query<O> query, final String tableName, final Connection connection){
        final String selectSql = String.format("SELECT objectKey FROM cqtbl_%s", tableName);
        PreparedStatement statement = null;
        try{
            List<WhereClause> additionalWhereClauses = Collections.singletonList(new WhereClause("objectKey = ?", objectKey));
            statement = createAndBindSelectPreparedStatement(selectSql, " LIMIT 1", additionalWhereClauses, query, connection);
            java.sql.ResultSet resultSet = statement.executeQuery();
            return resultSet.next();
        }catch (SQLException e){
            throw new IllegalStateException("Unable to execute contains. Query: " + query, e);
        }finally{
            DBUtils.closeQuietly(statement);
        }
    }

}