Search in sources :

Example 26 with BSONObject

use of org.bson.BSONObject in project mongo-java-driver by mongodb.

the class DefaultDBCallback method objectDone.

@Override
public Object objectDone() {
    String name = curName();
    BSONObject document = (BSONObject) super.objectDone();
    if (!(document instanceof BasicBSONList)) {
        Iterator<String> iterator = document.keySet().iterator();
        if (iterator.hasNext() && iterator.next().equals("$ref") && iterator.hasNext() && iterator.next().equals("$id")) {
            _put(name, new DBRef((String) document.get("$db"), (String) document.get("$ref"), document.get("$id")));
        }
    }
    return document;
}
Also used : BasicBSONList(org.bson.types.BasicBSONList) BSONObject(org.bson.BSONObject)

Example 27 with BSONObject

use of org.bson.BSONObject in project camel by apache.

the class MongoDbConversionsTest method testInsertBsonInputStream.

@Test
public void testInsertBsonInputStream() {
    assertEquals(0, testCollection.count());
    DefaultDBEncoder encoder = new DefaultDBEncoder();
    BSONObject bsonObject = new BasicDBObject();
    bsonObject.put("_id", "testInsertBsonString");
    Object result = template.requestBody("direct:insertJsonString", new ByteArrayInputStream(encoder.encode(bsonObject)));
    DBObject b = testCollection.find(new BasicDBObject("_id", "testInsertBsonString")).first();
    assertNotNull("No record with 'testInsertBsonString' _id", b);
}
Also used : DefaultDBEncoder(com.mongodb.DefaultDBEncoder) BasicDBObject(com.mongodb.BasicDBObject) ByteArrayInputStream(java.io.ByteArrayInputStream) BSONObject(org.bson.BSONObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) BSONObject(org.bson.BSONObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Test(org.junit.Test)

Example 28 with BSONObject

use of org.bson.BSONObject in project v7files by thiloplanz.

the class MapUtils method get.

private static Object get(Map<?, ?> b, String fieldName) {
    if (!fieldName.contains("."))
        return notNull(b.get(fieldName));
    String[] path = StringUtils.split(fieldName, ".", 2);
    Object nested = b.get(path[0]);
    if (nested == null)
        return null;
    if (nested instanceof BSONObject)
        return BSONUtils.get((BSONObject) nested, path[1]);
    if (nested instanceof Map<?, ?>)
        return get((Map<?, ?>) nested, path[1]);
    throw new IllegalArgumentException("cannot get field `" + fieldName + "` of " + b);
}
Also used : BSONObject(org.bson.BSONObject) BSONObject(org.bson.BSONObject) Map(java.util.Map)

Example 29 with BSONObject

use of org.bson.BSONObject in project v7files by thiloplanz.

the class BucketsServlet method doEchoPutGet.

private void doEchoPutGet(HttpServletRequest request, HttpServletResponse response, BSONObject bucket, byte[] sha) throws IOException {
    Content content = storage.getContent(sha);
    if (content == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Bucket '" + bucket.get("_id") + "' does not have a file matching digest '" + Hex.encodeHexString(sha) + "'");
        return;
    }
    BSONObject file = new BasicBSONObject("sha", sha);
    String customFilename = request.getParameter("filename");
    if (StringUtils.isNotBlank(customFilename))
        file.put("filename", customFilename);
    sendFile(request, response, sha, file, content);
}
Also used : BasicBSONObject(org.bson.BasicBSONObject) InlineContent(v7db.files.spi.InlineContent) Content(v7db.files.spi.Content) BasicBSONObject(org.bson.BasicBSONObject) BSONObject(org.bson.BSONObject)

Example 30 with BSONObject

use of org.bson.BSONObject in project v7files by thiloplanz.

the class BucketsServlet method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String _id = request.getPathInfo().substring(1);
    BSONObject bucket = bucketCollection.findOne(_id);
    if (bucket == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Bucket '" + _id + "' not found");
        return;
    }
    String mode = BSONUtils.getString(bucket, "POST");
    if ("FormPost".equals(mode)) {
        doFormPost(request, response, bucket);
        return;
    }
    // method not allowed
    super.doPost(request, response);
}
Also used : BasicBSONObject(org.bson.BasicBSONObject) BSONObject(org.bson.BSONObject)

Aggregations

BSONObject (org.bson.BSONObject)66 BasicBSONObject (org.bson.BasicBSONObject)31 BasicDBObject (com.mongodb.BasicDBObject)19 DBObject (com.mongodb.DBObject)10 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)6 LazyBSONObject (org.bson.LazyBSONObject)5 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)4 BSONFileSplit (com.mongodb.hadoop.input.BSONFileSplit)4 BSONWritable (com.mongodb.hadoop.io.BSONWritable)4 DBCollection (com.sequoiadb.base.DBCollection)4 Map (java.util.Map)4 ObjectId (org.bson.types.ObjectId)4 DBRef (com.mongodb.DBRef)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Configuration (org.apache.hadoop.conf.Configuration)3 Tuple (org.apache.pig.data.Tuple)3