Package com.mongodb

Examples of com.mongodb.BasicDBObject


  public Object dbTest(@QueryParam("queries") Optional<String> queries)
  {
    final Random random = new Random(System.currentTimeMillis());
    if (!queries.isPresent())
    {
      DBObject query = new BasicDBObject();
      query.put("_id", (random.nextInt(10000) + 1));
      DBCursor<World> dbCursor = collection.find(query);
      return (dbCursor.hasNext()) ? dbCursor.next() : null;
    }
    Integer totalQueries = Ints.tryParse(queries.orNull());
    if (totalQueries != null)
    {
      if (totalQueries > 500)
      {
        totalQueries = 500;
      }
      else if (totalQueries < 1)
      {
        totalQueries = 1;
      }
    }
    else
    {
      totalQueries = 1;
    }
    final World[] worlds = new World[totalQueries];
    for (int i = 0; i < totalQueries; i++)
    {
      DBObject query = new BasicDBObject();
      query.put("_id", (random.nextInt(10000) + 1));
      DBCursor<World> dbCursor = collection.find(query);
      worlds[i] = (dbCursor.hasNext()) ? dbCursor.next() : null;
    }
    return worlds;
  }
View Full Code Here


  @Test
  public void canSerializeAndDeserialize() throws Exception {
    MongoDBQueryDescriptor descriptor = new MongoDBQueryDescriptor(
        "test",
        Operation.FIND,
        new BasicDBObject( "foo", "bar" ),
        new BasicDBObject( "foo", 1 ),
        new BasicDBObject( "bar", 1 )
    );

    byte[] bytes = serialize( descriptor );
    MongoDBQueryDescriptor deserializedDescriptor = deserialize( bytes );
View Full Code Here

  @Override
  @SuppressWarnings("unchecked")
  public Map<String, Object> extractEntityTuple(SessionFactory sessionFactory, EntityKey key) {
    MongoDBDatastoreProvider provider = MongoDBTestHelper.getProvider( sessionFactory );
    DBObject finder = new BasicDBObject( MongoDBDialect.ID_FIELDNAME, key.getColumnValues()[0] );
    DBObject result = provider.getDatabase().getCollection( key.getTable() ).findOne( finder );
    replaceIdentifierColumnName( result, key );
    return result.toMap();
  }
View Full Code Here

  private DBObject getProjectionDBObject() {
    if ( projections.isEmpty() ) {
      return null;
    }

    DBObject projectionDBObject = new BasicDBObject();

    for ( String projection : projections ) {
      projectionDBObject.put( projection, 1 );
    }

    return projectionDBObject;
  }
View Full Code Here

  }

  @Override
  protected void addSortField(PropertyPath propertyPath, String collateName, boolean isAscending) {
    if ( orderBy == null ) {
      orderBy = new BasicDBObject();
    }

    String columnName = propertyHelper.getColumnName( targetType, propertyPath.asStringPathWithoutAlias() );

    // BasicDBObject is essentially a LinkedHashMap, so in case of several sort keys they'll be evaluated in the
View Full Code Here

    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 );

    List<String> selectedColumns = new ArrayList<String>();
    selectedColumns.add( "name" );
    Tuple tuple = this.getTuple( collectionName, "1234", selectedColumns );
View Full Code Here

   */
  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 ) );
    collection.update( query, updater );
  }
View Full Code Here

  }

  @Test
  public void shouldApplyConfiguredReadPreferenceForGettingEmbeddedAssociation() {
    // given a persisted player with one associated golf course
    BasicDBObject player = getPlayer();
    player.put( "playedCourses", getPlayedCoursesAssociationEmbedded() );

    MockMongoClient mockClient = mockClient()
        .insert( "GolfPlayer", player )
        .insert( "GolfCourse", getGolfCourse() )
        .build();
View Full Code Here

    sessions = configuration.buildSessionFactory();
  }

  private BasicDBObject getGolfCourse() {
    BasicDBObject bepplePeach = new BasicDBObject();
    bepplePeach.put( "_id", 1L );
    bepplePeach.put( "name", "Bepple Peach" );
    return bepplePeach;
  }
View Full Code Here

    bepplePeach.put( "name", "Bepple Peach" );
    return bepplePeach;
  }

  private BasicDBObject getPlayer() {
    BasicDBObject golfPlayer = new BasicDBObject();
    golfPlayer.put( "_id", 1L );
    golfPlayer.put( "name", "Ben" );
    golfPlayer.put( "handicap", 0.1 );
    return golfPlayer;
  }
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.