Java Code Examples for org.bson.BsonValue#getBsonType()
The following examples show how to use
org.bson.BsonValue#getBsonType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoQueryService.java From epcis with Apache License 2.0 | 5 votes |
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; }
Example 2
Source File: MongoQueryService.java From epcis with Apache License 2.0 | 5 votes |
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; }
Example 3
Source File: MongoTypeUtil.java From syncer with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static Object convertBson(BsonValue value) { switch (value.getBsonType()) { case INT64: return value.asInt64().getValue(); case INT32: return value.asInt32().getValue(); case BINARY: return value.asBinary().getData(); case DOUBLE: return value.asDouble().getValue(); case STRING: return value.asString().getValue(); case BOOLEAN: return value.asBoolean().getValue(); case DATE_TIME: // java mongo driver return date as java.util.Date return new Date(value.asDateTime().getValue()); case DECIMAL128: return value.asDecimal128().getValue().bigDecimalValue(); case OBJECT_ID: return value.asObjectId().toString(); case NULL: return null; case ARRAY: List<BsonValue> values = value.asArray().getValues(); List<Object> list = new ArrayList<>(); for (BsonValue bsonValue : values) { list.add(convertBson(bsonValue)); } return list; case DOCUMENT: HashMap<String, Object> map = new HashMap<>(); for (Map.Entry<String, BsonValue> o : value.asDocument().entrySet()) { map.put(o.getKey(), convertBson(o.getValue())); } return map; case TIMESTAMP: default: return value; } }
Example 4
Source File: MongoQueryService.java From epcis with Apache License 2.0 | 4 votes |
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; }
Example 5
Source File: MongoQueryService.java From epcis with Apache License 2.0 | 4 votes |
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; }