@Override public void encode(final BsonWriter writer, final BsonObjectId value, final EncoderContext encoderContext) { writer.writeObjectId(value.getValue()); }
@Override protected ObjectId doReadObjectId() { return currentValue.asObjectId().getValue(); }
private static ObjectId getElectionId(final BsonDocument isMasterResult) { return isMasterResult.containsKey("electionId") ? isMasterResult.getObjectId("electionId").getValue() : null; }
@Override public ObjectId getObjectId() { if (!fileId.isObjectId()) { throw new MongoGridFSException("Custom id type used for this GridFS upload stream"); } return fileId.asObjectId().getValue(); }
/** * The {@link ObjectId} for this file. * * Throws a MongoGridFSException if the file id is not an ObjectId. * * @return the id for this file. */ public ObjectId getObjectId() { if (!id.isObjectId()) { throw new MongoGridFSException("Custom id type used for this GridFS file"); } return id.asObjectId().getValue(); }
public void delete(Query query) { for (GridFSFile gridFSFile : find(query)) { getGridFs().delete(((BsonObjectId) gridFSFile.getId()).getValue()); } }
colValue = keyvalueforStruct.getValue().asObjectId().getValue().toString(); break; list.add(temp); } else if (arrValue.getBsonType() == BsonType.OBJECT_ID && valueType == BsonType.OBJECT_ID) { String temp = arrValue.asObjectId().getValue().toString(); list.add(temp); } else if (arrValue.getBsonType() == BsonType.DOUBLE && valueType == BsonType.DOUBLE) {
@Test public void withDate() { final Date date = new Date(); final ObjectId id = ObjectId.get(); final Jackson expected = ImmutableJackson.builder() .id(id) .prop1("prop1") .prop2("22") .date(new Date(date.getTime())) .build(); repository.insert(expected).getUnchecked(); check(collection.count()).is(1L); final Jackson actual = repository.findAll().fetchAll().getUnchecked().get(0); check(expected).is(actual); final BsonDocument doc = collection.find().first(); check(doc.keySet()).hasContentInAnyOrder("_id", "prop1", "prop2", "date", "uuid"); check(doc.get("date").asDateTime().getValue()).is(date.getTime()); check(doc.get("_id").asObjectId().getValue()).is(id); }
return value.asBoolean().getValue(); case OBJECT_ID: return value.asObjectId().getValue(); case DB_POINTER: return new DBRef(value.asDBPointer().getNamespace(), value.asDBPointer().getId());
public void delete(Query query) { for (GridFSFile x : find(query)) { getGridFs().delete(((BsonObjectId) x.getId()).getValue()); } }
break; case OBJECT_ID: writeObjectId(value.asObjectId().getValue()); break; case BOOLEAN:
private Object extractValue(BsonObjectId value, Class<?> valueType) { if (String.class.equals(valueType)) { return value.asObjectId().getValue().toHexString(); } else if (ObjectId.class.equals(valueType)) { return value.asObjectId().getValue(); } throw new IllegalArgumentException("Unsupported ID type: " + value.getClass()); }
return value.asBoolean().getValue(); case OBJECT_ID: return value.asObjectId().getValue(); case DB_POINTER: return new DBRef(value.asDBPointer().getNamespace(), value.asDBPointer().getId());
private static ObjectId getElectionId(final BsonDocument isMasterResult) { return isMasterResult.containsKey("electionId") ? isMasterResult.getObjectId("electionId").getValue() : null; }
@Override public ObjectId getObjectId() { if (!fileId.isObjectId()) { throw new MongoGridFSException("Custom id type used for this GridFS upload stream"); } return fileId.asObjectId().getValue(); }
/** * The {@link ObjectId} for this file. * * Throws a MongoGridFSException if the file id is not an ObjectId. * * @return the id for this file. */ public ObjectId getObjectId() { if (!id.isObjectId()) { throw new MongoGridFSException("Custom id type used for this GridFS file"); } return id.asObjectId().getValue(); }
@Override public ObjectId getObjectId() { if (!fileId.isObjectId()) { throw new MongoGridFSException("Custom id type used for this GridFS upload stream"); } return fileId.asObjectId().getValue(); }
/** * * @param exchange * @param etag * @return */ public static boolean checkReadEtag(HttpServerExchange exchange, BsonObjectId etag) { if (etag == null) { return false; } HeaderValues vs = exchange.getRequestHeaders().get(Headers.IF_NONE_MATCH); return vs == null || vs.getFirst() == null ? false : vs.getFirst().equals(etag.getValue().toString()); }
private void _transform(BsonDocument data) { data.keySet().stream().forEach(key -> { BsonValue value = data.get(key); if (value.isDocument()) { _transform(value.asDocument()); } else if (value.isObjectId()) { data.put(key, new BsonString(value .asObjectId() .getValue() .toString())); } }); } }
private static String getIdAsStringNoBrachets(BsonValue id) throws UnsupportedDocumentIdException { if (id == null) { return null; } else if (id.isString()) { return id.asString().getValue(); } else if (id.isObjectId()) { return id.asObjectId().getValue().toHexString(); } else { return JsonUtils.minify( JsonUtils.toJson(id)); } }