/** * Convert a given {@literal value} into a {@link Document}. * * @param value can be {@literal null}. * @return an empty {@link Document} if the source value is {@literal null}. */ protected Document toDocument(@Nullable Object value) { if (value instanceof Document) { return (Document) value; } Document document = new Document(); if (value != null) { converter.write(value, document); } return document; } }
@Override public BulkOperations insert(Object document) { Assert.notNull(document, "Document must not be null!"); if (document instanceof Document) { models.add(new InsertOneModel<>((Document) document)); return this; } Document sink = new Document(); mongoOperations.getConverter().write(document, sink); models.add(new InsertOneModel<>(sink)); return this; }
log.debug("Flush: saving: {}", dbQuery); mongoTemplate.getConverter().write(value, dbDoc); dbDoc.put(ENTITY_FIELD_CLASS, value.getClass().getName()); if (dbId != null) {
public ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType, @Nullable Object metadata) { Document document = null; if (metadata != null) { document = new Document(); converter.write(metadata, document); } return store(content, filename, contentType, document); }
@Override public BulkOperations insert(Object document) { Assert.notNull(document, "Document must not be null!"); if (document instanceof Document) { models.add(new InsertOneModel<>((Document) document)); return this; } Document sink = new Document(); mongoOperations.getConverter().write(document, sink); models.add(new InsertOneModel<>(sink)); return this; }
public DBObject toDBObject(Object obj) { DBObject dbObject = new BasicDBObject(); if (isStandardClass(obj.getClass())) { obj = new ValueWrapper(obj); } mongoTemplate.getConverter().write(obj, dbObject); return dbObject; }
@RestController public class MyWebservice { @Autowired private MongoConverter mongoConverter; @RequestMapping(value = "/order/{id}", method = PATCH, produces = APPLICATION_JSON_UTF8_VALUE, consumes = APPLICATION_JSON_UTF8_VALUE) public Order updateOrder(@PathVariable("id") String id, @RequestBody Order order) throws JsonProcessingException { order.setId(id); DBObject update = getDbObject(order); mongoTemplate.updateFirst(query(where("id").is(id)), Update.fromDBObject(new BasicDBObject("$set", update)).push("events", order), Order.class); return mongoTemplate.findOne(query(where("id").is(id)), Order.class); } private DBObject getDbObject(Object o) { BasicDBObject basicDBObject = new BasicDBObject(); mongoConverter.write(o, basicDBObject); return basicDBObject; } }
private void saveSnapshot(R record) { Preconditions.checkState(keepHistory, "keepHistory is disabled"); BasicDBObject dbDoc = new BasicDBObject(); mappingConverter.write(new HistoryRecord(record), dbDoc); dbDoc.append(F_RECORD_FK, new DBRef(null, collectionName, record.getId())); logger.trace("saving snapshot v."+record.getVer()+" of "+ record.getId()); mongoTemplate.getCollection(collectionNameHist).insert(dbDoc); }
log.debug("Flush: saving: {}", dbQuery); mongoTemplate.getConverter().write(value, dbDoc); dbDoc.put(ENTITY_FIELD_CLASS, value.getClass().getName()); if (dbId != null) {