Elffuss BraidHub

kikocis/java-driver public

Add size() method to BatchStatement class.

Since BatchStatement#getStatements() returns an immutable copy,
and that is probably a good design decision, then lets add a
size() method so that we don't need to create a copy by calling
batch.getStatements().size() in order to get the current number
of statements in the batch.
Changeset7d0ac686760d4d5cfe9955c6fbee4205ada9044ada5a0505b4424efa6f68fc7c
AuthorMichael Spiegel <spiegel@addthis.com> · 2014-09-03 15:08 -04:00
Committerolim7t <omichallat+github@gmail.com> · 2014-09-14 20:33 -07:00
Parents4c69fa26c718

Browse the files at this changeset

2 files changed

modified driver-core/src/main/java/com/datastax/driver/core/BatchStatement.java +9 −0
@@ -171,6 +171,15 @@
171171 return this;
172172 }
173173
174+ /**
175+ * Returns the number of elements in this batch.
176+ *
177+ * @return the number of elements in this batch.
178+ */
179+ public int size() {
180+ return statements.size();
181+ }
182+
174183 /**
175184 * Throws an {@code UnsupportedOperationException} as setting the serial consistency is
176185 * currently not supported for protocol batches by Cassandra.
modified driver-core/src/test/java/com/datastax/driver/core/BatchStatementTest.java +4 −0
@@ -44,6 +44,8 @@
4444 batch.add(st.bind("key1", 1));
4545 batch.add(st.bind("key2", 0));
4646
47+ assertEquals(3, batch.size());
48+
4749 session.execute(batch);
4850
4951 ResultSet rs = session.execute("SELECT * FROM test");
@@ -90,6 +92,8 @@
9092 batch.add(st.bind("key1", 1));
9193 batch.add(st.bind("key1", 2));
9294
95+ assertEquals(3, batch.size());
96+
9397 ResultSet rs = session.execute(batch);
9498 Row r = rs.one();
9599 assertTrue(!r.isNull("[applied]"));