Skip to content

Commit

Permalink
Changes the DAO to use the new JNoSQL database connection
Browse files Browse the repository at this point in the history
Also new methods to support Vaadin's lazy loading
  • Loading branch information
leomrlima committed May 24, 2018
1 parent 214890f commit 2eef919
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/main/java/leomrlima/languages/LanguageDB.java
@@ -1,22 +1,33 @@
package leomrlima.languages;

import static org.jnosql.diana.api.document.query.DocumentQueryBuilder.select;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.jnosql.artemis.document.DocumentTemplate;

@ApplicationScoped
public class LanguageDB {

private Set<Language> languages = new LinkedHashSet<>();


@Inject
private DocumentTemplate template;

public boolean addLanguage(Language language) {
return this.languages.add(Objects.requireNonNull(language, "language can't be null"));
return template.insert(language) != null;
}

public Collection<Language> getAllLanguages() {
return Collections.unmodifiableSet(languages);
return template.select(select().from("Language").build());
}

public int countAllLanguages() {
//FIXME: change then JNoSQL supports count!
return getAllLanguages().size();
}

public List<Language> fetchLanguages(int offset, int limit) {
return template.select(select().from("Language").start(offset).limit(limit).build());
}
}

0 comments on commit 2eef919

Please sign in to comment.