本文整理汇总了Java中org.apache.cassandra.db.marshal.SetType类的典型用法代码示例。如果您正苦于以下问题:Java SetType类的具体用法?Java SetType怎么用?Java SetType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SetType类属于org.apache.cassandra.db.marshal包,在下文中一共展示了SetType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateAssignableTo
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException
{
if (!(receiver.type instanceof SetType))
{
// We've parsed empty maps as a set literal to break the ambiguity so
// handle that case now
if ((receiver.type instanceof MapType) && elements.isEmpty())
return;
throw new InvalidRequestException(String.format("Invalid set literal for %s of type %s", receiver.name, receiver.type.asCQL3Type()));
}
ColumnSpecification valueSpec = Sets.valueSpecOf(receiver);
for (Term.Raw rt : elements)
{
if (!rt.isAssignableTo(keyspace, valueSpec))
throw new InvalidRequestException(String.format("Invalid set literal for %s: value %s is not of type %s", receiver.name, rt, valueSpec.type.asCQL3Type()));
}
}
示例2: fromSerialized
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
public static Value fromSerialized(ByteBuffer value, SetType type, int version) throws InvalidRequestException
{
try
{
// Collections have this small hack that validate cannot be called on a serialized object,
// but compose does the validation (so we're fine).
Set<?> s = (Set<?>)type.getSerializer().deserializeForNativeProtocol(value, version);
SortedSet<ByteBuffer> elements = new TreeSet<ByteBuffer>(type.getElementsType());
for (Object element : s)
elements.add(type.getElementsType().decompose(element));
return new Value(elements);
}
catch (MarshalException e)
{
throw new InvalidRequestException(e.getMessage());
}
}
示例3: validateAssignableTo
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
private void validateAssignableTo(ColumnSpecification receiver) throws InvalidRequestException
{
if (!(receiver.type instanceof SetType))
{
// We've parsed empty maps as a set literal to break the ambiguity so
// handle that case now
if (receiver.type instanceof MapType && elements.isEmpty())
return;
throw new InvalidRequestException(String.format("Invalid set literal for %s of type %s", receiver, receiver.type.asCQL3Type()));
}
ColumnSpecification valueSpec = Sets.valueSpecOf(receiver);
for (Term.Raw rt : elements)
{
if (!rt.isAssignableTo(valueSpec))
throw new InvalidRequestException(String.format("Invalid set literal for %s: value %s is not of type %s", receiver, rt, valueSpec.type.asCQL3Type()));
}
}
示例4: fromSerialized
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
public static Value fromSerialized(ByteBuffer value, SetType type) throws InvalidRequestException
{
try
{
// Collections have this small hack that validate cannot be called on a serialized object,
// but compose does the validation (so we're fine).
Set<?> s = (Set<?>)type.compose(value);
Set<ByteBuffer> elements = new LinkedHashSet<ByteBuffer>(s.size());
for (Object element : s)
elements.add(type.elements.decompose(element));
return new Value(elements);
}
catch (MarshalException e)
{
throw new InvalidRequestException(e.getMessage());
}
}
示例5: validateAssignableTo
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException
{
if (!(receiver.type instanceof SetType))
{
// We've parsed empty maps as a set literal to break the ambiguity so
// handle that case now
if (receiver.type instanceof MapType && elements.isEmpty())
return;
throw new InvalidRequestException(String.format("Invalid set literal for %s of type %s", receiver.name, receiver.type.asCQL3Type()));
}
ColumnSpecification valueSpec = Sets.valueSpecOf(receiver);
for (Term.Raw rt : elements)
{
if (!rt.testAssignment(keyspace, valueSpec).isAssignable())
throw new InvalidRequestException(String.format("Invalid set literal for %s: value %s is not of type %s", receiver.name, rt, valueSpec.type.asCQL3Type()));
}
}
示例6: testAssignment
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
public AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver)
{
if (!(receiver.type instanceof SetType))
{
// We've parsed empty maps as a set literal to break the ambiguity so handle that case now
if (receiver.type instanceof MapType && elements.isEmpty())
return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE;
return AssignmentTestable.TestResult.NOT_ASSIGNABLE;
}
// If there is no elements, we can't say it's an exact match (an empty set if fundamentally polymorphic).
if (elements.isEmpty())
return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE;
ColumnSpecification valueSpec = Sets.valueSpecOf(receiver);
return AssignmentTestable.TestResult.testAll(keyspace, valueSpec, elements);
}
示例7: fromSerialized
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
public static Value fromSerialized(ByteBuffer value, SetType type, int version) throws InvalidRequestException
{
try
{
// Collections have this small hack that validate cannot be called on a serialized object,
// but compose does the validation (so we're fine).
Set<?> s = (Set<?>)type.getSerializer().deserializeForNativeProtocol(value, version);
Set<ByteBuffer> elements = new LinkedHashSet<ByteBuffer>(s.size());
for (Object element : s)
elements.add(type.elements.decompose(element));
return new Value(elements);
}
catch (MarshalException e)
{
throw new InvalidRequestException(e.getMessage());
}
}
示例8: testDataTypeSetInstantiation
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
public void testDataTypeSetInstantiation() {
DataType type = DataType.set(DataType.text());
CellValidator cv = cellValidator(type);
assertNotNull(cv);
assertEquals(cv.getValidatorClassName(), SetType.class.getName());
assertNotNull(cv.getValidatorTypes());
assertEquals(cv.validatorKind(), Kind.SET);
assertEquals(cv.getValidatorTypes().size(), 1);
assertEquals(cv.getValidatorTypes().iterator().next(), "text");
assertEquals(DataType.Name.SET, cv.getCqlTypeName());
try {
Collection<String> types = cv.getValidatorTypes();
types.add("test");
fail("Validator types collection must be inmutable");
} catch (Exception ex) {
// ok
}
// assertNotNull(cv.getAbstractType());
// assertEquals(cv.getAbstractType(), SetType.getInstance(UTF8Type.instance));
}
示例9: testValidatorClassToKind
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
public void testValidatorClassToKind() {
assertEquals(Kind.validatorClassToKind(null), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(TimeUUIDType.class), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(UTF8Type.class), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(Int32Type.class), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(BooleanType.class), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(TimestampType.class), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(DecimalType.class), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(LongType.class), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(DoubleType.class), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(FloatType.class), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(InetAddressType.class), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(IntegerType.class), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(UUIDType.class), Kind.NOT_A_COLLECTION);
assertEquals(Kind.validatorClassToKind(SetType.class), Kind.SET);
assertEquals(Kind.validatorClassToKind(ListType.class), Kind.LIST);
assertEquals(Kind.validatorClassToKind(MapType.class), Kind.MAP);
}
示例10: fromSerialized
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
public static Value fromSerialized(ByteBuffer value, SetType type) throws InvalidRequestException
{
try
{
// Collections have this small hack that validate cannot be called on a serialized object,
// but compose does the validation (so we're fine).
Set<?> s = type.compose(value);
Set<ByteBuffer> elements = new LinkedHashSet<ByteBuffer>(s.size());
for (Object element : s)
elements.add(type.elements.decompose(element));
return new Value(elements);
}
catch (MarshalException e)
{
throw new InvalidRequestException(e.getMessage());
}
}
示例11: supports
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
/**
* Returns {@code true} if the specified Cassandra type/marshaller is supported, {@code false} otherwise.
*
* @param type A Cassandra type/marshaller.
* @return {@code true} if the specified Cassandra type/marshaller is supported, {@code false} otherwise.
*/
public boolean supports(final AbstractType<?> type) {
AbstractType<?> checkedType = type;
if (type.isCollection()) {
if (type instanceof MapType<?, ?>) {
checkedType = ((MapType<?, ?>) type).getValuesType();
} else if (type instanceof ListType<?>) {
checkedType = ((ListType<?>) type).getElementsType();
} else if (type instanceof SetType) {
checkedType = ((SetType<?>) type).getElementsType();
}
}
if (type instanceof ReversedType) {
ReversedType reversedType = (ReversedType) type;
checkedType = reversedType.baseType;
}
for (AbstractType<?> n : supportedTypes) {
if (checkedType.getClass() == n.getClass()) {
return true;
}
}
return false;
}
示例12: validateAssignableTo
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException
{
if (!(receiver.type instanceof SetType))
{
// We've parsed empty maps as a set literal to break the ambiguity so
// handle that case now
if (receiver.type instanceof MapType && elements.isEmpty())
return;
throw new InvalidRequestException(String.format("Invalid set literal for %s of type %s", receiver, receiver.type.asCQL3Type()));
}
ColumnSpecification valueSpec = Sets.valueSpecOf(receiver);
for (Term.Raw rt : elements)
{
if (!rt.isAssignableTo(keyspace, valueSpec))
throw new InvalidRequestException(String.format("Invalid set literal for %s: value %s is not of type %s", receiver, rt, valueSpec.type.asCQL3Type()));
}
}
示例13: prepare
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
public Term prepare(String keyspace, ColumnSpecification receiver) throws InvalidRequestException
{
validateAssignableTo(keyspace, receiver);
// We've parsed empty maps as a set literal to break the ambiguity so
// handle that case now
if (receiver.type instanceof MapType && elements.isEmpty())
return new Maps.Value(Collections.<ByteBuffer, ByteBuffer>emptyMap());
ColumnSpecification valueSpec = Sets.valueSpecOf(receiver);
Set<Term> values = new HashSet<Term>(elements.size());
boolean allTerminal = true;
for (Term.Raw rt : elements)
{
Term t = rt.prepare(keyspace, valueSpec);
if (t.containsBindMarker())
throw new InvalidRequestException(String.format("Invalid set literal for %s: bind variables are not supported inside collection literals", receiver.name));
if (t instanceof Term.NonTerminal)
allTerminal = false;
values.add(t);
}
DelayedValue value = new DelayedValue(((SetType)receiver.type).getElementsType(), values);
return allTerminal ? value.bind(QueryOptions.DEFAULT) : value;
}
示例14: equals
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
public boolean equals(SetType st, Value v)
{
if (elements.size() != v.elements.size())
return false;
Iterator<ByteBuffer> thisIter = elements.iterator();
Iterator<ByteBuffer> thatIter = v.elements.iterator();
AbstractType elementsType = st.getElementsType();
while (thisIter.hasNext())
if (elementsType.compare(thisIter.next(), thatIter.next()) != 0)
return false;
return true;
}
示例15: makeTerminal
import org.apache.cassandra.db.marshal.SetType; //导入依赖的package包/类
private static Term.Terminal makeTerminal(Function fun, ByteBuffer result, int version) throws InvalidRequestException
{
if (!(fun.returnType() instanceof CollectionType))
return new Constants.Value(result);
switch (((CollectionType)fun.returnType()).kind)
{
case LIST: return Lists.Value.fromSerialized(result, (ListType)fun.returnType(), version);
case SET: return Sets.Value.fromSerialized(result, (SetType)fun.returnType(), version);
case MAP: return Maps.Value.fromSerialized(result, (MapType)fun.returnType(), version);
}
throw new AssertionError();
}