/** @see DATADOC-246 */
  @Test
  public void updatesDBRefsCorrectly() {

    DBRef first = new DBRef(factory.getDb(), "foo", new ObjectId());
    DBRef second = new DBRef(factory.getDb(), "bar", new ObjectId());

    template.updateFirst(
        null, Update.update("dbRefs", Arrays.asList(first, second)), ClassWithDBRefs.class);
  }
 private String toString(MongoDbFactory mongoDbFactory) {
   if (mongoDbFactory == null) {
     return "<none>";
   } else {
     try {
       return mongoDbFactory.getDb().getMongo().getAddress().toString();
     } catch (Exception ex) {
       return "<invalid address> " + mongoDbFactory.getDb().getMongo().toString();
     }
   }
 }
  /** @see DATAMONGO-331 */
  @Test
  public void readsReplicasWriteConcernCorrectly() {

    AbstractApplicationContext ctx =
        new ClassPathXmlApplicationContext("namespace/db-factory-bean-custom-write-concern.xml");
    MongoDbFactory factory = ctx.getBean("second", MongoDbFactory.class);
    DB db = factory.getDb();

    assertThat(db.getWriteConcern(), is(WriteConcern.REPLICAS_SAFE));
    ctx.close();
  }
  /** @see DATAMONGO-306 */
  @Test
  public void setsUpMongoDbFactoryUsingAMongoUriWithoutCredentials() {

    reader.loadBeanDefinitions(new ClassPathResource("namespace/mongo-uri-no-credentials.xml"));
    BeanDefinition definition = factory.getBeanDefinition("mongoDbFactory");
    ConstructorArgumentValues constructorArguments = definition.getConstructorArgumentValues();

    assertThat(constructorArguments.getArgumentCount(), is(1));
    ValueHolder argument = constructorArguments.getArgumentValue(0, MongoURI.class);
    assertThat(argument, is(notNullValue()));

    MongoDbFactory dbFactory = factory.getBean("mongoDbFactory", MongoDbFactory.class);
    DB db = dbFactory.getDb();
    assertThat(db.getName(), is("database"));
  }
 /**
  * Return the status of the mongo db.
  *
  * @return
  */
 @RequestMapping(value = "/hsummary/health", method = RequestMethod.GET)
 @ResponseBody
 public Status getDBStatus() {
   try {
     mongoDbFactory.getDb().getStats();
     return Status.UP;
   } catch (Exception e) {
     LOG.error(e.getMessage(), e);
     return Status.DOWN;
   }
 }
  /** @see DATAMONGO-897 */
  @Test
  public void
      updateOnDbrefPropertyOfInterfaceTypeWithoutExplicitGetterForIdShouldBeMappedCorrectly() {

    Update update =
        new Update().set("referencedDocument", new InterfaceDocumentDefinitionImpl("1", "Foo"));
    DBObject mappedObject =
        mapper.getMappedObject(
            update.getUpdateObject(),
            context.getPersistentEntity(DocumentWithReferenceToInterfaceImpl.class));

    DBObject $set = DBObjectTestUtils.getAsDBObject(mappedObject, "$set");
    Object model = $set.get("referencedDocument");

    DBRef expectedDBRef = new DBRef(factory.getDb(), "interfaceDocumentDefinitionImpl", "1");
    assertThat(model, allOf(instanceOf(DBRef.class), IsEqual.<Object>equalTo(expectedDBRef)));
  }
예제 #7
0
 public void connectDB() {
   DB db = mongo.getDb();
 }