use of org.apache.gora.mongodb.utils.BSONDecorator in project gora by apache.
the class MongoStore method fromMongoMap.
/* pp */
Object fromMongoMap(final String docf, final Schema fieldSchema, final BSONDecorator easybson, final Field f) {
BasicDBObject map = easybson.getDBObject(docf);
Map<Utf8, Object> rmap = new HashMap<>();
if (map == null) {
return new DirtyMapWrapper(rmap);
}
for (Entry<String, Object> e : map.entrySet()) {
String mapKey = e.getKey();
String decodedMapKey = decodeFieldKey(mapKey);
DocumentFieldType storeType = mapping.getDocumentFieldType(docf);
Object o = fromDBObject(fieldSchema.getValueType(), storeType, f, mapKey, new BSONDecorator(map));
rmap.put(new Utf8(decodedMapKey), o);
}
return new DirtyMapWrapper<>(rmap);
}
use of org.apache.gora.mongodb.utils.BSONDecorator in project gora by apache.
the class MongoStore method fromMongoList.
/* pp */
Object fromMongoList(final String docf, final Schema fieldSchema, final BSONDecorator easybson, final Field f) {
List<Object> list = easybson.getDBList(docf);
List<Object> rlist = new ArrayList<>();
if (list == null) {
return new DirtyListWrapper(rlist);
}
for (Object item : list) {
DocumentFieldType storeType = mapping.getDocumentFieldType(docf);
Object o = fromDBObject(fieldSchema.getElementType(), storeType, f, "item", new BSONDecorator(new BasicDBObject("item", item)));
rlist.add(o);
}
return new DirtyListWrapper<>(rlist);
}
use of org.apache.gora.mongodb.utils.BSONDecorator in project gora by apache.
the class MongoStore method newInstance.
// //////////////////////////////////////////////////////// DESERIALIZATION
/**
* Build a new instance of the persisted class from the {@link DBObject}
* retrieved from the database.
*
* @param obj
* the {@link DBObject} that results from the query to the database
* @param fields
* the list of fields to be mapped to the persistence class instance
* @return a persistence class instance which content was deserialized from
* the {@link DBObject}
*/
public T newInstance(final DBObject obj, final String[] fields) {
if (obj == null)
return null;
BSONDecorator easybson = new BSONDecorator(obj);
// Create new empty persistent bean instance
T persistent = newPersistent();
String[] dbFields = getFieldsToQuery(fields);
// Populate each field
for (String f : dbFields) {
// Check the field exists in the mapping and in the db
String docf = mapping.getDocumentField(f);
if (docf == null || !easybson.containsField(docf))
continue;
DocumentFieldType storeType = mapping.getDocumentFieldType(docf);
Field field = fieldMap.get(f);
Schema fieldSchema = field.schema();
LOG.debug("Load from DBObject (MAIN), field:{}, schemaType:{}, docField:{}, storeType:{}", new Object[] { field.name(), fieldSchema.getType(), docf, storeType });
Object result = fromDBObject(fieldSchema, storeType, field, docf, easybson);
persistent.put(field.pos(), result);
}
persistent.clearDirty();
return persistent;
}
use of org.apache.gora.mongodb.utils.BSONDecorator in project gora by apache.
the class TestMongoStore method testFromMongoList_empty.
@Test
public void testFromMongoList_empty() throws Exception {
MongoStore store = new MongoStore();
String field = "myField";
BasicDBObject emptyField = new BasicDBObject(field, new BasicDBList());
Object item = store.fromMongoList(field, null, new BSONDecorator(emptyField), null);
assertNotNull(item);
}
use of org.apache.gora.mongodb.utils.BSONDecorator in project gora by apache.
the class TestMongoStore method testFromMongoList_null.
@Test
public void testFromMongoList_null() throws Exception {
MongoStore store = new MongoStore();
BasicDBObject noField = new BasicDBObject();
String field = "myField";
Object item = store.fromMongoList(field, null, new BSONDecorator(noField), null);
assertNotNull(item);
}
Aggregations