All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.astyanax.cql.reads.CqlColumnFamilyQueryImpl Maven / Gradle / Ivy

package com.netflix.astyanax.cql.reads;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import com.netflix.astyanax.connectionpool.Host;
import com.netflix.astyanax.cql.CqlKeyspaceImpl.KeyspaceContext;
import com.netflix.astyanax.cql.reads.model.CqlRowSlice;
import com.netflix.astyanax.cql.util.CFQueryContext;
import com.netflix.astyanax.model.ColumnFamily;
import com.netflix.astyanax.model.ConsistencyLevel;
import com.netflix.astyanax.query.AllRowsQuery;
import com.netflix.astyanax.query.ColumnFamilyQuery;
import com.netflix.astyanax.query.CqlQuery;
import com.netflix.astyanax.query.IndexQuery;
import com.netflix.astyanax.query.RowQuery;
import com.netflix.astyanax.query.RowSliceQuery;
import com.netflix.astyanax.retry.RetryPolicy;

/**
 * Base impl for {@link ColumnFamilyQuery} interface. This class is the root for all read operations in Astyanax.
 * From this class, we can branch into either {@link RowQuery} or {@link RowSliceQuery}. 
 *  
 * The current class manages the column family context, retry policy and the consistency level for the read queries underneath.
 *  
 *  Important classes to see are
 *  {@link CqlRowQueryImpl}
 *  {@link CqlRowSliceQueryImpl}
 *  {@link CqlAllRowsQueryImpl}
 *  
 * @author poberai
 *
 * @param 
 * @param 
 */
public class CqlColumnFamilyQueryImpl implements ColumnFamilyQuery {

	private final KeyspaceContext ksContext;
	private final CFQueryContext cfContext;
	
	private boolean useCaching = false;
	
	public CqlColumnFamilyQueryImpl(KeyspaceContext ksCtx, ColumnFamily cf) {
		this.ksContext = ksCtx;
		this.cfContext = new CFQueryContext(cf);
		this.cfContext.setConsistencyLevel(ConsistencyLevel.CL_ONE);
	}
	
	@Override
	public ColumnFamilyQuery setConsistencyLevel(ConsistencyLevel clLevel) {
		this.cfContext.setConsistencyLevel(clLevel);
		return this;
	}

	@Override
	public ColumnFamilyQuery withRetryPolicy(RetryPolicy retry) {
		this.cfContext.setRetryPolicy(retry.duplicate());
		return this;
	}

	@Override
	public ColumnFamilyQuery pinToHost(Host host) {
		throw new UnsupportedOperationException("Operation not supported");
	}

	@Override
	public RowQuery getKey(K rowKey) {
		return new CqlRowQueryImpl(ksContext, cfContext, rowKey, useCaching);
	}

	@Override
	public RowQuery getRow(K rowKey) {
		return new CqlRowQueryImpl(ksContext, cfContext, rowKey, useCaching);
	}

	@Override
	public RowSliceQuery getKeyRange(K startKey, K endKey, String startToken, String endToken, int count) {
		return getRowRange(startKey, endKey, startToken, endToken, count);
	}

	@Override
	public RowSliceQuery getRowRange(K startKey, K endKey, String startToken, String endToken, int count) {
		CqlRowSlice rowSlice = new CqlRowSlice(startKey, endKey, startToken, endToken, count);
		return new CqlRowSliceQueryImpl(ksContext, cfContext, rowSlice, useCaching);
	}

	@Override
	public RowSliceQuery getKeySlice(K... keys) {
		return getRowSlice(keys);
	}

	@Override
	public RowSliceQuery getRowSlice(K... keys) {
		List keyList = Arrays.asList(keys);
		return getRowSlice(keyList);
	}

	@Override
	public RowSliceQuery getKeySlice(Collection keys) {
		return getRowSlice(keys);
	}

	@Override
	public RowSliceQuery getRowSlice(Collection keys) {
		CqlRowSlice rowSlice = new CqlRowSlice(keys);
		return new CqlRowSliceQueryImpl(ksContext, cfContext, rowSlice, useCaching);
	}

	@Override
	public RowSliceQuery getKeySlice(Iterable keys) {
		return getRowSlice(keys);
	}

	@Override
	public RowSliceQuery getRowSlice(Iterable keys) {
		List keyList = new ArrayList();
		for (K key : keys) {
			keyList.add(key);
		}
		return getRowSlice(keyList);
	}

	@Override
	public AllRowsQuery getAllRows() {
		return new CqlAllRowsQueryImpl(ksContext.getKeyspaceContext(), cfContext.getColumnFamily());
	}

	@Override
	public CqlQuery withCql(String cql) {
		return new DirectCqlQueryImpl(ksContext, cfContext, cql);
	}

	@Override
	public IndexQuery searchWithIndex() {
		throw new UnsupportedOperationException("Operation not supported");
	}

	@Override
	public ColumnFamilyQuery withCaching(boolean condition) {
		this.useCaching = condition;
		return this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy