Example usage for com.mongodb BasicDBList get

List of usage examples for com.mongodb BasicDBList get

Introduction

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

Prototype

public Object get(final String key) 

Source Link

Document

Gets a value at an index.

Usage

From source file:org.aw20.mongoworkbench.command.PassThruMongoCommand.java

License:Open Source License

public BasicDBList getResults() {
    BasicDBList list = (BasicDBList) resultObj;

    for (int x = 0; x < list.size(); x++) {
        Object o = list.get(x);
        if (!(o instanceof DBObject)) {
            BasicDBObject dbo = new BasicDBObject("1", o);
            list.set(x, fixNumbers(dbo));
        }//from  w ww .  j a va  2  s.c om
    }

    return list;
}

From source file:org.aw20.mongoworkbench.command.RemoveMongoCommand.java

License:Open Source License

@Override
public void execute() throws Exception {
    MongoClient mdb = MongoFactory.getInst().getMongo(sName);

    if (mdb == null)
        throw new Exception("no server selected");

    if (sDb == null)
        throw new Exception("no database selected");

    MongoFactory.getInst().setActiveDB(sDb);

    DB db = mdb.getDB(sDb);//from  www.j a  v  a  2  s  . c o m
    BasicDBObject cmdMap = parseMongoCommandString(db, cmd);

    if (!cmdMap.containsField("removeArgs"))
        throw new Exception("no remove document");

    DBCollection collection = db.getCollection(sColl);

    BasicDBList args = (BasicDBList) cmdMap.get("removeArgs");

    // Run the command
    db.requestStart();
    WriteResult writeresult;
    try {
        writeresult = collection.remove((DBObject) args.get(0), WriteConcern.JOURNAL_SAFE);
    } finally {
        db.requestDone();
    }

    // Get the result
    Map mwriteresult = (Map) JSON.parse(writeresult.toString());
    mwriteresult.put("exeDate", new Date());

    EventWorkBenchManager.getInst().onEvent(Event.WRITERESULT, mwriteresult);

    setMessage("Removed");
}

From source file:org.aw20.mongoworkbench.eclipse.view.table.QueryData.java

License:Open Source License

public QueryData(BasicDBList listdata, String firstColumn) {
    List<Map> data = new ArrayList<Map>(listdata.size());
    for (int x = 0; x < listdata.size(); x++)
        data.add(((DBObject) listdata.get(x)).toMap());

    init(data, firstColumn);/*from w  w w  .  jav a  2s .co  m*/
}

From source file:org.aw20.mongoworkbench.eclipse.view.wizard.AggregateWizard.java

License:Open Source License

@Override
public boolean onWizardCommand(MongoCommand cmd, BasicDBObject dbo) {
    if (!cmd.getClass().getName().equals(AggregateMongoCommand.class.getName()))
        return false;

    if (!dbo.containsField("aggregateArg"))
        return false;

    BasicDBList args = (BasicDBList) dbo.get("aggregateArg");
    if (args.size() == 0)
        return false;

    // remove all the tabs
    while (tabFolder.getItemCount() > 0)
        tabFolder.getItem(0).dispose();//from   www . j a v  a  2 s . co m

    for (int x = 0; x < args.size(); x++) {
        TabItem tbtmPipe = new TabItem(tabFolder, SWT.NONE);
        tbtmPipe.setText("Pipe#" + (x + 1));
        Text textPipe = MSwtUtil.createText(tabFolder);
        textPipe.setText(JSONFormatter.format(args.get(x)));
        tbtmPipe.setControl(textPipe);
    }

    if (tabFolder.getItemCount() > 1)
        btnRemovePipe.setEnabled(true);
    else
        btnRemovePipe.setEnabled(false);

    return true;
}

From source file:org.aw20.mongoworkbench.eclipse.view.wizard.FindWizard.java

License:Open Source License

@Override
public boolean onWizardCommand(MongoCommand cmd, BasicDBObject dbo) {
    if (!cmd.getClass().getName().equals(FindMongoCommand.class.getName()))
        return false;

    if (!dbo.containsField("findArg"))
        return false;

    BasicDBList dbList = (BasicDBList) dbo.get("findArg");

    if (dbList.size() == 1) {
        textKeys.setText("");
        textQuery.setText(JSONFormatter.format(dbList.get(0)));
    } else if (dbList.size() == 2) {
        textKeys.setText(JSONFormatter.format(dbList.get(1)));
        textQuery.setText(JSONFormatter.format(dbList.get(0)));
    } else {/* ww w  .jav  a2s .co m*/
        textKeys.setText("");
        textQuery.setText("");
    }

    if (dbo.containsField("sort")) {
        textSort.setText(JSONFormatter.format(dbo.get("sort")));
    } else {
        textSort.setText("");
    }

    return true;
}

From source file:org.aw20.mongoworkbench.eclipse.view.wizard.MapReduceWizard.java

License:Open Source License

@Override
public boolean onWizardCommand(MongoCommand cmd, BasicDBObject dbo) {
    if (!cmd.getClass().getName().equals(MapReduceMongoCommand.class.getName()))
        return false;

    if (!dbo.containsField("mapreduceArgs"))
        return false;

    BasicDBList dbList = (BasicDBList) dbo.get("mapreduceArgs");

    BasicDBObject options = (BasicDBObject) dbList.get(2);

    // Input section
    if (options.containsField("query")) {
        textMRQuery.setText(JSONFormatter.format(options.get("query")));
    } else {/*www .jav a2s.  c o m*/
        textMRQuery.setText("");
    }

    if (options.containsField("sort")) {
        textMRSort.setText(JSONFormatter.format(options.get("sort")));
    } else {
        textMRSort.setText("");
    }

    if (options.containsField("limit")) {
        textMRLimit.setText((String) options.get("sort"));
    } else {
        textMRLimit.setText("");
    }

    // Scope section
    if (options.containsField("scope")) {
        textMRScope.setText(JSONFormatter.format(options.get("scope")));
    } else {
        textMRScope.setText("");
    }

    // Map section
    textMRMap.setText(((Code) (dbList.get(0))).getCode());

    // Reduce Section
    textMRReduce.setText(((Code) (dbList.get(1))).getCode());

    // Finalize
    if (options.containsField("finalize")) {
        textMRFinalize.setText(((Code) options.get("finalize")).getCode());
    } else {
        textMRFinalize.setText("");
    }

    // Output section
    combo.select(0);
    textMRCollection.setText("");
    textMRDatabase.setText("");
    btnSharded.setSelection(false);
    btnJsmode.setSelection(false);
    btnNonatomic.setSelection(false);
    btnVerbose.setSelection(false);

    if (options.get("out") instanceof String) {
        textMRCollection.setText((String) options.get("out"));
    } else if (options.get("out") instanceof BasicDBObject) {
        BasicDBObject out = (BasicDBObject) options.get("out");

        if (out.containsField("inline")) {
        } else if (out.containsField("replace")) {
            combo.select(1);
            textMRCollection.setText((String) out.get("replace"));
        } else if (out.containsField("merge")) {
            combo.select(2);
            textMRCollection.setText((String) out.get("merge"));
        } else if (out.containsField("reduce")) {
            combo.select(3);
            textMRCollection.setText((String) out.get("reduce"));
        }

        if (out.containsField("sharded"))
            btnSharded.setSelection(StringUtil.toBoolean(out.get("sharded"), false));

        if (out.containsField("nonAtomic"))
            btnNonatomic.setSelection(StringUtil.toBoolean(out.get("nonAtomic"), false));

        if (out.containsField("db"))
            textMRDatabase.setText((String) out.get("db"));
    }

    if (options.containsField("jsMode"))
        btnJsmode.setSelection(StringUtil.toBoolean(options.get("jsMode"), false));

    if (options.containsField("verbose"))
        btnVerbose.setSelection(StringUtil.toBoolean(options.get("verbose"), false));

    return true;
}

From source file:org.aw20.mongoworkbench.eclipse.view.wizard.UpdateWizard.java

License:Open Source License

@Override
public boolean onWizardCommand(MongoCommand cmd, BasicDBObject dbo) {
    if (!cmd.getClass().getName().equals(UpdateMongoCommand.class.getName()))
        return false;

    if (!dbo.containsField("updateArg"))
        return false;

    BasicDBList list = (BasicDBList) dbo.get("updateArg");

    // Set the fields of the wizard from the command
    textUpdateQuery.setText(JSONFormatter.format(((BasicDBObject) list.get(0)).toMap()));
    textUpdateUpdate.setText(JSONFormatter.format(((BasicDBObject) list.get(1)).toMap()));

    if (list.size() >= 3)
        btnUpdateUpsert.setSelection(StringUtil.toBoolean(list.get(2), false));
    else/*  ww  w.  j a  va 2  s  .  c om*/
        btnUpdateUpsert.setSelection(false);

    if (list.size() >= 4)
        btnUpdateMulti.setSelection(StringUtil.toBoolean(list.get(3), false));
    else
        btnUpdateMulti.setSelection(false);

    return true;
}

From source file:org.codinjutsu.tools.mongo.view.model.JsonTreeModel.java

License:Apache License

public static void processDbObject(JsonTreeNode parentNode, DBObject mongoObject) {
    if (mongoObject instanceof BasicDBList) {
        BasicDBList mongoObjectList = (BasicDBList) mongoObject;
        for (int i = 0; i < mongoObjectList.size(); i++) {
            Object mongoObjectOfList = mongoObjectList.get(i);
            JsonTreeNode currentNode = new JsonTreeNode(
                    MongoValueDescriptor.createDescriptor(i, mongoObjectOfList));
            if (mongoObjectOfList instanceof DBObject) {
                processDbObject(currentNode, (DBObject) mongoObjectOfList);
            }//from w w  w  . ja v  a2  s . c  om
            parentNode.add(currentNode);
        }
    } else if (mongoObject instanceof BasicDBObject) {
        BasicDBObject basicDBObject = (BasicDBObject) mongoObject;
        for (String key : basicDBObject.keySet()) {
            Object value = basicDBObject.get(key);
            JsonTreeNode currentNode = new JsonTreeNode(MongoKeyValueDescriptor.createDescriptor(key, value));
            if (value instanceof DBObject) {
                processDbObject(currentNode, (DBObject) value);
            }
            parentNode.add(currentNode);
        }
    }
}

From source file:org.codinjutsu.tools.nosql.mongo.view.model.JsonTreeModel.java

License:Apache License

public static void processDbObject(NoSqlTreeNode parentNode, DBObject mongoObject) {
    if (mongoObject instanceof BasicDBList) {
        BasicDBList mongoObjectList = (BasicDBList) mongoObject;
        for (int i = 0; i < mongoObjectList.size(); i++) {
            Object mongoObjectOfList = mongoObjectList.get(i);
            NoSqlTreeNode currentNode = new NoSqlTreeNode(
                    MongoValueDescriptor.createDescriptor(i, mongoObjectOfList));
            if (mongoObjectOfList instanceof DBObject) {
                processDbObject(currentNode, (DBObject) mongoObjectOfList);
            }//w  ww .jav a2 s . c  o  m
            parentNode.add(currentNode);
        }
    } else if (mongoObject instanceof BasicDBObject) {
        BasicDBObject basicDBObject = (BasicDBObject) mongoObject;
        for (String key : basicDBObject.keySet()) {
            Object value = basicDBObject.get(key);
            NoSqlTreeNode currentNode = new NoSqlTreeNode(MongoKeyValueDescriptor.createDescriptor(key, value));
            if (value instanceof DBObject) {
                processDbObject(currentNode, (DBObject) value);
            }
            parentNode.add(currentNode);
        }
    }
}

From source file:org.craftercms.social.util.support.impl.TargetMapReduseParser.java

License:Open Source License

@Override
public List<String> parseList(Map<?, ?> rawResults) {
    List<String> lst = new ArrayList<String>();
    BasicDBList results = ((BasicDBList) rawResults.get("results"));
    for (int i = 0; i < results.size(); i++) {
        DBObject result = (DBObject) results.get(i);
        DBObject id = (DBObject) result.get("_id");
        lst.add((String) id.get("target"));
    }// www.j a  v  a 2s. c o  m
    return lst;
}