info.archinnov.achilles.iterator.ThriftJoinSliceIterator Maven / Gradle / Ivy
package info.archinnov.achilles.iterator;
import static info.archinnov.achilles.dao.ThriftAbstractDao.DEFAULT_LENGTH;
import static info.archinnov.achilles.iterator.ThriftAbstractSliceIterator.IteratorType.THRIFT_JOIN_SLICE_ITERATOR;
import info.archinnov.achilles.consistency.AchillesConsistencyLevelPolicy;
import info.archinnov.achilles.context.execution.SafeExecutionContext;
import info.archinnov.achilles.dao.ThriftGenericEntityDao;
import info.archinnov.achilles.entity.metadata.PropertyMeta;
import info.archinnov.achilles.entity.operations.ThriftJoinEntityLoader;
import org.apache.cassandra.utils.Pair;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import me.prettyprint.hector.api.beans.Composite;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.query.SliceQuery;
/**
* ThriftJoinSliceIterator
*
* @author DuyHai DOAN
*
* Modification of original version from Hector ColumnSliceIterator
*
*/
public class ThriftJoinSliceIterator extends
ThriftAbstractSliceIterator>
{
private SliceQuery query;
private PropertyMeta propertyMeta;
private ThriftJoinEntityLoader joinHelper = new ThriftJoinEntityLoader();
private ThriftGenericEntityDao joinEntityDao;
public ThriftJoinSliceIterator( //
AchillesConsistencyLevelPolicy policy, //
ThriftGenericEntityDao joinEntityDao, //
String cf, PropertyMeta propertyMeta, //
SliceQuery query, Composite start, //
final Composite finish, boolean reversed)
{
this(policy, joinEntityDao, cf, propertyMeta, query, start, finish, reversed,
DEFAULT_LENGTH);
}
public ThriftJoinSliceIterator(AchillesConsistencyLevelPolicy policy, //
ThriftGenericEntityDao joinEntityDao, //
String cf, PropertyMeta propertyMeta, //
SliceQuery query, Composite start, //
final Composite finish, boolean reversed, int count)
{
this(policy, joinEntityDao, cf, propertyMeta, query, start, new ColumnSliceFinish()
{
@Override
public Composite function()
{
return finish;
}
}, reversed, count);
}
public ThriftJoinSliceIterator(AchillesConsistencyLevelPolicy policy, //
ThriftGenericEntityDao joinEntityDao, //
String cf, PropertyMeta propertyMeta, //
SliceQuery query, Composite start, //
ColumnSliceFinish finish, boolean reversed)
{
this(policy, joinEntityDao, cf, propertyMeta, query, start, finish, reversed,
DEFAULT_LENGTH);
}
public ThriftJoinSliceIterator(AchillesConsistencyLevelPolicy policy, //
ThriftGenericEntityDao joinEntityDao, //
String cf, PropertyMeta propertyMeta, //
SliceQuery query, Composite start, //
ColumnSliceFinish finish, boolean reversed, int count)
{
super(policy, cf, start, finish, reversed, count);
this.joinEntityDao = joinEntityDao;
this.propertyMeta = propertyMeta;
this.query = query;
this.query.setRange(this.start, this.finish.function(), this.reversed, this.count);
}
@Override
protected Iterator> fetchData()
{
Iterator> iter = executeWithInitialConsistencyLevel(new SafeExecutionContext>>()
{
@Override
public Iterator> execute()
{
return query.execute().get().getColumns().iterator();
}
});
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy