use of org.apache.gora.persistency.impl.DirtyListWrapper in project gora by apache.
the class AerospikeStore method getDeserializedObject.
/**
* Method to get Avro mapped persistent object from the record retrieved from the database
*
* @param binValue value retrieved from database
* @param binDataType data type of the database value
* @param schema corresponding schema in the persistent class
* @return persistent object
*/
private Object getDeserializedObject(Object binValue, String binDataType, Schema schema) {
Object result;
switch(schema.getType()) {
case MAP:
Map<String, Object> rawMap = (Map<String, Object>) binValue;
Map<Utf8, Object> deserializableMap = new HashMap<>();
if (rawMap == null) {
result = new DirtyMapWrapper(deserializableMap);
break;
}
for (Map.Entry<?, ?> e : rawMap.entrySet()) {
Schema innerSchema = schema.getValueType();
Object obj = getDeserializedObject(e.getValue(), e.getValue().getClass().getSimpleName(), innerSchema);
if (e.getKey().getClass().getSimpleName().equalsIgnoreCase("Utf8")) {
deserializableMap.put((Utf8) e.getKey(), obj);
} else {
deserializableMap.put(new Utf8((String) e.getKey()), obj);
}
}
result = new DirtyMapWrapper<>(deserializableMap);
break;
case ARRAY:
List<Object> rawList = (List<Object>) binValue;
List<Object> deserializableList = new ArrayList<>();
if (rawList == null) {
return new DirtyListWrapper(deserializableList);
}
for (Object item : rawList) {
Object obj = getDeserializedObject(item, item.getClass().getSimpleName(), schema.getElementType());
deserializableList.add(obj);
}
result = new DirtyListWrapper<>(deserializableList);
break;
case RECORD:
result = (PersistentBase) binValue;
break;
case UNION:
int index = getUnionSchema(binValue, schema);
Schema resolvedSchema = schema.getTypes().get(index);
result = getDeserializedObject(binValue, binDataType, resolvedSchema);
break;
case ENUM:
result = AvroUtils.getEnumValue(schema, (String) binValue);
break;
case BYTES:
result = ByteBuffer.wrap((byte[]) binValue);
break;
case STRING:
if (binValue instanceof org.apache.avro.util.Utf8)
result = binValue;
else
result = new Utf8((String) binValue);
break;
case INT:
if (binDataType.equalsIgnoreCase("long")) {
result = Math.toIntExact((Long) binValue);
} else {
result = binValue;
}
break;
default:
result = binValue;
}
return result;
}
use of org.apache.gora.persistency.impl.DirtyListWrapper in project gora by apache.
the class RethinkDBStore method convertDocFieldToAvroList.
private Object convertDocFieldToAvroList(final String docf, final Schema fieldSchema, final MapObject<String, Object> doc, final Schema.Field f, final RethinkDBMapping.DocumentFieldType storeType) throws GoraException {
if (storeType == RethinkDBMapping.DocumentFieldType.LIST || storeType == null) {
List<Object> list = (List<Object>) doc.get(docf);
List<Object> rlist = new ArrayList<>();
if (list == null) {
return new DirtyListWrapper(rlist);
}
for (Object item : list) {
MapObject<String, Object> innerDoc = new MapObject();
innerDoc.put("item", item);
Object o = convertDocFieldToAvroField(fieldSchema.getElementType(), storeType, f, "item", innerDoc);
rlist.add(o);
}
return new DirtyListWrapper<>(rlist);
}
return null;
}
Aggregations