Examples of DBObject


Examples of com.mongodb.DBObject

  /*
   * Insert the tuple and return an object containing the id in the field ID_FIELDNAME
   */
  private DBObject insertDBObject(EntityKeyMetadata entityKeyMetadata, Tuple tuple, WriteConcern writeConcern) {
    DBObject dbObject = objectForInsert( tuple, ( (MongoDBTupleSnapshot) tuple.getSnapshot() ).getDbObject() );
    getCollection( entityKeyMetadata ).insert( dbObject, writeConcern );
    return dbObject;
  }
View Full Code Here

Examples of com.mongodb.DBObject

  }

  @Override
  public void removeTuple(EntityKey key, TupleContext tupleContext) {
    DBCollection collection = getCollection( key );
    DBObject toDelete = prepareIdObject( key );
    WriteConcern writeConcern = getWriteConcern( tupleContext );

    collection.remove( toDelete, writeConcern );
  }
View Full Code Here

Examples of com.mongodb.DBObject

    collection.remove( toDelete, writeConcern );
  }

  @Override
  public boolean removeTupleWithOptimisticLock(EntityKey entityKey, Tuple oldLockState, TupleContext tupleContext) {
    DBObject toDelete = prepareIdObject( entityKey );

    for ( String versionColumn : oldLockState.getColumnNames() ) {
      toDelete.put( versionColumn, oldLockState.get( versionColumn ) );
    }

    DBCollection collection = getCollection( entityKey );
    DBObject deleted = collection.findAndRemove( toDelete );

    return deleted != null;
  }
View Full Code Here

Examples of com.mongodb.DBObject

  }

  //not for embedded
  private DBObject findAssociation(AssociationKey key, AssociationContext associationContext, AssociationStorageStrategy storageStrategy) {
    ReadPreference readPreference = getReadPreference( associationContext );
    final DBObject associationKeyObject = associationKeyToObject( key, storageStrategy );

    return getAssociationCollection( key, storageStrategy ).findOne( associationKeyObject, getProjection( key, false ), readPreference );
  }
View Full Code Here

Examples of com.mongodb.DBObject

    // We need to execute the previous operations first or it won't be able to find the key that should have
    // been created
    executeBatch( associationContext.getOperationsQueue() );
    if ( storageStrategy == AssociationStorageStrategy.IN_ENTITY ) {
      DBObject entity = getEmbeddingEntity( key, associationContext );

      if ( entity != null && hasField( entity, key.getMetadata().getCollectionRole() ) ) {
        return new Association( new MongoDBAssociationSnapshot( entity, key, storageStrategy ) );
      }
      else {
        return null;
      }
    }
    final DBObject result = findAssociation( key, associationContext, storageStrategy );
    if ( result == null ) {
      return null;
    }
    else {
      return new Association( new MongoDBAssociationSnapshot( result, key, storageStrategy ) );
View Full Code Here

Examples of com.mongodb.DBObject

  @Override
  public Association createAssociation(AssociationKey key, AssociationContext associationContext) {
    AssociationStorageStrategy storageStrategy = getAssociationStorageStrategy( key, associationContext );

    DBObject document = storageStrategy == AssociationStorageStrategy.IN_ENTITY
        ? getEmbeddingEntity( key, associationContext )
        : associationKeyToObject( key, storageStrategy );

    return new Association( new MongoDBAssociationSnapshot( document, key, storageStrategy ) );
  }
View Full Code Here

Examples of com.mongodb.DBObject

    if ( rowKeyColumnsToPersist.length == 1 ) {
      return row.get( rowKeyColumnsToPersist[0] );
    }
    // otherwise a DBObject with the row contents
    else {
      DBObject rowObject = new BasicDBObject( rowKeyColumnsToPersist.length );
      for ( String column : rowKeyColumnsToPersist ) {
        rowObject.put( column, row.get( column ) );
      }

      return rowObject;
    }
  }
View Full Code Here

Examples of com.mongodb.DBObject

  }

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

    AssociationStorageStrategy storageStrategy = getAssociationStorageStrategy( key, associationContext );
    WriteConcern writeConcern = getWriteConcern( associationContext );

    List<?> rows = getAssociationRows( association, key );
    Object toStore = key.getMetadata().isOneToOne() ? rows.get( 0 ) : rows;

    // We need to execute the previous operations first or it won't be able to find the key that should have
    // been created
    executeBatch( associationContext.getOperationsQueue() );
    if ( storageStrategy == AssociationStorageStrategy.IN_ENTITY ) {
      collection = this.getCollection( key.getEntityKey() );
      query = this.prepareIdObject( key.getEntityKey() );
      associationField = key.getMetadata().getCollectionRole();

      ( (MongoDBTupleSnapshot) associationContext.getEntityTuple().getSnapshot() ).getDbObject().put( key.getMetadata().getCollectionRole(), toStore );
    }
    else {
      collection = getAssociationCollection( key, storageStrategy );
      query = assocSnapshot.getQueryObject();
      associationField = ROWS_FIELDNAME;
    }

    DBObject update = new BasicDBObject( "$set", new BasicDBObject( associationField, toStore ) );

    collection.update( query, update, true, false, writeConcern );
  }
View Full Code Here

Examples of com.mongodb.DBObject

  public void removeAssociation(AssociationKey key, AssociationContext associationContext) {
    AssociationStorageStrategy storageStrategy = getAssociationStorageStrategy( key, associationContext );
    WriteConcern writeConcern = getWriteConcern( associationContext );

    if ( storageStrategy == AssociationStorageStrategy.IN_ENTITY ) {
      DBObject entity = this.prepareIdObject( key.getEntityKey() );
      if ( entity != null ) {
        BasicDBObject updater = new BasicDBObject();
        addSubQuery( "$unset", updater, key.getMetadata().getCollectionRole(), Integer.valueOf( 1 ) );
        ( (MongoDBTupleSnapshot) associationContext.getEntityTuple().getSnapshot() ).getDbObject().removeField( key.getMetadata().getCollectionRole() );
        getCollection( key.getEntityKey() ).update( entity, updater, true, false, writeConcern );
      }
    }
    else {
      DBCollection collection = getAssociationCollection( key, storageStrategy );
      DBObject query = associationKeyToObject( key, storageStrategy );

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

Examples of com.mongodb.DBObject

  }

  @Override
  public Number nextValue(NextValueRequest request) {
    DBCollection currentCollection = getCollection( request.getKey().getTable() );
    DBObject query = this.prepareIdObject( request.getKey() );
    //all columns should match to find the value

    String valueColumnName = request.getKey().getMetadata().getValueColumnName();

    BasicDBObject update = new BasicDBObject();
    //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 = Integer.valueOf( request.getIncrement() );
    this.addSubQuery( "$inc", update, valueColumnName, incrementObject );
    DBObject result = currentCollection.findAndModify( query, null, null, false, update, false, true );
    Object idFromDB;
    idFromDB = result == null ? null : result.get( valueColumnName );
    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, valueColumnName, request.getInitialValue() );
      currentCollection.findAndModify( query, null, null, false, updateForInitial, false, true );
      idFromDB = request.getInitialValue(); //first time we ask this value
    }
    else {
      idFromDB = result.get( valueColumnName );
    }
    if ( idFromDB.getClass().equals( Integer.class ) || idFromDB.getClass().equals( Long.class ) ) {
      Number id = (Number) idFromDB;
      //idFromDB is the one used and the BD contains the next available value to use
      return id;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.