本文整理汇总了Java中org.bson.BsonType.DOCUMENT属性的典型用法代码示例。如果您正苦于以下问题:Java BsonType.DOCUMENT属性的具体用法?Java BsonType.DOCUMENT怎么用?Java BsonType.DOCUMENT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.bson.BsonType
的用法示例。
在下文中一共展示了BsonType.DOCUMENT属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleArrayForBsonReader
private Object handleArrayForBsonReader(BsonReader bsonReader, Field field, BsonMapperConfig bsonMapperConfig) {
Class<?> fieldType = field.getType();
ArrayList<Object> arrayList = new ArrayList<Object>();
bsonReader.readStartArray();
while (bsonReader.readBsonType() != BsonType.END_OF_DOCUMENT) {
BsonType currentBsonType = bsonReader.getCurrentBsonType();
if (currentBsonType == BsonType.NULL) {
continue;
}
if (currentBsonType == BsonType.ARRAY) {
arrayList.add(decode(bsonReader, field, bsonMapperConfig));
} else {
Object javaValue;
if (currentBsonType == BsonType.DOCUMENT) {
javaValue = BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonReader, fieldType.getComponentType(), bsonMapperConfig);
} else {
javaValue = BsonValueConverterRepertory.getByteIOConverterByBsonType(currentBsonType).decode(bsonReader);
}
arrayList.add(javaValue);
}
}
bsonReader.readEndArray();
return arrayList.toArray((Object[]) Array.newInstance(fieldType.getComponentType(), 0));
}
示例2: getBsonType
protected BsonType getBsonType(Object value) {
if (value == null) {
return BsonType.NULL;
} else if (value instanceof Boolean) {
return BsonType.BOOLEAN;
} else if (value instanceof Double) {
return BsonType.DOUBLE;
} else if (value instanceof Integer) {
return BsonType.INT32;
} else if (value instanceof Long) {
return BsonType.INT64;
} else if (value instanceof String) {
return BsonType.STRING;
} else if (isObjectIdInstance(value)) {
return BsonType.OBJECT_ID;
} else if (isObjectInstance(value)) {
return BsonType.DOCUMENT;
} else if (isArrayInstance(value)) {
return BsonType.ARRAY;
} else {
return null;
}
}
示例3: decode
@Override
default T decode(BsonReader reader, DecoderContext decoderContext) {
T newInstance;
if (reader.getCurrentBsonType() == null || reader.getCurrentBsonType() == BsonType.DOCUMENT) {
reader.readStartDocument();
newInstance = decodeFields(reader, decoderContext, newInstance());
reader.readEndDocument();
return newInstance;
} else {
LOGGER.error("Expected to read document but reader is in state {}. Skipping value!", reader.getCurrentBsonType());
reader.skipValue();
return null;
}
}
示例4: getJavaValueByBinaryReader
private Object getJavaValueByBinaryReader(BsonReader bsonReader, Field field, BsonMapperConfig bsonMapperConfig) {
BsonType currentBsonType = bsonReader.getCurrentBsonType();
if (currentBsonType == BsonType.DOCUMENT) {
return decode(bsonReader, field.getType(), bsonMapperConfig);
}
if (currentBsonType == BsonType.ARRAY) {
return BsonValueConverterRepertory.getBsonArrayConverter().decode(bsonReader, field, bsonMapperConfig);
}
if (currentBsonType == BsonType.OBJECT_ID) {
ObjectId objectId = (ObjectId) BsonValueConverterRepertory.getByteIOConverterByBsonType(currentBsonType).decode(bsonReader);
return getObjectIdByRealType(field.getType(), objectId);
}
return BsonValueConverterRepertory.getByteIOConverterByBsonType(currentBsonType).decode(bsonReader);
}
示例5: handleCollectionForBsonReader
Object handleCollectionForBsonReader(BsonReader bsonReader, Field field, BsonMapperConfig bsonMapperConfig) {
Class<?> fieldType = field.getType();
Class<?> implClass = Utils.giveImplClassIfSupport(fieldType);
if (Utils.isUnableAddCollectionClazz(implClass)) {
return null;
}
BsonArrayField bsonArrayField = Utils.getBsonArrayFieldAnnotation(field);
Class<?> targetComponentClazz = bsonArrayField.componentType();
Object collectionObject = Utils.newInstanceByClazz(implClass);
Method method;
try {
method = implClass.getMethod("add", Object.class);
} catch (NoSuchMethodException e) {
throw new BsonMapperConverterException("NoSuchMethodException", e);
}
bsonReader.readStartArray();
while (bsonReader.readBsonType() != BsonType.END_OF_DOCUMENT) {
BsonType currentBsonType = bsonReader.getCurrentBsonType();
if (currentBsonType == BsonType.NULL) {
continue;
}
if (currentBsonType == BsonType.ARRAY) {
Utils.methodInvoke(method, collectionObject, decode(bsonReader, field, bsonMapperConfig));
} else {
Object javaValue;
if (currentBsonType == BsonType.DOCUMENT) {
javaValue = BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonReader, targetComponentClazz, bsonMapperConfig);
} else {
javaValue = BsonValueConverterRepertory.getByteIOConverterByBsonType(currentBsonType).decode(bsonReader);
}
Utils.methodInvoke(method, collectionObject, javaValue);
}
}
bsonReader.readEndArray();
return collectionObject;
}
示例6: startReadMap
public Map<String, ?> startReadMap(String field) {
BsonType currentType = reader.getCurrentBsonType();
if (currentType == BsonType.NULL) {
reader.readNull();
return null;
}
if (currentType != BsonType.DOCUMENT) {
logger.warn("unexpected field type, field={}, type={}", field, currentType);
reader.skipValue();
return null;
}
return new LinkedHashMap<>();
}
示例7: startReadEntity
public boolean startReadEntity(String field) {
BsonType currentType = reader.getCurrentBsonType();
if (currentType != null && currentType == BsonType.NULL) {
reader.readNull();
return false;
}
if (currentType != null && currentType != BsonType.DOCUMENT) {
logger.warn("unexpected field type, field={}, type={}", field, currentType);
reader.skipValue();
return false;
}
return true;
}
示例8: isExtensionFilterPassed
private boolean isExtensionFilterPassed(String type, BsonArray paramArray, BsonDocument ext, boolean isTopLevel) {
type = MongoWriterUtil.encodeMongoObjectKey(type);
Iterator<String> keyIterator = ext.keySet().iterator();
while (keyIterator.hasNext()) {
String key = keyIterator.next();
BsonValue sub = ext.get(key);
if (isTopLevel == false) {
if (key.equals(type)) {
for (int i = 0; i < paramArray.size(); i++) {
BsonValue param = paramArray.get(i);
if (sub.getBsonType() == param.getBsonType() && sub.toString().equals(param.toString())) {
return true;
}
if (param.getBsonType() == BsonType.REGULAR_EXPRESSION
&& sub.getBsonType() == BsonType.STRING) {
if (Pattern.matches(param.asRegularExpression().getPattern(), sub.asString().getValue()))
return true;
}
}
return false;
}
}
if (sub.getBsonType() == BsonType.DOCUMENT) {
if (isExtensionFilterPassed(type, paramArray, sub.asDocument(), false) == true) {
return true;
}
}
}
return false;
}
示例9: isCompExtensionFilterPassed
private boolean isCompExtensionFilterPassed(String type, String comp, BsonArray paramArray, BsonDocument ext) {
type = MongoWriterUtil.encodeMongoObjectKey(type);
Iterator<String> keyIterator = ext.keySet().iterator();
while (keyIterator.hasNext()) {
String key = keyIterator.next();
BsonValue sub = ext.get(key);
if (key.equals(type)) {
for (int i = 0; i < paramArray.size(); i++) {
BsonValue param = paramArray.get(i);
if (sub.getBsonType() == param.getBsonType()) {
if (sub.getBsonType() == BsonType.INT32) {
if (comp.equals("GT")) {
if (sub.asInt32().getValue() > param.asInt32().getValue())
return true;
} else if (comp.equals("GE")) {
if (sub.asInt32().getValue() >= param.asInt32().getValue())
return true;
} else if (comp.equals("LT")) {
if (sub.asInt32().getValue() < param.asInt32().getValue())
return true;
} else if (comp.equals("LE")) {
if (sub.asInt32().getValue() <= param.asInt32().getValue())
return true;
}
} else if (sub.getBsonType() == BsonType.INT64) {
if (comp.equals("GT")) {
if (sub.asInt64().getValue() > param.asInt64().getValue())
return true;
} else if (comp.equals("GE")) {
if (sub.asInt64().getValue() >= param.asInt64().getValue())
return true;
} else if (comp.equals("LT")) {
if (sub.asInt64().getValue() < param.asInt64().getValue())
return true;
} else if (comp.equals("LE")) {
if (sub.asInt64().getValue() <= param.asInt64().getValue())
return true;
}
} else if (sub.getBsonType() == BsonType.DOUBLE) {
if (comp.equals("GT")) {
if (sub.asDouble().getValue() > param.asDouble().getValue())
return true;
} else if (comp.equals("GE")) {
if (sub.asDouble().getValue() >= param.asDouble().getValue())
return true;
} else if (comp.equals("LT")) {
if (sub.asDouble().getValue() < param.asDouble().getValue())
return true;
} else if (comp.equals("LE")) {
if (sub.asDouble().getValue() <= param.asDouble().getValue())
return true;
}
} else if (sub.getBsonType() == BsonType.DATE_TIME) {
if (comp.equals("GT")) {
if (sub.asDateTime().getValue() > param.asDateTime().getValue())
return true;
} else if (comp.equals("GE")) {
if (sub.asDateTime().getValue() >= param.asDateTime().getValue())
return true;
} else if (comp.equals("LT")) {
if (sub.asDateTime().getValue() < param.asDateTime().getValue())
return true;
} else if (comp.equals("LE")) {
if (sub.asDateTime().getValue() <= param.asDateTime().getValue())
return true;
}
}
}
}
return false;
}
if (sub.getBsonType() == BsonType.DOCUMENT) {
if (isCompExtensionFilterPassed(type, comp, paramArray, sub.asDocument()) == true) {
return true;
}
}
}
return false;
}