当前位置: 首页>>代码示例>>Java>>正文


Java BSONDecorator类代码示例

本文整理汇总了Java中org.apache.gora.mongodb.utils.BSONDecorator的典型用法代码示例。如果您正苦于以下问题:Java BSONDecorator类的具体用法?Java BSONDecorator怎么用?Java BSONDecorator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BSONDecorator类属于org.apache.gora.mongodb.utils包,在下文中一共展示了BSONDecorator类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fromMongoUnion

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
private Object fromMongoUnion(final Schema fieldSchema,
    final DocumentFieldType storeType, final Field field, final String docf,
    final BSONDecorator easybson) {
  Object result;// schema [type0, type1]
  Type type0 = fieldSchema.getTypes().get(0).getType();
  Type type1 = fieldSchema.getTypes().get(1).getType();

  // Check if types are different and there's a "null", like ["null","type"]
  // or ["type","null"]
  if (!type0.equals(type1)
      && (type0.equals(Type.NULL) || type1.equals(Type.NULL))) {
    Schema innerSchema = fieldSchema.getTypes().get(1);
    LOG.debug(
        "Load from DBObject (UNION), schemaType:{}, docField:{}, storeType:{}",
        new Object[] { innerSchema.getType(), docf, storeType });
    // Deserialize as if schema was ["type"]
    result = fromDBObject(innerSchema, storeType, field, docf, easybson);
  } else {
    throw new IllegalStateException(
        "MongoStore doesn't support 3 types union field yet. Please update your mapping");
  }
  return result;
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:24,代码来源:MongoStore.java

示例2: fromMongoList

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
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);
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:18,代码来源:MongoStore.java

示例3: fromMongoMap

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
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);
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:19,代码来源:MongoStore.java

示例4: fromMongoList

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:gora,代码行数:18,代码来源:MongoStore.java

示例5: fromMongoMap

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:gora,代码行数:19,代码来源:MongoStore.java

示例6: newInstance

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
/**
 * 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}
 * @throws IOException
 */
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;
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:42,代码来源:MongoStore.java

示例7: fromMongoRecord

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
@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) {
  }
  Persistent record = 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;
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:31,代码来源:MongoStore.java

示例8: testFromMongoList_null

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
@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);
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:10,代码来源:TestMongoStore.java

示例9: testFromMongoList_empty

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
@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);
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:10,代码来源:TestMongoStore.java

示例10: testFromMongoMap_null

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
@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);
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:10,代码来源:TestMongoStore.java

示例11: testFromMongoMap_empty

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
@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);
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:10,代码来源:TestMongoStore.java

示例12: newInstance

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:gora,代码行数:41,代码来源:MongoStore.java

示例13: fromMongoRecord

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
@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;
}
 
开发者ID:apache,项目名称:gora,代码行数:31,代码来源:MongoStore.java

示例14: fromDBObject

import org.apache.gora.mongodb.utils.BSONDecorator; //导入依赖的package包/类
private Object fromDBObject(final Schema fieldSchema,
    final DocumentFieldType storeType, final Field field, final String docf,
    final BSONDecorator easybson) {
  Object result = null;
  switch (fieldSchema.getType()) {
  case MAP:
    result = fromMongoMap(docf, fieldSchema, easybson, field);
    break;
  case ARRAY:
    result = fromMongoList(docf, fieldSchema, easybson, field);
    break;
  case RECORD:
    DBObject rec = easybson.getDBObject(docf);
    if (rec == null) {
      result = null;
      break;
    }
    result = fromMongoRecord(fieldSchema, docf, rec);
    break;
  case BOOLEAN:
    result = easybson.getBoolean(docf);
    break;
  case DOUBLE:
    result = easybson.getDouble(docf);
    break;
  case FLOAT:
    result = easybson.getDouble(docf).floatValue();
    break;
  case INT:
    result = easybson.getInt(docf);
    break;
  case LONG:
    result = easybson.getLong(docf);
    break;
  case STRING:
    result = fromMongoString(storeType, docf, easybson);
    break;
  case ENUM:
    result = AvroUtils.getEnumValue(fieldSchema, easybson.getUtf8String(docf)
        .toString());
    break;
  case BYTES:
  case FIXED:
    result = easybson.getBytes(docf);
    break;
  case NULL:
    result = null;
    break;
  case UNION:
    result = fromMongoUnion(fieldSchema, storeType, field, docf, easybson);
    break;
  default:
    LOG.warn("Unable to read {}", docf);
    break;
  }
  return result;
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:58,代码来源:MongoStore.java


注:本文中的org.apache.gora.mongodb.utils.BSONDecorator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。