Package com.mongodb

Examples of com.mongodb.MongoClient


        new DbJobCmd(mongo.getDB("admin"), cmd, this, null).addJob();
    }

    public void currentOps(ButtonBase button) {
        final MongoClient mongo = getMongoNode().getMongoClient();
        final DBObject query = ((DocBuilderField) getBoundUnit(Item.currentOpsQuery)).getDBObject();
        CollectionPanel.doFind(mongo.getDB("admin").getCollection("$cmd.sys.inprog"), query);
    }
View Full Code Here


        final DBObject query = ((DocBuilderField) getBoundUnit(Item.currentOpsQuery)).getDBObject();
        CollectionPanel.doFind(mongo.getDB("admin").getCollection("$cmd.sys.inprog"), query);
    }

    public void killOp(ButtonBase button) {
        final MongoClient mongo = getMongoNode().getMongoClient();
        final int opid = getIntFieldValue(Item.killOpId);
        final DBObject query = new BasicDBObject("op", opid);
        CollectionPanel.doFind(mongo.getDB("admin").getCollection("$cmd.sys.killop"), query);
    }
View Full Code Here

        new DbJobCmd(getCollectionNode().getDbNode().getDb(), cmd).addJob();
    }

    public void fixCollection(ButtonBase button) {
        final MongoClient m = getCollectionNode().getDbNode().getMongoNode().getMongoClient();
        ArrayList<MongoNode> mongoNodes = UMongo.instance.getMongos();
        String[] mongonames = new String[mongoNodes.size() - 1];
        MongoClient[] mongos = new MongoClient[mongonames.length];
        int i = 0;
        for (MongoNode node : mongoNodes) {
            MongoClient m2 = node.getMongoClient();
            if (m == m2) {
                continue;
            }
            mongonames[i] = m2.toString();
            mongos[i] = m2;
            ++i;
        }
        ComboBox src = (ComboBox) getBoundUnit(Item.fcSrcMongo);
        src.items = mongonames;
        src.structureComponent();
        FormDialog dialog = (FormDialog) getBoundUnit(Item.fcDialog);
        if (!dialog.show()) {
            return;
        }

        final DBCollection dstCol = getCollectionNode().getCollection();
        final MongoClient srcMongo = mongos[src.getIntValue()];
        final boolean upsert = getBooleanFieldValue(Item.fcUpsert);

        final String dbname = dstCol.getDB().getName();
        final String colname = dstCol.getName();
        final DBCollection srcCol = srcMongo.getDB(dbname).getCollection(colname);
        String txt = "About to copy from ";
        txt += srcMongo.getConnectPoint() + "(" + srcCol.count() + ")";
        txt += " to ";
        txt += m.getConnectPoint() + "(" + dstCol.count() + ")";
        if (!new ConfirmDialog(null, "Confirm Fix Collection", null, txt).show()) {
            return;
        }
View Full Code Here

    void disconnect(MongoNode node) {
        mongos.remove(node);

        node.removeNode();
        MongoClient mongo = ((MongoNode) node).getMongoClient();
        mongo.close();

        if (mongos.size() > 0) {
            MongoNode other = mongos.get(0);
            getTree().expandNode(other);
            getTree().selectNode(other);
View Full Code Here

    }
   
    public ServerNode(ServerAddress serverAddress, MongoClientOptions opts, boolean isReplica, boolean isConfig) {
        setLabel(serverAddress.toString());
        this.serverAddress = serverAddress;
        serverMongo = new MongoClient(serverAddress, opts);
        serverMongo.addOption( Bytes.QUERYOPTION_SLAVEOK );
        this.isReplica = isReplica;
        this.isConfig = isConfig;
       
        try {
View Full Code Here

   
    public ServerNode(String host, MongoClientOptions opts, boolean isReplica, boolean isConfig) throws UnknownHostException {
        setLabel(host);
        this.host = host;
        this.serverAddress = new ServerAddress(host);
        serverMongo = new MongoClient(serverAddress, opts);
        serverMongo.addOption( Bytes.QUERYOPTION_SLAVEOK );
        this.isReplica = isReplica;
        this.isConfig = isConfig;
       
        try {
View Full Code Here

   
    public void connect() {
        try {
            ConnectDialog dialog = (ConnectDialog) getBoundUnit(Item.connectDialog);
            ProgressDialog progress = (ProgressDialog) getBoundUnit(Item.connectProgressDialog);
            MongoClient mongo = null;
            List<String> dbs = new ArrayList<String>();
            String uri = dialog.getStringFieldValue(ConnectDialog.Item.uri);
            if (!uri.trim().isEmpty()) {
                if (!uri.startsWith(MongoURI.MONGODB_PREFIX)) {
                    uri = MongoURI.MONGODB_PREFIX + uri;
                }
                MongoClientURI muri = new MongoClientURI(uri);
                mongo = new MongoClient(muri);
                String db = muri.getDatabase();
                if (db != null && !db.trim().isEmpty()) {
                    dbs.add(db.trim());
                }
            } else {
                String servers = dialog.getStringFieldValue(ConnectDialog.Item.servers);
                if (servers.trim().isEmpty()) {
                    return;
                }
                String[] serverList = servers.split(",");
                ArrayList<ServerAddress> addrs = new ArrayList<ServerAddress>();
                for (String server : serverList) {
                    String[] tmp = server.split(":");
                    if (tmp.length > 1) {
                        addrs.add(new ServerAddress(tmp[0], Integer.valueOf(tmp[1]).intValue()));
                    } else {
                        addrs.add(new ServerAddress(tmp[0]));
                    }
                }
                if ("Direct".equals(dialog.getStringFieldValue(ConnectDialog.Item.connectionMode)))
                    mongo = new MongoClient(addrs.get(0), dialog.getMongoClientOptions());
                else
                    mongo = new MongoClient(addrs, dialog.getMongoClientOptions());

                String sdbs = dialog.getStringFieldValue(ConnectDialog.Item.databases);
                if (!sdbs.trim().isEmpty()) {
                    for (String db : sdbs.split(",")) {
                        dbs.add(db.trim());
                    }
                }
            }

            if (dbs.size() == 0) {
                dbs = null;
            }

            String user = dialog.getStringFieldValue(ConnectDialog.Item.user).trim();
            String password = dialog.getStringFieldValue(ConnectDialog.Item.password);
            if (!user.isEmpty()) {
                // authenticate against all dbs
                if (dbs != null) {
                    for (String db : dbs) {
                        mongo.getDB(db).authenticate(user, password.toCharArray());
                    }
                } else {
                    mongo.getDB("admin").authenticate(user, password.toCharArray());
                }
            }

            final MongoClient fmongo = mongo;
            final List<String> fdbs = dbs;
            // doing in background can mean concurrent modification, but dialog is modal so unlikely
            progress.show(new ProgressDialogWorker(progress) {
                @Override
                protected void finished() {
View Full Code Here

    dbLocal.set(null);
  }

  private static void initThread() {
    try {
      MongoClient client = new MongoClient(Config.mgHost, Config.mgPort);
      DB db = client.getDB(Config.mgDb);
      if (db.authenticate(Config.mgUser, Config.mgPassword.toCharArray())) {
        clientLocal.set(client);
        dbLocal.set(db);
      }
    } catch (UnknownHostException e) {
View Full Code Here

    protected AdvancedDatastore ads;
    protected Morphia morphia = new Morphia();

    protected TestBase() {
        try {
      this.mongo = new MongoClient();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    }
View Full Code Here

  private static class MongoConnectionManager {
    private final Datastore db;
    public static final String DB_NAME = "cal_dev";
    public MongoConnectionManager(String host, int port) {
      try {
        Mongo m = new MongoClient(host, port);
        db = new Morphia().map(BookingDetail.class).createDatastore(m, DB_NAME);
        db.ensureIndexes();
      } catch (Exception e) {
        throw new RuntimeException("Error initializing mongo db", e);
      }
View Full Code Here

TOP

Related Classes of com.mongodb.MongoClient

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.