Package com.mongodb

Examples of com.mongodb.DBCollection


    throw new UnsupportedOperationException( "Not implemented yet" );
  }

  private MongoDBResultTupleIterable getResultsCursor() {
    EntityKeyMetadata keyMetaData = getKeyMetaData( entityType );
    DBCollection collection = provider.getDatabase().getCollection( keyMetaData.getTable() );

    DBCursor cursor = isProjection() ? collection.find( query, projections ) : collection.find( query );

    return new MongoDBResultTupleIterable( cursor, keyMetaData );
  }
View Full Code Here


    DBObject toSave = this.prepareIdObject( key );
    return new Tuple( new MongoDBTupleSnapshot( toSave, key ) );
  }

  private DBObject getObjectAsEmbeddedAssociation(AssociationKey key) {
    DBCollection collection = this.getCollection( key.getEntityKey() );
    DBObject searchObject = this.prepareIdObject( key.getEntityKey() );
    DBObject restrictionObject = this.getSearchObject( key, true );
    return collection.findOne( searchObject, restrictionObject );
  }
View Full Code Here

    DBObject restrictionObject = this.getSearchObject( key, true );
    return collection.findOne( searchObject, restrictionObject );
  }

  private DBObject getObject(EntityKey key, TupleContext tupleContext) {
    DBCollection collection = this.getCollection( key );
    DBObject searchObject = this.prepareIdObject( key );
    BasicDBObject restrictionObject = this.getSearchObject( tupleContext );
    return collection.findOne( searchObject, restrictionObject );
  }
View Full Code Here

    this.getCollection( key ).update( idObject, updater, true, false );
  }

  @Override
  public void removeTuple(EntityKey key) {
    DBCollection collection = this.getCollection( key );
    DBObject toDelete = this.prepareIdObject( key );
    collection.remove( toDelete );
  }
View Full Code Here

          addEmptyAssociationField( key, entity );
        }
      }
      return new Association( new MongoDBAssociationSnapshot( entity, key, provider.getAssociationStorage() ) );
    }
    DBCollection associations = getAssociationCollection( key );
    DBObject assoc = MongoHelpers.associationKeyToObject( provider.getAssociationStorage(), key );

    assoc.put( ROWS_FIELDNAME, Collections.EMPTY_LIST );
    associations.insert( assoc );

    return new Association( new MongoDBAssociationSnapshot( assoc, key, provider.getAssociationStorage() ) );
  }
View Full Code Here

    return new BasicDBObject( "$push", new BasicDBObject( associationField, row ) );
  }

  @Override
  public void updateAssociation(Association association, AssociationKey key) {
    DBCollection collection;
    DBObject query;
    MongoDBAssociationSnapshot assocSnapshot = (MongoDBAssociationSnapshot) association.getSnapshot();
    String associationField;

    if ( isEmbeddedInEntity( key, provider.getAssociationStorage() ) ) {
      collection = this.getCollection( key.getEntityKey() );
      query = this.prepareIdObject( key.getEntityKey() );
      associationField = key.getCollectionRole();
    }
    else {
      collection = getAssociationCollection( key );
      query = assocSnapshot.getQueryObject();
      associationField = ROWS_FIELDNAME;
    }

    for ( AssociationOperation action : association.getOperations() ) {
      RowKey rowKey = action.getKey();
      Tuple rowValue = action.getValue();

      DBObject update = null;

      switch ( action.getType() ) {
      case CLEAR:
        update = new BasicDBObject( "$set", new BasicDBObject( associationField, Collections.EMPTY_LIST ) );
        break;
      case PUT_NULL:
      case PUT:
        update = putAssociationRowKey( rowValue, associationField, key );
        break;
      case REMOVE:
        update = removeAssociationRowKey( assocSnapshot, rowKey, associationField );
        break;
      }

      if ( update != null ) {
        collection.update( query, update, true, false );
      }
    }
  }
View Full Code Here

        this.addSubQuery( "$unset", updater, key.getCollectionRole(), ONE );
        this.getCollection( key.getEntityKey() ).update( entity, updater, true, false );
      }
    }
    else {
      DBCollection collection = getAssociationCollection( key );
      DBObject query = MongoHelpers.associationKeyToObject( provider.getAssociationStorage(), key );

      int nAffected = collection.remove( query ).getN();
      log.removedAssociation( nAffected );
    }
  }
View Full Code Here

    return new Tuple( EmptyTupleSnapshot.SINGLETON );
  }

  @Override
  public void nextValue(RowKey key, IntegralDataTypeHolder value, int increment, int initialValue) {
    DBCollection currentCollection = this.currentDB.getCollection( key.getTable() );
    DBObject query = this.prepareIdObject( key );
    //all columns should match to find the value

    BasicDBObject update = new BasicDBObject();
    //FIXME should "value" be hardcoded?
    //FIXME how to set the initialValue if the document is not present? It seems the inc value is used as initial new value
    Integer incrementObject = increment == 1 ? ONE : Integer.valueOf( increment );
    this.addSubQuery( "$inc", update, SEQUENCE_VALUE, incrementObject );
    DBObject result = currentCollection.findAndModify( query, null, null, false, update, false, true );
    Object idFromDB;
    idFromDB = result == null ? null : result.get( SEQUENCE_VALUE );
    if ( idFromDB == null ) {
      //not inserted yet so we need to add initial value to increment to have the right next value in the DB
      //FIXME that means there is a small hole as when there was not value in the DB, we do add initial value in a non atomic way
      BasicDBObject updateForInitial = new BasicDBObject();
      this.addSubQuery( "$inc", updateForInitial, SEQUENCE_VALUE, initialValue );
      currentCollection.findAndModify( query, null, null, false, updateForInitial, false, true );
      idFromDB = initialValue; //first time we ask this value
    }
    else {
      idFromDB = result.get( SEQUENCE_VALUE );
    }
View Full Code Here

  @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

        }
    }
   
    @CheckForNull
    <T extends Document> T findUncached(Collection<T> collection, String key) {
        DBCollection dbCollection = getDBCollection(collection);
        long start = start();
        try {
            DBObject obj = dbCollection.findOne(getByKeyQuery(key).get());
            if (obj == null) {
                return null;
            }
            T doc = convertFromDBObject(collection, obj);
            if (doc != null) {
View Full Code Here

TOP

Related Classes of com.mongodb.DBCollection

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.