Examples of DBObject


Examples of com.mongodb.DBObject

            return null;
        }
        logger.debug("Searching {} in {}", info[1], info[0]);
        final DBCollection col = this.getCollection(info[0]);
        if ( col != null ) {
            final DBObject obj = col.findOne(QueryBuilder.start(getPROP_PATH()).is(info[1]).get());
            logger.debug("Found {}", obj);
            if ( obj != null ) {
                return new MongoDBResource(resourceResolver,
                        path,
                        info[0],
View Full Code Here

Examples of com.mongodb.DBObject

        final String collectionName = query.substring( 0, query.indexOf( ".find(" ) );
        DBCollection col = this.getCollection( collectionName );
        if ( col != null )
        {
            String criteria = query.trim().substring( query.indexOf( ".find(" ) + 6, query.length() - 1 );
            DBObject dbObject = (DBObject) JSON.parse( criteria );
            final DBCursor cur = col.find( dbObject );
            final String rootPath = context.getRootWithSlash();
           
            return new Iterator<Resource>() {

                public boolean hasNext() {
                    return cur.hasNext();
                }

                public Resource next() {
                    final DBObject obj = cur.next();
                    final String objPath = obj.get(getPROP_PATH()).toString();
                    final int lastSlash = objPath.lastIndexOf('/');
                    final String name;
                    if (lastSlash == -1) {
                        name = objPath;
                    } else {
View Full Code Here

Examples of com.mongodb.DBObject

      String.class);
  }

  @Override
  public List<SoilData> fetchNewestSoilData(int page, int pageSize) {
    DBObject orderBy = new BasicDBObject("_id", -1);
    int skip = page * pageSize;
    return soilDataCollection.find().sort(orderBy).skip(skip).limit(pageSize).toArray();
  }
View Full Code Here

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

Examples of com.mongodb.DBObject

      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

Examples of com.mongodb.DBObject

    }
    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

Examples of com.mongodb.DBObject

  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

Examples of com.mongodb.DBObject

    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

Examples of com.mongodb.DBObject

  @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

Examples of com.mongodb.DBObject

  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
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.