Example usage for org.springframework.data.mongodb.core MongoTemplate findAllAndRemove

List of usage examples for org.springframework.data.mongodb.core MongoTemplate findAllAndRemove

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core MongoTemplate findAllAndRemove.

Prototype

@Override
    public <T> List<T> findAllAndRemove(Query query, Class<T> entityClass) 

Source Link

Usage

From source file:curly.artifactory.ArtifactoryTestHelper.java

public static Artifact createArtifact(MongoTemplate mongoTemplate) {
    mongoTemplate.findAllAndRemove(new Query(), Artifact.class);
    Artifact artifact = new Artifact();
    Set<Language> languages = new HashSet<>(0);
    Set<Tag> tags = new HashSet<>(0);
    tags.add(new Tag("document"));
    tags.add(new Tag("nosql"));
    languages.add(new Language("java"));
    languages.add(new Language("groovy"));
    languages.add(new Language("ruby"));
    languages.add(new Language("scala"));
    languages.add(new Language("javascript"));
    artifact.setName("curly");
    artifact.setDescription("a hobby project");
    artifact.setAuthor("joaoevangelista");
    artifact.setCategory(new Category("database"));
    artifact.setHomePage("http://example.com");
    artifact.setIncubation(LocalDate.now().toString());
    artifact.setLanguages(languages);//from  w  ww . j a v a  2 s  .c o m
    artifact.setTags(tags);
    artifact.setOwner("6969");
    mongoTemplate.insert(artifact);
    Assert.assertTrue(artifact.getId() != null);
    try {
        System.out.println(new ObjectMapper().writeValueAsString(artifact));
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    return artifact;
}

From source file:io.curly.tagger.TagHelper.java

public Tag createTag(MongoTemplate mongoTemplate) {
    mongoTemplate.findAllAndRemove(new Query(), Tag.class);
    Tag tag = new Tag(null, "love");
    mongoTemplate.insert(tag);/*  w  w w. jav  a  2 s  . c o m*/
    Assert.notNull(tag.getId(), "Must be generate!");
    return tag;
}