Package com.mongodb

Examples of com.mongodb.MongoClient


     * @throws Exception If an error occurred while trying to connect.
     */
    public MongoConnection(String host, int port, String database) throws Exception {
        MongoClientOptions options = getDefaultBuilder().build();
        ServerAddress serverAddress = new ServerAddress(host, port);
        mongo = new MongoClient(serverAddress, options);
        db = mongo.getDB(database);
    }
View Full Code Here


            private MongoClient mongo;
            @Override
            protected Repository[] internalSetUpCluster(int n) throws Exception {
                Repository[] cluster = new Repository[n];
                stores = new SegmentStore[cluster.length];
                mongo = new MongoClient(host, port);
                for (int i = 0; i < cluster.length; i++) {
                    stores[i] = new MongoStore(mongo.getDB(unique), cacheSizeMB);
                    Oak oak = new Oak(new SegmentNodeStore(stores[i]));
                    cluster[i] = new Jcr(oak).createRepository();
                }
View Full Code Here

                    }

                    description += ", server=" + server;
                    if (portInt > 0) {
                        description += ", port=" + portInt;
                        database = new MongoClient(server, portInt).getDB(databaseName);
                    } else {
                        database = new MongoClient(server).getDB(databaseName);
                    }
                } else {
                    database = new MongoClient().getDB(databaseName);
                }
            } catch (final Exception e) {
                LOGGER.error("Failed to obtain a database instance from the MongoClient at server [{}] and "
                        + "port [{}].", server, port);
                return null;
View Full Code Here

   * @param database Mongo database name, e.g. "foodmart"
   */
  public MongoSchema(String host, String database) {
    super();
    try {
      MongoClient mongo = new MongoClient(host);
      this.mongoDb = mongo.getDB(database);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

  @Override
  public void start() {
    if ( !isCacheStarted ) {
      try {
        ServerAddress serverAddress = new ServerAddress( config.getHost(), config.getPort() );
        this.mongo = new MongoClient( serverAddress, config.buildOptions() );
        this.isCacheStarted = true;
      }
      catch ( UnknownHostException e ) {
        throw log.mongoOnUnknownHost( config.getHost() );
      }
View Full Code Here

    public OakSegmentMKRepositoryStub(Properties settings) throws RepositoryException {
        super(settings);

        Session session = null;
        try {
            this.connection = new MongoClient(HOST, PORT);
            Jcr jcr = new Jcr(new Oak(new SegmentNodeStore(
                    new MongoStore(connection.getDB(DB), 4))));
            this.repository = jcr.createRepository();

            session = getRepository().login(superuser);
View Full Code Here

        }));
    }

    public static boolean isAvailable() {
        try {
            MongoClient mongo = new MongoClient(HOST, PORT);
            try {
                mongo.getDatabaseNames();
                return true;
            } finally {
                mongo.close();
            }
        } catch (Exception e) {
            return false;
        }
    }
View Full Code Here

    String host = dbHost;
    int port = Integer.parseInt(dbPort);
    try {
      // New MongoDB Client, see http://docs.mongodb.org/manual/release-notes/drivers-write-concern/
      mongo = new MongoClient(host, port);
    } catch (UnknownHostException e) {
      throw new PersistenceStartException("Unable to resolve the MongoDb hostname", e);
    }

    try {
View Full Code Here

        ServerAddress serverAddress = new ServerAddress( config.getHost(), config.getPort() );
        MongoClientOptions clientOptions = config.buildOptions();

        log.connectingToMongo( config.getHost(), config.getPort(), clientOptions.getConnectTimeout() );

        this.mongo = new MongoClient( serverAddress, clientOptions );
      }
      catch ( UnknownHostException e ) {
        throw log.mongoOnUnknownHost( config.getHost() );
      }
      catch ( RuntimeException e ) {
View Full Code Here

   * @param database Mongo database name, e.g. "foodmart"
   */
  public MongoSchema(String host, String database) {
    super();
    try {
      MongoClient mongo = new MongoClient(host);
      this.mongoDb = mongo.getDB(database);
    } catch (Exception e) {
      throw new RuntimeException(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.