Search in sources :

Example 6 with BSONDecorator

use of org.apache.gora.mongodb.utils.BSONDecorator in project gora by apache.

the class MongoStore method fromMongoRecord.

@SuppressWarnings({ "unchecked", "rawtypes" })
private Object fromMongoRecord(final Schema fieldSchema, final String docf, final DBObject rec) {
    Object result;
    BSONDecorator innerBson = new BSONDecorator(rec);
    Class<?> clazz = null;
    try {
        clazz = ClassLoadingUtils.loadClass(fieldSchema.getFullName());
    } catch (ClassNotFoundException e) {
    }
    PersistentBase record = (PersistentBase) new BeanFactoryImpl(keyClass, clazz).newPersistent();
    for (Field recField : fieldSchema.getFields()) {
        Schema innerSchema = recField.schema();
        DocumentFieldType innerStoreType = mapping.getDocumentFieldType(innerSchema.getName());
        String innerDocField = mapping.getDocumentField(recField.name()) != null ? mapping.getDocumentField(recField.name()) : recField.name();
        String fieldPath = docf + "." + innerDocField;
        LOG.debug("Load from DBObject (RECORD), field:{}, schemaType:{}, docField:{}, storeType:{}", new Object[] { recField.name(), innerSchema.getType(), fieldPath, innerStoreType });
        record.put(recField.pos(), fromDBObject(innerSchema, innerStoreType, recField, innerDocField, innerBson));
    }
    result = record;
    return result;
}
Also used : Field(org.apache.avro.Schema.Field) PersistentBase(org.apache.gora.persistency.impl.PersistentBase) BSONDecorator(org.apache.gora.mongodb.utils.BSONDecorator) DocumentFieldType(org.apache.gora.mongodb.store.MongoMapping.DocumentFieldType) Schema(org.apache.avro.Schema) BeanFactoryImpl(org.apache.gora.persistency.impl.BeanFactoryImpl)

Example 7 with BSONDecorator

use of org.apache.gora.mongodb.utils.BSONDecorator in project gora by apache.

the class TestMongoStore method testFromMongoMap_empty.

@Test
public void testFromMongoMap_empty() throws Exception {
    MongoStore store = new MongoStore();
    String field = "myField";
    BasicDBObject emptyField = new BasicDBObject(field, new BasicDBObject());
    Object item = store.fromMongoMap(field, null, new BSONDecorator(emptyField), null);
    assertNotNull(item);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) BSONDecorator(org.apache.gora.mongodb.utils.BSONDecorator) BasicDBObject(com.mongodb.BasicDBObject) Test(org.junit.Test)

Example 8 with BSONDecorator

use of org.apache.gora.mongodb.utils.BSONDecorator in project gora by apache.

the class TestMongoStore method testFromMongoMap_null.

@Test
public void testFromMongoMap_null() throws Exception {
    MongoStore store = new MongoStore();
    BasicDBObject noField = new BasicDBObject();
    String field = "myField";
    Object item = store.fromMongoMap(field, null, new BSONDecorator(noField), null);
    assertNotNull(item);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) BSONDecorator(org.apache.gora.mongodb.utils.BSONDecorator) BasicDBObject(com.mongodb.BasicDBObject) Test(org.junit.Test)

Aggregations

BSONDecorator (org.apache.gora.mongodb.utils.BSONDecorator)8 BasicDBObject (com.mongodb.BasicDBObject)4 DocumentFieldType (org.apache.gora.mongodb.store.MongoMapping.DocumentFieldType)4 Test (org.junit.Test)4 Schema (org.apache.avro.Schema)2 Field (org.apache.avro.Schema.Field)2 BasicDBList (com.mongodb.BasicDBList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Utf8 (org.apache.avro.util.Utf8)1 BeanFactoryImpl (org.apache.gora.persistency.impl.BeanFactoryImpl)1 DirtyListWrapper (org.apache.gora.persistency.impl.DirtyListWrapper)1 DirtyMapWrapper (org.apache.gora.persistency.impl.DirtyMapWrapper)1 PersistentBase (org.apache.gora.persistency.impl.PersistentBase)1