Пример #1
0
 @Override
 public void dropSchemaAndDatabase(SessionFactory sessionFactory) {
   MongoDBDatastoreProvider provider = getProvider(sessionFactory);
   try {
     provider.getDatabase().dropDatabase();
   } catch (MongoException ex) {
     throw log.unableToDropDatabase(ex, provider.getDatabase().getName());
   }
 }
Пример #2
0
 @Override
 @SuppressWarnings("unchecked")
 public Map<String, Object> extractEntityTuple(Session session, EntityKey key) {
   MongoDBDatastoreProvider provider = MongoDBTestHelper.getProvider(session.getSessionFactory());
   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();
 }
Пример #3
0
 public static Map<String, DBObject> getIndexes(
     OgmSessionFactory sessionFactory, String collection) {
   MongoDBDatastoreProvider provider = MongoDBTestHelper.getProvider(sessionFactory);
   List<DBObject> indexes = provider.getDatabase().getCollection(collection).getIndexInfo();
   Map<String, DBObject> indexMap = new HashMap<>();
   for (DBObject index : indexes) {
     indexMap.put(index.get("name").toString(), index);
   }
   return indexMap;
 }
Пример #4
0
  @Override
  public long getNumberOfEntities(SessionFactory sessionFactory) {
    MongoDBDatastoreProvider provider = MongoDBTestHelper.getProvider(sessionFactory);
    DB db = provider.getDatabase();
    int count = 0;

    for (String collectionName : getEntityCollections(sessionFactory)) {
      count += db.getCollection(collectionName).count();
    }

    return count;
  }
Пример #5
0
  public static void assertDbObject(
      OgmSessionFactory sessionFactory,
      String collection,
      String queryDbObject,
      String projectionDbObject,
      String expectedDbObject) {
    DBObject finder = (DBObject) JSON.parse(queryDbObject);
    DBObject fields = projectionDbObject != null ? (DBObject) JSON.parse(projectionDbObject) : null;

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

    assertJsonEquals(expectedDbObject, actual.toString());
  }
 @Override
 public void start() {
   try {
     super.start();
   } catch (Exception e) {
   }
 }
  /**
   * To be sure the datastoreProvider retrieves only the columns we want, an extra column is
   * manually added to the association document
   */
  @Override
  protected void addExtraColumn() {
    MongoDBDatastoreProvider provider =
        (MongoDBDatastoreProvider) super.getService(DatastoreProvider.class);
    DB database = provider.getDatabase();
    DBCollection collection = database.getCollection("Associations");

    final BasicDBObject idObject = new BasicDBObject(2);
    idObject.append("Project_id", "projectID");
    idObject.append("table", "Project_Module");

    BasicDBObject query = new BasicDBObject(1);
    query.put("_id", idObject);

    BasicDBObject updater = new BasicDBObject(1);
    updater.put("$push", new BasicDBObject("extraColumn", 1));
    collection.update(query, updater);
  }
Пример #8
0
 public static void dropIndexes(OgmSessionFactory sessionFactory, String collection) {
   MongoDBDatastoreProvider provider = MongoDBTestHelper.getProvider(sessionFactory);
   provider.getDatabase().getCollection(collection).dropIndexes();
 }