Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.netflix.astyanax.cql.reads;
import static com.datastax.driver.core.querybuilder.QueryBuilder.gte;
import static com.datastax.driver.core.querybuilder.QueryBuilder.in;
import static com.datastax.driver.core.querybuilder.QueryBuilder.lte;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicReference;
import com.datastax.driver.core.BoundStatement;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.RegularStatement;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;
import com.datastax.driver.core.querybuilder.Select.Where;
import com.netflix.astyanax.cql.reads.model.CqlRowSlice.RowRange;
import com.netflix.astyanax.cql.schema.CqlColumnFamilyDefinitionImpl;
import com.netflix.astyanax.ddl.ColumnDefinition;
import com.netflix.astyanax.query.RowSliceQuery;
/**
* Just like {@link FlatTableRowQueryGen} this class encapsulates the functionality for row query generation for
* Astyanax {@link RowSliceQuery}(s).
*
* The class uses a collection of query generators to handle all sort of RowSliceQuery permutations like
* 1. Selecting all columns for a row collection
* 2. Selecting a column set for a row collection
* 3. Selecting all columns for a row range
* 4. Selecting a column set for a row range
*
* Note that this class supports query generation for flat tables only.
* For tables with clustering keys see {@link CFRowKeysQueryGen} and {@link CFRowRangeQueryGen}.
*
* Also, just like the other query generators, use this with caution when using caching of {@link PreparedStatement}
* See {@link FlatTableRowQueryGen} for a detailed explanation of why PreparedStatement caching will not work for queries
* that do not have the same signatures.
*
* @author poberai
*
*/
public class FlatTableRowSliceQueryGen {
protected AtomicReference sessionRef = new AtomicReference(null);
protected final String keyspace;
protected final CqlColumnFamilyDefinitionImpl cfDef;
protected final String partitionKeyCol;
protected final String[] allPrimayKeyCols;
protected final List regularCols;
protected static final String BIND_MARKER = "?";
public FlatTableRowSliceQueryGen(Session session, String keyspaceName, CqlColumnFamilyDefinitionImpl cfDefinition) {
this.keyspace = keyspaceName;
this.cfDef = cfDefinition;
this.sessionRef.set(session);
partitionKeyCol = cfDef.getPartitionKeyColumnDefinition().getName();
allPrimayKeyCols = cfDef.getAllPkColNames();
regularCols = cfDef.getRegularColumnDefinitionList();
}
/**
*
* SOME BASIC UTILITY METHODS USED BY ALL THE ROW SLICE QUERY GENERATORS
*/
protected Select selectAllColumnsFromKeyspaceAndCF() {
Select.Selection select = QueryBuilder.select();
for (int i=0; i> SelectAllColumnsForRowKeys = new QueryGenCache>(sessionRef) {
@Override
public Callable getQueryGen(final CqlRowSliceQueryImpl, ?> rowSliceQuery) {
return new Callable() {
@Override
public RegularStatement call() throws Exception {
Select select = selectAllColumnsFromKeyspaceAndCF();
return select.where(in(partitionKeyCol, rowSliceQuery.getRowSlice().getKeys().toArray()));
}
};
}
@Override
public BoundStatement bindValues(PreparedStatement pStatement, CqlRowSliceQueryImpl, ?> rowSliceQuery) {
return pStatement.bind(rowSliceQuery.getRowSlice().getKeys().toArray());
}
};
private QueryGenCache> SelectColumnSetForRowKeys = new QueryGenCache>(sessionRef) {
@Override
public Callable getQueryGen(final CqlRowSliceQueryImpl, ?> rowSliceQuery) {
return new Callable() {
@Override
public RegularStatement call() throws Exception {
Select.Selection select = QueryBuilder.select();
select.column(partitionKeyCol);
for (Object col : rowSliceQuery.getColumnSlice().getColumns()) {
String columnName = (String)col;
select.column(columnName).ttl(columnName).writeTime(columnName);
}
return select.from(keyspace, cfDef.getName()).where(in(partitionKeyCol, rowSliceQuery.getRowSlice().getKeys().toArray()));
}
};
}
@Override
public BoundStatement bindValues(PreparedStatement pStatement, CqlRowSliceQueryImpl, ?> rowSliceQuery) {
List