com.netflix.astyanax.cql.reads.DirectCqlQueryImpl Maven / Gradle / Ivy
package com.netflix.astyanax.cql.reads;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.apache.commons.lang.NotImplementedException;
import com.datastax.driver.core.BoundStatement;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.SimpleStatement;
import com.datastax.driver.core.Statement;
import com.google.common.util.concurrent.ListenableFuture;
import com.netflix.astyanax.CassandraOperationType;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.connectionpool.OperationResult;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import com.netflix.astyanax.cql.CqlAbstractExecutionImpl;
import com.netflix.astyanax.cql.CqlKeyspaceImpl.KeyspaceContext;
import com.netflix.astyanax.cql.reads.model.DirectCqlResult;
import com.netflix.astyanax.cql.util.CFQueryContext;
import com.netflix.astyanax.model.ColumnFamily;
import com.netflix.astyanax.model.CqlResult;
import com.netflix.astyanax.query.CqlQuery;
import com.netflix.astyanax.query.PreparedCqlQuery;
/**
*
* Impl for {@link CqlQuery} that allows users to directly send CQL3 over java driver
* @author poberai
*
* @param
* @param
*/
public class DirectCqlQueryImpl implements CqlQuery {
private final KeyspaceContext ksContext;
private final CFQueryContext cfContext;
private final String basicCqlQuery;
public DirectCqlQueryImpl(KeyspaceContext ksCtx, CFQueryContext cfCtx, String basicCqlQuery) {
this.ksContext = ksCtx;
this.cfContext = cfCtx;
this.basicCqlQuery = basicCqlQuery;
}
@Override
public OperationResult> execute() throws ConnectionException {
return new InternalExecutionImpl(new SimpleStatement(basicCqlQuery)).execute();
}
@Override
public ListenableFuture>> executeAsync() throws ConnectionException {
return new InternalExecutionImpl(new SimpleStatement(basicCqlQuery)).executeAsync();
}
@Override
public CqlQuery useCompression() {
throw new UnsupportedOperationException("Operation not supported");
}
protected class InternalPreparedStatement implements PreparedCqlQuery {
private final PreparedStatement pStatement;
protected InternalPreparedStatement() {
pStatement = ksContext.getSession().prepare(basicCqlQuery);
}
@Override
public PreparedCqlQuery withByteBufferValue(V value, Serializer serializer) {
return new InternalBoundStatement(pStatement).withByteBufferValue(value, serializer);
}
@Override
public PreparedCqlQuery withValue(ByteBuffer value) {
return new InternalBoundStatement(pStatement).withValue(value);
}
@Override
public PreparedCqlQuery withValues(List values) {
return new InternalBoundStatement(pStatement).withValues(values);
}
@Override
public PreparedCqlQuery withStringValue(String value) {
return new InternalBoundStatement(pStatement).withStringValue(value);
}
@Override
public PreparedCqlQuery withIntegerValue(Integer value) {
return new InternalBoundStatement(pStatement).withIntegerValue(value);
}
@Override
public PreparedCqlQuery withBooleanValue(Boolean value) {
return new InternalBoundStatement(pStatement).withBooleanValue(value);
}
@Override
public PreparedCqlQuery withDoubleValue(Double value) {
return new InternalBoundStatement(pStatement).withDoubleValue(value);
}
@Override
public PreparedCqlQuery withLongValue(Long value) {
return new InternalBoundStatement(pStatement).withLongValue(value);
}
@Override
public PreparedCqlQuery withFloatValue(Float value) {
return new InternalBoundStatement(pStatement).withFloatValue(value);
}
@Override
public PreparedCqlQuery withShortValue(Short value) {
return new InternalBoundStatement(pStatement).withShortValue(value);
}
@Override
public PreparedCqlQuery withUUIDValue(UUID value) {
return new InternalBoundStatement(pStatement).withUUIDValue(value);
}
@Override
public OperationResult> execute() throws ConnectionException {
throw new NotImplementedException();
}
@Override
public ListenableFuture>> executeAsync() throws ConnectionException {
throw new NotImplementedException();
}
}
protected class InternalBoundStatement implements PreparedCqlQuery {
final List