RDBDocumentStoreJDBC { private static void setIdInStatement(RDBTableMetaData tmd, PreparedStatement stmt, int idx, String id) throws SQLException { try { if (tmd.isIdBinary()) { stmt.setBytes(idx, UTF8Encoder.encodeAsByteArray(id)); } else { if (!UTF8Encoder.canEncode(id)) { throw new IOException("can not encode as UTF-8"); } stmt.setString(idx, id); } } catch (IOException ex) { LOG.warn("Invalid ID: " + id, ex); throw asDocumentStoreException(ex, "Invalid ID: " + id); } } 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 batchUpdateResult() throws SQLException { assumeTrue(super.dsf != DocumentStoreFixture.RDB_ORACLE); String table = ((RDBDocumentStore) super.ds).getTable(Collection.NODES).getName(); Connection con = super.rdbDataSource.getConnection(); con.setReadOnly(false); try { PreparedStatement st = con.prepareStatement("DELETE FROM " + table + " WHERE ID in (?, ?, ?)"); setIdInStatement(st, 1, "key-1"); setIdInStatement(st, 2, "key-2"); setIdInStatement(st, 3, "key-3"); st.executeUpdate(); st.close(); con.commit(); st = con.prepareStatement("INSERT INTO " + table + " (id) VALUES (?)"); setIdInStatement(st, 1, "key-3"); st.executeUpdate(); st.close(); con.commit(); removeMe.add("key-3"); PreparedStatement batchSt = con.prepareStatement("UPDATE " + table + " SET data = '{}' WHERE id = ?"); setIdInStatement(batchSt, 1, "key-1"); batchSt.addBatch(); setIdInStatement(batchSt, 1, "key-2"); batchSt.addBatch(); setIdInStatement(batchSt, 1, "key-3"); batchSt.addBatch(); int[] batchResult = batchSt.executeBatch(); batchSt.close(); con.commit(); assertEquals(3, batchResult.length); assertFalse("Row was updated although not present, status: " + batchResult[0], isSuccess(batchResult[0])); assertFalse("Row was updated although not present, status: " + batchResult[1], isSuccess(batchResult[1])); assertTrue("Row should be updated correctly.", isSuccess(batchResult[2])); } finally { con.close(); } }
@Test public void statementCloseTest() throws SQLException { String table = ((RDBDocumentStore) super.ds).getTable(Collection.NODES).getName(); Connection con = super.rdbDataSource.getConnection(); con.setReadOnly(true); try { PreparedStatement st = con.prepareStatement("SELECT id from " + table + " WHERE id = ?"); setIdInStatement(st, 1, "key-1"); ResultSet rs = st.executeQuery(); st.close(); LOG.info(super.rdbDataSource + " on " + super.dsname + " - statement.close() closes ResultSet: " + rs.isClosed()); con.commit(); } finally { con.close(); } }