DBQueries { public static <O> java.sql.ResultSet search(final Query<O> query, final String tableName, final Connection connection){ final String selectSql = String.format("SELECT DISTINCT objectKey FROM cqtbl_%s",tableName); PreparedStatement statement = null; try{ statement = createAndBindSelectPreparedStatement(selectSql, "", Collections.<WhereClause>emptyList(), query, connection); return statement.executeQuery(); }catch(Exception e){ DBUtils.closeQuietly(statement); throw new IllegalStateException("Unable to execute search. Query: " + query, e); } }  static void createIndexTable(final String tableName, final Class<K> objectKeyClass, final Class<A> valueClass, final Connection connection); static boolean indexTableExists(final String tableName, final Connection connection); static void createIndexOnTable(final String tableName, final Connection connection); static void suspendSyncAndJournaling(final Connection connection); static void setSyncAndJournaling(final Connection connection, final SQLiteConfig.SynchronousMode pragmaSynchronous, final SQLiteConfig.JournalMode pragmaJournalMode); static SQLiteConfig.SynchronousMode getPragmaSynchronousOrNull(final Connection connection); static SQLiteConfig.JournalMode getPragmaJournalModeOrNull(final Connection connection); static void dropIndexOnTable(final String tableName, final Connection connection); static void dropIndexTable(final String tableName, final Connection connection); static void clearIndexTable(final String tableName, final Connection connection); static void compactDatabase(final Connection connection); static void expandDatabase(final Connection connection, long numBytes); static long getDatabaseSize(final Connection connection); static int bulkAdd(Iterable<Row<K, A>> rows, final String tableName, final Connection connection); static int bulkRemove(Iterable<K> objectKeys, final String tableName, final Connection connection); static int count(final Query<O> query, final String tableName, final Connection connection); static int countDistinct(final Query<O> query, final String tableName, final Connection connection); static java.sql.ResultSet search(final Query<O> query, final String tableName, final Connection connection); static java.sql.ResultSet getDistinctKeys(final Query<O> query, boolean descending, final String tableName, final Connection connection); static java.sql.ResultSet getKeysAndValues(final Query<O> query, boolean descending, final String tableName, final Connection connection); static int getCountOfDistinctKeys(final String tableName, final Connection connection); static java.sql.ResultSet getDistinctKeysAndCounts(boolean sortByKeyDescending, final String tableName, final Connection connection); static java.sql.ResultSet getAllIndexEntries(final String tableName, final Connection connection); static java.sql.ResultSet getIndexEntryByObjectKey(final K key , final String tableName, final Connection connection); static boolean contains(final K objectKey, final Query<O> query, final String tableName, final Connection connection);  }
@Test public void testSearch_Equal() throws SQLException { Connection connection = null; ResultSet resultSet = null; try { ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true); initWithTestData(connectionManager); Equal<Car, String> equal = equal(Car.FEATURES, "abs"); connection = connectionManager.getConnection(null, noQueryOptions()); resultSet = DBQueries.search(equal, NAME, connection); assertResultSetObjectKeysOrderAgnostic(resultSet, Arrays.asList(1, 3)); }finally { DBUtils.closeQuietly(connection); DBUtils.closeQuietly(resultSet); } }
@Test public void testSearch_LessThan() throws SQLException { Connection connection = null; ResultSet resultSet = null; try { ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true); initWithTestData(connectionManager); LessThan<Car, String> lessThan = lessThan(Car.FEATURES, "abz"); connection = connectionManager.getConnection(null, noQueryOptions()); resultSet = DBQueries.search(lessThan, NAME, connection); assertResultSetObjectKeysOrderAgnostic(resultSet, Arrays.asList(1, 3)); }finally { DBUtils.closeQuietly(connection); DBUtils.closeQuietly(resultSet); } }
@Test public void testSearch_GreaterThan() throws SQLException { Connection connection = null; ResultSet resultSet = null; try { ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true); initWithTestData(connectionManager); GreaterThan<Car, String> greaterThan = greaterThan(Car.FEATURES, "abz"); connection = connectionManager.getConnection(null, noQueryOptions()); resultSet = DBQueries.search(greaterThan, NAME, connection); assertResultSetObjectKeysOrderAgnostic(resultSet, Arrays.asList(1, 2)); }finally { DBUtils.closeQuietly(connection); DBUtils.closeQuietly(resultSet); } }
@Test public void testSearch_Between() throws SQLException { Connection connection = null; ResultSet resultSet = null; try { ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true); initWithTestData(connectionManager); Between<Car, String> between = between(Car.FEATURES, "a", "b"); connection = connectionManager.getConnection(null, noQueryOptions()); resultSet = DBQueries.search(between, NAME, connection); assertResultSetObjectKeysOrderAgnostic(resultSet, Arrays.asList(1, 2, 3)); }finally { DBUtils.closeQuietly(connection); DBUtils.closeQuietly(resultSet); } }
@Test public void testSearch_StringStartsWith() throws SQLException { Connection connection = null; ResultSet resultSet = null; try { ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true); initWithTestData(connectionManager); StringStartsWith<Car, String> startsWith = startsWith(Car.FEATURES, "ab"); connection = connectionManager.getConnection(null, noQueryOptions()); resultSet = DBQueries.search(startsWith, NAME, connection); assertResultSetObjectKeysOrderAgnostic(resultSet, Arrays.asList(1, 3)); }finally { DBUtils.closeQuietly(connection); DBUtils.closeQuietly(resultSet); } }
@Test public void testSearch_Has() throws SQLException { Connection connection = null; ResultSet resultSet = null; try { ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true); initWithTestData(connectionManager); connection = connectionManager.getConnection(null, noQueryOptions()); resultSet = DBQueries.search(has(selfAttribute(Car.class)), NAME, connection); assertResultSetObjectKeysOrderAgnostic(resultSet, Arrays.asList(1, 2, 3)); }finally { DBUtils.closeQuietly(connection); DBUtils.closeQuietly(resultSet); } }