Package com.mongodb

Examples of com.mongodb.DB$CommandResultPair


    @Override
    public void setUpCluster(MicroKernel[] cluster) throws Exception {
        MongoConnection connection = getMongoConnection();
        openConnection();
        DB db = connection.getDB();
        dropCollections(db);

        for (int i = 0; i < cluster.length; i++) {
            cluster[i] = new DocumentMK.Builder().
                    setMongoDB(db).setBlobStore(blobStore).setClusterId(i).open();
View Full Code Here


     * @return a DataContext object that matches the request
     */
    public static UpdateableDataContext createMongoDbDataContext(String hostname, Integer port, String databaseName,
            String username, char[] password, SimpleTableDef[] tableDefs) {
        try {
            DB mongoDb;
            if (port == null) {
                mongoDb = new Mongo(hostname).getDB(databaseName);
            } else {
                mongoDb = new Mongo(hostname, port).getDB(databaseName);
            }
            if (username != null) {
                mongoDb.authenticate(username, password);
            }

            if (tableDefs == null || tableDefs.length == 0) {
                return new MongoDbDataContext(mongoDb);
            }
View Full Code Here

    public DB getDB(String database, String username, String password) {

        if(log.isDebugEnabled()) {
            log.debug("username: " + username+", password: " + password+", database: " + database);
        }
        DB db = mongo.getDB(database);
        boolean authenticated = db.isAuthenticated();

        if(!authenticated) {
            if(username != null && password != null && username.length() > 0 && password.length() > 0) {
                authenticated = db.authenticate(username, password.toCharArray());
            }
        }
        if(log.isDebugEnabled()) {
            log.debug("authenticated: " + authenticated);
        }
View Full Code Here

        res.sampleStart();

        try {
            MongoDB mongoDB = MongoSourceElement.getMongoDB(getSource());
            MongoScriptRunner runner = new MongoScriptRunner();
            DB db = mongoDB.getDB(getDatabase(), getUsername(), getPassword());
            res.latencyEnd();
            Object result = runner.evaluate(db, data);
            EvalResultHandler handler = new EvalResultHandler();
            String resultAsString = handler.handle(result);
            res.setResponseData(resultAsString.getBytes());
View Full Code Here

        System.out.println("getDB");

        BeeMongo mongo = BeeMongo.getInstance();
        assertNotNull(mongo);

        DB db = mongo.getDB(DB_NAME, null, null);
        assertNotNull(db);

        boolean result = false;
        try {
            result = mongo.addUser(db, DB_USER, DB_PSW, false);
View Full Code Here

        System.out.println("getCollectionNames");

        BeeMongo mongo = BeeMongo.getInstance();
        assertNotNull(mongo);

        DB db = mongo.getDB(DB_NAME, DB_USER, DB_PSW);
        assertNotNull(db);
        Set<String> names = db.getCollectionNames();
        System.out.println("count: " + names.size());
        System.out.println(names.toString());
    }
View Full Code Here

     * @throws StandardCodedException
     */
    public final DB getDB(final String dbname,
            final String username, final String password) throws StandardCodedException {
        try {
            final DB db = this.getMongo().getDB(dbname);
            if (StringUtils.hasText(username)
                    && StringUtils.hasText(password)
                    && !db.isAuthenticated()) {
                if (!db.authenticate(username, password.toCharArray())) {
                    throw this.getError403();
                }
            }
            return db;
        } catch (UnknownHostException t) {
View Full Code Here

    public final boolean addUser(final String dbname, final String authusername,
            final String authpassword, final String username,
            final String password, final boolean readOnly) throws StandardCodedException {
        try {
            final DB db = this.getDB(dbname, authusername, authpassword);
            return this.addUser(db, username, password, readOnly);
        } catch (Throwable t) {
            throw this.getError500(t);
        }
    }
View Full Code Here

    }

    public final List<DBObject> getDBUsers(final String dbname, final String authusername,
            final String authpassword) throws StandardCodedException {
        try {
            final DB db = this.getDB(dbname, authusername, authpassword);
            if (null != db) {
                if (db.collectionExists(COLL_SYSTEMUSERS)) {
                    final DBCollection coll = db.getCollection(COLL_SYSTEMUSERS);
                    return coll.find().toArray();
                }
            }
        } catch (Throwable t) {
            throw this.getError500(t);
View Full Code Here

public class MongoDbTest {
   
    @Test
    @Ignore
    public void manyChildNodes() {
        DB db = MongoUtils.getConnection().getDB();
        MongoUtils.dropCollections(db);
        DBCollection nodes = db.getCollection(Collection.NODES.toString());
        DBObject index = new BasicDBObject();
        // modification time (descending)
        index.put("_mod", -1L);
        // and then id (ascending)
        index.put("_id", 1L);
        DBObject options = new BasicDBObject();
        // options.put("unique", Boolean.TRUE);
        nodes.ensureIndex(index, options)
       
        // index on (_id, _mod):
        // Query plan: { "cursor" : "BtreeCursor _id_1__mod_-1" ,
        // "isMultiKey" : false , "n" : 2000 , "nscannedObjects" : 2000 ,
        // "nscanned" : 954647 , "nscannedObjectsAllPlans" : 1907080 ,
        // "nscannedAllPlans" : 2859727 , "scanAndOrder" : false ,
        // "indexOnly" : true , "nYields" : 5 , "nChunkSkips" : 0 ,
        // "millis" : 5112 ,...
        // Time: 2229 ms
        // Count: 2000
       
        // index on (_mod, _id)
        // Query plan: { "cursor" : "BtreeCursor _mod_-1__id_1" ,
        // "isMultiKey" : false , "n" : 2000 , "nscannedObjects" : 2000 ,
        // "nscanned" : 2000 , "nscannedObjectsAllPlans" : 2203 ,
        // "nscannedAllPlans" : 2203 , "scanAndOrder" : false ,
        // "indexOnly" : true , "nYields" : 0 , "nChunkSkips" : 0 ,
        // "millis" : 3 ,...
        // Time: 43 ms
        // Count: 2000
       
        int children = 1000000;
        int perInsert = 1000;
        int group = 0;
        String parent = "/parent/node/abc";
        for (int i = 0; i < children;) {
            DBObject[] inserts = new DBObject[perInsert];
            group++;
            for (int j = 0; j < perInsert; j++, i++) {
                BasicDBObject doc = new BasicDBObject();
                inserts[j] = doc;
                doc.put("_id", parent + "/node" + i);
                doc.put("_mod", group);
            }
            nodes.insert(inserts, WriteConcern.SAFE);
            log("inserted " + i + "/" + children);
        }
        QueryBuilder queryBuilder = QueryBuilder.start("_mod");
        queryBuilder.greaterThanEquals(group - 1);
        queryBuilder.and("_id").greaterThan(parent + "/");
        queryBuilder.and("_id").lessThanEquals(parent + "0");
        DBObject query = queryBuilder.get();
        BasicDBObject keys = new BasicDBObject();
        keys.put("_id", 1);
        DBCursor cursor = nodes.find(query, keys);
        int count = 0;
        log("Query plan: " + cursor.explain());
        long time = System.currentTimeMillis();
        while (cursor.hasNext()) {
            DBObject obj = cursor.next();
            // dummy read operation (to ensure we did get the data)
            obj.get("_id");
            count++;
            // log(" read " + obj);
        }
        time = System.currentTimeMillis() - time;
        log("Time: " + time + " ms");
        log("Count: " + count);
        db.getMongo().close();
    }
View Full Code Here

TOP

Related Classes of com.mongodb.DB$CommandResultPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.