本文整理汇总了Java中org.apache.cassandra.db.marshal.UserType类的典型用法代码示例。如果您正苦于以下问题:Java UserType类的具体用法?Java UserType怎么用?Java UserType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserType类属于org.apache.cassandra.db.marshal包,在下文中一共展示了UserType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateCell
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
public void validateCell(Cell cell)
{
if (cell.isTombstone())
{
if (cell.value().hasRemaining())
throw new MarshalException("A tombstone should not have a value");
if (cell.path() != null)
validateCellPath(cell.path());
}
else if(type.isUDT())
{
// To validate a non-frozen UDT field, both the path and the value
// are needed, the path being an index into an array of value types.
((UserType)type).validateCell(cell);
}
else
{
type.validateCellValue(cell.value());
if (cell.path() != null)
validateCellPath(cell.path());
}
}
示例2: validateAssignableTo
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException
{
if (!(receiver.type instanceof UserType))
throw new InvalidRequestException(String.format("Invalid user type literal for %s of type %s", receiver, receiver.type.asCQL3Type()));
UserType ut = (UserType)receiver.type;
for (int i = 0; i < ut.size(); i++)
{
ColumnIdentifier field = new ColumnIdentifier(ut.fieldName(i), UTF8Type.instance);
Term.Raw value = entries.get(field);
if (value == null)
continue;
ColumnSpecification fieldSpec = fieldSpecOf(receiver, i);
if (!value.isAssignableTo(keyspace, fieldSpec))
throw new InvalidRequestException(String.format("Invalid user type literal for %s: field %s is not of type %s", receiver, field, fieldSpec.type.asCQL3Type()));
}
}
示例3: newSelectorFactory
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
public Selector.Factory newSelectorFactory(CFMetaData cfm,
List<ColumnDefinition> defs) throws InvalidRequestException
{
Selector.Factory factory = selected.newSelectorFactory(cfm, defs);
AbstractType<?> type = factory.newInstance().getType();
if (!(type instanceof UserType))
throw new InvalidRequestException(
String.format("Invalid field selection: %s of type %s is not a user type",
selected,
type.asCQL3Type()));
UserType ut = (UserType) type;
for (int i = 0; i < ut.size(); i++)
{
if (!ut.fieldName(i).equals(field.bytes))
continue;
return FieldSelector.newFactory(ut, i, factory);
}
throw new InvalidRequestException(String.format("%s of type %s has no field %s",
selected,
type.asCQL3Type(),
field));
}
示例4: validateAssignableTo
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException
{
if (!(receiver.type instanceof UserType))
throw new InvalidRequestException(String.format("Invalid user type literal for %s of type %s", receiver, receiver.type.asCQL3Type()));
UserType ut = (UserType)receiver.type;
for (int i = 0; i < ut.size(); i++)
{
ColumnIdentifier field = new ColumnIdentifier(ut.fieldName(i), UTF8Type.instance);
Term.Raw value = entries.get(field);
if (value == null)
continue;
ColumnSpecification fieldSpec = fieldSpecOf(receiver, i);
if (!value.testAssignment(keyspace, fieldSpec).isAssignable())
throw new InvalidRequestException(String.format("Invalid user type literal for %s: field %s is not of type %s", receiver, field, fieldSpec.type.asCQL3Type()));
}
}
示例5: validateAssignableTo
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException
{
if (!(receiver.type instanceof UserType))
throw new InvalidRequestException(String.format("Invalid user type literal for %s of type %s", receiver, receiver.type.asCQL3Type()));
UserType ut = (UserType)receiver.type;
for (int i = 0; i < ut.types.size(); i++)
{
ColumnIdentifier field = new ColumnIdentifier(ut.columnNames.get(i), UTF8Type.instance);
Term.Raw value = entries.get(field);
if (value == null)
throw new InvalidRequestException(String.format("Invalid user type literal for %s: missing field %s", receiver, field));
ColumnSpecification fieldSpec = fieldSpecOf(receiver, i);
if (!value.isAssignableTo(keyspace, fieldSpec))
throw new InvalidRequestException(String.format("Invalid user type literal for %s: field %s is not of type %s", receiver, field, fieldSpec.type.asCQL3Type()));
}
}
示例6: with
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
/**
* Create a Types instance with the provided type added
*/
public Types with(UserType type)
{
if (get(type.name).isPresent())
throw new IllegalStateException(format("Type %s already exists", type.name));
return builder().add(this).add(type).build();
}
示例7: without
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
/**
* Creates a Types instance with the type with the provided name removed
*/
public Types without(ByteBuffer name)
{
UserType type =
get(name).orElseThrow(() -> new IllegalStateException(format("Type %s doesn't exists", name)));
return builder().add(filter(this, t -> t != type)).build();
}
示例8: equals
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
@Override
public boolean equals(Object o)
{
if (this == o)
return true;
if (!(o instanceof Types))
return false;
Types other = (Types) o;
if (types.size() != other.types.size())
return false;
Iterator<Map.Entry<ByteBuffer, UserType>> thisIter = this.types.entrySet().iterator();
Iterator<Map.Entry<ByteBuffer, UserType>> otherIter = other.types.entrySet().iterator();
while (thisIter.hasNext())
{
Map.Entry<ByteBuffer, UserType> thisNext = thisIter.next();
Map.Entry<ByteBuffer, UserType> otherNext = otherIter.next();
if (!thisNext.getKey().equals(otherNext.getKey()))
return false;
if (!thisNext.getValue().equals(otherNext.getValue(), true)) // ignore freezing
return false;
}
return true;
}
示例9: prepare
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
UserType prepare(String keyspace, Types types)
{
List<FieldIdentifier> preparedFieldNames =
fieldNames.stream()
.map(t -> FieldIdentifier.forInternalString(t))
.collect(toList());
List<AbstractType<?>> preparedFieldTypes =
fieldTypes.stream()
.map(t -> t.prepareInternal(keyspace, types).getType())
.collect(toList());
return new UserType(keyspace, bytes(name), preparedFieldNames, preparedFieldTypes, true);
}
示例10: parse
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
public static AbstractType<?> parse(String keyspace, String unparsed, Types userTypes)
{
String lowercased = unparsed.toLowerCase();
// fast path for the common case of a primitive type
if (PRIMITIVE_TYPES.contains(lowercased))
return CQL3Type.Native.valueOf(unparsed.toUpperCase()).getType();
// special-case top-level UDTs
UserType udt = userTypes.getNullable(bytes(lowercased));
if (udt != null)
return udt;
return parseRaw(unparsed).prepareInternal(keyspace, userTypes).getType();
}
示例11: getTypes
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
private static Types getTypes() {
if (knownTypes.isEmpty()) {
return Types.none();
} else {
return Types.of(knownTypes.values().toArray(new UserType[0]));
}
}
示例12: fieldSpecOf
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
public static ColumnSpecification fieldSpecOf(ColumnSpecification column, int field)
{
UserType ut = (UserType)column.type;
return new ColumnSpecification(column.ksName,
column.cfName,
new ColumnIdentifier(column.name + "." + UTF8Type.instance.compose(ut.fieldName(field)), true),
ut.fieldType(field));
}
示例13: checkForDuplicateNames
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
public static void checkForDuplicateNames(UserType type) throws InvalidRequestException
{
for (int i = 0; i < type.size() - 1; i++)
{
ByteBuffer fieldName = type.fieldName(i);
for (int j = i+1; j < type.size(); j++)
{
if (fieldName.equals(type.fieldName(j)))
throw new InvalidRequestException(String.format("Duplicate field name %s in type %s",
UTF8Type.instance.getString(fieldName),
UTF8Type.instance.getString(type.name)));
}
}
}
示例14: createType
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
private UserType createType() throws InvalidRequestException
{
List<ByteBuffer> names = new ArrayList<>(columnNames.size());
for (ColumnIdentifier name : columnNames)
names.add(name.bytes);
List<AbstractType<?>> types = new ArrayList<>(columnTypes.size());
for (CQL3Type.Raw type : columnTypes)
types.add(type.prepare(keyspace()).getType());
return new UserType(name.getKeyspace(), name.getUserTypeName(), names, types);
}
示例15: addType
import org.apache.cassandra.db.marshal.UserType; //导入依赖的package包/类
private static void addType(UserType ut)
{
KSMetaData ksm = Schema.instance.getKSMetaData(ut.keyspace);
assert ksm != null;
logger.info("Loading {}", ut);
ksm.userTypes.addType(ut);
if (!StorageService.instance.isClientMode())
MigrationManager.instance.notifyCreateUserType(ut);
}