Example usage for com.mongodb DBObject putAll

List of usage examples for com.mongodb DBObject putAll

Introduction

In this page you can find the example usage for com.mongodb DBObject putAll.

Prototype

void putAll(BSONObject o);

Source Link

Document

Sets all key/value pairs from an object into this object

Usage

From source file:v7db.files.mongodb.V7GridFS.java

License:Open Source License

private void updateContents(DBObject metaData, InputStream contents) throws IOException {

    Object fileId = metaData.get("_id");
    ContentPointer oldContents = getContentPointer(metaData);
    String filename = (String) metaData.get("filename");
    String contentType = (String) metaData.get("contentType");

    BSONObject newContent = storage.insertContentsAndBackRefs(contents, fileId, filename, contentType);

    // check if it has changed
    ContentPointer newContents = getContentPointer(newContent);
    if (newContents.contentEquals(oldContents))
        return;//from w w  w.ja  v  a  2 s .  c  om

    metaData.removeField("sha");
    metaData.removeField("length");
    metaData.removeField("in");

    metaData.putAll(newContent);

    updateMetaData(metaData);
}

From source file:v7db.files.mongodb.V7GridFS.java

License:Open Source License

private void updateContents(DBObject metaData, byte[] contents, int offset, int len) throws IOException {

    Object fileId = metaData.get("_id");
    ContentPointer oldContents = getContentPointer(metaData);
    String filename = (String) metaData.get("filename");
    String contentType = (String) metaData.get("contentType");

    // for up to 55 bytes, storing the complete file inline
    // takes less space than just storing the SHA-1 and length
    // 20 (SHA-1) + 1 (sha - in) + 6 (length) + 4 (int32) + 2*12
    // (ObjectId back-references)
    BSONObject newContent = storage.inlineOrInsertContentsAndBackRefs(55, contents, offset, len, fileId,
            filename, contentType);/*w w  w.  j ava2s .c o  m*/

    // check if it has changed
    ContentPointer newContents = getContentPointer(newContent);
    if (newContents.contentEquals(oldContents))
        return;

    metaData.removeField("sha");
    metaData.removeField("length");
    metaData.removeField("in");

    metaData.putAll(newContent);

    updateMetaData(metaData);
}

From source file:v7views.mongo.V7Collection.java

License:Open Source License

private DBObject merge(BSONBackedObject filter, DBObject baseFilter) {
    DBObject x = filter == null ? new BasicDBObject() : filter.getDBObject();
    if (baseFilter != null) {
        x.putAll(baseFilter);
    }/*from  ww w  . j  a va 2  s.c  o  m*/
    return x;
}