Package com.mongodb

Examples of com.mongodb.DBObject


      queries = Helper.getQueries(exchange);
    }
   
    World[] worlds = new World[queries];
    for (int i = 0; i < queries; i++) {
      DBObject object = database.getCollection("World").findOne(
          new BasicDBObject("_id", Helper.randomWorld()));
      worlds[i] = new World(
          //
          // The creation script for the Mongo database inserts these numbers as
          // JavaScript numbers, which resolve to Doubles in Java.
          //
          ((Number) object.get("_id")).intValue(),
          ((Number) object.get("randomNumber")).intValue());
    }
    exchange.getResponseHeaders().put(
        Headers.CONTENT_TYPE, JSON_UTF8);
   
    if (multiple)
View Full Code Here


      return;
    }
    List<Fortune> fortunes = new ArrayList<>();
    DBCursor cursor = database.getCollection("Fortune").find();
    while (cursor.hasNext()) {
      DBObject object = cursor.next();
      fortunes.add(new Fortune(
          ((Number) object.get("_id")).intValue(),
          (String) object.get("message")));
    }
    fortunes.add(new Fortune(0, "Additional fortune added at request time."));
    Collections.sort(fortunes);
    Mustache mustache = mustacheFactory.compile("hello/fortunes.mustache");
    StringWriter writer = new StringWriter();
View Full Code Here

    }
    int queries = Helper.getQueries(exchange);
    World[] worlds = new World[queries];
    for (int i = 0; i < queries; i++) {
      int id = Helper.randomWorld();
      DBObject key = new BasicDBObject("_id", id);
      //
      // The requirements for the test dictate that we must fetch the World
      // object from the data store and read its randomNumber field, even though
      // we could technically avoid doing either of those things and still
      // produce the correct output and side effects.
      //
      DBObject object = database.getCollection("World").findOne(key);
     
      @SuppressWarnings("unused")
      // Per test requirement the old value must be read
      int oldRandomNumber = ((Number) object.get("randomNumber")).intValue();
     
      int newRandomNumber = Helper.randomWorld();
      object.put("randomNumber", newRandomNumber);
      database.getCollection("World").update(key, object);
      worlds[i] = new World(id, newRandomNumber);
    }
    exchange.getResponseHeaders().put(
        Headers.CONTENT_TYPE, JSON_UTF8);
View Full Code Here

  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

    for ( String entityCollection : getEntityCollections( sessionFactory ) ) {
      DBCursor entities = db.getCollection( entityCollection ).find();

      while ( entities.hasNext() ) {
        DBObject entity = entities.next();
        associationCount += getNumberOfEmbeddedAssociations( entity );
      }
    }

    return associationCount;
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

  public GridDialect getGridDialect(DatastoreProvider datastoreProvider) {
    return new MongoDBDialect( (MongoDBDatastoreProvider) datastoreProvider );
  }

  public static void assertDbObject(OgmSessionFactory sessionFactory, String collection, String queryDbObject, String expectedDbObject) {
    DBObject finder = (DBObject) JSON.parse( queryDbObject );
    DBObject expected = (DBObject) JSON.parse( expectedDbObject );

    MongoDBDatastoreProvider provider = MongoDBTestHelper.getProvider( sessionFactory );
    DBObject actual = provider.getDatabase().getCollection( collection ).findOne( finder );

    assertThat( actual ).isEqualTo( expected );
  }
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

        new Tuple( new MongoDBTupleSnapshot( null, null, null ) )
    );

    final Association association = getService( GridDialect.class ).getAssociation( associationKey, associationContext );
    final MongoDBAssociationSnapshot associationSnapshot = (MongoDBAssociationSnapshot) association.getSnapshot();
    final DBObject assocObject = associationSnapshot.getDBObject();
    this.checkLoading( assocObject );

    session.delete( mongodb );
    session.delete( infinispan );
    session.delete( hibernateOGM );
View Full Code Here

    throw new UnsupportedOperationException( "The MongoDB GridDialect does not support locking" );
  }

  @Override
  public Tuple getTuple(EntityKey key, TupleContext tupleContext) {
    DBObject found = this.getObject( key, tupleContext );
    if ( found != null ) {
      return new Tuple( new MongoDBTupleSnapshot( found, key.getMetadata(), UPDATE ) );
    }
    else if ( isInTheQueue( key, tupleContext ) ) {
      // The key has not been inserted in the db but it is in the queue
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.