Package com.mongodb

Examples of com.mongodb.BasicDBObject


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

  @Override
  public boolean updateTupleWithOptimisticLock(EntityKey entityKey, Tuple oldLockState, Tuple tuple, TupleContext tupleContext) {
    BasicDBObject idObject = this.prepareIdObject( entityKey );

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

    DBObject updater = objectForUpdate( tuple, idObject );
    DBObject doc = getCollection( entityKey ).findAndModify( idObject, updater );
View Full Code Here


  }

  private DBObject objectForUpdate(Tuple tuple, DBObject idObject) {
    MongoDBTupleSnapshot snapshot = (MongoDBTupleSnapshot) tuple.getSnapshot();

    BasicDBObject updater = new BasicDBObject();
    for ( TupleOperation operation : tuple.getOperations() ) {
      String column = operation.getColumn();
      if ( notInIdField( snapshot, column ) ) {
        switch ( operation.getType() ) {
        case PUT_NULL:
        case PUT:
          this.addSubQuery( "$set", updater, column, operation.getValue() );
          break;
        case REMOVE:
          this.addSubQuery( "$unset", updater, column, Integer.valueOf( 1 ) );
          break;
        }
      }
    }
    /*
    * Needed because in case of object with only an ID field
    * the "_id" won't be persisted properly.
    * With this adjustment, it will work like this:
    *  if the object (from snapshot) doesn't exist so create the one represented by updater
    *  so if at this moment the "_id" is not enforce properly an ObjectID will be created by the server instead
    *  of the custom id
     */
    if ( updater.size() == 0 ) {
      return idObject;
    }
    return updater;
  }
View Full Code Here

    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

      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

    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 );
      }
    }
View Full Code Here

    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 {
View Full Code Here

    if ( storageStrategy == AssociationStorageStrategy.IN_ENTITY ) {
      throw new AssertionFailure( MongoHelpers.class.getName()
          + ".associationKeyToObject should not be called for associations embedded in entity documents");
    }
    Object[] columnValues = key.getColumnValues();
    DBObject columns = new BasicDBObject( columnValues.length );

    int i = 0;
    for ( String name : key.getColumnNames() ) {
      columns.put( name, columnValues[i++] );
    }

    BasicDBObject idObject = new BasicDBObject( 1 );

    if ( storageStrategy == AssociationStorageStrategy.GLOBAL_COLLECTION ) {
      columns.put( MongoDBDialect.TABLE_FIELDNAME, key.getTable() );
    }
    idObject.put( MongoDBDialect.ID_FIELDNAME, columns );
    return idObject;
  }
View Full Code Here

      }
      return this;
    }

    private MongoRelations prepareRelations(DBObject db) {
      DBObject relation = new BasicDBObject();
      // 恒定信息: JID, 创建者
      relation.put(Dictionary.FIELD_JID, MongoUtils.asString(db, Dictionary.FIELD_JID));
      relation.put(Dictionary.FIELD_CREATOR, MongoUtils.asString(db, Dictionary.FIELD_CREATOR));
      // 加载Roles
      for (Object each : MongoUtils.asList(db, Dictionary.FIELD_ROLES)) {
        DBObject roles = DBObject.class.cast(each);
        relation.put(Dictionary.FIELD_ROLES, roles);
        // 加载岗位
        relation.put(Dictionary.FIELD_AFFILIATION, this.affiliations.get(roles.get(Dictionary.FIELD_JID)));
        super.add(new MongoRelation(relation));
      }
      return this;
    }
View Full Code Here

        this.searches = searches;
    }

    @Override
    public Dashboard load(String id) throws NotFoundException {
        BasicDBObject o = (BasicDBObject) get(DashboardImpl.class, id);

        if (o == null) {
            throw new NotFoundException();
        }

        return new DashboardImpl((ObjectId) o.get("_id"), o.toMap());
    }
View Full Code Here

    @Override
    public List<Dashboard> all() {
        List<Dashboard> dashboards = Lists.newArrayList();

        List<DBObject> results = query(DashboardImpl.class, new BasicDBObject());
        for (DBObject o : results) {
            Map<String, Object> fields = o.toMap();
            Dashboard dashboard = new DashboardImpl((ObjectId) o.get("_id"), fields);

            // Add all widgets of this dashboard.
View Full Code Here

TOP

Related Classes of com.mongodb.BasicDBObject

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.