diff --git a/src/main/java/org/springframework/cassandra/core/BoundStatementFactory.java b/src/main/java/org/springframework/cassandra/core/BoundStatementFactory.java
index 21c4fd1cd..df861ea69 100644
--- a/src/main/java/org/springframework/cassandra/core/BoundStatementFactory.java
+++ b/src/main/java/org/springframework/cassandra/core/BoundStatementFactory.java
@@ -15,6 +15,16 @@
*/
package org.springframework.cassandra.core;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.springframework.util.CollectionUtils;
+
+import com.datastax.driver.core.BoundStatement;
+import com.datastax.driver.core.PreparedStatement;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.core.exceptions.DriverException;
+
/**
* This is the primary class in core for binding many values to a Cassandra PreparedStatement.
*
@@ -26,6 +36,91 @@ package org.springframework.cassandra.core;
* @author David Webb
*
*/
-public class BoundStatementFactory {
+public class BoundStatementFactory implements PreparedStatementCreator, CqlProvider {
+ private final String cql;
+ private PreparedStatement preparedStatement;
+ private List> values = new LinkedList>();
+
+ public BoundStatementFactory(String cql) {
+ this.cql = cql;
+ }
+
+ public void addValues(List... values) {
+ this.values.add(CollectionUtils.arrayToList(values));
+ }
+
+ public void addValues(Object[]... values) {
+ for (int i = 0; values != null && i < values.length; i++) {
+ this.values.add(CollectionUtils.arrayToList(values[i]));
+ }
+ }
+
+ public void replaceValues(List... values) {
+ this.values = CollectionUtils.arrayToList(values);
+ }
+
+ public void replaceValues(Object[]... values) {
+ noValues();
+ for (int i = 0; values != null && i < values.length; i++) {
+ this.values.add(CollectionUtils.arrayToList(values[i]));
+ }
+
+ }
+
+ public void noValues() {
+ this.values = new LinkedList>();
+ }
+
+ /* (non-Javadoc)
+ * @see org.springframework.cassandra.core.CqlProvider#getCql()
+ */
+ @Override
+ public String getCql() {
+ return this.cql;
+ }
+
+ /* (non-Javadoc)
+ * @see org.springframework.cassandra.core.PreparedStatementCreator#createPreparedStatement(com.datastax.driver.core.Session)
+ */
+ @Override
+ public PreparedStatement createPreparedStatement(Session session) throws DriverException {
+ if (preparedStatement == null) {
+ preparedStatement = session.prepare(this.cql);
+ }
+ return preparedStatement;
+ }
+
+ /**
+ * Bind all values with the single CQL (PreparedStatement) and return BoundStatements read for execution.
+ *
+ * @return
+ * @throws DriverException
+ */
+ public List bindValues() throws DriverException {
+
+ LinkedList boundStatements = new LinkedList();
+
+ for (List> list : this.values) {
+
+ // Test the type of the first value
+ Object v = list.get(0);
+
+ Object[] vls;
+ if (v instanceof CqlParameterValue) {
+ LinkedList