info.archinnov.achilles.iterator.ThriftSliceIterator Maven / Gradle / Ivy
package info.archinnov.achilles.iterator;
/**
* ThriftSliceIterator
*
* @author DuyHai DOAN
*
* Modification of original version from Hector ColumnSliceIterator
*
*/
import static info.archinnov.achilles.dao.ThriftAbstractDao.DEFAULT_LENGTH;
import static info.archinnov.achilles.iterator.ThriftAbstractSliceIterator.IteratorType.THRIFT_SLICE_ITERATOR;
import info.archinnov.achilles.consistency.AchillesConsistencyLevelPolicy;
import info.archinnov.achilles.context.execution.SafeExecutionContext;
import java.util.Iterator;
import me.prettyprint.hector.api.beans.Composite;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.query.SliceQuery;
public class ThriftSliceIterator extends ThriftAbstractSliceIterator>
{
private SliceQuery query;
public ThriftSliceIterator(AchillesConsistencyLevelPolicy policy, String cf,
SliceQuery query, Composite start, final Composite finish,
boolean reversed)
{
this(policy, cf, query, start, finish, reversed, DEFAULT_LENGTH);
}
public ThriftSliceIterator(AchillesConsistencyLevelPolicy policy, String cf,
SliceQuery query, Composite start, final Composite finish,
boolean reversed, int count)
{
this(policy, cf, query, start, new ColumnSliceFinish()
{
@Override
public Composite function()
{
return finish;
}
}, reversed, count);
}
public ThriftSliceIterator(AchillesConsistencyLevelPolicy policy, String cf,
SliceQuery query, Composite start, ColumnSliceFinish finish,
boolean reversed)
{
this(policy, cf, query, start, finish, reversed, DEFAULT_LENGTH);
}
public ThriftSliceIterator(AchillesConsistencyLevelPolicy policy, String cf,
SliceQuery query, Composite start, ColumnSliceFinish finish,
boolean reversed, int count)
{
super(policy, cf, start, finish, reversed, count);
this.query = query;
this.query.setRange(this.start, this.finish.function(), this.reversed, this.count);
}
@Override
protected Iterator> fetchData()
{
return executeWithInitialConsistencyLevel(new SafeExecutionContext>>()
{
@Override
public Iterator> execute()
{
return query.execute().get().getColumns().iterator();
}
});
}
@Override
protected void changeQueryRange()
{
query.setRange(start, finish.function(), reversed, count);
}
@Override
protected void resetStartColumn(HColumn column)
{
start = column.getName();
}
@Override
public IteratorType type()
{
return THRIFT_SLICE_ITERATOR;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy