Example usage for com.mongodb BasicDBObject BasicDBObject

List of usage examples for com.mongodb BasicDBObject BasicDBObject

Introduction

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

Prototype

public BasicDBObject(final Map map) 

Source Link

Document

Creates an object from a map.

Usage

From source file:ch.agent.crnickl.mongodb.MongoDatabaseMethods.java

License:Apache License

protected <T> com.mongodb.DBObject asQuery(DBObjectId id) throws T2DBException {
    com.mongodb.DBObject bo = new BasicDBObject(1);
    try {//from w ww .  j  av a  2 s .  c o  m
        bo.put(MongoDatabase.FLD_ID, ((MongoDBObjectId) id).value());
    } catch (ClassCastException e) {
        throw T2DBMMsg.exception(e, J.J81012, id.toString());
    }
    return bo;
}

From source file:ch.agent.crnickl.mongodb.MongoDatabaseMethods.java

License:Apache License

/**
 * Return an array of key-value pairs as a DBObject. The array must be
 * non-empty and its length must be even. Non-even elements (the keys) must
 * be non-null Strings. Even elements must be BSON compatible (this is not
 * enforced by this method but violations are detected later).
 * /*  w w  w. j av a  2s  . c  om*/
 * @param arg
 *            an non-empty array of arguments of even length
 * @return a DBObject
 * @throws IllegalArgumentException
 */
protected com.mongodb.DBObject mongoObject(Object... arg) {
    if (arg.length == 0 || arg.length % 2 != 0)
        throw new IllegalArgumentException(new T2DBMMsg(J.J81014, arg.length).toString());
    com.mongodb.DBObject operand = new BasicDBObject(arg.length / 2);
    for (int i = 0; i < arg.length; i++) {
        if (arg[i] == null)
            throw new IllegalArgumentException(new T2DBMMsg(J.J81016, i).toString());
        try {
            operand.put((String) arg[i], arg[++i]);
        } catch (ClassCastException e) {
            throw new IllegalArgumentException(new T2DBMMsg(J.J81016, i).toString(), e);
        }
    }
    return operand;
}