Package org.springframework.data.mongodb.core

Examples of org.springframework.data.mongodb.core.MongoTemplate$FindCallback


  @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

    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 MongoTemplate mongoTemplate(MongoDbFactory mongoDbFactory)
      throws UnknownHostException {
    return new MongoTemplate(mongoDbFactory);
  }
View Full Code Here

  @Test
  public void mongoIsUp() throws Exception {
    CommandResult commandResult = mock(CommandResult.class);
    given(commandResult.getString("version")).willReturn("2.6.4");
    MongoTemplate mongoTemplate = mock(MongoTemplate.class);
    given(mongoTemplate.executeCommand("{ buildInfo: 1 }")).willReturn(commandResult);
    MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);

    Health health = healthIndicator.health();
    assertEquals(Status.UP, health.getStatus());
    assertEquals("2.6.4", health.getDetails().get("version"));
View Full Code Here

    verify(mongoTemplate).executeCommand("{ buildInfo: 1 }");
  }

  @Test
  public void mongoIsDown() throws Exception {
    MongoTemplate mongoTemplate = mock(MongoTemplate.class);
    given(mongoTemplate.executeCommand("{ buildInfo: 1 }")).willThrow(
        new MongoException("Connection failed"));
    MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);

    Health health = healthIndicator.health();
    assertEquals(Status.DOWN, health.getStatus());
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);
    Person p2 = new Person("Anna", 31, c);
    mongoOps.insert(p);
    mongoOps.insert(p2);
    log.info("Insert: " + p);
   
    // Find
    p = mongoOps.findById(p.getId(), Person.class);   
    log.info("Found: " + p);
   
    // Update
    mongoOps.updateFirst(query(where("name").is("Joe")), update("age", 35), Person.class);
    //mongoOps.updateMulti(query(where("name").is("Joe")), update("age", 36), Person.class);
    p = mongoOps.findOne(query(where("name").is("Joe")), Person.class);
    log.info("Updated: " + p);
   
    // Delete
    mongoOps.remove(p);
   
    // Check that deletion worked
    List<Person> people =  mongoOps.findAll(Person.class);
    log.info("Number of people = : " + people.size());

   
    //mongoOps.dropCollection(Person.class);
  }
View Full Code Here

        return rdbmsServiceCreator.createService(rdbmsServiceInfo);
    }

    @Bean
    public MongoTemplate mongoTemplate() {
        return new MongoTemplate(mongoDbFactory());
    }
View Full Code Here

    @Autowired
    public void setMongoDbFactory(final MongoDbFactory factory) {
        if (factory == null) {
            throw new IllegalArgumentException("factory must not be null");
        }
        mongoTemplate = new MongoTemplate(factory);
    }
View Full Code Here

   * @return A {@link MongoTemplate} for POJOs support.
   */
  @Bean
  public MongoTemplate mongoTemplate(final MongoDbFactory mongoDbFactory) {
    Validate.notNull(mongoDbFactory, "The mongo database factory is required.");
    return new MongoTemplate(mongoDbFactory);
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.mongodb.core.MongoTemplate$FindCallback

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.