Package com.mongodb

Examples of com.mongodb.DB


    return names;
  }

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

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


    /**
     * Builds and returns a mock MongoDB client based on the given configuration.
     */
    public MockMongoClient build() {
      DB database = mock( DB.class );

      DBCollection defaultCollection = mock( DBCollection.class );
      when( database.getCollection( anyString() ) ).thenReturn( defaultCollection );

      for ( Entry<String, DBCollection> collection : collections.entrySet() ) {
        when( database.getCollection( collection.getKey() ) ).thenReturn( collection.getValue() );
      }

      MongoClient mongoClient = mock( MongoClient.class );
      when( mongoClient.getDatabaseNames() ).thenReturn( Collections.<String>emptyList() );
      when( mongoClient.getDB( anyString() ) ).thenReturn( database );
View Full Code Here

  public void testLoadSelectedColumns() {
    final String collectionName = "Drink";

    MongoDBDatastoreProvider provider = (MongoDBDatastoreProvider) this.getService( DatastoreProvider.class );

    DB database = provider.getDatabase();
    DBCollection collection = database.getCollection( collectionName );
    BasicDBObject water = new BasicDBObject();
    water.put( "_id", "1234" );
    water.put( "name", "Water" );
    water.put( "volume", "1L" );
    collection.insert( water );
View Full Code Here

   * To be sure the datastoreProvider retrieves only the columns we want,
   * an extra column is manually added to the association document
   */
  protected void addExtraColumn() {
    MongoDBDatastoreProvider provider = (MongoDBDatastoreProvider) this.getService( DatastoreProvider.class );
    DB database = provider.getDatabase();
    DBCollection collection = database.getCollection( "associations_Project_Module" );
    BasicDBObject query = new BasicDBObject( 1 );
    query.put( "_id", new BasicDBObject( "Project_id", "projectID" ) );

    BasicDBObject updater = new BasicDBObject( 1 );
    updater.put( "$push", new BasicDBObject( "extraColumn", 1 ) );
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() );
        }
      }
      String databaseName = config.getDatabaseName();
View Full Code Here

  }

  @Override
  protected void addExtraColumn() {
    MongoDBDatastoreProvider provider = (MongoDBDatastoreProvider) super.getService( DatastoreProvider.class );
    DB database = provider.getDatabase();
    DBCollection collection = database.getCollection( "Project" );

    BasicDBObject query = new BasicDBObject( 1 );
    query.put( "_id", "projectID" );

    BasicDBObject updater = new BasicDBObject( 1 );
View Full Code Here

   * an extra column is manually added to the association document
   */
  @Override
  protected void addExtraColumn() {
    MongoDBDatastoreProvider provider = (MongoDBDatastoreProvider) super.getService( DatastoreProvider.class );
    DB database = provider.getDatabase();
    DBCollection collection = database.getCollection( "Associations" );

    final BasicDBObject idObject = new BasicDBObject( 2 );
    idObject.append( "Project_id", "projectID" );
    idObject.append( "table", "Project_Module" );

View Full Code Here

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

  @Override
  public void forEachTuple(ModelConsumer 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 MongoDBTupleSnapshot( dbObject, entityKeyMetadata, UPDATE ) ) );
      }
    }
  }
View Full Code Here

        Mongo oldMongo;
        do {
            oldMongo = m_mongoRef.get();
        } while (!m_mongoRef.compareAndSet(oldMongo, newMongo));
       
        DB db = newMongo.getDB(m_dbName);
        if ((userName != null) && (password != null)) {
            if (!db.authenticate(userName, password.toCharArray())) {
                return false;
            }
        }
       
        return true;
View Full Code Here

    public DBCollection getCollection() {
        Mongo mongo = m_mongoRef.get();
        if (mongo == null) {
            throw new MongoException("Not connected to MongoDB!");
        }
        DB db = mongo.getDB(m_dbName);
        return db.getCollection(m_collectionName);
    }
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.