Package com.mongodb

Examples of com.mongodb.DB


    }

    @Override
    public void setUpCluster(MicroKernel[] cluster) throws Exception {
        MongoConnection connection = getMongoConnection();
        DB db = connection.getDB();
        dropCollections(db);

        for (int i = 0; i < cluster.length; i++) {
            cluster[i] = new MongoMK.Builder().
                    setMongoDB(db).setClusterId(i).open();
View Full Code Here


    }

    @Override
    public void tearDownCluster(MicroKernel[] cluster) {
        try {
            DB db = getMongoConnection().getDB();
            dropCollections(db);
            mongoConnection.close();
            mongoConnection = null;
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

    @Ignore
    @Test
    public void performBenchMark_WriteConcern() throws UnknownHostException, InterruptedException {
        Mongo mongo = new Mongo(new DBAddress(remoteServer));
        final DB db = mongo.getDB(TEST_DB1);
        final DBCollection nodes = db.getCollection("nodes");
        final DBCollection blobs = db.getCollection("blobs");
        int readers = 0;
        int writers = 2;
        for(WriteConcern wc : namedConcerns.keySet()){
            prepareDB(nodes,blobs);
            final Benchmark b = new Benchmark(nodes, blobs);
View Full Code Here

            ps.println(r.toString());
        }
    }

    private void run(Mongo mongo, boolean useSameDB, boolean remote) throws InterruptedException {
        final DB nodeDB = mongo.getDB(TEST_DB1);
        final DB blobDB = useSameDB ? mongo.getDB(TEST_DB1) : mongo.getDB(TEST_DB2);
        final DBCollection nodes = nodeDB.getCollection("nodes");
        final DBCollection blobs = blobDB.getCollection("blobs");

        for (int readers : READERS) {
            for (int writers : WRITERS) {
                prepareDB(nodes,blobs);
                final Benchmark b = new Benchmark(nodes, blobs);
View Full Code Here

        DBCollection dbCol = null;
       
        if (dynamicDB == null && dynamicCollection == null) {
            dbCol = endpoint.getDbCollection();
        } else {
            DB db = null;

            if (dynamicDB == null) {
                db = endpoint.getDb();
            } else {
                db = endpoint.getMongoConnection().getDB(dynamicDB);
            }

            if (dynamicCollection == null) {
                dbCol = db.getCollection(endpoint.getCollection());
            } else {
                dbCol = db.getCollection(dynamicCollection);

                // on the fly add index
                if (dynamicIndex == null) {
                    endpoint.ensureIndex(dbCol, endpoint.createIndex());
                } else {
View Full Code Here

                                                      @PluginAttr("port") final String port,
                                                      @PluginAttr("username") final String username,
                                                      @PluginAttr("password") final String password,
                                                      @PluginAttr("factoryClassName") final String factoryClassName,
                                                      @PluginAttr("factoryMethodName") final String factoryMethodName) {
        DB database;
        String description;
        if (factoryClassName != null && factoryClassName.length() > 0 &&
                factoryMethodName != null && factoryMethodName.length() > 0) {
            try {
                final Class<?> factoryClass = Class.forName(factoryClassName);
                final Method method = factoryClass.getMethod(factoryMethodName);
                final Object object = method.invoke(null);

                if (object instanceof DB) {
                    database = (DB) object;
                } else if (object instanceof MongoClient) {
                    if (databaseName != null && databaseName.length() > 0) {
                        database = ((MongoClient) object).getDB(databaseName);
                    } else {
                        LOGGER.error("The factory method [{}.{}()] returned a MongoClient so the database name is "
                                + "required.", factoryClassName, factoryMethodName);
                        return null;
                    }
                } else if (object == null) {
                    LOGGER.error("The factory method [{}.{}()] returned null.", factoryClassName, factoryMethodName);
                    return null;
                } else {
                    LOGGER.error("The factory method [{}.{}()] returned an unsupported type [{}].", factoryClassName,
                            factoryMethodName, object.getClass().getName());
                    return null;
                }

                description = "database=" + database.getName();
                final List<ServerAddress> addresses = database.getMongo().getAllAddress();
                if (addresses.size() == 1) {
                    description += ", server=" + addresses.get(0).getHost() + ", port=" + addresses.get(0).getPort();
                } else {
                    description += ", servers=[";
                    for (final ServerAddress address : addresses) {
                        description += " { " + address.getHost() + ", " + address.getPort() + " } ";
                    }
                    description += "]";
                }
            } catch (final ClassNotFoundException e) {
                LOGGER.error("The factory class [{}] could not be loaded.", factoryClassName, e);
                return null;
            } catch (final NoSuchMethodException e) {
                LOGGER.error("The factory class [{}] does not have a no-arg method named [{}].", factoryClassName,
                        factoryMethodName, e);
                return null;
            } catch (final Exception e) {
                LOGGER.error("The factory method [{}.{}()] could not be invoked.", factoryClassName, factoryMethodName,
                        e);
                return null;
            }
        } else if (databaseName != null && databaseName.length() > 0) {
            description = "database=" + databaseName;
            try {
                if (server != null && server.length() > 0) {
                    int portInt = 0;
                    if (port != null && port.length() > 0) {
                        try {
                            portInt = Integer.parseInt(port);
                        } catch (final NumberFormatException ignore) {
                            // we don't care
                        }
                    }

                    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;
            }
        } else {
            LOGGER.error("No factory method was provided so the database name is required.");
            return null;
        }

        if (!database.isAuthenticated()) {
            if (username != null && username.length() > 0 && password != null && password.length() > 0) {
                description += ", username=" + username + ", passwordHash="
                        + NameUtil.md5(password + MongoDBProvider.class.getName());
            } else {
                LOGGER.error("The database is not already authenticated so you must supply a username and password "
View Full Code Here

        return new BasicDBObject()
            .append(FIELD_FEATURE, feature.name());
    }

    protected DBCollection togglzCollection() {
        DB db = mongoClient.getDB(dbname);
        db.setWriteConcern(writeConcert);
        if (username != null && password != null) {
            db.authenticate(username, password);
        }
        return db.getCollection(collection);
    }
View Full Code Here

    return null; // all other types handled as in hibernate-ogm-core
  }

  @Override
  public void forEachTuple(Consumer consumer, EntityKeyMetadata... entityKeyMetadatas) {
    DB db = provider.getDatabase();
    for ( EntityKeyMetadata entityKeyMetadata : entityKeyMetadatas ) {
      DBCollection collection = db.getCollection( entityKeyMetadata.getTable() );
      for ( DBObject dbObject : collection.find() ) {
        consumer.consume( new Tuple( new MassIndexingMongoDBTupleSnapshot( dbObject, entityKeyMetadata ) ) );
      }
    }
  }
View Full Code Here

  }

  private DB extractDatabase() {
    try {
      if ( config.getUsername() != null ) {
        DB admin = this.mongo.getDB( "admin" );
        boolean auth = admin.authenticate( config.getUsername(), config.getPassword().toCharArray() );
        if ( !auth ) {
          throw log.authenticationFailed( config.getUsername() );
        }
      }
      if ( !this.mongo.getDatabaseNames().contains( config.getDatabaseName() ) ) {
View Full Code Here

    private MicroKernel createMicroKernel() throws Exception {
        MongoConnection connection = new MongoConnection(HOST,
                PORT, DB);
        connections.add(connection);
        DB mongoDB = connection.getDB();
        return new MongoMK.Builder().setMongoDB(mongoDB).open();
    }
View Full Code Here

TOP

Related Classes of com.mongodb.DB

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.