RDBDocumentStoreJDBC { @NotNull public Iterator<RDBRow> queryAsIterator(RDBConnectionHandler ch, RDBTableMetaData tmd, String minId, String maxId, List<String> excludeKeyPatterns, List<QueryCondition> conditions, int limit, String sortBy) throws SQLException { return new ResultSetIterator(ch, tmd, minId, maxId, excludeKeyPatterns, conditions, limit, sortBy); } RDBDocumentStoreJDBC(RDBDocumentStoreDB dbInfo, RDBDocumentSerializer ser, int queryHitsLimit, int queryTimeLimit); boolean appendingUpdate(Connection connection, RDBTableMetaData tmd, String id, Long modified,
            boolean setModifiedConditionally, Number hasBinary, Boolean deletedOnce, Long modcount, Long cmodcount,
            Long oldmodcount, String appendData); int delete(Connection connection, RDBTableMetaData tmd, List<String> allIds); int delete(Connection connection, RDBTableMetaData tmd, Map<String, Long> toDelete); int deleteWithCondition(Connection connection, RDBTableMetaData tmd, List<QueryCondition> conditions); long determineServerTimeDifferenceMillis(Connection connection); Set<String> insert(Connection connection, RDBTableMetaData tmd, List<T> documents); Set<String> update(Connection connection, RDBTableMetaData tmd, List<T> documents, boolean upsert); @NotNull List<RDBRow> query(Connection connection, RDBTableMetaData tmd, String minId, String maxId,
            List<String> excludeKeyPatterns, List<QueryCondition> conditions, int limit); long getLong(Connection connection, RDBTableMetaData tmd, String aggregate, String field, String minId, String maxId,
            List<String> excludeKeyPatterns, List<QueryCondition> conditions); @NotNull Iterator<RDBRow> queryAsIterator(RDBConnectionHandler ch, RDBTableMetaData tmd, String minId, String maxId,
            List<String> excludeKeyPatterns, List<QueryCondition> conditions, int limit, String sortBy); List<RDBRow> read(Connection connection, RDBTableMetaData tmd, Collection<String> allKeys); @Nullable RDBRow read(Connection connection, RDBTableMetaData tmd, String id, long lastmodcount, long lastmodified); boolean update(Connection connection, RDBTableMetaData tmd, String id, Long modified, Number hasBinary,
            Boolean deletedOnce, Long modcount, Long cmodcount, Long oldmodcount, String data);  }
@Test public void queryIteratorNotStartedTest() throws SQLException { insertTestResource(this.getClass().getName() + "." + name.getMethodName()); MyConnectionHandler ch = new MyConnectionHandler(super.rdbDataSource); RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES); List<QueryCondition> conditions = Collections.emptyList(); Iterator<RDBRow> qi = jdbc.queryAsIterator(ch, tmd, null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, conditions, Integer.MAX_VALUE, null); assertTrue(qi instanceof Closeable); assertEquals(1, ch.cnt.get()); Utils.closeIfCloseable(qi); assertEquals(0, ch.cnt.get()); }
@Test public void queryIteratorConsumedTest() throws SQLException { insertTestResource(this.getClass().getName() + "." + name.getMethodName()); LogCustomizer customLogs = LogCustomizer.forLogger(RDBDocumentStoreJDBC.class.getName()).enable(Level.DEBUG) .contains("Query on ").create(); customLogs.starting(); MyConnectionHandler ch = new MyConnectionHandler(super.rdbDataSource); RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES); List<QueryCondition> conditions = Collections.emptyList(); try { Iterator<RDBRow> qi = jdbc.queryAsIterator(ch, tmd, null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, conditions, Integer.MAX_VALUE, null); assertTrue(qi instanceof Closeable); assertEquals(1, ch.cnt.get()); while (qi.hasNext()) { qi.next(); } assertEquals(0, ch.cnt.get()); assertEquals("should have a DEBUG level log entry", 1, customLogs.getLogs().size()); } finally { customLogs.finished(); customLogs = null; } }
@Test public void queryIteratorNotConsumedTest() throws SQLException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { LogCustomizer customLogs = LogCustomizer.forLogger(RDBDocumentStoreJDBC.class.getName()).enable(Level.DEBUG).contains("finalizing unclosed").create(); customLogs.starting(); insertTestResource(this.getClass().getName() + "." + name.getMethodName()); MyConnectionHandler ch = new MyConnectionHandler(super.rdbDataSource); RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES); List<QueryCondition> conditions = Collections.emptyList(); Iterator<RDBRow> qi = jdbc.queryAsIterator(ch, tmd, null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, conditions, Integer.MAX_VALUE, null); assertTrue(qi instanceof Closeable); assertEquals(1, ch.cnt.get()); Method fin = qi.getClass().getDeclaredMethod("finalize"); try { fin.setAccessible(true); fin.invoke(qi); assertTrue("finalizing non-consumed iterator should generate log entry", customLogs.getLogs().size() >= 1); } finally { Utils.closeIfCloseable(qi); fin.setAccessible(false); customLogs.finished(); } }