Java Code Examples for org.bson.BsonType#INT32

The following examples show how to use org.bson.BsonType#INT32 . 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: AbstractJsonCodec.java    From vertx-mongo-client with Apache License 2.0 6 votes vote down vote up
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;
  }
}
 
Example 2
Source File: BsonReaderWrapper.java    From core-ng-project with Apache License 2.0 5 votes vote down vote up
public Integer readInteger(String field) {
    BsonType currentType = reader.getCurrentBsonType();
    if (currentType == BsonType.NULL) {
        reader.readNull();
        return null;
    } else if (currentType == BsonType.INT32) {
        return reader.readInt32();
    } else {
        logger.warn("unexpected field type, field={}, type={}", field, currentType);
        reader.skipValue();
        return null;
    }
}
 
Example 3
Source File: BsonReaderWrapper.java    From core-ng-project with Apache License 2.0 5 votes vote down vote up
public Long readLong(String field) {
    BsonType currentType = reader.getCurrentBsonType();
    if (currentType == BsonType.NULL) {
        reader.readNull();
        return null;
    } else if (currentType == BsonType.INT32) {
        return (long) reader.readInt32();
    } else if (currentType == BsonType.INT64) {
        return reader.readInt64();
    } else {
        logger.warn("unexpected field type, field={}, type={}", field, currentType);
        reader.skipValue();
        return null;
    }
}
 
Example 4
Source File: MongoQueryService.java    From epcis with Apache License 2.0 4 votes vote down vote up
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 vote down vote up
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;
}