Java Code Examples for org.bson.BsonType#DATE_TIME

The following examples show how to use org.bson.BsonType#DATE_TIME . 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: LocalDateTimeCodec.java    From core-ng-project with Apache License 2.0 5 votes vote down vote up
static LocalDateTime read(BsonReader reader, String field) {
    BsonType currentType = reader.getCurrentBsonType();
    if (currentType == BsonType.NULL) {
        reader.readNull();
        return null;
    } else if (currentType == BsonType.DATE_TIME) {
        return LocalDateTime.ofInstant(Instant.ofEpochMilli(reader.readDateTime()), ZoneId.systemDefault());
    } else {
        LOGGER.warn("unexpected field type, field={}, type={}", field, currentType);
        reader.skipValue();
        return null;
    }
}
 
Example 2
Source File: ZonedDateTimeCodec.java    From core-ng-project with Apache License 2.0 5 votes vote down vote up
static ZonedDateTime read(BsonReader reader, String field) {
    BsonType currentType = reader.getCurrentBsonType();
    if (currentType == BsonType.NULL) {
        reader.readNull();
        return null;
    } else if (currentType == BsonType.DATE_TIME) {
        return ZonedDateTime.ofInstant(Instant.ofEpochMilli(reader.readDateTime()), ZoneId.systemDefault());
    } else {
        LOGGER.warn("unexpected field type, field={}, type={}", field, currentType);
        reader.skipValue();
        return null;
    }
}
 
Example 3
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 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;
}