本文整理汇总了Java中com.datastax.driver.core.TypeCodec类的典型用法代码示例。如果您正苦于以下问题:Java TypeCodec类的具体用法?Java TypeCodec怎么用?Java TypeCodec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TypeCodec类属于com.datastax.driver.core包,在下文中一共展示了TypeCodec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildColumn
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
private TableColumn<ConnectionData, String> buildColumn(String name, int columnWidth, Function<ConnectionData,
String> extractor) {
TableColumn<ConnectionData, String> column = new TableColumn<>();
Label columnLabel = new Label(name);
column.setCellFactory(cellFactory(TypeCodec.varchar()));
column.setCellValueFactory(param -> {
String field = extractor.apply(param.getValue());
return new SimpleObjectProperty<>(field);
});
column.setOnEditCommit(event -> log.info("edit"));
column.setGraphic(columnLabel);
column.setMinWidth(columnWidth);
return column;
}
示例2: initializeUDTs
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
private static void initializeUDTs(Session session) {
Schema.ensureExists(DEFAULT_KEYSPACE + "_udts", session);
MappingManager mapping = new MappingManager(session);
// The UDTs are hardcoded against the zipkin keyspace.
// If a different keyspace is being used the codecs must be re-applied to this different keyspace
TypeCodec<TraceIdUDT> traceIdCodec = mapping.udtCodec(TraceIdUDT.class);
TypeCodec<EndpointUDT> endpointCodec = mapping.udtCodec(EndpointUDT.class);
TypeCodec<AnnotationUDT> annoCodec = mapping.udtCodec(AnnotationUDT.class);
TypeCodec<BinaryAnnotationUDT> bAnnoCodec = mapping.udtCodec(BinaryAnnotationUDT.class);
KeyspaceMetadata keyspace =
session.getCluster().getMetadata().getKeyspace(session.getLoggedKeyspace());
session.getCluster().getConfiguration().getCodecRegistry()
.register(
new TypeCodecImpl(keyspace.getUserType("trace_id"), TraceIdUDT.class, traceIdCodec))
.register(
new TypeCodecImpl(keyspace.getUserType("endpoint"), EndpointUDT.class, endpointCodec))
.register(
new TypeCodecImpl(keyspace.getUserType("annotation"), AnnotationUDT.class, annoCodec))
.register(
new TypeCodecImpl(keyspace.getUserType("binary_annotation"), BinaryAnnotationUDT.class,
bAnnoCodec));
}
示例3: verifyNextRow
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
private String verifyNextRow(ResultSet rs) {
String rowid = null;
for (int col=0; col < 137; col++) {
Row row = rs.one();
assertNotNull(row);
if (rowid == null) {
rowid = row.get("rowid", TypeCodec.varchar());
} else {
assertEquals(row.get("rowid", TypeCodec.varchar()), rowid);
}
assertEquals((long) row.get("col", TypeCodec.bigint()), col);
assertEquals( row.get("data", TypeCodec.blob()).asIntBuffer().get(), col);
}
return rowid;
}
示例4: registerCodecs
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
private void registerCodecs()
{
complexTypeCodecs = getCodecsForUserDefinedTypes();
if (complexTypeCodecs != null) {
CodecRegistry registry = cluster.getConfiguration().getCodecRegistry();
if (cluster.getConfiguration().getProtocolOptions().getProtocolVersion().toInt() < 4) {
LOG.error("Custom codecs are not supported for protocol version < 4");
throw new RuntimeException("Custom codecs are not supported for protocol version < 4");
}
for (String typeCodecStr : complexTypeCodecs.keySet()) {
TypeCodec codec = complexTypeCodecs.get(typeCodecStr);
registry.register(codec);
userDefinedTypesClass.put(typeCodecStr, codec.getJavaType().getRawType());
}
} else {
complexTypeCodecs = new HashMap<>();
}
}
示例5: getCodecsForUserDefinedTypes
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
@Override
public Map<String, TypeCodec> getCodecsForUserDefinedTypes()
{
Map<String, TypeCodec> allCodecs = new HashMap<>();
CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry();
UserType addressType = cluster.getMetadata().getKeyspace(getConnectionStateManager().getKeyspaceName())
.getUserType("address");
TypeCodec<UDTValue> addressTypeCodec = codecRegistry.codecFor(addressType);
AddressCodec addressCodec = new AddressCodec(addressTypeCodec, Address.class);
allCodecs.put("currentaddress", addressCodec);
UserType userFullNameType = cluster.getMetadata().getKeyspace(getConnectionStateManager().getKeyspaceName())
.getUserType("fullname");
TypeCodec<UDTValue> userFullNameTypeCodec = codecRegistry.codecFor(userFullNameType);
FullNameCodec fullNameCodec = new FullNameCodec(userFullNameTypeCodec, FullName.class);
allCodecs.put("username", fullNameCodec);
return allCodecs;
}
示例6: cellFactory
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
public static <S, T> Callback<TableColumn<S, T>, TableCell<S, T>> cellFactory(
TypeCodec<T> codec) {
return TextFieldTableCell.forTableColumn(new StringConverter<T>() {
@Override
public String toString(T object) {
return codec.format(object);
}
@Override
public T fromString(String string) {
return codec.parse(string);
}
});
}
示例7: test
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
@Override
public boolean test(DataObject data) {
TypeCodec<?> typeCodec = getColumnCodec(data.get(getField()));
Object expected = typeCodec.parse(getValue());
Object actual = data.get(getField());
if (expected instanceof Comparable && actual instanceof Comparable) {
//noinspection unchecked
return Comparable.class.cast(actual).compareTo(expected) != 0;
} else {
return expected != actual;
}
}
示例8: test
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
@Override
public boolean test(DataObject data) {
TypeCodec<?> typeCodec = getColumnCodec(data.get(getField()));
Object expected = typeCodec.parse(getValue());
Object actual = data.get(getField());
if (expected instanceof Comparable && actual instanceof Comparable) {
//noinspection unchecked
return Comparable.class.cast(actual).compareTo(expected) < 0;
} else {
return false;
}
}
示例9: test
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
@Override
public boolean test(DataObject data) {
TypeCodec<?> typeCodec = getColumnCodec(data.get(getField()));
Object expected = typeCodec.parse(getValue());
Object actual = data.get(getField());
if (expected instanceof Comparable && actual instanceof Comparable) {
//noinspection unchecked
return Comparable.class.cast(actual).compareTo(expected) <= 0;
} else {
return false;
}
}
示例10: test
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
@Override
public boolean test(DataObject data) {
TypeCodec<?> typeCodec = getColumnCodec(data.get(getField()));
Object expected = typeCodec.parse(getValue());
Object actual = data.get(getField());
if (expected instanceof Comparable && actual instanceof Comparable) {
//noinspection unchecked
return Comparable.class.cast(actual).compareTo(expected) >= 0;
} else {
return false;
}
}
示例11: test
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
@Override
public boolean test(DataObject data) {
TypeCodec<?> typeCodec = getColumnCodec(data.get(getField()));
Object expected = typeCodec.parse(getValue());
Object actual = data.get(getField());
if (expected instanceof Comparable && actual instanceof Comparable) {
//noinspection unchecked
return Comparable.class.cast(actual).compareTo(expected) > 0;
} else {
return false;
}
}
示例12: registerCodecIfNotFound
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
private void registerCodecIfNotFound(CodecRegistry registry, TypeCodec<?> codec) {
try {
registry.codecFor(codec.getCqlType(), codec.getJavaType());
} catch (CodecNotFoundException e) {
registry.register(codec);
}
}
示例13: codecsFor
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
static TypeCodec<Object>[] codecsFor(DataType[] dataType)
{
TypeCodec<Object>[] codecs = new TypeCodec[dataType.length];
for (int i = 0; i < dataType.length; i++)
codecs[i] = codecFor(dataType[i]);
return codecs;
}
示例14: javaTypes
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
/**
* Construct an array containing the Java classes for the given Java Driver {@link com.datastax.driver.core.DataType}s.
*
* @param dataTypes array with UDF argument types
* @param calledOnNullInput whether to allow {@code null} as an argument value
* @return array of same size with UDF arguments
*/
public static Class<?>[] javaTypes(TypeCodec<Object>[] dataTypes, boolean calledOnNullInput)
{
Class<?>[] paramTypes = new Class[dataTypes.length];
for (int i = 0; i < paramTypes.length; i++)
{
Class<?> clazz = asJavaClass(dataTypes[i]);
if (!calledOnNullInput)
{
// only care about classes that can be used in a data type
if (clazz == Integer.class)
clazz = int.class;
else if (clazz == Long.class)
clazz = long.class;
else if (clazz == Byte.class)
clazz = byte.class;
else if (clazz == Short.class)
clazz = short.class;
else if (clazz == Float.class)
clazz = float.class;
else if (clazz == Double.class)
clazz = double.class;
else if (clazz == Boolean.class)
clazz = boolean.class;
}
paramTypes[i] = clazz;
}
return paramTypes;
}
示例15: serialize
import com.datastax.driver.core.TypeCodec; //导入依赖的package包/类
public static ByteBuffer serialize(TypeCodec<?> codec, int protocolVersion, Object value)
{
if (!codec.getJavaType().getRawType().isAssignableFrom(value.getClass()))
throw new InvalidTypeException("Invalid value for CQL type " + codec.getCqlType().getName().toString());
return ((TypeCodec)codec).serialize(value, ProtocolVersion.fromInt(protocolVersion));
}