本文整理汇总了Java中com.datastax.driver.core.CodecRegistry.codecFor方法的典型用法代码示例。如果您正苦于以下问题:Java CodecRegistry.codecFor方法的具体用法?Java CodecRegistry.codecFor怎么用?Java CodecRegistry.codecFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.datastax.driver.core.CodecRegistry
的用法示例。
在下文中一共展示了CodecRegistry.codecFor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCodecsForUserDefinedTypes
import com.datastax.driver.core.CodecRegistry; //导入方法依赖的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;
}
示例2: registerCodecIfNotFound
import com.datastax.driver.core.CodecRegistry; //导入方法依赖的package包/类
private void registerCodecIfNotFound(CodecRegistry registry, TypeCodec<?> codec) {
try {
registry.codecFor(codec.getCqlType(), codec.getJavaType());
} catch (CodecNotFoundException e) {
registry.register(codec);
}
}
示例3: serialize
import com.datastax.driver.core.CodecRegistry; //导入方法依赖的package包/类
/**
* Serialize a field using the data type passed.
* @param dataType
* @param value
* @return
*/
@SuppressWarnings("unchecked")
public <T> ByteBuffer serialize(DataType dataType, Object value) {
final CodecRegistry codecRegistry = getCodecRegistry();
final TypeCodec<T> typeCodec = codecRegistry.codecFor(dataType);
return typeCodec.serialize((T)value, protocolVersion);
}
示例4: fromUdtValue
import com.datastax.driver.core.CodecRegistry; //导入方法依赖的package包/类
/**
* @param datatype the db datatype
* @param udtValue the udt value
* @param fieldtype1 the field 1 type
* @param fieldtype2 the field 2 type
* @param fieldname the fieldname
* @return the mapped value or <code>null</code>
*/
public <T> Object fromUdtValue(DataType datatype,
UDTValue udtValue,
Class<?> fieldtype1,
Class<?> fieldtype2,
String fieldname) {
final CodecRegistry codecRegistry = getCodecRegistry();
// build-in type
if (isBuildInType(datatype)) {
final TypeCodec<T> typeCodec = codecRegistry.codecFor(datatype);
try {
if (udtValue.isNull(fieldname)) return null;
return typeCodec.deserialize(udtValue.getBytesUnsafe(fieldname), protocolVersion);
} catch(IllegalArgumentException ex) {
return null;
}
// udt collection
} else if (datatype.isCollection()) {
// set
if (DataType.Name.SET == datatype.getName()) {
return fromUdtValues(datatype.getTypeArguments().get(0),
ImmutableSet.copyOf(udtValue.getSet(fieldname, UDTValue.class)),
fieldtype2);
// list
} else if (DataType.Name.LIST == datatype.getName()) {
return fromUdtValues(datatype.getTypeArguments().get(0),
ImmutableList.copyOf(udtValue.getList(fieldname, UDTValue.class)),
fieldtype2);
// map
} else {
if (isBuildInType(datatype.getTypeArguments().get(0))) {
return fromUdtValues(datatype.getTypeArguments().get(0),
datatype.getTypeArguments().get(1),
ImmutableMap.<Object, Object>copyOf(udtValue.getMap(fieldname, fieldtype1, UDTValue.class)),
fieldtype1,
fieldtype2);
} else if (isBuildInType(datatype.getTypeArguments().get(1))) {
return fromUdtValues(datatype.getTypeArguments().get(0),
datatype.getTypeArguments().get(1),
ImmutableMap.<Object, Object>copyOf(udtValue.getMap(fieldname, UDTValue.class, fieldtype2)),
fieldtype1,
fieldtype2);
} else {
return fromUdtValues(datatype.getTypeArguments().get(0),
datatype.getTypeArguments().get(1),
ImmutableMap.<Object, Object>copyOf(udtValue.getMap(fieldname, UDTValue.class, UDTValue.class)),
fieldtype1,
fieldtype2);
}
}
// udt
} else {
return fromUdtValue(datatype, udtValue, fieldtype1);
}
}
示例5: deserialize
import com.datastax.driver.core.CodecRegistry; //导入方法依赖的package包/类
/**
* jwestra: 3.x API change
* deserialize a single field in a UDTValue map
* @param dataType
* @param udtValue
* @param fieldname
* @return
*/
public <T> T deserialize(DataType dataType, UDTValue udtValue, String fieldname) {
final CodecRegistry codecRegistry = getCodecRegistry();
final TypeCodec<T> typeCodec = codecRegistry.codecFor(dataType);
return typeCodec.deserialize(udtValue.getBytesUnsafe(fieldname), protocolVersion);
}