public class CFRowRangeQueryGen extends CFRowSliceQueryGen
CFRowKeysQueryGen for that implementation. The current class is meant for row range queries only.
Each of the query generators uses the QueryGenCache so that it can cache the PreparedStatement as well
for future use by queries with the same signatures.
But one must use this with care, since the subsequent query must have the exact signature, else binding values with
the previously constructed prepared statement will break.
Here is a simple example of a bad query that is not cacheable.
Say that we want a simple query with a column range in it.
ks.prepareQuery(myCF)
.getRow("1")
.withColumnSlice("colStart")
.execute();
In most cases this query lends itself to a CQL3 representation as follows
SELECT * FROM ks.mfCF WHERE KEY = ? AND COLUMN1 > ?;
Now say that we want to perform a successive query (with caching turned ON), but add to the column range query
ks.prepareQuery(myCF)
.getRow("1")
.withColumnSlice("colStart", "colEnd")
.execute();
NOTE THE USE OF BOTH colStart AND colEnd <----- THIS IS A DIFFERENT QUERY SIGNATURE
AND THE CQL QUERY WILL PROBABLY LOOK LIKE
SELECT * FROM ks.mfCF WHERE KEY = ? AND COLUMN1 > ? AND COLUMN1 < ?; <----- NOTE THE EXTRA BIND MARKER AT THE END FOR THE colEnd
If we re-use the previously cached prepared statement, then it will not work for the new query signature. The way out of this is to NOT
use caching with different query signatures.allPrimayKeyCols, BIND_MARKER, cfDef, clusteringKeyCols, isCompositeColumn, keyspace, partitionKeyCol, regularCols, sessionRef| Constructor and Description |
|---|
CFRowRangeQueryGen(com.datastax.driver.core.Session session,
java.lang.String keyspaceName,
CqlColumnFamilyDefinitionImpl cfDefinition)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
com.datastax.driver.core.BoundStatement |
getQueryStatement(CqlRowSliceQueryImpl<?,?> rowSliceQuery,
boolean useCaching)
Main method used to generate the query for the specified row slice query.
|
addWhereClauseForColumnRange, addWhereClauseForCompositeColumnRange, bindMarkerArray, bindWhereClauseForColumnRange, bindWhereClauseForCompositeColumnRange, selectAllColumnsFromKeyspaceAndCFpublic CFRowRangeQueryGen(com.datastax.driver.core.Session session,
java.lang.String keyspaceName,
CqlColumnFamilyDefinitionImpl cfDefinition)
session - keyspaceName - cfDefinition - public com.datastax.driver.core.BoundStatement getQueryStatement(CqlRowSliceQueryImpl<?,?> rowSliceQuery, boolean useCaching)
rowSliceQuery: - The Astaynax query for which we need to generate a java driver queryuseCaching: - boolean condition indicating whether we should use a previously cached prepared stmt or not.
If false, then the cache is ignored and we generate the prepared stmt for this query
If true, then the cached prepared stmt is used. If the cache has not been inited,
then the prepared stmt is constructed for this query and subsequently cached