
info.archinnov.achilles.helper.ThriftPropertyHelper Maven / Gradle / Ivy
package info.archinnov.achilles.helper;
import static me.prettyprint.hector.api.beans.AbstractComposite.ComponentEquality.*;
import info.archinnov.achilles.annotations.CompoundKey;
import info.archinnov.achilles.entity.metadata.CompoundKeyProperties;
import info.archinnov.achilles.entity.metadata.PropertyMeta;
import info.archinnov.achilles.entity.parsing.CompoundKeyParser;
import info.archinnov.achilles.proxy.MethodInvoker;
import info.archinnov.achilles.serializer.ThriftSerializerTypeInferer;
import info.archinnov.achilles.type.WideMap;
import info.archinnov.achilles.validation.Validator;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import me.prettyprint.hector.api.Serializer;
import me.prettyprint.hector.api.beans.AbstractComposite.ComponentEquality;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* ThriftPropertyHelper
*
* @author DuyHai DOAN
*
*/
public class ThriftPropertyHelper extends PropertyHelper
{
private static final Logger log = LoggerFactory.getLogger(ThriftPropertyHelper.class);
private CompoundKeyParser parser = new CompoundKeyParser();
private MethodInvoker invoker = new MethodInvoker();
public String determineCompatatorTypeAliasForCompositeCF(PropertyMeta, ?> propertyMeta,
boolean forCreation)
{
log
.debug("Determine the Comparator type alias for composite-based column family using propertyMeta of field {} ",
propertyMeta.getPropertyName());
Class> nameClass = propertyMeta.getKeyClass();
List comparatorTypes = new ArrayList();
String comparatorTypesAlias;
if (nameClass.getAnnotation(CompoundKey.class) != null)
{
CompoundKeyProperties multiKeyProperties = parser.parseCompoundKey(nameClass);
for (Class> clazz : multiKeyProperties.getComponentClasses())
{
Serializer> srz = ThriftSerializerTypeInferer.getSerializer(clazz);
if (forCreation)
{
comparatorTypes.add(srz.getComparatorType().getTypeName());
}
else
{
comparatorTypes.add("org.apache.cassandra.db.marshal."
+ srz.getComparatorType().getTypeName());
}
}
if (forCreation)
{
comparatorTypesAlias = "(" + StringUtils.join(comparatorTypes, ',') + ")";
}
else
{
comparatorTypesAlias = "CompositeType(" + StringUtils.join(comparatorTypes, ',')
+ ")";
}
}
else
{
String typeAlias = ThriftSerializerTypeInferer
.getSerializer(nameClass)
.getComparatorType()
.getTypeName();
if (forCreation)
{
comparatorTypesAlias = "(" + typeAlias + ")";
}
else
{
comparatorTypesAlias = "CompositeType(org.apache.cassandra.db.marshal." + typeAlias
+ ")";
}
}
log.trace("Comparator type alias : {}", comparatorTypesAlias);
return comparatorTypesAlias;
}
public void checkBounds(PropertyMeta, ?> propertyMeta, K start, K end,
WideMap.OrderingMode ordering,
boolean isCompoundKey)
{
log.trace("Check composites {} / {} with respect to ordering mode {}", start, end,
ordering.name());
if (start != null && end != null)
{
if (propertyMeta.isSingleKey())
{
@SuppressWarnings("unchecked")
Comparable startComp = (Comparable) start;
if (WideMap.OrderingMode.DESCENDING.equals(ordering))
{
Validator
.validateTrue(startComp.compareTo(end) >= 0,
"For reverse range query, start value should be greater or equal to end value");
}
else
{
Validator.validateTrue(startComp.compareTo(end) <= 0,
"For range query, start value should be lesser or equal to end value");
}
}
else
{
List componentGetters = propertyMeta
.getComponentGetters();
String propertyName = propertyMeta.getPropertyName();
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy