Package com.mongodb

Examples of com.mongodb.DB$CommandResultPair


  @Singleton
  public DB getDB() {

    // MongoDB Setup
    final MongoURI mongoUri = new MongoURI(configuration.getMongoUri());
    final DB db;
    try {
      db = mongoUri.connectDB();
    } catch (UnknownHostException e) {
      throw new IllegalArgumentException("Cannot connect to MongoDB",e);
    }

    // Authenticate
    if (mongoUri.getUsername() != null && mongoUri.getPassword() != null) {
      db.authenticate(mongoUri.getUsername(), mongoUri.getPassword());
    }

    return db;

  }
View Full Code Here


       
        options.connectionsPerHost = PropertiesUtil.toInteger(props.get(PROP_NUM_CONNECTIONS), DEFAULT_NUMCONNECTIONS);
        options.threadsAllowedToBlockForConnectionMultiplier = PropertiesUtil.toInteger(props.get(PROP_THREAD_MULTIPLIER), DEFAULT_THREAD_MULTIPLIER);
        final Mongo m = new Mongo(address, options);

        final DB database = m.getDB( db );
        logger.info("Connected to database {}", database);

        this.context = new MongoDBContext(database,
                roots[0],
                PropertiesUtil.toStringArray(props.get(PROP_FILTER_COLLECTIONS)),
View Full Code Here

        properties.getProperty("mysql.password"));
    final DataSource postgresql = Helper.newDataSource(
        properties.getProperty("postgresql.uri"),
        properties.getProperty("postgresql.user"),
        properties.getProperty("postgresql.password"));
    final DB mongodb = new MongoClient(properties.getProperty("mongodb.host"))
        .getDB(properties.getProperty("mongodb.name"));
    //
    // The world cache is primed at startup with all values.  It doesn't
    // matter which database backs it; they all contain the same information
    // and the CacheLoader.load implementation below is never invoked.
View Full Code Here

  {
    Mongo mongo = new Mongo(config.mongohost, config.mongoport);
    MongoManaged mongoManaged = new MongoManaged(mongo);
    environment.manage(mongoManaged);
    environment.addHealthCheck(new MongoHealthCheck(mongo));
    DB db = mongo.getDB(config.mongodb);
    JacksonDBCollection<World, String> worlds = JacksonDBCollection.wrap(db.getCollection("world"), World.class, String.class);
    environment.addResource(new WorldResource(worlds));
    environment.addResource(new JsonResource());
  }
View Full Code Here

        properties.getProperty("mysql.password"));
    final DataSource postgresql = Helper.newDataSource(
        properties.getProperty("postgresql.uri"),
        properties.getProperty("postgresql.user"),
        properties.getProperty("postgresql.password"));
    final DB mongodb = new MongoClient(properties.getProperty("mongodb.host"))
        .getDB(properties.getProperty("mongodb.name"));
    //
    // The world cache is primed at startup with all values.  It doesn't
    // matter which database backs it; they all contain the same information
    // and the CacheLoader.load implementation below is never invoked.
View Full Code Here

  }

  @Override
  public long getNumberOfEntities(SessionFactory sessionFactory) {
    MongoDBDatastoreProvider provider = MongoDBTestHelper.getProvider( sessionFactory );
    DB db = provider.getDatabase();
    int count = 0;

    for ( String collectionName : getEntityCollections( sessionFactory ) ) {
      count += db.getCollection( collectionName ).count();
    }

    return count;
  }
View Full Code Here

    return associationCount;
  }

  public long getNumberOfAssociationsFromGlobalCollection(SessionFactory sessionFactory) {
    DB db = getProvider( sessionFactory ).getDatabase();
    return db.getCollection( MongoDBConfiguration.DEFAULT_ASSOCIATION_STORE ).count();
  }
View Full Code Here

    DB db = getProvider( sessionFactory ).getDatabase();
    return db.getCollection( MongoDBConfiguration.DEFAULT_ASSOCIATION_STORE ).count();
  }

  public long getNumberOfAssociationsFromDedicatedCollections(SessionFactory sessionFactory) {
    DB db = getProvider( sessionFactory ).getDatabase();

    Set<String> associationCollections = getDedicatedAssociationCollections( sessionFactory );
    long associationCount = 0;
    for ( String collectionName : associationCollections ) {
      associationCount += db.getCollection( collectionName ).count();
    }

    return associationCount;
  }
View Full Code Here

  }

  // TODO Use aggregation framework for a more efficient solution; Given that there will only be a few
  // test collections/entities, that's good enough for now
  public long getNumberOfEmbeddedAssociations(SessionFactory sessionFactory) {
    DB db = getProvider( sessionFactory ).getDatabase();
    long associationCount = 0;

    for ( String entityCollection : getEntityCollections( sessionFactory ) ) {
      DBCursor entities = db.getCollection( entityCollection ).find();

      while ( entities.hasNext() ) {
        DBObject entity = entities.next();
        associationCount += getNumberOfEmbeddedAssociations( entity );
      }
View Full Code Here

  private boolean isAssociation(Object field) {
    return ( field instanceof List );
  }

  private Set<String> getEntityCollections(SessionFactory sessionFactory) {
    DB db = MongoDBTestHelper.getProvider( sessionFactory ).getDatabase();
    Set<String> names = new HashSet<String>();

    for ( String collectionName : db.getCollectionNames() ) {
      if ( !isSystemCollection( collectionName ) &&
          !isDedicatedAssociationCollection( collectionName ) &&
          !isGlobalAssociationCollection( collectionName ) ) {
        names.add( collectionName );
      }
View Full Code Here

TOP

Related Classes of com.mongodb.DB$CommandResultPair

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.