# IGNITE-32: warnings for batches.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/54ed9b13 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/54ed9b13 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/54ed9b13 Branch: refs/heads/sprint-1 Commit: 54ed9b1327734e6a9f4e7cb94c0c481c78c3752d Parents: 8117134 Author: AKuznetsov <akuznet...@gridgain.com> Authored: Mon Feb 2 20:27:19 2015 +0700 Committer: AKuznetsov <akuznet...@gridgain.com> Committed: Mon Feb 2 20:27:19 2015 +0700 ---------------------------------------------------------------------- .../ignite/cache/store/jdbc/JdbcCacheStore.java | 50 +++++++++++++++----- .../store/jdbc/PojoJdbcCacheStoreTest.java | 2 + 2 files changed, 40 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/54ed9b13/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java index 15e1373..9ad64ab 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java @@ -731,7 +731,7 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements G } if (!currKeyTypeId.equals(keyTypeId)) { - mergeStmt.executeBatch(); + executeBatch(mergeStmt, "writeAll", cnt); currKeyTypeId = keyTypeId; @@ -744,12 +744,15 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements G mergeStmt.addBatch(); - if (cnt++ % batchSz == 0) - mergeStmt.executeBatch(); + if (++cnt % batchSz == 0) { + executeBatch(mergeStmt, "writeAll", cnt); + + cnt = 0; + } } if (mergeStmt != null && cnt % batchSz != 0) - mergeStmt.executeBatch(); + executeBatch(mergeStmt, "writeAll", cnt); } catch (SQLException e) { throw new CacheWriterException("Failed to write entries in database", e); @@ -796,6 +799,28 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements G } } + /** + * @param stmt Statement. + * @param stmtType Statement type for error message. + * @param batchSz Expected batch size. + */ + private void executeBatch(Statement stmt, String stmtType, int batchSz) throws SQLException { + int[] rowCounts = stmt.executeBatch(); + + int numOfRowCnt = rowCounts.length; + + if (numOfRowCnt != batchSz) + log.warning("JDBC driver did not return the expected number of row counts," + + " actual row count: " + numOfRowCnt + " expected: " + batchSz); + + for (int rowCount : rowCounts) + if (rowCount != 1) { + log.warning("Batch " + stmtType + " returned unexpected row count from " + stmtType + " statement"); + + break; + } + } + /** {@inheritDoc} */ @Override public void deleteAll(Collection<?> keys) throws CacheWriterException { assert keys != null; @@ -823,25 +848,26 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements G } if (!currKeyTypeId.equals(keyTypeId)) { - delStmt.executeBatch(); - - currKeyTypeId = keyTypeId; + executeBatch(delStmt, "deleteAll", cnt); cnt = 0; + + currKeyTypeId = keyTypeId; } fillKeyParameters(delStmt, em, key); delStmt.addBatch(); - if (cnt++ % batchSz == 0) - delStmt.executeBatch(); + if (++cnt % batchSz == 0) { + executeBatch(delStmt, "deleteAll", cnt); + + cnt = 0; + } } if (delStmt != null && cnt % batchSz != 0) - delStmt.executeBatch(); - - // TODO check delete result? + executeBatch(delStmt, "deleteAll", cnt); } catch (SQLException e) { throw new CacheWriterException("Failed to remove values from database", e); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/54ed9b13/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/PojoJdbcCacheStoreTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/PojoJdbcCacheStoreTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/PojoJdbcCacheStoreTest.java index b7acf23..b8b751b 100644 --- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/PojoJdbcCacheStoreTest.java +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/PojoJdbcCacheStoreTest.java @@ -345,6 +345,8 @@ public class PojoJdbcCacheStoreTest extends GridCommonAbstractTest { assertEquals(v3, store.load(k3)); + store.deleteAll(Arrays.asList(new OrganizationKey(-100))); + // Remove all. store.deleteAll(Arrays.asList(k3));