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


Java BsonDocument.get方法代码示例

本文整理汇总了Java中org.bson.BsonDocument.get方法的典型用法代码示例。如果您正苦于以下问题:Java BsonDocument.get方法的具体用法?Java BsonDocument.get怎么用?Java BsonDocument.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bson.BsonDocument的用法示例。


在下文中一共展示了BsonDocument.get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPatchAppliedCleanly

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
    public void testPatchAppliedCleanly() throws Exception {
        for (int i = 0; i < jsonNode.size(); i++) {
        	BsonDocument node = jsonNode.get(i).asDocument();
        	
            BsonValue first = node.get("first");
            BsonValue second = node.get("second");
            BsonArray patch = node.getArray("patch");
            String message = node.containsKey("message") ? node.getString("message").getValue() : "";

//            System.out.println("Test # " + i);
//            System.out.println(first);
//            System.out.println(second);
//            System.out.println(patch);

            BsonValue secondPrime = BsonPatch.apply(patch, first);
//            System.out.println(secondPrime);
            Assert.assertThat(message, secondPrime, equalTo(second));
        }

    }
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:22,代码来源:JsonDiffTest2.java

示例2: convertBinaryUUID

import org.bson.BsonDocument; //导入方法依赖的package包/类
/**
 * Converts a binary uuid to a standard uuid
 *
 * @param json The json string (should contain "$binary" and "$type" or something like that)
 * @return The uuid
 */
private UUID convertBinaryUUID(String key, String json) {
    BsonDocument document = BsonDocument.parse(json);

    BsonValue value = document.get(key);
    if(!(value instanceof BsonBinary)) {
        return null;
    }
    byte[] bytes = ((BsonBinary) value).getData();
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    long l1 = bb.getLong();
    long l2 = bb.getLong();

    return new UUID(l1, l2);
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:22,代码来源:DbFilter.java

示例3: toBson

import org.bson.BsonDocument; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> BsonValue toBson(Object value, Class<T> clazz) {
	if(value == null) {
		return new BsonNull();
	}
	if(value instanceof BsonValue) {
		return (BsonValue) value;
	}
	final Codec<T> codec = registry.get(clazz);
	final String key = "value";
	final BsonDocument document = new BsonDocument();
	final BsonWriter writer = new BsonDocumentWriter(document);
	writer.writeStartDocument();
	writer.writeName(key);
	codec.encode(writer, (T) value, EncoderContext.builder().build());
	writer.writeEndDocument();
	return document.get(key);
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:19,代码来源:SmofParser.java

示例4: toBson

import org.bson.BsonDocument; //导入方法依赖的package包/类
BsonValue toBson() {
  @SuppressWarnings("unchecked")
  Encoder<T> encoder = BsonEncoding.encoderFor((Class<T>) value.getClass(), adapter);
  BsonDocument bson = new BsonDocument();
  org.bson.BsonWriter writer = new BsonDocumentWriter(bson);
  // Bson doesn't allow to write directly scalars / primitives, they have to be embedded in a document.
  writer.writeStartDocument();
  writer.writeName("$");
  encoder.encode(writer, value, EncoderContext.builder().build());
  writer.writeEndDocument();
  writer.flush();
  return bson.get("$");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:Support.java

示例5: testOperation

import org.bson.BsonDocument; //导入方法依赖的package包/类
private void testOperation() throws Exception {
    BsonDocument node = p.getNode();

    BsonValue doc = node.get("node");
    BsonValue expected = node.get("expected");
    BsonArray patch = node.getArray("op");
    String message = node.containsKey("message") ? node.getString("message").getValue() : "";

    BsonValue result = BsonPatch.apply(patch, doc);
    String failMessage = "The following test failed: \n" +
         "message: " + message + '\n' +
         "at: " + p.getSourceFile();
    assertEquals(failMessage, expected, result);
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:15,代码来源:AbstractTest.java

示例6: testError

import org.bson.BsonDocument; //导入方法依赖的package包/类
private void testError() throws  ClassNotFoundException {
    BsonDocument node = p.getNode();
    BsonValue first = node.get("node");
    BsonArray patch = node.getArray("op");
    String message = node.containsKey("message") ? node.getString("message").getValue() : "";
    Class<?> type =
            node.containsKey("type") ? exceptionType(node.getString("type").getValue()) : BsonPatchApplicationException.class;

    try {
        BsonPatch.apply(patch, first);

        fail(errorMessage("Failure expected: " + message));
    } catch (Exception e) {
        if (matchOnErrors()) {
            StringWriter fullError = new StringWriter();
            e.printStackTrace(new PrintWriter(fullError));

            assertThat(
                    errorMessage("Operation failed but with wrong exception type", e),
                    e,
                    instanceOf(type));
            if (message != null) {
                assertThat(
                        errorMessage("Operation failed but with wrong message", e),
                        e.getMessage(),
                        containsString(message));    // equalTo would be better, but fail existing tests
            }
        }
    }
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:31,代码来源:AbstractTest.java

示例7: decode

import org.bson.BsonDocument; //导入方法依赖的package包/类
/**
 * 反序列化BsonDocument到POJO/decode BsonDocument->POJO
 *
 * @param bsonDocument
 * @param targetClazz
 * @param bsonMapperConfig
 * @param <T>
 * @return
 */
<T> T decode(BsonDocument bsonDocument, Class<T> targetClazz, BsonMapperConfig bsonMapperConfig) {
    MAPPER_LAYER_COUNTER.addCount(bsonMapperConfig);
    try {
        List<Field> allField = Utils.getAllField(targetClazz);
        T target = Utils.newInstanceByClazz(targetClazz);
        for (Field field : allField) {
            if (isIgnored(field)) {
                continue;
            }
            String bsonName = getBsonName(field);
            BsonValue bsonValue = bsonDocument.get(bsonName);
            if (bsonValue == null || bsonValue.isNull()) {
                continue;
            }
            Object javaValue;
            try {
                javaValue = getJavaValueFromBsonValue(bsonValue, field, bsonMapperConfig);
            } catch (BsonMapperConverterException e) {
                throw new BsonMapperConverterException("error when try to get java value from Bson.BsonName:" + bsonName, e);
            }
            setJavaValueToField(targetClazz, target, field, javaValue);
        }
        return target;
    } finally {
        MAPPER_LAYER_COUNTER.reduceCount();
    }
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:37,代码来源:BsonDocumentConverter.java

示例8: toMap

import org.bson.BsonDocument; //导入方法依赖的package包/类
private Map<?, ?> toMap(BsonDocument document, PrimaryField fieldOpts) {
	final Map<Object, Object> map = new LinkedHashMap<>();
	final Pair<SecondaryField, SecondaryField> mapClass = getMapFields(fieldOpts);

	for(String bsonKey : document.keySet()) {
		final BsonValue bsonValue = document.get(bsonKey);
		final Object key = toMapKey(bsonKey, mapClass.getKey());
		final Object value = toMapValue(bsonValue, mapClass.getValue());
		map.put(key, value);
	}

	return map;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:14,代码来源:ObjectParser.java

示例9: handleField

import org.bson.BsonDocument; //导入方法依赖的package包/类
private <T> void handleField(BsonDocument document, BsonBuilder<T> builder, PrimaryField field) {
	final BsonValue fieldValue = document.get(field.getName());
	final Object parsedObj;
	if(fieldValue != null) {
		if(fieldValue.isObjectId()) {
			builder.append2LazyElements(field, fieldValue.asObjectId().getValue());
		}
		else {
			parsedObj = topParser.fromBson(fieldValue, field);
			builder.append2AdditionalFields(field.getRawField(), parsedObj);
		}
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:14,代码来源:ObjectParser.java

示例10: serializeWithCodec

import org.bson.BsonDocument; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected final <T> BsonValue serializeWithCodec(Codec<T> codec, Object value) {
	checkArgument(codec != null, "Cannot find a valid codec to serialize: " + value);
	final BsonDocument document = new BsonDocument();
	final String name = "result";
	final BsonDocumentWriter writer = new BsonDocumentWriter(document);
	writer.writeStartDocument();
	writer.writeName(name);
	codec.encode(writer, (T) value, EncoderContext.builder().build());
	writer.writeEndDocument();
	return document.get(name);
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:13,代码来源:AbstractBsonParser.java

示例11: getFromDocument

import org.bson.BsonDocument; //导入方法依赖的package包/类
private BsonValue getFromDocument(BsonDocument document, String field) {
	final BsonValue value = document.get(field);
	return value == null ? new BsonNull() : value;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:5,代码来源:ObjectParser.java


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