Package com.mongodb

Examples of com.mongodb.DBObject


    return new Tuple( new MongoDBTupleSnapshot( new BasicDBObject(), entityKeyMetadata, SnapshotType.INSERT ) );
  }

  @Override
  public Tuple createTuple(EntityKey key, TupleContext tupleContext) {
    DBObject toSave = this.prepareIdObject( key );
    return new Tuple( new MongoDBTupleSnapshot( toSave, key.getMetadata(), SnapshotType.INSERT ) );
  }
View Full Code Here


  /**
   * Returns a {@link DBObject} representing the entity which embeds the specified association.
   */
  private DBObject getEmbeddingEntity(AssociationKey key, AssociationContext associationContext) {
    DBObject embeddingEntityDocument = associationContext.getEntityTuple() != null ? ( (MongoDBTupleSnapshot) associationContext.getEntityTuple().getSnapshot() ).getDbObject() : null;

    if ( embeddingEntityDocument != null ) {
      return embeddingEntityDocument;
    }
    else {
      ReadPreference readPreference = getReadPreference( associationContext );

      DBCollection collection = getCollection( key.getEntityKey() );
      DBObject searchObject = prepareIdObject( key.getEntityKey() );
      DBObject projection = getProjection( key, true );

      return collection.findOne( searchObject, projection, readPreference );
    }
  }
View Full Code Here

  private DBObject getObject(EntityKey key, TupleContext tupleContext) {
    ReadPreference readPreference = getReadPreference( tupleContext );

    DBCollection collection = getCollection( key );
    DBObject searchObject = prepareIdObject( key );
    BasicDBObject projection = getProjection( tupleContext );

    return collection.findOne( searchObject, projection, readPreference );
  }
View Full Code Here

    if ( columnNames.length == 1 ) {
      object = new BasicDBObject( ID_FIELDNAME, columnValues[0] );
    }
    else {
      object = new BasicDBObject();
      DBObject idObject = new BasicDBObject();
      for ( int i = 0; i < columnNames.length; i++ ) {
        String columnName = columnNames[i];
        Object columnValue = columnValues[i];

        if ( columnName.contains( PROPERTY_SEPARATOR ) ) {
          int dotIndex = columnName.indexOf( PROPERTY_SEPARATOR );
          String shortColumnName = columnName.substring( dotIndex + 1 );
          idObject.put( shortColumnName, columnValue );
        }
        else {
          idObject.put( columnNames[i], columnValue );
        }

      }
      object.put( ID_FIELDNAME, idObject );
    }
View Full Code Here

  @Override
  public void insertOrUpdateTuple(EntityKey key, Tuple tuple, TupleContext tupleContext) {
    BasicDBObject idObject = this.prepareIdObject( key );

    DBObject updater = objectForUpdate( tuple, idObject );
    WriteConcern writeConcern = getWriteConcern( tupleContext );

    getCollection( key ).update( idObject, updater, true, false, writeConcern );
  }
View Full Code Here

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

    DBObject updater = objectForUpdate( tuple, idObject );
    DBObject doc = getCollection( entityKey ).findAndModify( idObject, updater );

    return doc != null;
  }
View Full Code Here

  }

  @Override
  public void insertTuple(EntityKeyMetadata entityKeyMetadata, Tuple tuple, TupleContext tupleContext) {
    WriteConcern writeConcern = getWriteConcern( tupleContext );
    DBObject objectWithId = insertDBObject( entityKeyMetadata, tuple, writeConcern );
    String idColumnName = entityKeyMetadata.getColumnNames()[0];
    tuple.put( idColumnName, objectWithId.get( ID_FIELDNAME ) );
  }
View Full Code Here

  /*
   * 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

  }

  @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

    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

TOP

Related Classes of com.mongodb.DBObject

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.