本文整理汇总了Java中org.apache.gora.cassandra.serializers.GoraSerializerTypeInferer.getSerializer方法的典型用法代码示例。如果您正苦于以下问题:Java GoraSerializerTypeInferer.getSerializer方法的具体用法?Java GoraSerializerTypeInferer.getSerializer怎么用?Java GoraSerializerTypeInferer.getSerializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.gora.cassandra.serializers.GoraSerializerTypeInferer
的用法示例。
在下文中一共展示了GoraSerializerTypeInferer.getSerializer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromByteBuffer
import org.apache.gora.cassandra.serializers.GoraSerializerTypeInferer; //导入方法依赖的package包/类
protected Object fromByteBuffer(Schema schema, ByteBuffer byteBuffer) {
Object value = null;
Serializer<?> serializer = GoraSerializerTypeInferer.getSerializer(schema);
if (serializer == null) {
LOG.warn("Schema: " + schema.getName() + " is not supported. No serializer "
+ "could be found. Please report this to [email protected]");
} else {
value = serializer.fromByteBuffer(byteBuffer);
if (schema.getType().equals(Type.RECORD) || schema.getType().equals(Type.MAP) ){
try {
value = AvroSerializerUtil.deserializer(value, schema);
} catch (IOException e) {
LOG.warn(field.name() + " named field could not be deserialized.");
}
}
}
return value;
}
示例2: toByteBuffer
import org.apache.gora.cassandra.serializers.GoraSerializerTypeInferer; //导入方法依赖的package包/类
/**
* Serialize value to ByteBuffer using
* {@link org.apache.gora.cassandra.serializers.GoraSerializerTypeInferer#getSerializer(Object)}.
* @param value the member value {@link java.lang.Object}.
* @return ByteBuffer object
*/
public ByteBuffer toByteBuffer(Object value) {
ByteBuffer byteBuffer = null;
Serializer<Object> serializer = GoraSerializerTypeInferer.getSerializer(value);
if (serializer == null) {
LOG.warn("Serializer not found for: " + value.toString());
}
else {
LOG.debug(serializer.getClass() + " selected as appropriate Serializer.");
byteBuffer = serializer.toByteBuffer(value);
}
if (byteBuffer == null) {
LOG.warn("Serialization value for: " + value.getClass().getName() + " = null");
}
return byteBuffer;
}
示例3: initialize
import org.apache.gora.cassandra.serializers.GoraSerializerTypeInferer; //导入方法依赖的package包/类
public void initialize(Class<K> keyClass, Class<T> persistentClass) throws Exception {
this.keyClass = keyClass;
// get cassandra mapping with persistent class
this.persistentClass = persistentClass;
this.cassandraMapping = CassandraMappingManager.getManager().get(persistentClass);
// LOG.info("persistentClass=" + persistentClass.getName() + " -> cassandraMapping=" + cassandraMapping);
this.cluster = HFactory.getOrCreateCluster(this.cassandraMapping.getClusterName(), new CassandraHostConfigurator(this.cassandraMapping.getHostName()));
// add keyspace to cluster
checkKeyspace();
// Just create a Keyspace object on the client side, corresponding to an already existing keyspace with already created column families.
this.keyspace = HFactory.createKeyspace(this.cassandraMapping.getKeyspaceName(), this.cluster);
this.keySerializer = GoraSerializerTypeInferer.getSerializer(keyClass);
this.mutator = HFactory.createMutator(this.keyspace, this.keySerializer);
}
示例4: toByteBuffer
import org.apache.gora.cassandra.serializers.GoraSerializerTypeInferer; //导入方法依赖的package包/类
/**
* Serialize value to ByteBuffer.
* @param value the member value
* @return ByteBuffer object
*/
@SuppressWarnings("unchecked")
public ByteBuffer toByteBuffer(Object value) {
ByteBuffer byteBuffer = null;
Serializer serializer = GoraSerializerTypeInferer.getSerializer(value);
if (serializer == null) {
LOG.info("Serializer not found for: " + value.toString());
}
else {
byteBuffer = serializer.toByteBuffer(value);
}
if (byteBuffer == null) {
LOG.info("value class=" + value.getClass().getName() + " value=" + value + " -> null");
}
return byteBuffer;
}
示例5: initialize
import org.apache.gora.cassandra.serializers.GoraSerializerTypeInferer; //导入方法依赖的package包/类
/**
* Given our key, persistentClass from
* {@link org.apache.gora.cassandra.store.CassandraStore#initialize(Class, Class, Properties)}
* we make best efforts to dictate our data model.
* We make a quick check within {@link org.apache.gora.cassandra.store.CassandraClient#checkKeyspace(String)
* to see if our keyspace has already been invented, this simple check prevents us from
* recreating the keyspace if it already exists.
* We then simple specify (based on the input keyclass) an appropriate serializer
* via {@link org.apache.gora.cassandra.serializers.GoraSerializerTypeInferer} before
* defining a mutator from and by which we can mutate this object.
* @param keyClass the Key by which we wish o assign a record object
* @param persistentClass the generated {@link org.apache.org.gora.persistency.Peristent} bean representing the data.
* @param properties key value pairs from gora.properties
* @throws Exception
*/
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) throws Exception {
this.keyClass = keyClass;
// get cassandra mapping with persistent class
this.persistentClass = persistentClass;
this.cassandraMapping = CassandraMappingManager.getManager().get(persistentClass);
Map<String, String> accessMap = null;
if (properties != null) {
String username = properties
.getProperty("gora.cassandrastore.username");
if (username != null) {
accessMap = new HashMap<>();
accessMap.put("username", username);
String password = properties
.getProperty("gora.cassandrastore.password");
if (password != null) {
accessMap.put("password", password);
}
}
}
this.cluster = HFactory.getOrCreateCluster(this.cassandraMapping.getClusterName(),
new CassandraHostConfigurator(this.cassandraMapping.getHostName()), accessMap);
// add keyspace to cluster
checkKeyspace();
// Just create a Keyspace object on the client side, corresponding to an already
// existing keyspace with already created column families.
this.keyspace = HFactory.createKeyspace(this.cassandraMapping.getKeyspaceName(), this.cluster);
this.keySerializer = GoraSerializerTypeInferer.getSerializer(keyClass);
if (this.keySerializer == null)
LOG.error("Serializer for " + keyClass + " not found.");
this.mutator = HFactory.createMutator(this.keyspace, this.keySerializer);
}
示例6: fromByteBuffer
import org.apache.gora.cassandra.serializers.GoraSerializerTypeInferer; //导入方法依赖的package包/类
protected Object fromByteBuffer(Schema schema, ByteBuffer byteBuffer) {
Object value = null;
Serializer<?> serializer = GoraSerializerTypeInferer.getSerializer(schema);
if (serializer == null) {
LOG.info("Schema is not supported: " + schema.toString());
} else {
value = serializer.fromByteBuffer(byteBuffer);
}
return value;
}