info.archinnov.achilles.entity.operations.ThriftSliceQueryExecutor Maven / Gradle / Ivy
package info.archinnov.achilles.entity.operations;
import info.archinnov.achilles.clustered.ClusteredEntityFactory;
import info.archinnov.achilles.consistency.AchillesConsistencyLevelPolicy;
import info.archinnov.achilles.context.ConfigurationContext;
import info.archinnov.achilles.context.ThriftPersistenceContext;
import info.archinnov.achilles.context.ThriftPersistenceContextFactory;
import info.archinnov.achilles.entity.metadata.EntityMeta;
import info.archinnov.achilles.entity.metadata.PropertyMeta;
import info.archinnov.achilles.entity.operations.impl.ThriftQueryExecutorImpl;
import info.archinnov.achilles.exception.AchillesException;
import info.archinnov.achilles.iterator.ThriftClusteredEntityIterator;
import info.archinnov.achilles.iterator.ThriftCounterClusteredEntityIterator;
import info.archinnov.achilles.iterator.ThriftCounterSliceIterator;
import info.archinnov.achilles.iterator.ThriftJoinSliceIterator;
import info.archinnov.achilles.iterator.ThriftSliceIterator;
import info.archinnov.achilles.query.SliceQuery;
import info.archinnov.achilles.type.ConsistencyLevel;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import me.prettyprint.hector.api.beans.Composite;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.beans.HCounterColumn;
import com.google.common.collect.Lists;
public class ThriftSliceQueryExecutor extends SliceQueryExecutor
{
private AchillesConsistencyLevelPolicy consistencyPolicy;
private ClusteredEntityFactory factory = new ClusteredEntityFactory();
private ThriftQueryExecutorImpl executorImpl = new ThriftQueryExecutorImpl();
private ThriftPersistenceContextFactory contextFactory;
public ThriftSliceQueryExecutor(ThriftPersistenceContextFactory contextFactory, ConfigurationContext configContext)
{
super(new ThriftEntityProxifier());
this.contextFactory = contextFactory;
this.consistencyPolicy = configContext.getConsistencyPolicy();
defaultReadLevel = consistencyPolicy.getDefaultGlobalReadConsistencyLevel();
}
@Override
public List get(final SliceQuery sliceQuery)
{
ThriftPersistenceContext context = buildContextForQuery(sliceQuery);
EntityMeta meta = sliceQuery.getMeta();
PropertyMeta, ?> pm = meta.getFirstMeta();
List clusteredEntities = null;
switch (pm.type())
{
case JOIN_SIMPLE:
case SIMPLE:
List> hColumns = executorImpl
.findColumns(sliceQuery, context);
clusteredEntities = factory.buildClusteredEntities(sliceQuery.getEntityClass(), context,
hColumns);
break;
case COUNTER:
List> hCounterColumns = executorImpl.findCounterColumns(
sliceQuery, context);
clusteredEntities = factory.buildCounterClusteredEntities(sliceQuery.getEntityClass(),
context, hCounterColumns);
break;
default:
throw new AchillesException("Cannot get entities for clustered value of type '"
+ pm.type().name() + "' and clustered entity class '"
+ sliceQuery.getEntityClass().getCanonicalName() + "'");
}
return Lists.transform(clusteredEntities, getProxyTransformer(sliceQuery, Arrays.asList(pm.getGetter())));
}
@Override
public Iterator iterator(final SliceQuery sliceQuery)
{
ThriftPersistenceContext context = buildContextForQuery(sliceQuery);
EntityMeta meta = sliceQuery.getMeta();
PropertyMeta, ?> pm = meta.getFirstMeta();
Class entityClass = sliceQuery.getEntityClass();
switch (pm.type())
{
case SIMPLE:
ThriftSliceIterator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy