use of org.apache.gora.persistency.Persistent in project gora by apache.
the class CassandraStore method getUnionSchema.
/**
* Given an object and the object schema this function obtains,
* from within the UNION schema, the position of the type used.
* If no data type can be inferred then we return a default value
* of position 0.
* @param pValue
* @param pUnionSchema
* @return the unionSchemaPosition.
*/
private int getUnionSchema(Object pValue, Schema pUnionSchema) {
int unionSchemaPos = 0;
// String valueType = pValue.getClass().getSimpleName();
for (Schema currentSchema : pUnionSchema.getTypes()) {
Type schemaType = currentSchema.getType();
if (pValue instanceof CharSequence && schemaType.equals(Type.STRING))
return unionSchemaPos;
else if (pValue instanceof ByteBuffer && schemaType.equals(Type.BYTES))
return unionSchemaPos;
else if (pValue instanceof Integer && schemaType.equals(Type.INT))
return unionSchemaPos;
else if (pValue instanceof Long && schemaType.equals(Type.LONG))
return unionSchemaPos;
else if (pValue instanceof Double && schemaType.equals(Type.DOUBLE))
return unionSchemaPos;
else if (pValue instanceof Float && schemaType.equals(Type.FLOAT))
return unionSchemaPos;
else if (pValue instanceof Boolean && schemaType.equals(Type.BOOLEAN))
return unionSchemaPos;
else if (pValue instanceof Map && schemaType.equals(Type.MAP))
return unionSchemaPos;
else if (pValue instanceof List && schemaType.equals(Type.ARRAY))
return unionSchemaPos;
else if (pValue instanceof Persistent && schemaType.equals(Type.RECORD))
return unionSchemaPos;
unionSchemaPos++;
}
// if we weren't able to determine which data type it is, then we return the default
return DEFAULT_UNION_SCHEMA;
}
use of org.apache.gora.persistency.Persistent in project gora by apache.
the class GoraSerializerTypeInferer method getSerializer.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> Serializer<T> getSerializer(Object value) {
Serializer serializer = null;
if (value == null) {
serializer = ByteBufferSerializer.get();
} else if (value instanceof CharSequence) {
serializer = CharSequenceSerializer.get();
} else if (value instanceof Utf8) {
serializer = CharSequenceSerializer.get();
} else if (value instanceof Boolean) {
serializer = BooleanSerializer.get();
} else if (value instanceof ByteBuffer) {
serializer = ByteBufferSerializer.get();
} else if (value instanceof byte[]) {
serializer = BytesArraySerializer.get();
} else if (value instanceof Double) {
serializer = DoubleSerializer.get();
} else if (value instanceof Float) {
serializer = FloatSerializer.get();
} else if (value instanceof Integer) {
serializer = IntegerSerializer.get();
} else if (value instanceof Long) {
serializer = LongSerializer.get();
} else if (value instanceof String) {
serializer = StringSerializer.get();
} else if (value instanceof SpecificFixed) {
serializer = SpecificFixedSerializer.get(value.getClass());
} else if (value instanceof GenericArray) {
Schema schema = ((GenericArray) value).getSchema();
if (schema.getType() == Type.ARRAY) {
schema = schema.getElementType();
}
serializer = ListSerializer.get(schema);
} else if (value instanceof Map) {
Map map = (Map) value;
if (map.size() == 0) {
serializer = ByteBufferSerializer.get();
} else {
Object value0 = map.values().iterator().next();
Schema schema = TypeUtils.getSchema(value0);
serializer = MapSerializer.get(schema);
}
} else if (value instanceof Persistent) {
serializer = ObjectSerializer.get();
} else {
serializer = SerializerTypeInferer.getSerializer(value);
}
return serializer;
}
use of org.apache.gora.persistency.Persistent in project gora by apache.
the class SolrStore method getUnionSchema.
/**
* Given an object and the object schema this function obtains, from within
* the UNION schema, the position of the type used. If no data type can be
* inferred then we return a default value of position 0.
*
* @param pValue
* @param pUnionSchema
* @return the unionSchemaPosition.
*/
private int getUnionSchema(Object pValue, Schema pUnionSchema) {
int unionSchemaPos = 0;
for (Schema currentSchema : pUnionSchema.getTypes()) {
Type schemaType = currentSchema.getType();
if (pValue instanceof Utf8 && schemaType.equals(Type.STRING))
return unionSchemaPos;
else if (pValue instanceof ByteBuffer && schemaType.equals(Type.BYTES))
return unionSchemaPos;
else if (pValue instanceof Integer && schemaType.equals(Type.INT))
return unionSchemaPos;
else if (pValue instanceof Long && schemaType.equals(Type.LONG))
return unionSchemaPos;
else if (pValue instanceof Double && schemaType.equals(Type.DOUBLE))
return unionSchemaPos;
else if (pValue instanceof Float && schemaType.equals(Type.FLOAT))
return unionSchemaPos;
else if (pValue instanceof Boolean && schemaType.equals(Type.BOOLEAN))
return unionSchemaPos;
else if (pValue instanceof Map && schemaType.equals(Type.MAP))
return unionSchemaPos;
else if (pValue instanceof List && schemaType.equals(Type.ARRAY))
return unionSchemaPos;
else if (pValue instanceof Persistent && schemaType.equals(Type.RECORD))
return unionSchemaPos;
unionSchemaPos++;
}
// default
return DEFAULT_UNION_SCHEMA;
}
use of org.apache.gora.persistency.Persistent in project camel by apache.
the class GoraProducerTest method shouldInvokeDastorePut.
@Test
public void shouldInvokeDastorePut() throws Exception {
when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage);
when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("PUT");
final Long sampleKey = new Long(2);
when(mockCamelMessage.getHeader(GoraAttribute.GORA_KEY.value)).thenReturn(sampleKey);
final Persistent sampleValue = mock(Persistent.class);
when(mockCamelMessage.getBody(Persistent.class)).thenReturn(sampleValue);
final Message outMessage = mock(Message.class);
when(mockCamelExchange.getOut()).thenReturn(outMessage);
final GoraProducer producer = new GoraProducer(mockGoraEndpoint, mockGoraConfiguration, mockDatastore);
producer.process(mockCamelExchange);
verify(mockCamelExchange, atLeastOnce()).getIn();
verify(mockCamelMessage, atLeastOnce()).getHeader(GoraAttribute.GORA_OPERATION.value);
verify(mockCamelMessage, atLeastOnce()).getHeader(GoraAttribute.GORA_KEY.value);
verify(mockCamelMessage, atLeastOnce()).getBody(Persistent.class);
verify(mockDatastore, atMost(1)).put(sampleKey, sampleValue);
}
Aggregations