@Override public BsonDateTime decode(final BsonReader reader, final DecoderContext decoderContext) { return new BsonDateTime(reader.readDateTime()); }
@Override protected void doWriteDateTime(final long value) { write(new BsonDateTime(value)); }
@Override @SuppressWarnings("deprecation") public void encode(final BsonWriter writer, final GridFSFile value, final EncoderContext encoderContext) { BsonDocument bsonDocument = new BsonDocument(); bsonDocument.put("_id", value.getId()); bsonDocument.put("filename", new BsonString(value.getFilename())); bsonDocument.put("length", new BsonInt64(value.getLength())); bsonDocument.put("chunkSize", new BsonInt32(value.getChunkSize())); bsonDocument.put("uploadDate", new BsonDateTime(value.getUploadDate().getTime())); if (value.getMD5() != null) { bsonDocument.put("md5", new BsonString(value.getMD5())); } Document metadata = value.getMetadata(); if (metadata != null) { bsonDocument.put("metadata", new BsonDocumentWrapper<Document>(metadata, documentCodec)); } Document extraElements = value.getExtraElements(); if (extraElements != null) { bsonDocument.putAll(new BsonDocumentWrapper<Document>(extraElements, documentCodec)); } bsonDocumentCodec.encode(writer, bsonDocument, encoderContext); }
@Override public BsonValue toBson(Object data) { return new BsonDateTime(((java.util.Date)data).getTime()); } }
@Override public BsonValue toBson(Object data) { return new BsonDateTime(((java.util.Date)data).getTime()); } }
@Override public BsonValue toBson(Object data) { return new BsonDateTime(((java.util.Date)data).getTime()); } }
@Override public BsonValue toBson(Object data) { return new BsonDateTime(((java.util.Date)data).getTime()); } }
@Override public BsonValue toBson(Object data) { return new BsonDateTime(((java.util.Date)data).getTime()); } }
@Override public BsonValue toBson(Object data) { return new BsonDateTime(((java.util.Date)data).getTime()); } }
private Object convertObject(DomainSpecificValue domainSpecificValue) { Object value = domainSpecificValue.getValue(); if (value == null) { return null; } if (value.getClass().isArray()) { List<Object> newValue = new ArrayList<>(((Object[])value).length); Collections.addAll(newValue, (Object[])value); value = newValue; } else if (ReadableInstant.class.isAssignableFrom(value.getClass())) { value = new BsonDateTime(((ReadableInstant)value).getMillis()); } return value; }
@Override protected void append(ILoggingEvent e) { ZoneId zoneId = ZoneId.of(this.zoneId); // Offset in milliseconds based on the informed Zone long offset = zoneId.getRules().getOffset(Instant.now()).getTotalSeconds() * 1000; Map<String, Object> objLog = new HashMap<>(); objLog.put("ts", new BsonDateTime(e.getTimeStamp() + offset)); objLog.put("trace", BasicDBObject.parse(e.getFormattedMessage())); objLog.put("level", e.getLevel().toString()); objLog.put("logger", e.getLoggerName()); objLog.put("thread", e.getThreadName()); if (e.hasCallerData()) { StackTraceElement st = e.getCallerData()[0]; String callerData = String.format("%s.%s:%d", st.getClassName(), st.getMethodName(), st.getLineNumber()); objLog.put("caller", callerData); } Map<String, String> mdc = e.getMDCPropertyMap(); if (mdc != null && !mdc.isEmpty()) { objLog.put("mdc", new BasicDBObject(mdc)); } collection.insertOne(new Document(objLog)); }
private static BsonDateTime getIdAsDate(String id) throws IllegalArgumentException { BsonValue ret = JsonUtils.parse(id); if (ret.isDateTime()) { return ret.asDateTime(); } else if (ret.isInt32()) { return new BsonDateTime(0l + ret.asInt32().getValue()); } else if (ret.isInt64()) { return new BsonDateTime(ret.asInt64().getValue()); } else { throw new IllegalArgumentException("The id is not a valid number " + id); } }
private ServerHeartbeatSucceededEvent newEvent(int connectionIndex, long localTime, long lastWriteDate) { ConnectionDescription description = connections.get(connectionIndex); BsonDocument reply = new BsonDocument("localTime", new BsonDateTime(localTime)); reply.put("hosts", new BsonArray(hostValues)); BsonDocument lastWrite = new BsonDocument("lastWriteDate", new BsonDateTime(lastWriteDate)); reply.put("lastWrite", lastWrite); return new ServerHeartbeatSucceededEvent(description.getConnectionId(), reply, 0); } }
@Override public BsonValue visit(DateValue value, Void arg) { Instant instant = value.getValue().atStartOfDay().toInstant(ZoneOffset.UTC); return new BsonDateTime(instant.toEpochMilli()); }
if (BsonBoolean.TRUE.equals(entry.getValue())) { ret.put(entry.getKey(), new BsonDateTime(currentTimeMillis)); } else if (entry.getValue().isDocument() && entry.getValue().asDocument(). entry.getValue().asDocument().get("$type"))) { ret.put(entry.getKey(), new BsonDateTime(currentTimeMillis));
@Override public WriteModel<BsonDocument> createWriteModel(SinkDocument document) { BsonDocument vd = document.getValueDoc().orElseThrow( () -> new DataException("error: cannot build the WriteModel since" + " the value document was missing unexpectedly") ); BsonDateTime dateTime = new BsonDateTime(Instant.now().toEpochMilli()); return new UpdateOneModel<>( new BsonDocument(DBCollection.ID_FIELD_NAME, vd.get(DBCollection.ID_FIELD_NAME)), new BsonDocument("$set", vd.append(FIELDNAME_MODIFIED_TS, dateTime)) .append("$setOnInsert", new BsonDocument(FIELDNAME_INSERTED_TS, dateTime)), UPDATE_OPTIONS ); } }
@Override public WriteModel<BsonDocument> createWriteModel(SinkDocument document) { BsonDocument vd = document.getValueDoc().orElseThrow( () -> new DataException("error: cannot build the WriteModel since" + " the value document was missing unexpectedly") ); BsonDateTime dateTime = new BsonDateTime(Instant.now().toEpochMilli()); return new UpdateOneModel<>( new BsonDocument(DBCollection.ID_FIELD_NAME, vd.get(DBCollection.ID_FIELD_NAME)), new BsonDocument("$set", vd.append(FIELDNAME_MODIFIED_TS, dateTime)) .append("$setOnInsert", new BsonDocument(FIELDNAME_INSERTED_TS, dateTime)), UPDATE_OPTIONS ); } }
new BsonDateTime(Instant.now().getEpochSecond() * 1000));
@Override @SuppressWarnings("deprecation") public void encode(final BsonWriter writer, final GridFSFile value, final EncoderContext encoderContext) { BsonDocument bsonDocument = new BsonDocument(); bsonDocument.put("_id", value.getId()); bsonDocument.put("filename", new BsonString(value.getFilename())); bsonDocument.put("length", new BsonInt64(value.getLength())); bsonDocument.put("chunkSize", new BsonInt32(value.getChunkSize())); bsonDocument.put("uploadDate", new BsonDateTime(value.getUploadDate().getTime())); if (value.getMD5() != null) { bsonDocument.put("md5", new BsonString(value.getMD5())); } Document metadata = value.getMetadata(); if (metadata != null) { bsonDocument.put("metadata", new BsonDocumentWrapper<Document>(metadata, documentCodec)); } Document extraElements = value.getExtraElements(); if (extraElements != null) { bsonDocument.putAll(new BsonDocumentWrapper<Document>(extraElements, documentCodec)); } bsonDocumentCodec.encode(writer, bsonDocument, encoderContext); }
return new BsonDateTime( ((com.torodb.mongowp.bson.BsonDateTime) value).getMillisFromUnix()); case DB_POINTER: {