From 22b6a53a88d4ba285ed2c9ddbf5e2bf1d81bd598 Mon Sep 17 00:00:00 2001 From: David Webb Date: Mon, 9 Dec 2013 13:30:51 -0500 Subject: [PATCH] DATACASS-32 : WIP : Removed optionsByName for Query Options override. --- .../cassandra/core/CassandraOperations.java | 210 --------- .../cassandra/core/CassandraTemplate.java | 432 ++++++------------ 2 files changed, 130 insertions(+), 512 deletions(-) diff --git a/spring-cassandra/src/main/java/org/springframework/cassandra/core/CassandraOperations.java b/spring-cassandra/src/main/java/org/springframework/cassandra/core/CassandraOperations.java index 02d8d9ec6..31bee51a9 100644 --- a/spring-cassandra/src/main/java/org/springframework/cassandra/core/CassandraOperations.java +++ b/spring-cassandra/src/main/java/org/springframework/cassandra/core/CassandraOperations.java @@ -66,19 +66,6 @@ public interface CassandraOperations { */ T query(final String cql, ResultSetExtractor rse) throws DataAccessException; - /** - * Executes the provided CQL Query, and extracts the results with the ResultSetExtractor. - * - * @param cql The Query - * @param rse The implementation for extracting the ResultSet - * @param optionsByName Query Options Map - * - * @return - * @throws DataAccessException - */ - T query(final String cql, ResultSetExtractor rse, final Map optionsByName) - throws DataAccessException; - /** * Executes the provided CQL Query, and extracts the results with the ResultSetExtractor. * @@ -101,18 +88,6 @@ public interface CassandraOperations { */ T queryAsynchronously(final String cql, ResultSetFutureExtractor rse) throws DataAccessException; - /** - * Executes the provided CQL Query asynchronously, and extracts the results with the ResultSetFutureExtractor - * - * @param cql The Query - * @param rse The implementation for extracting the future results - * @param optionsByName Query Options Map - * @return - * @throws DataAccessException - */ - T queryAsynchronously(final String cql, ResultSetFutureExtractor rse, final Map optionsByName) - throws DataAccessException; - /** * Executes the provided CQL Query asynchronously, and extracts the results with the ResultSetFutureExtractor * @@ -134,17 +109,6 @@ public interface CassandraOperations { */ void query(final String cql, RowCallbackHandler rch) throws DataAccessException; - /** - * Executes the provided CQL Query, and then processes the results with the RowCallbackHandler. - * - * @param cql The Query - * @param rch The implementation for processing the rows returned. - * @param options Query Options Map - * @throws DataAccessException - */ - void query(final String cql, RowCallbackHandler rch, final Map optionsByName) - throws DataAccessException; - /** * Executes the provided CQL Query, and then processes the results with the RowCallbackHandler. * @@ -176,18 +140,6 @@ public interface CassandraOperations { */ List query(final String cql, RowMapper rowMapper) throws DataAccessException; - /** - * Executes the provided CQL Query, and maps all Rows returned with the supplied RowMapper. - * - * @param cql The Query - * @param rowMapper The implementation for mapping all rows - * @param optionsByName Query Options Map - * @return List of processed by the RowMapper - * @throws DataAccessException - */ - List query(final String cql, RowMapper rowMapper, final Map optionsByName) - throws DataAccessException; - /** * Executes the provided CQL Query, and maps all Rows returned with the supplied RowMapper. * @@ -363,9 +315,6 @@ public interface CassandraOperations { */ T query(final String cql, PreparedStatementBinder psb, ResultSetExtractor rse) throws DataAccessException; - T query(final String cql, PreparedStatementBinder psb, ResultSetExtractor rse, - final Map optionsByName) throws DataAccessException; - T query(final String cql, PreparedStatementBinder psb, ResultSetExtractor rse, final QueryOptions options) throws DataAccessException; @@ -381,20 +330,6 @@ public interface CassandraOperations { */ void query(final String cql, PreparedStatementBinder psb, RowCallbackHandler rch) throws DataAccessException; - /** - * Converts the CQL provided into a {@link SimplePreparedStatementCreator}. Then, the PreparedStatementBinder will - * bind its values to the bind variables in the provided CQL String. The results of the PreparedStatement are - * processed with the RowCallbackHandler implementation provided and nothing is returned. - * - * @param cql The Query to Prepare - * @param psb The Binding implementation - * @param rch The RowCallbackHandler for processing the ResultSet - * @param optionsByName The Query Options Map - * @throws DataAccessException - */ - void query(final String cql, PreparedStatementBinder psb, RowCallbackHandler rch, - final Map optionsByName) throws DataAccessException; - /** * Converts the CQL provided into a {@link SimplePreparedStatementCreator}. Then, the PreparedStatementBinder will * bind its values to the bind variables in the provided CQL String. The results of the PreparedStatement are @@ -423,22 +358,6 @@ public interface CassandraOperations { */ List query(final String cql, PreparedStatementBinder psb, RowMapper rowMapper) throws DataAccessException; - /** - * Converts the CQL provided into a {@link SimplePreparedStatementCreator}. Then, the PreparedStatementBinder will - * bind its values to the bind variables in the provided CQL String. The results of the PreparedStatement are - * processed with the RowMapper implementation provided and a List is returned with elements of Type for each Row - * returned. - * - * @param cql The Query to Prepare - * @param psb The Binding implementation - * @param rowMapper The implementation for Mapping a Row to Type - * @param optionsByName The Query Options Map - * @return List of for each Row returned from the Query. - * @throws DataAccessException - */ - List query(final String cql, PreparedStatementBinder psb, RowMapper rowMapper, - final Map optionsByName) throws DataAccessException; - /** * Converts the CQL provided into a {@link SimplePreparedStatementCreator}. Then, the PreparedStatementBinder will * bind its values to the bind variables in the provided CQL String. The results of the PreparedStatement are @@ -467,20 +386,6 @@ public interface CassandraOperations { */ T query(PreparedStatementCreator psc, ResultSetExtractor rse) throws DataAccessException; - /** - * Uses the provided PreparedStatementCreator to prepare a new Session call. This can only be used for CQL - * Statements that do not have data binding. The results of the PreparedStatement are processed with - * ResultSetExtractor implementation provided by the Application Code. - * - * @param psc The implementation to create the PreparedStatement - * @param rse Implementation for extracting from the ResultSet - * @param optionsByName The Query Options Map - * @return Type which is the output of the ResultSetExtractor - * @throws DataAccessException - */ - T query(PreparedStatementCreator psc, ResultSetExtractor rse, final Map optionsByName) - throws DataAccessException; - /** * Uses the provided PreparedStatementCreator to prepare a new Session call. This can only be used for CQL * Statements that do not have data binding. The results of the PreparedStatement are processed with @@ -506,19 +411,6 @@ public interface CassandraOperations { */ void query(PreparedStatementCreator psc, RowCallbackHandler rch) throws DataAccessException; - /** - * Uses the provided PreparedStatementCreator to prepare a new Session call. This can only be used for CQL - * Statements that do not have data binding. The results of the PreparedStatement are processed with - * RowCallbackHandler and nothing is returned. - * - * @param psc The implementation to create the PreparedStatement - * @param rch The implementation to process Results - * @param optionsByName The Query Options Map - * @throws DataAccessException - */ - void query(PreparedStatementCreator psc, RowCallbackHandler rch, final Map optionsByName) - throws DataAccessException; - /** * Uses the provided PreparedStatementCreator to prepare a new Session call. This can only be used for CQL * Statements that do not have data binding. The results of the PreparedStatement are processed with @@ -544,20 +436,6 @@ public interface CassandraOperations { */ List query(PreparedStatementCreator psc, RowMapper rowMapper) throws DataAccessException; - /** - * Uses the provided PreparedStatementCreator to prepare a new Session call. This can only be used for CQL - * Statements that do not have data binding. The results of the PreparedStatement are processed with RowMapper - * implementation provided and a List is returned with elements of Type for each Row returned. - * - * @param psc The implementation to create the PreparedStatement - * @param rowMapper The implementation for mapping each Row returned. - * @param optionsByName The Query Options Map - * @return List of Type mapped from each Row in the Results - * @throws DataAccessException - */ - List query(PreparedStatementCreator psc, RowMapper rowMapper, final Map optionsByName) - throws DataAccessException; - /** * Uses the provided PreparedStatementCreator to prepare a new Session call. This can only be used for CQL * Statements that do not have data binding. The results of the PreparedStatement are processed with RowMapper @@ -572,21 +450,6 @@ public interface CassandraOperations { List query(PreparedStatementCreator psc, RowMapper rowMapper, final QueryOptions options) throws DataAccessException; - /** - * Uses the provided PreparedStatementCreator to prepare a new Session call. Binds the values from the - * PreparedStatementBinder to the available bind variables. The results of the PreparedStatement are processed with - * ResultSetExtractor implementation provided by the Application Code. - * - * @param psc The implementation to create the PreparedStatement - * @param psb The implementation to bind variables to values - * @param rse Implementation for extracting from the ResultSet - * @param optionsByName The Query Options Map - * @return Type which is the output of the ResultSetExtractor - * @throws DataAccessException - */ - T query(PreparedStatementCreator psc, final PreparedStatementBinder psb, final ResultSetExtractor rse, - final Map optionsByName) throws DataAccessException; - /** * Uses the provided PreparedStatementCreator to prepare a new Session call. Binds the values from the * PreparedStatementBinder to the available bind variables. The results of the PreparedStatement are processed with @@ -616,21 +479,6 @@ public interface CassandraOperations { T query(PreparedStatementCreator psc, final PreparedStatementBinder psb, final ResultSetExtractor rse) throws DataAccessException; - /** - * Uses the provided PreparedStatementCreator to prepare a new Session call. Binds the values from the - * PreparedStatementBinder to the available bind variables. The results of the PreparedStatement are processed with - * RowCallbackHandler and nothing is returned. - * - * @param psc The implementation to create the PreparedStatement - * @param psb The implementation to bind variables to values - * @param rch The implementation to process Results - * @param optionsByName The Query Options Map - * @return Type which is the output of the ResultSetExtractor - * @throws DataAccessException - */ - void query(PreparedStatementCreator psc, final PreparedStatementBinder psb, final RowCallbackHandler rch, - final Map optionsByName) throws DataAccessException; - /** * Uses the provided PreparedStatementCreator to prepare a new Session call. Binds the values from the * PreparedStatementBinder to the available bind variables. The results of the PreparedStatement are processed with @@ -660,21 +508,6 @@ public interface CassandraOperations { void query(PreparedStatementCreator psc, final PreparedStatementBinder psb, final RowCallbackHandler rch) throws DataAccessException; - /** - * Uses the provided PreparedStatementCreator to prepare a new Session call. Binds the values from the - * PreparedStatementBinder to the available bind variables. The results of the PreparedStatement are processed with - * RowMapper implementation provided and a List is returned with elements of Type for each Row returned. - * - * @param psc The implementation to create the PreparedStatement - * @param psb The implementation to bind variables to values - * @param rowMapper The implementation for mapping each Row returned. - * @param optionsByName The Query Options Map - * @return Type which is the output of the ResultSetExtractor - * @throws DataAccessException - */ - List query(PreparedStatementCreator psc, final PreparedStatementBinder psb, final RowMapper rowMapper, - final Map optionsByName) throws DataAccessException; - /** * Uses the provided PreparedStatementCreator to prepare a new Session call. Binds the values from the * PreparedStatementBinder to the available bind variables. The results of the PreparedStatement are processed with @@ -729,21 +562,6 @@ public interface CassandraOperations { */ Session getSession(); - /** - * This is an operation designed for high performance writes. The cql is used to create a PreparedStatement once, then - * all row values are bound to the single PreparedStatement and executed against the Session. - * - *

- * This is used internally by the other ingest() methods, but can be used if you want to write your own RowIterator. - * The Object[] length returned by the next() implementation must match the number of bind variables in the CQL. - *

- * - * @param cql The CQL - * @param rowIterator Implementation to provide the Object[] to be bound to the CQL. - * @param optionsByName The Query Options Map - */ - void ingest(String cql, RowIterator rowIterator, Map optionsByName); - /** * This is an operation designed for high performance writes. The cql is used to create a PreparedStatement once, then * all row values are bound to the single PreparedStatement and executed against the Session. @@ -773,20 +591,6 @@ public interface CassandraOperations { */ void ingest(String cql, RowIterator rowIterator); - /** - * This is an operation designed for high performance writes. The cql is used to create a PreparedStatement once, then - * all row values are bound to the single PreparedStatement and executed against the Session. - * - *

- * The List length must match the number of bind variables in the CQL. - *

- * - * @param cql The CQL - * @param rows List of List with data to bind to the CQL. - * @param optionsByName The Query Options Map - */ - void ingest(String cql, List> rows, Map optionsByName); - /** * This is an operation designed for high performance writes. The cql is used to create a PreparedStatement once, then * all row values are bound to the single PreparedStatement and executed against the Session. @@ -814,20 +618,6 @@ public interface CassandraOperations { */ void ingest(String cql, List> rows); - /** - * This is an operation designed for high performance writes. The cql is used to create a PreparedStatement once, then - * all row values are bound to the single PreparedStatement and executed against the Session. - * - *

- * The Object[] length of the nested array must match the number of bind variables in the CQL. - *

- * - * @param cql The CQL - * @param rows Object array of Object array of values to bind to the CQL. - * @param optionsByName The Query Options Map - */ - void ingest(String cql, Object[][] rows, Map optionsByName); - /** * This is an operation designed for high performance writes. The cql is used to create a PreparedStatement once, then * all row values are bound to the single PreparedStatement and executed against the Session. diff --git a/spring-cassandra/src/main/java/org/springframework/cassandra/core/CassandraTemplate.java b/spring-cassandra/src/main/java/org/springframework/cassandra/core/CassandraTemplate.java index fb3dc87d7..cb0d43913 100644 --- a/spring-cassandra/src/main/java/org/springframework/cassandra/core/CassandraTemplate.java +++ b/spring-cassandra/src/main/java/org/springframework/cassandra/core/CassandraTemplate.java @@ -17,7 +17,6 @@ package org.springframework.cassandra.core; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -31,7 +30,6 @@ import org.springframework.util.Assert; import com.datastax.driver.core.BoundStatement; import com.datastax.driver.core.ColumnDefinitions; import com.datastax.driver.core.ColumnDefinitions.Definition; -import com.datastax.driver.core.DataType; import com.datastax.driver.core.Host; import com.datastax.driver.core.Metadata; import com.datastax.driver.core.PreparedStatement; @@ -92,33 +90,23 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public void execute(final String cql) throws DataAccessException { - doExecute(cql, Collections. emptyMap()); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#queryAsynchronously(java.lang.String, org.springframework.cassandra.core.ResultSetFutureExtractor, java.util.Map) - */ - @Override - public T queryAsynchronously(final String cql, ResultSetFutureExtractor rse, - final Map optionsByName) throws DataAccessException { - return rse.extractData(execute(new SessionCallback() { - @Override - public ResultSetFuture doInSession(Session s) throws DataAccessException { - Statement statement = new SimpleStatement(cql); - addQueryOptions(statement, optionsByName); - return s.executeAsync(statement); - } - })); + doExecute(cql, null); } /* (non-Javadoc) * @see org.springframework.cassandra.core.CassandraOperations#queryAsynchronously(java.lang.String, org.springframework.cassandra.core.ResultSetFutureExtractor, org.springframework.cassandra.core.QueryOptions) */ @Override - public T queryAsynchronously(String cql, ResultSetFutureExtractor rse, QueryOptions options) + public T queryAsynchronously(final String cql, ResultSetFutureExtractor rse, final QueryOptions options) throws DataAccessException { - Assert.notNull(options); - return queryAsynchronously(cql, rse, options.toMap()); + return rse.extractData(execute(new SessionCallback() { + @Override + public ResultSetFuture doInSession(Session s) throws DataAccessException { + Statement statement = new SimpleStatement(cql); + addQueryOptions(statement, options); + return s.executeAsync(statement); + } + })); } /* (non-Javadoc) @@ -126,18 +114,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public T queryAsynchronously(final String cql, ResultSetFutureExtractor rse) throws DataAccessException { - return queryAsynchronously(cql, rse, Collections. emptyMap()); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#query(java.lang.String, org.springframework.cassandra.core.ResultSetExtractor) - */ - public T query(String cql, ResultSetExtractor rse, Map optionsByName) - throws DataAccessException { - Assert.notNull(cql); - Assert.notNull(optionsByName); - ResultSet rs = doExecute(cql, optionsByName); - return rse.extractData(rs); + return queryAsynchronously(cql, rse, null); } /* (non-Javadoc) @@ -145,7 +122,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public T query(String cql, ResultSetExtractor rse) throws DataAccessException { - return query(cql, rse, Collections. emptyMap()); + return query(cql, rse, null); } /* (non-Javadoc) @@ -153,16 +130,9 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public T query(String cql, ResultSetExtractor rse, QueryOptions options) throws DataAccessException { - Assert.notNull(options); - return query(cql, rse, options.toMap()); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#query(java.lang.String, org.springframework.cassandra.core.RowCallbackHandler, java.util.Map) - */ - @Override - public void query(String cql, RowCallbackHandler rch, Map optionsByName) throws DataAccessException { - process(doExecute(cql, optionsByName), rch); + Assert.notNull(cql); + ResultSet rs = doExecute(cql, options); + return rse.extractData(rs); } /* (non-Javadoc) @@ -170,25 +140,14 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public void query(String cql, RowCallbackHandler rch, QueryOptions options) throws DataAccessException { - Assert.notNull(options); - query(cql, rch, options.toMap()); + process(doExecute(cql, options), rch); } /* (non-Javadoc) * @see org.springframework.cassandra.core.CassandraOperations#query(java.lang.String, org.springframework.cassandra.core.RowCallbackHandler) */ public void query(String cql, RowCallbackHandler rch) throws DataAccessException { - query(cql, rch, Collections. emptyMap()); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#query(java.lang.String, org.springframework.cassandra.core.RowMapper, java.util.Map) - */ - @Override - public List query(String cql, RowMapper rowMapper, Map optionsByName) - throws DataAccessException { - Assert.notNull(optionsByName); - return process(doExecute(cql, optionsByName), rowMapper); + query(cql, rch, null); } /* (non-Javadoc) @@ -196,50 +155,49 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public List query(String cql, RowMapper rowMapper, QueryOptions options) throws DataAccessException { - Assert.notNull(options); - return query(cql, rowMapper, options.toMap()); + return process(doExecute(cql, options), rowMapper); } /* (non-Javadoc) * @see org.springframework.cassandra.core.CassandraOperations#query(java.lang.String, org.springframework.cassandra.core.RowMapper) */ public List query(String cql, RowMapper rowMapper) throws DataAccessException { - return query(cql, rowMapper, Collections. emptyMap()); + return query(cql, rowMapper, null); } /* (non-Javadoc) * @see org.springframework.cassandra.core.CassandraOperations#queryForList(java.lang.String) */ public List> queryForListOfMap(String cql) throws DataAccessException { - return processListOfMap(doExecute(cql, Collections. emptyMap())); + return processListOfMap(doExecute(cql, null)); } /* (non-Javadoc) * @see org.springframework.cassandra.core.CassandraOperations#queryForList(java.lang.String, java.lang.Class) */ public List queryForList(String cql, Class elementType) throws DataAccessException { - return processList(doExecute(cql, Collections. emptyMap()), elementType); + return processList(doExecute(cql, null), elementType); } /* (non-Javadoc) * @see org.springframework.cassandra.core.CassandraOperations#queryForMap(java.lang.String) */ public Map queryForMap(String cql) throws DataAccessException { - return processMap(doExecute(cql, Collections. emptyMap())); + return processMap(doExecute(cql, null)); } /* (non-Javadoc) * @see org.springframework.cassandra.core.CassandraOperations#queryForObject(java.lang.String, java.lang.Class) */ public T queryForObject(String cql, Class requiredType) throws DataAccessException { - return processOne(doExecute(cql, Collections. emptyMap()), requiredType); + return processOne(doExecute(cql, null), requiredType); } /* (non-Javadoc) * @see org.springframework.cassandra.core.CassandraOperations#queryForObject(java.lang.String, org.springframework.cassandra.core.RowMapper) */ public T queryForObject(String cql, RowMapper rowMapper) throws DataAccessException { - return processOne(doExecute(cql, Collections. emptyMap()), rowMapper); + return processOne(doExecute(cql, null), rowMapper); } /** @@ -267,7 +225,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe * @param callback * @return */ - protected ResultSet doExecute(final String cql, final Map optionsByName) { + protected ResultSet doExecute(final String cql, final QueryOptions options) { logger.info(cql); @@ -276,7 +234,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe @Override public ResultSet doInSession(Session s) throws DataAccessException { SimpleStatement statement = new SimpleStatement(cql); - addQueryOptions(statement, optionsByName); + addQueryOptions(statement, options); return s.execute(statement); } }); @@ -288,13 +246,13 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe * @param callback * @return */ - protected ResultSet doExecute(final BoundStatement bs, final Map optionsByName) { + protected ResultSet doExecute(final BoundStatement bs, final QueryOptions options) { return doExecute(new SessionCallback() { @Override public ResultSet doInSession(Session s) throws DataAccessException { - addQueryOptions(bs, optionsByName); + addQueryOptions(bs, options); return s.execute(bs); } }); @@ -326,7 +284,6 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe for (Definition def : cols.asList()) { String name = def.getName(); - DataType dataType = def.getType(); map.put(name, def.getType().deserialize(row.getBytesUnsafe(name))); } @@ -528,24 +485,13 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe return execute(new SimplePreparedStatementCreator(cql), action); } - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#query(org.springframework.cassandra.core.PreparedStatementCreator, org.springframework.cassandra.core.ResultSetExtractor, java.util.Map) - */ - @Override - public T query(PreparedStatementCreator psc, ResultSetExtractor rse, Map optionsByName) - throws DataAccessException { - Assert.notNull(optionsByName); - return query(psc, null, rse, optionsByName); - } - /* (non-Javadoc) * @see org.springframework.cassandra.core.CassandraOperations#query(org.springframework.cassandra.core.PreparedStatementCreator, org.springframework.cassandra.core.ResultSetExtractor, org.springframework.cassandra.core.QueryOptions) */ @Override public T query(PreparedStatementCreator psc, ResultSetExtractor rse, QueryOptions options) throws DataAccessException { - Assert.notNull(options); - return query(psc, rse, options.toMap()); + return query(psc, null, rse, options); } /* (non-Javadoc) @@ -553,17 +499,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public T query(PreparedStatementCreator psc, ResultSetExtractor rse) throws DataAccessException { - return query(psc, rse, Collections. emptyMap()); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#query(org.springframework.cassandra.core.PreparedStatementCreator, org.springframework.cassandra.core.RowCallbackHandler, java.util.Map) - */ - @Override - public void query(PreparedStatementCreator psc, RowCallbackHandler rch, Map optionsByName) - throws DataAccessException { - Assert.notNull(optionsByName); - query(psc, null, rch, optionsByName); + return query(psc, rse, null); } /* (non-Javadoc) @@ -572,8 +508,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe @Override public void query(PreparedStatementCreator psc, RowCallbackHandler rch, QueryOptions options) throws DataAccessException { - Assert.notNull(options); - query(psc, rch, options.toMap()); + query(psc, null, rch, options); } /* (non-Javadoc) @@ -581,17 +516,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public void query(PreparedStatementCreator psc, RowCallbackHandler rch) throws DataAccessException { - query(psc, rch, Collections. emptyMap()); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#query(org.springframework.cassandra.core.PreparedStatementCreator, org.springframework.cassandra.core.RowMapper, java.util.Map) - */ - @Override - public List query(PreparedStatementCreator psc, RowMapper rowMapper, Map optionsByName) - throws DataAccessException { - Assert.notNull(optionsByName); - return query(psc, null, rowMapper, optionsByName); + query(psc, rch, null); } /* (non-Javadoc) @@ -600,8 +525,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe @Override public List query(PreparedStatementCreator psc, RowMapper rowMapper, QueryOptions options) throws DataAccessException { - Assert.notNull(options); - return query(psc, rowMapper, options.toMap()); + return query(psc, null, rowMapper, options); } /* (non-Javadoc) @@ -609,41 +533,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public List query(PreparedStatementCreator psc, RowMapper rowMapper) throws DataAccessException { - return query(psc, rowMapper, Collections. emptyMap()); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#query(org.springframework.cassandra.core.PreparedStatementCreator, org.springframework.cassandra.core.PreparedStatementSetter, org.springframework.cassandra.core.ResultSetExtractor) - */ - public T query(PreparedStatementCreator psc, final PreparedStatementBinder psb, final ResultSetExtractor rse, - final Map optionsByName) throws DataAccessException { - - Assert.notNull(rse, "ResultSetExtractor must not be null"); - logger.debug("Executing prepared CQL query"); - - return execute(psc, new PreparedStatementCallback() { - public T doInPreparedStatement(PreparedStatement ps) throws DriverException { - ResultSet rs = null; - BoundStatement bs = null; - if (psb != null) { - bs = psb.bindValues(ps); - } else { - bs = ps.bind(); - } - rs = doExecute(bs, optionsByName); - return rse.extractData(rs); - } - }); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#query(java.lang.String, org.springframework.cassandra.core.PreparedStatementBinder, org.springframework.cassandra.core.ResultSetExtractor, java.util.Map) - */ - @Override - public T query(String cql, PreparedStatementBinder psb, ResultSetExtractor rse, - Map optionsByName) throws DataAccessException { - Assert.notNull(optionsByName); - return query(new SimplePreparedStatementCreator(cql), psb, rse, optionsByName); + return query(psc, rowMapper, null); } /* (non-Javadoc) @@ -652,8 +542,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe @Override public T query(String cql, PreparedStatementBinder psb, ResultSetExtractor rse, QueryOptions options) throws DataAccessException { - Assert.notNull(options); - return query(cql, psb, rse, options.toMap()); + return query(new SimplePreparedStatementCreator(cql), psb, rse, options); } /* (non-Javadoc) @@ -661,17 +550,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public T query(String cql, PreparedStatementBinder psb, ResultSetExtractor rse) throws DataAccessException { - return query(cql, psb, rse, Collections. emptyMap()); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#query(java.lang.String, org.springframework.cassandra.core.PreparedStatementBinder, org.springframework.cassandra.core.RowCallbackHandler, java.util.Map) - */ - @Override - public void query(String cql, PreparedStatementBinder psb, RowCallbackHandler rch, Map optionsByName) - throws DataAccessException { - Assert.notNull(optionsByName); - query(new SimplePreparedStatementCreator(cql), psb, rch, optionsByName); + return query(cql, psb, rse, null); } /* (non-Javadoc) @@ -680,8 +559,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe @Override public void query(String cql, PreparedStatementBinder psb, RowCallbackHandler rch, QueryOptions options) throws DataAccessException { - Assert.notNull(options); - query(cql, psb, rch, options.toMap()); + query(new SimplePreparedStatementCreator(cql), psb, rch, options); } /* (non-Javadoc) @@ -689,17 +567,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public void query(String cql, PreparedStatementBinder psb, RowCallbackHandler rch) throws DataAccessException { - query(cql, psb, rch, Collections. emptyMap()); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#query(java.lang.String, org.springframework.cassandra.core.PreparedStatementBinder, org.springframework.cassandra.core.RowMapper, java.util.Map) - */ - @Override - public List query(String cql, PreparedStatementBinder psb, RowMapper rowMapper, - Map optionsByName) throws DataAccessException { - Assert.notNull(optionsByName); - return query(new SimplePreparedStatementCreator(cql), psb, rowMapper, optionsByName); + query(cql, psb, rch, null); } /* (non-Javadoc) @@ -708,8 +576,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe @Override public List query(String cql, PreparedStatementBinder psb, RowMapper rowMapper, QueryOptions options) throws DataAccessException { - Assert.notNull(options); - return query(cql, psb, rowMapper, options.toMap()); + return query(new SimplePreparedStatementCreator(cql), psb, rowMapper, options); } /* (non-Javadoc) @@ -717,72 +584,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public List query(String cql, PreparedStatementBinder psb, RowMapper rowMapper) throws DataAccessException { - return query(cql, psb, rowMapper, Collections. emptyMap()); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#query(org.springframework.cassandra.core.PreparedStatementCreator, org.springframework.cassandra.core.PreparedStatementBinder, org.springframework.cassandra.core.RowCallbackHandler) - */ - @Override - public void query(PreparedStatementCreator psc, final PreparedStatementBinder psb, final RowCallbackHandler rch, - final Map optionsByName) throws DataAccessException { - Assert.notNull(rch, "RowCallbackHandler must not be null"); - logger.debug("Executing prepared CQL query"); - - execute(psc, new PreparedStatementCallback() { - public Object doInPreparedStatement(PreparedStatement ps) throws DriverException { - ResultSet rs = null; - BoundStatement bs = null; - if (psb != null) { - bs = psb.bindValues(ps); - } else { - bs = ps.bind(); - } - rs = doExecute(bs, optionsByName); - process(rs, rch); - return null; - } - }); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#query(org.springframework.cassandra.core.PreparedStatementCreator, org.springframework.cassandra.core.PreparedStatementBinder, org.springframework.cassandra.core.RowMapper) - */ - @Override - public List query(PreparedStatementCreator psc, final PreparedStatementBinder psb, - final RowMapper rowMapper, final Map optionsByName) throws DataAccessException { - Assert.notNull(rowMapper, "RowMapper must not be null"); - logger.debug("Executing prepared CQL query"); - - return execute(psc, new PreparedStatementCallback>() { - public List doInPreparedStatement(PreparedStatement ps) throws DriverException { - ResultSet rs = null; - BoundStatement bs = null; - if (psb != null) { - bs = psb.bindValues(ps); - } else { - bs = ps.bind(); - } - rs = doExecute(bs, optionsByName); - - return process(rs, rowMapper); - } - }); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#execute(java.lang.String, org.springframework.cassandra.core.RowProvider, int) - */ - @Override - public void ingest(String cql, RowIterator rowIterator, Map optionsByName) { - - PreparedStatement preparedStatement = getSession().prepare(cql); - addPreparedStatementOptions(preparedStatement, optionsByName); - - while (rowIterator.hasNext()) { - getSession().execute(preparedStatement.bind(rowIterator.next())); - } - + return query(cql, psb, rowMapper, null); } /* (non-Javadoc) @@ -790,8 +592,13 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public void ingest(String cql, RowIterator rowIterator, QueryOptions options) { - Assert.notNull(options); - ingest(cql, rowIterator, options.toMap()); + + PreparedStatement preparedStatement = getSession().prepare(cql); + addPreparedStatementOptions(preparedStatement, options); + + while (rowIterator.hasNext()) { + getSession().execute(preparedStatement.bind(rowIterator.next())); + } } /* (non-Javadoc) @@ -799,16 +606,15 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public void ingest(String cql, RowIterator rowIterator) { - ingest(cql, rowIterator, Collections. emptyMap()); + ingest(cql, rowIterator, null); } /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#execute(java.lang.String, java.util.List) + * @see org.springframework.cassandra.core.CassandraOperations#ingest(java.lang.String, java.util.List, org.springframework.cassandra.core.QueryOptions) */ @Override - public void ingest(String cql, final List> rows, Map optionsByName) { + public void ingest(String cql, final List> rows, QueryOptions options) { - Assert.notNull(optionsByName); Assert.notNull(rows); Assert.notEmpty(rows); @@ -826,34 +632,23 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe return i.hasNext(); } - }, optionsByName); + }, options); } - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#ingest(java.lang.String, java.util.List, org.springframework.cassandra.core.QueryOptions) - */ - @Override - public void ingest(String cql, List> rows, QueryOptions options) { - Assert.notNull(options); - ingest(cql, rows, options.toMap()); - } - /* (non-Javadoc) * @see org.springframework.cassandra.core.CassandraOperations#ingest(java.lang.String, java.util.List) */ @Override public void ingest(String cql, List> rows) { - ingest(cql, rows, Collections. emptyMap()); + ingest(cql, rows, null); } /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#execute(java.lang.String, java.lang.Object[][]) + * @see org.springframework.cassandra.core.CassandraOperations#ingest(java.lang.String, java.lang.Object[][], org.springframework.cassandra.core.QueryOptions) */ @Override - public void ingest(String cql, final Object[][] rows, final Map optionsByName) { - - Assert.notNull(optionsByName); + public void ingest(String cql, final Object[][] rows, QueryOptions options) { ingest(cql, new RowIterator() { @@ -869,16 +664,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe return index < rows.length; } - }, optionsByName); - } - - /* (non-Javadoc) - * @see org.springframework.cassandra.core.CassandraOperations#ingest(java.lang.String, java.lang.Object[][], org.springframework.cassandra.core.QueryOptions) - */ - @Override - public void ingest(String cql, final Object[][] rows, QueryOptions options) { - Assert.notNull(options); - ingest(cql, rows, options.toMap()); + }, options); } /* (non-Javadoc) @@ -886,7 +672,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe */ @Override public void ingest(String cql, final Object[][] rows) { - ingest(cql, rows, Collections. emptyMap()); + ingest(cql, rows, null); } /* (non-Javadoc) @@ -895,7 +681,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe @Override public void truncate(String tableName) throws DataAccessException { Truncate truncate = QueryBuilder.truncate(tableName); - doExecute(truncate.getQueryString(), Collections. emptyMap()); + doExecute(truncate.getQueryString(), null); } /** @@ -904,22 +690,20 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe * @param q * @param optionsByName */ - protected static void addQueryOptions(Query q, Map optionsByName) { + protected static void addQueryOptions(Query q, QueryOptions options) { - if (optionsByName == null) { + if (options == null) { return; } /* * Add Query Options */ - if (optionsByName.get(QueryOptions.QueryOptionMapKeys.CONSISTENCY_LEVEL) != null) { - q.setConsistencyLevel(ConsistencyLevelResolver.resolve((ConsistencyLevel) optionsByName - .get(QueryOptions.QueryOptionMapKeys.CONSISTENCY_LEVEL))); + if (options.getConsistencyLevel() != null) { + q.setConsistencyLevel(ConsistencyLevelResolver.resolve(options.getConsistencyLevel())); } - if (optionsByName.get(QueryOptions.QueryOptionMapKeys.RETRY_POLICY) != null) { - q.setRetryPolicy(RetryPolicyResolver.resolve((RetryPolicy) optionsByName - .get(QueryOptions.QueryOptionMapKeys.RETRY_POLICY))); + if (options.getRetryPolicy() != null) { + q.setRetryPolicy(RetryPolicyResolver.resolve(options.getRetryPolicy())); } } @@ -930,22 +714,20 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe * @param q * @param optionsByName */ - protected static void addPreparedStatementOptions(PreparedStatement s, Map optionsByName) { + protected static void addPreparedStatementOptions(PreparedStatement s, QueryOptions options) { - if (optionsByName == null) { + if (options == null) { return; } /* * Add Query Options */ - if (optionsByName.get(QueryOptions.QueryOptionMapKeys.CONSISTENCY_LEVEL) != null) { - s.setConsistencyLevel(ConsistencyLevelResolver.resolve((ConsistencyLevel) optionsByName - .get(QueryOptions.QueryOptionMapKeys.CONSISTENCY_LEVEL))); + if (options.getConsistencyLevel() != null) { + s.setConsistencyLevel(ConsistencyLevelResolver.resolve(options.getConsistencyLevel())); } - if (optionsByName.get(QueryOptions.QueryOptionMapKeys.RETRY_POLICY) != null) { - s.setRetryPolicy(RetryPolicyResolver.resolve((RetryPolicy) optionsByName - .get(QueryOptions.QueryOptionMapKeys.RETRY_POLICY))); + if (options.getRetryPolicy() != null) { + s.setRetryPolicy(RetryPolicyResolver.resolve(options.getRetryPolicy())); } } @@ -954,10 +736,25 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe * @see org.springframework.cassandra.core.CassandraOperations#query(org.springframework.cassandra.core.PreparedStatementCreator, org.springframework.cassandra.core.PreparedStatementBinder, org.springframework.cassandra.core.ResultSetExtractor, org.springframework.cassandra.core.QueryOptions) */ @Override - public T query(PreparedStatementCreator psc, PreparedStatementBinder psb, ResultSetExtractor rse, - QueryOptions options) throws DataAccessException { - Assert.notNull(options); - return query(psc, psb, rse, options.toMap()); + public T query(PreparedStatementCreator psc, final PreparedStatementBinder psb, final ResultSetExtractor rse, + final QueryOptions options) throws DataAccessException { + + Assert.notNull(rse, "ResultSetExtractor must not be null"); + logger.debug("Executing prepared CQL query"); + + return execute(psc, new PreparedStatementCallback() { + public T doInPreparedStatement(PreparedStatement ps) throws DriverException { + ResultSet rs = null; + BoundStatement bs = null; + if (psb != null) { + bs = psb.bindValues(ps); + } else { + bs = ps.bind(); + } + rs = doExecute(bs, options); + return rse.extractData(rs); + } + }); } /* (non-Javadoc) @@ -966,17 +763,33 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe @Override public T query(PreparedStatementCreator psc, PreparedStatementBinder psb, ResultSetExtractor rse) throws DataAccessException { - return query(psc, psb, rse, Collections. emptyMap()); + return query(psc, psb, rse, null); } /* (non-Javadoc) * @see org.springframework.cassandra.core.CassandraOperations#query(org.springframework.cassandra.core.PreparedStatementCreator, org.springframework.cassandra.core.PreparedStatementBinder, org.springframework.cassandra.core.RowCallbackHandler, org.springframework.cassandra.core.QueryOptions) */ @Override - public void query(PreparedStatementCreator psc, PreparedStatementBinder psb, RowCallbackHandler rch, - QueryOptions options) throws DataAccessException { - Assert.notNull(options); - query(psc, psb, rch, options.toMap()); + public void query(PreparedStatementCreator psc, final PreparedStatementBinder psb, final RowCallbackHandler rch, + final QueryOptions options) throws DataAccessException { + + Assert.notNull(rch, "RowCallbackHandler must not be null"); + logger.debug("Executing prepared CQL query"); + + execute(psc, new PreparedStatementCallback() { + public Object doInPreparedStatement(PreparedStatement ps) throws DriverException { + ResultSet rs = null; + BoundStatement bs = null; + if (psb != null) { + bs = psb.bindValues(ps); + } else { + bs = ps.bind(); + } + rs = doExecute(bs, options); + process(rs, rch); + return null; + } + }); } /* (non-Javadoc) @@ -985,17 +798,32 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe @Override public void query(PreparedStatementCreator psc, PreparedStatementBinder psb, RowCallbackHandler rch) throws DataAccessException { - query(psc, psb, rch, Collections. emptyMap()); + query(psc, psb, rch, null); } /* (non-Javadoc) * @see org.springframework.cassandra.core.CassandraOperations#query(org.springframework.cassandra.core.PreparedStatementCreator, org.springframework.cassandra.core.PreparedStatementBinder, org.springframework.cassandra.core.RowMapper, org.springframework.cassandra.core.QueryOptions) */ @Override - public List query(PreparedStatementCreator psc, PreparedStatementBinder psb, RowMapper rowMapper, - QueryOptions options) throws DataAccessException { - Assert.notNull(options); - return query(psc, psb, rowMapper, options.toMap()); + public List query(PreparedStatementCreator psc, final PreparedStatementBinder psb, + final RowMapper rowMapper, final QueryOptions options) throws DataAccessException { + Assert.notNull(rowMapper, "RowMapper must not be null"); + logger.debug("Executing prepared CQL query"); + + return execute(psc, new PreparedStatementCallback>() { + public List doInPreparedStatement(PreparedStatement ps) throws DriverException { + ResultSet rs = null; + BoundStatement bs = null; + if (psb != null) { + bs = psb.bindValues(ps); + } else { + bs = ps.bind(); + } + rs = doExecute(bs, options); + + return process(rs, rowMapper); + } + }); } /* (non-Javadoc) @@ -1004,7 +832,7 @@ public class CassandraTemplate extends CassandraAccessor implements CassandraOpe @Override public List query(PreparedStatementCreator psc, PreparedStatementBinder psb, RowMapper rowMapper) throws DataAccessException { - return query(psc, psb, rowMapper, Collections. emptyMap()); + return query(psc, psb, rowMapper, null); } } \ No newline at end of file