Package org.springframework.data.mongodb.core

Examples of org.springframework.data.mongodb.core.SimpleMongoDbFactory


  }

  @Test
  public void testWriteConcern() throws Exception {

    SimpleMongoDbFactory dbFactory = new SimpleMongoDbFactory(new MongoClient("localhost"), "database");
    dbFactory.setWriteConcern(WriteConcern.SAFE);
    dbFactory.getDb();

    assertThat(ReflectionTestUtils.getField(dbFactory, "writeConcern"), is((Object) WriteConcern.SAFE));
  }
View Full Code Here


    assertThat(db.getWriteConcern(), is(WriteConcern.REPLICAS_SAFE));
    ctx.close();
  }

  private void assertWriteConcern(ClassPathXmlApplicationContext ctx, WriteConcern expectedWriteConcern) {
    SimpleMongoDbFactory dbFactory = ctx.getBean("first", SimpleMongoDbFactory.class);
    DB db = dbFactory.getDb();
    assertThat(db.getName(), is("db"));

    WriteConcern configuredConcern = (WriteConcern) ReflectionTestUtils.getField(dbFactory, "writeConcern");

    MyWriteConcern myDbFactoryWriteConcern = new MyWriteConcern(configuredConcern);
View Full Code Here

   * @return
   * @throws Exception
   */
  @Bean
  public MongoDbFactory mongoDbFactory() throws Exception {
    return new SimpleMongoDbFactory(mongo(), getDatabaseName(), getUserCredentials(), getAuthenticationDatabaseName());
  }
View Full Code Here

  @Produces
  @ApplicationScoped
  public MongoOperations createMongoTemplate() throws UnknownHostException, MongoException {

    MongoDbFactory factory = new SimpleMongoDbFactory(new MongoClient(), "database");
    return new MongoTemplate(factory);
  }
View Full Code Here

  @EnableMongoRepositories(basePackages = "org.springframework.data.mongodb.repository")
  static class Config {

    @Bean
    public MongoOperations mongoTemplate() throws Exception {
      return new MongoTemplate(new SimpleMongoDbFactory(new MongoClient(), "database"));
    }
View Full Code Here

  @EnableMongoAuditing
  static class SimpleConfigWithRepositories {

    @Bean
    public MongoTemplate mongoTemplate() throws UnknownHostException {
      return new MongoTemplate(new SimpleMongoDbFactory(new MongoClient(), "database"));
    }
View Full Code Here

  @EnableMongoAuditing
  static class SimpleConfig {

    @Bean
    public MongoTemplate mongoTemplate() throws UnknownHostException {
      return new MongoTemplate(new SimpleMongoDbFactory(new MongoClient(), "database"));
    }
View Full Code Here

  @Before
  public void setUp() throws Exception {

    this.mongo = new MongoClient();

    SimpleMongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(this.mongo, DATABASE_NAME);

    MongoMappingContext context = new MongoMappingContext();
    context.setInitialEntitySet(Collections.singleton(Person.class));
    context.afterPropertiesSet();

    this.converter = new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory), context);
    this.operations = new MongoTemplate(new SimpleMongoDbFactory(this.mongo, DATABASE_NAME), converter);

    MongoRepositoryFactoryBean<PersonRepository, Person, ObjectId> factory = new MongoRepositoryFactoryBean<PersonRepository, Person, ObjectId>();
    factory.setMongoOperations(operations);
    factory.setRepositoryInterface(PersonRepository.class);
    factory.afterPropertiesSet();
View Full Code Here

  @Bean
  @ConditionalOnMissingBean
  public MongoDbFactory mongoDbFactory(Mongo mongo) throws Exception {
    String db = this.properties.getMongoClientDatabase();
    return new SimpleMongoDbFactory(mongo, db);
  }
View Full Code Here

  private static final Log log = LogFactory.getLog(MongoApp.class);

  public static void main(String[] args) throws Exception {
  BasicConfigurator.configure();   
   
    MongoOperations mongoOps = new MongoTemplate(new SimpleMongoDbFactory(new Mongo(), "database"));

    // Insert is used to initially store the object into the database.
    Car c = new Car("Red", "Opel");
    mongoOps.insert(c);
    Person p = new Person("Joe", 34, c);
View Full Code Here

TOP

Related Classes of org.springframework.data.mongodb.core.SimpleMongoDbFactory

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.