Example usage for com.mongodb Mongo Mongo

List of usage examples for com.mongodb Mongo Mongo

Introduction

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

Prototype

Mongo(final MongoClientURI mongoURI) 

Source Link

Usage

From source file:com.hangum.tadpole.erd.core.utils.TadpoleModelUtils.java

License:Open Source License

/**
 * table?   .//from  w  ww .jav  a 2  s  . co m
 * 
 * @param strTBName
 * @return
 * @throws Exception
 */
public List<TableColumnDAO> getColumns(String db, String strTBName) throws Exception {
    if (DBDefine.getDBDefine(userDB.getTypes()) != DBDefine.MONGODB_DEFAULT) {
        SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);

        Map<String, String> param = new HashMap<String, String>();
        param.put("db", db);
        param.put("table", strTBName);

        return sqlClient.queryForList("tableColumnList", param);
    } else if (DBDefine.getDBDefine(userDB.getTypes()) == DBDefine.MONGODB_DEFAULT) {

        Mongo mongo = new Mongo(new DBAddress(userDB.getUrl()));
        com.mongodb.DB mongoDB = mongo.getDB(userDB.getDb());
        DBCollection coll = mongoDB.getCollection(strTBName);

        return MongoDBTableColumn.tableColumnInfo(coll.getIndexInfo(), coll.findOne());
    }

    return null;
}

From source file:com.hangum.tadpole.mongodb.core.test.ReplicaSetConnnection.java

License:Open Source License

/**
 * mongo db ./*from w  w w  .j  ava  2s .  c  o m*/
 * 
 * @return
 */
public Mongo connection(String uri, int port) throws Exception {
    List<ServerAddress> listServerList = new ArrayList<ServerAddress>();

    listServerList.add(new ServerAddress(serverurl, port));

    String[] urls = StringUtils.split(SERVER_URL, ",");
    for (String ipPort : urls) {
        String[] strIpPort = StringUtils.split(ipPort, ":");

        listServerList.add(new ServerAddress(strIpPort[0], Integer.parseInt(strIpPort[1])));
    }

    Mongo m = null;
    //      try {
    m = new Mongo(listServerList);//uri, port);
    //         List<String> listDB = m.getDatabaseNames();
    //         for (String dbName : listDB) {
    //            System.out.println(dbName);
    //         }

    // authentication(optional)
    // boolean auth = db.authenticate(myUserName, myPassword);

    //      } catch (UnknownHostException e) {
    //         e.printStackTrace();
    //      } catch (MongoException e) {
    //         e.printStackTrace();
    //      }

    return m;
}

From source file:com.hangum.tadpole.mongodb.core.test.UpdateEx.java

License:Open Source License

public static void dropCollection(String name) throws Exception {
    if (m == null)
        m = new Mongo(MangoDB_IP);
    DB db = m.getDB(DB_NAME);/*from  w w  w  .ja va  2 s .  c o m*/
    DBCollection coll = db.getCollection(name);
    coll.drop();
}

From source file:com.hangum.tadpole.mongodb.core.test.UpdateEx.java

License:Open Source License

public static DBCollection retvCollection(String name) throws Exception {
    if (m == null)
        m = new Mongo(MangoDB_IP);
    DB db = m.getDB(DB_NAME);/*from  w w  w  . j av a 2s . c  o m*/

    DBCollection coll = db.getCollection(name);
    return coll;
}

From source file:com.hangum.tadpole.mongodb.erd.core.dnd.TableTransferDropTargetListener.java

License:Open Source License

/**
 * table?   ./*from  w  w w . j a v  a2 s . c om*/
 * 
 * @param strTBName
 * @return
 * @throws Exception
 */
public List<CollectionFieldDAO> getColumns(String strTBName) throws Exception {
    Mongo mongo = new Mongo(new DBAddress(userDB.getUrl()));
    com.mongodb.DB mongoDB = mongo.getDB(userDB.getDb());
    DBCollection coll = mongoDB.getCollection(strTBName);

    return MongoDBTableColumn.tableColumnInfo(coll.getIndexInfo(), coll.findOne());
}

From source file:com.hangum.tadpole.rdb.core.viewers.object.ExplorerViewer.java

License:Open Source License

/**
 * table   .//from  w w  w.j av a 2s.  c  o m
 */
public void refreshTable(final String source) {

    try {
        if (DBDefine.getDBDefine(userDB.getTypes()) != DBDefine.MONGODB_DEFAULT) {

            SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
            showTables = sqlClient.queryForList("tableList", userDB.getDb()); //$NON-NLS-1$

            // mongo db
        } else if (DBDefine.getDBDefine(userDB.getTypes()) == DBDefine.MONGODB_DEFAULT) {

            Mongo mongo = new Mongo(new DBAddress(userDB.getUrl()));
            DB mongoDB = mongo.getDB(userDB.getDb());

            if (showTables != null)
                showTables.clear();
            else
                showTables = new ArrayList<TableDAO>();

            for (String col : mongoDB.getCollectionNames()) {
                TableDAO dao = new TableDAO();
                dao.setName(col);

                showTables.add(dao);
            }
        }

        tableListViewer.setInput(showTables);
        tableListViewer.refresh();

    } catch (Exception e) {
        logger.error(source + " Table Referesh", e);

        if (showTables != null)
            showTables.clear();
        tableListViewer.setInput(showTables);
        tableListViewer.refresh();

        Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
        if ("DB".equals(source)) //$NON-NLS-1$
            ExceptionDetailsErrorDialog.openError(getSite().getShell(), "Error", Messages.ExplorerViewer_4, //$NON-NLS-1$
                    errStatus);
        else
            ExceptionDetailsErrorDialog.openError(getSite().getShell(), "Error", Messages.ExplorerViewer_86, //$NON-NLS-1$
                    errStatus);
    }

}

From source file:com.ikanow.infinit.e.data_model.store.MongoDbConnection.java

License:Apache License

/**
 * Class Constructor used to establish the mongo object
 * // w ww .j  ava  2 s .  c  o m
 * @param  server   the server location ( example localhost )
 * @throws MongoException 
 * @throws UnknownHostException 
 */
public MongoDbConnection(String server) throws UnknownHostException, MongoException {
    this.server = server;
    mongo = new Mongo(this.server);
}

From source file:com.ineunet.knife.persist.mongo.MongoDBServerImpl.java

License:Apache License

public MongoDBServerImpl() throws Exception {
    String url = ConfigFactory.getKnifeConfig().get(ConfigKeysDB.mongo_db_addr, "localhost");
    this.dbName = ConfigFactory.getKnifeConfig().get(ConfigKeysDB.mongo_db_defaultdb, "knife");
    String[] addrs = url.split(",");
    List<ServerAddress> sa = new ArrayList<ServerAddress>();
    for (String ad : addrs) {
        String[] tmp = ad.split(":");
        if (tmp.length == 1) {
            sa.add(new ServerAddress(tmp[0], defaultPort));
        } else {/*  w w  w .jav a  2s . com*/
            sa.add(new ServerAddress(tmp[0], Integer.parseInt(tmp[1])));
        }
    }

    this.mongo = new Mongo(sa);
    mongo.setWriteConcern(WriteConcern.SAFE);
}

From source file:com.jagornet.dhcp.db.MongoLeaseManager.java

License:Open Source License

public void init() throws Exception {
    mongoClient = new Mongo(getMongoServer());
    mongoClient.setWriteConcern(WriteConcern.SAFE); // throw exceptions on failed write
    database = mongoClient.getDB("jagornet-dhcpv6");
    log.info("Connected to jagornet-dhcpv6 via Mongo client: " + mongoClient.toString());
    dhcpLeases = database.getCollection("DHCPLEASE");
    dhcpLeases.ensureIndex(new BasicDBObject("ipAddress", 1), "pkey", true);
    dhcpLeases.ensureIndex(new BasicDBObject("duid", 1).append("iatype", 1).append("iaid", 1), "tuple", false);
    dhcpLeases.ensureIndex("duid");
    dhcpLeases.ensureIndex("iatype");
    dhcpLeases.ensureIndex("state");
    dhcpLeases.ensureIndex("validEndTime");
}

From source file:com.jaspersoft.mongodb.connection.MongoDbConnection.java

License:Open Source License

private void create(String mongoURI) throws JRException {
    close();// w  ww. j  a v  a 2s  .  com
    try {
        client = new Mongo(mongoURIObject = new MongoURI(mongoURI));
    } catch (Exception e) {
        logger.error(e);
        throw new JRException(e.getMessage());
    }
}