Example usage for com.mongodb MongoClient MongoClient

List of usage examples for com.mongodb MongoClient MongoClient

Introduction

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

Prototype

public MongoClient(final MongoClientURI uri) 

Source Link

Document

Creates a Mongo described by a URI.

Usage

From source file:com.gemini.geminimain.GeminiMain.java

private static List<GeminiServer> getNetworkServersFromDB(String netStart, String netEnd)
        throws UnknownHostException {
    //setup the mongodb access
    mongoClient = new MongoClient(DB_SERVER);

    GeminiNetworkRepositoryMongoDBImpl netDB = new GeminiNetworkRepositoryMongoDBImpl(mongoClient, morphia,
            "Gemini");
    GeminiNetwork aNet = netDB.getNetByStartAndEnd(netStart, netEnd);

    //close the db client
    mongoClient.close();//from w ww. j a va  2 s  . c  o  m

    return aNet.getServers();
}

From source file:com.gemini.geminimain.GeminiMain.java

private static GeminiServer getServerFromDB(String srvName) throws UnknownHostException {
    //setup the mongodb access
    mongoClient = new MongoClient(DB_SERVER);

    GeminiServerRepositoryMongoDBImpl srvDB = new GeminiServerRepositoryMongoDBImpl(mongoClient, morphia,
            "Gemini");
    GeminiServer aSrv = srvDB.getServerByName(srvName);

    //close the db client
    mongoClient.close();/*www  .java 2  s .  co  m*/

    return aSrv;
}

From source file:com.gemini.geminimain.GeminiMain.java

private static List<GeminiEnvironment> getEnvironments(String tenantID) throws UnknownHostException {
    //setup the mongodb access
    mongoClient = new MongoClient(DB_SERVER);

    GeminiTenantRepositoryMongoDBImpl tenantDB = new GeminiTenantRepositoryMongoDBImpl(mongoClient, morphia,
            "Gemini");
    GeminiTenant aTenant = tenantDB.getTenantByName(tenantID);
    if (aTenant == null) {
        Logger.error("Could not find tenant with ID {}", tenantID);
        return null;
    }// w w w.  ja  v  a 2 s . c o  m

    //close the db client
    mongoClient.close();

    return aTenant.getEnvironments();
}

From source file:com.gemini.geminimain.GeminiMain.java

private static List<GeminiApplication> getEnvApplications(String tenantID, String envName)
        throws UnknownHostException {
    //setup the mongodb access
    mongoClient = new MongoClient(DB_SERVER);

    GeminiTenantRepositoryMongoDBImpl tenantDB = new GeminiTenantRepositoryMongoDBImpl(mongoClient, morphia,
            "Gemini");
    GeminiTenant aTenant = tenantDB.getTenantByName(tenantID);
    if (aTenant == null) {
        Logger.error("Could not find tenant with ID {}", tenantID);
        return null;
    }//from   w ww. j a v  a 2s.  co m

    //close the db client
    mongoClient.close();

    GeminiEnvironment env = aTenant.getEnvironments().stream().filter(e -> e.getName().equals(envName))
            .findFirst().get();
    return env.getApplications();
}

From source file:com.gemini.geminimain.GeminiMain.java

private static List<GeminiNetwork> getEnvNetworks(String tenantID, String envName) throws UnknownHostException {
    //setup the mongodb access
    mongoClient = new MongoClient(DB_SERVER);

    GeminiTenantRepositoryMongoDBImpl tenantDB = new GeminiTenantRepositoryMongoDBImpl(mongoClient, morphia,
            "Gemini");
    GeminiTenant aTenant = tenantDB.getTenantByName(tenantID);
    if (aTenant == null) {
        Logger.error("Could not find tenant with ID {}", tenantID);
        return null;
    }/*from   ww w . j av a  2s  .co  m*/

    //close the db client
    mongoClient.close();

    GeminiEnvironment env = aTenant.getEnvironments().stream().filter(e -> e.getName().equals(envName))
            .findFirst().get();
    return env.getNetworks();
}

From source file:com.github.achatain.catalog.module.CatalogConfig.java

License:Open Source License

CatalogConfig() {
    properties = loadProperties();
    mongoClient = new MongoClient(new MongoClientURI(properties.getProperty("mongodb.url")));
}

From source file:com.github.bluetiger9.nosql.benchmarking.clients.document.mongodb.MongoDBClient.java

License:Open Source License

@Override
public void connect() throws ClientException {
    try {/* w w w  .  j  a v a2  s. co  m*/
        for (String server : StringUtils
                .split(properties.getProperty(CommonClientProperties.PROPERTY_SERVERS, DEFAULT_SERVERS), ',')) {
            servers.add(getServerAddress(server));
        }

        client = new MongoClient(servers);
        db = client.getDB(dbName);
        dbCollection = db.getCollection(collection);
    } catch (Exception e) {
        throw new ClientException("connection error", e);
    }
}

From source file:com.github.cherimojava.data.mongo.MongoBase.java

License:Apache License

@Before
public final void dbSetup() throws IOException {
    client = new MongoClient(new ServerAddress("localhost", Suite.getPort()));
    db = client.getDatabase(this.getClass().getSimpleName());
    collectionCleanUp = Lists.newArrayList();
}

From source file:com.github.cherimojava.orchidae.config.cfgMongo.java

License:Apache License

@Bean
MongoDatabase mongoDatabase() throws UnknownHostException {
    return new MongoClient(new ServerAddress("localhost", mongoPort())).getDatabase(mongoDBName);
}

From source file:com.github.krr.mongodb.aggregate.support.config.MongoClientTestConfiguration.java

License:Apache License

private MongoClient getMongoClient() throws IOException {
    return new MongoClient(new ServerAddress(mongodProcess.getConfig().net().getServerAddress(),
            mongodProcess.getConfig().net().getPort()));
}