• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java BsonInvalidOperationException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: method_decode_should_evocate_functions_that_reade_user_attributes

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Test
public void method_decode_should_evocate_functions_that_reade_user_attributes() throws Exception {
    DecoderContext decoderContext = DecoderContext.builder().build();
    PowerMockito.when(reader.readString("password")).thenReturn(PASSWORD);
    PowerMockito.when(reader.readString("phone")).thenReturn(PHONE);
    PowerMockito.when(reader.readBoolean("enable")).thenReturn(ENABLE);
    PowerMockito.when(reader.readBoolean("extraction")).thenReturn(EXTRACTIONENABLED);
    PowerMockito.when(reader.readString("surname")).thenReturn(SURNAME);
    PowerMockito.when(reader.readString("name")).thenReturn(NAME);
    PowerMockito.when(reader.readBoolean("adm")).thenReturn(ADMIN);
    PowerMockito.when(reader.readString("uuid")).thenReturn(UUIDString);
    PowerMockito.when(reader.readString("email")).thenReturn(EMAIL);
    PowerMockito.when(reader.readString("acronym")).thenReturn(FIELDCENTERACRONYM);
    PowerMockito.when(reader.readBsonType()).thenReturn(BsonType.END_OF_DOCUMENT);
    doThrow(new BsonInvalidOperationException("teste")).when(reader).readNull("fieldCenter");
    doThrow(new BsonInvalidOperationException("teste")).when(reader).readNull("extraction");
    User userLocal = UserCodec.decode(reader,  decoderContext);
    assertEquals(userLocal.getEmail(),EMAIL);
    assertEquals(userLocal.getPassword(),PASSWORD);
    assertEquals(userLocal.getPhone(),PHONE);
    assertEquals(userLocal.isEnable(),ENABLE);
    assertEquals(userLocal.isExtractionEnabled(),EXTRACTIONENABLED);
    assertEquals(userLocal.getName(),NAME);
    assertEquals(userLocal.getFieldCenter().getAcronym(),FIELDCENTERACRONYM);
    assertEquals(userLocal.getUuid().toString(),UUID.fromString(UUIDString).toString());
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:27,代码来源:UserCodecTest.java


示例2: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	final BsonType type = reader.getCurrentBsonType();
	switch(type) {
	case INT32:
		return decode(reader.readInt32() != 0);
	case NULL:
		return null;
	case STRING:
		return decode(Boolean.parseBoolean(reader.readString()));
	case BOOLEAN:
		return decode(reader.readBoolean());
		//$CASES-OMITTED$
	default:
		final String errMsg = format("Invalid date type, found: %s", type);
		throw new BsonInvalidOperationException(errMsg); 
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:19,代码来源:AbstractBooleanCodec.java


示例3: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	final BsonType type = reader.getCurrentBsonType();
	switch(type) {
	case DATE_TIME:
		return decode(reader.readDateTime());
	case DOUBLE:
		return decode((long) reader.readDouble());
	case INT32:
		return decode(reader.readInt32());
	case INT64:
		return decode(reader.readInt64());
	case NULL:
		return null;
	case STRING:
		return decode(Long.valueOf(reader.readString()));
		//$CASES-OMITTED$
	default:
		final String errMsg = format("Invalid date type, found: %s", type);
		throw new BsonInvalidOperationException(errMsg); 
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:23,代码来源:AbstractTimeCodec.java


示例4: parse

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
/**
 * @param json
 * @return either a BsonDocument or a BsonArray from the json string
 * @throws JsonParseException
 */
public static BsonValue parse(String json)
        throws JsonParseException {
    if (json == null) {
        return null;
    }

    String trimmed = json.trim();

    if (trimmed.startsWith("{")) {
        try {
            return BsonDocument.parse(json);
        } catch (BsonInvalidOperationException ex) {
            // this can happen parsing a bson type, e.g.
            // {"$oid": "xxxxxxxx" }
            // the string starts with { but is not a document
            return getBsonValue(json);
        }
    } else if (trimmed.startsWith("[")) {
        return BSON_ARRAY_CODEC.decode(
                new JsonReader(json),
                DecoderContext.builder().build());
    } else {
        return getBsonValue(json);
    }
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:31,代码来源:JsonUtils.java


示例5: write_map_with_null_values_to_bson

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Test public void
write_map_with_null_values_to_bson() {
    Map<String, Integer> mapToSerialise = new HashMap<>();
    mapToSerialise.put("foo", 42);
    mapToSerialise.put("bar", null);

    BsonDocument doc = (BsonDocument) BsonMapSerialiser
            .writingValuesWith(BsonSerialisers.toInteger)
            .apply(mapToSerialise);

    assertEquals("invalid foo", 42, doc.getInt32("foo").getValue());
    try {
        Integer value = doc.getInt32("bar").getValue();
        fail("bar should not have been written to the document");
    } catch (BsonInvalidOperationException e) {
        // expected
    }
}
 
开发者ID:poetix,项目名称:octarine,代码行数:19,代码来源:SerialisationTest.java


示例6: fromBson

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public <T> T fromBson(BsonValue value, Class<T> type, SmofField fieldOpts) {
	checkArgument(value != null, "A value must be specified.");
	checkArgument(type != null, "A type must be specified.");
	final Codec<T> codec = getCodec(type);
	try {
		return deserializeWithCodec(codec, value);
	} catch (BsonInvalidOperationException e) {
		handleError(new RuntimeException("Cannot parse value for type: " + fieldOpts.getName(), e));
		return null;
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:13,代码来源:AbstractBsonParser.java


示例7: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	try {
		return Enum.valueOf(clazz, reader.readString());
	} catch (IllegalArgumentException e) {
		throw new BsonInvalidOperationException(e.getMessage());
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:9,代码来源:EnumCodec.java


示例8: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	final BsonType type = reader.getCurrentBsonType();
	switch(type) {
	case DATE_TIME:
		return decode(Long.toString(reader.readDateTime()));
	case DOUBLE:
		return decode(Double.toString(reader.readDouble()));
	case INT32:
		return decode(Integer.toString(reader.readInt32()));
	case INT64:
		return decode(Long.toString(reader.readInt64()));
	case NULL:
		return null;
	case STRING:
		return decode(reader.readString());
	case BINARY:
		return decode(new String(reader.readBinaryData().getData()));
	case BOOLEAN:
		return decode(Boolean.toString(reader.readBoolean()));
	case JAVASCRIPT:
		return decode(reader.readJavaScript());
	case JAVASCRIPT_WITH_SCOPE:
		return decode(reader.readJavaScriptWithScope());
	case OBJECT_ID:
		return decode(reader.readObjectId().toHexString());
	case REGULAR_EXPRESSION:
		return decode(reader.readRegularExpression().getPattern());
	case SYMBOL:
		return decode(reader.readSymbol());
		//$CASES-OMITTED$
	default:
		final String errMsg = format("Invalid date type, found: %s", type);
		throw new BsonInvalidOperationException(errMsg); 
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:37,代码来源:AbstractStringCodec.java


示例9: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	final BsonType type = reader.getCurrentBsonType();
	if(type == BsonType.BINARY) {
		return decode(reader.readBinaryData());
	}
	final String errMsg = format("Invalid date type, found: %s", type);
	throw new BsonInvalidOperationException(errMsg); 
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:10,代码来源:AbstractBytesCodec.java


示例10: getInstance

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
private Collection<Byte> getInstance() {
	try {
		return CollectionUtils.create(encoderClass);
	} catch (InstantiationException | IllegalAccessException | IllegalArgumentException 
			| SecurityException e) {
		throw new BsonInvalidOperationException(e.getMessage());
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:9,代码来源:ByteCollectionCodec.java


示例11: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public Float decode(final BsonReader reader, final DecoderContext decoderContext) {
    double value = reader.readDouble();
    if (value < -Float.MAX_VALUE || value > Float.MAX_VALUE) {
        throw new BsonInvalidOperationException(format("%s can not be converted into a Float.", value));
    }
    return (float) value;
}
 
开发者ID:andyphillips404,项目名称:awplab-core,代码行数:9,代码来源:CorrectedFloatCodec.java


示例12: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public Class decode(BsonReader reader, DecoderContext decoderContext) {
	String className = reader.readString();
	try {
		return Class.forName(className);
	}
	catch (ClassNotFoundException e) {
		throw new BsonInvalidOperationException(
				String.format("Cannot create class from string '%s'", className));
	}
}
 
开发者ID:ralscha,项目名称:bsoncodec,代码行数:12,代码来源:ClassStringCodec.java


示例13: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public URL decode(BsonReader reader, DecoderContext decoderContext) {
	String urlString = reader.readString();
	try {
		return new URL(urlString);
	}
	catch (MalformedURLException e) {
		throw new BsonInvalidOperationException(
				String.format("Cannot create URL from string '%s'", urlString));

	}
}
 
开发者ID:ralscha,项目名称:bsoncodec,代码行数:13,代码来源:URLStringCodec.java


示例14: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public URI decode(BsonReader reader, DecoderContext decoderContext) {
	String uriString = reader.readString();
	try {
		return new URI(uriString);
	}
	catch (URISyntaxException e) {
		throw new BsonInvalidOperationException(
				String.format("Cannot create URI from string '%s'", uriString));

	}
}
 
开发者ID:ralscha,项目名称:bsoncodec,代码行数:13,代码来源:URIStringCodec.java


示例15: addDecodeStatements

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public void addDecodeStatements(TypeMirror type, CodeGeneratorContext ctx) {
	Builder builder = ctx.builder();
	switch (type.getKind()) {
	case BOOLEAN:
		builder.addStatement(ctx.setter("reader.readBoolean()"));
		break;
	case BYTE:
		builder.addStatement(ctx.setter("(byte)reader.readInt32()"));
		break;
	case SHORT:
		builder.addStatement(ctx.setter("(short)reader.readInt32()"));
		break;
	case INT:
		builder.addStatement(ctx.setter("reader.readInt32()"));
		break;
	case LONG:
		builder.addStatement(ctx.setter("reader.readInt64()"));
		break;
	case CHAR:
		builder.addStatement("String string = reader.readString()");
		builder.beginControlFlow("if (string.length() != 1)");
		builder.addStatement(
				"throw new $T(String.format(\"Attempting to builder the string '%s' to a character, but its length is not equal to one\", string))",
				BsonInvalidOperationException.class);
		builder.endControlFlow();
		builder.addStatement(ctx.setter("string.charAt(0)"));
		break;
	case FLOAT:
		builder.addStatement(ctx.setter("(float)reader.readDouble()"));
		break;
	case DOUBLE:
		builder.addStatement(ctx.setter("reader.readDouble()"));
		break;
	default:
		break;
	}

}
 
开发者ID:ralscha,项目名称:bsoncodec-apt,代码行数:40,代码来源:PrimitiveDelegate.java


示例16: applyUnsafe

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public Validation<T> applyUnsafe(BsonValue p) throws BsonInvalidOperationException {
    try {
        return validated(reader.apply(p));
    } catch (RecordValidationException e) {
        return e.toValidation();
    }
}
 
开发者ID:poetix,项目名称:octarine,代码行数:9,代码来源:BsonValidRecordDeserialiser.java


示例17: apply

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
default S apply(BsonValue p) {
    try {
        return applyUnsafe(p);
    } catch (BsonInvalidOperationException e) {
        throw new BsonDeserialisationException(e);
    }
}
 
开发者ID:poetix,项目名称:octarine,代码行数:8,代码来源:SafeBsonDeserialiser.java


示例18: valuesFrom

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
Stream<Value> valuesFrom(BsonValue bsonValue) throws BsonInvalidOperationException {
    BsonDocument doc = bsonValue.asDocument();
    return deserialiserMap.values().stream()
            .map(d -> d.apply(doc))
            .filter(Optional::isPresent)
            .map(Optional::get);
}
 
开发者ID:poetix,项目名称:octarine,代码行数:8,代码来源:BsonRecordDeserialiser.java


示例19: applyUnsafe

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public PMap<String, T> applyUnsafe(BsonValue p) throws BsonInvalidOperationException {
    BsonDocument doc = p.asDocument();
    Map<String, T> values = new HashMap<>();
    for (Map.Entry<String,BsonValue> e : doc.entrySet()) {
        values.put(e.getKey(), valueDeserialiser.apply(e.getValue()));
    }

    return HashTreePMap.from(values);
}
 
开发者ID:poetix,项目名称:octarine,代码行数:11,代码来源:BsonMapDeserialiser.java


示例20: addDecodeStatements

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public void addDecodeStatements(TypeMirror type, CodeGeneratorContext ctx) {
	MethodSpec.Builder builder = ctx.builder();

	if (Util.isSameType(type, Boolean.class)) {
		builder.addStatement(ctx.setter("$T.valueOf(reader.readBoolean())"),
				Boolean.class);
	}
	else if (Util.isSameType(type, Byte.class)) {
		builder.addStatement(ctx.setter("$T.valueOf((byte)reader.readInt32())"),
				Byte.class);
	}
	else if (Util.isSameType(type, Short.class)) {
		builder.addStatement(ctx.setter("$T.valueOf((short)reader.readInt32())"),
				Short.class);
	}
	else if (Util.isSameType(type, Integer.class)) {
		builder.addStatement(ctx.setter("$T.valueOf(reader.readInt32())"),
				Integer.class);
	}
	else if (Util.isSameType(type, Long.class)) {
		builder.addStatement(ctx.setter("$T.valueOf(reader.readInt64())"),
				Long.class);
	}
	else if (Util.isSameType(type, Character.class)) {
		builder.addStatement("String string = reader.readString()");
		builder.beginControlFlow("if (string.length() != 1)");
		builder.addStatement(
				"throw new $T(String.format(\"Attempting to builder the string '%s' to a character, but its length is not equal to one\", string))",
				BsonInvalidOperationException.class);
		builder.endControlFlow();
		builder.addStatement(ctx.setter("$T.valueOf(string.charAt(0))"),
				Character.class);
	}
	else if (Util.isSameType(type, Float.class)) {
		builder.addStatement(ctx.setter("$T.valueOf((float)reader.readDouble())"),
				Float.class);
	}
	else if (Util.isSameType(type, Double.class)) {
		builder.addStatement(ctx.setter("$T.valueOf(reader.readDouble())"),
				Double.class);
	}
}
 
开发者ID:ralscha,项目名称:bsoncodec-apt,代码行数:44,代码来源:PrimitiveWrapperDelegate.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CancelDelegationTokenOp类代码示例发布时间:2022-05-22
下一篇:
Java PacketListener类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap