Skip to content

Commit

Permalink
feat: update structure
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <[email protected]>
  • Loading branch information
otaviojava committed Sep 18, 2024
1 parent a907909 commit 153e1d2
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 240 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.jnosql.demoee;

import jakarta.data.page.Pageable;
import jakarta.data.repository.PageableRepository;
import jakarta.data.page.PageRequest;
import jakarta.data.repository.BasicRepository;
import jakarta.data.repository.Repository;

import java.util.stream.Stream;

@Repository
public interface AuthorWithBooksRepository extends PageableRepository<AuthorWithBooks, String> {
Stream<AuthorWithBooks> findByName(String name, Pageable pageable);
public interface AuthorWithBooksRepository extends BasicRepository<AuthorWithBooks, String> {
Stream<AuthorWithBooks> findByName(String name, PageRequest pageable);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package org.jnosql.demoee;

import jakarta.data.page.Pageable;
import jakarta.data.page.PageRequest;
import jakarta.data.repository.*;
import jakarta.ws.rs.QueryParam;

import java.util.stream.Stream;

@Repository
public interface BookWithAuthorRepository extends PageableRepository<BookWithAuthor, String> {
public interface BookWithAuthorRepository extends BasicRepository<BookWithAuthor, String> {
@Query("select * from BookWithAuthor where author._id = @authorId")
Stream<BookWithAuthor> listBooksByAuthorId(@Param("authorId") String id);

Stream<BookWithAuthor> findByTitleLike(String title, Pageable pageable);
Stream<BookWithAuthor> findByTitleLike(String title, PageRequest pageable);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jnosql.demoee;

import jakarta.data.page.Pageable;
import jakarta.data.Order;
import jakarta.data.page.PageRequest;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

Expand Down Expand Up @@ -36,12 +37,12 @@ public AuthorWithBooks save(AuthorWithBooks author) {
return author;
}

public Stream<AuthorWithBooks> findAuthorsByName(String name, Pageable pageable) {
public Stream<AuthorWithBooks> findAuthorsByName(String name, PageRequest pageable) {
return authorWithBooksRepository.findByName(name, pageable);
}

public Stream<AuthorWithBooks> listAuthors(Pageable pageable) {
return authorWithBooksRepository.findAll(pageable).stream();
public Stream<AuthorWithBooks> listAuthors(PageRequest pageable) {
return authorWithBooksRepository.findAll(pageable, Order.by()).stream();
}

public Optional<AuthorWithBooks> findAuthorById(String authorId) {
Expand All @@ -58,11 +59,11 @@ public BookWithAuthor save(BookWithAuthor bookWithAuthor) {
return bookWithAuthor;
}

public Stream<BookWithAuthor> findBooksByTitle(String title, Pageable pageable) {
public Stream<BookWithAuthor> findBooksByTitle(String title, PageRequest pageable) {
return bookWithAuthorRepository.findByTitleLike(title, pageable);
}

public Stream<BookWithAuthor> listBooks(Pageable pageable) {
return bookWithAuthorRepository.findAll(pageable).stream();
public Stream<BookWithAuthor> listBooks(PageRequest pageable) {
return bookWithAuthorRepository.findAll(pageable, Order.by()).stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@


import jakarta.data.Direction;
import jakarta.data.page.Pageable;
import jakarta.data.page.PageRequest;
import jakarta.data.Sort;

import java.util.Arrays;
import java.util.Objects;

public interface PageableResource {


default Pageable createPageable(String orderBy, int page, int pageSize) {
return Pageable.ofSize(pageSize).page(page)
.sortBy(Arrays.stream(orderBy.split(","))
.map(this::convertToSort)
.filter(Objects::nonNull)
.toList());
default PageRequest createPageable(String orderBy, int page, int pageSize) {
return PageRequest.ofPage(page).size(pageSize);
}


Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.jnosql.demoee;

import jakarta.data.repository.PageableRepository;

import jakarta.data.repository.BasicRepository;
import jakarta.data.repository.Repository;

@Repository
public interface DogRepository extends PageableRepository<Dog, String> {
public interface DogRepository extends BasicRepository<Dog, String> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import com.github.javafaker.Faker;


import jakarta.data.page.Pageable;
import jakarta.data.Order;
import jakarta.data.Sort;
import jakarta.data.page.PageRequest;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.DELETE;
Expand Down Expand Up @@ -53,8 +54,10 @@ public List<Dog> random(){
@GET
public List<Dog> findAll(@QueryParam("page") @DefaultValue("1") long page,
@QueryParam("size") @DefaultValue("10") int size){
Pageable pageable = Pageable.ofPage(page).size(size).sortBy(Sort.asc("name"));
return this.repository.findAll(pageable).content();
PageRequest pageable = PageRequest.ofPage(page).size(size);

Order<Dog> order = Order.by(Sort.asc("name"));
return this.repository.findAll(pageable, order).content();
}

@POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import com.github.javafaker.Faker;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.nosql.document.DocumentTemplate;


import org.bson.types.ObjectId;
import org.eclipse.jnosql.mapping.document.DocumentTemplate;

import java.util.List;
import java.util.Optional;
Expand Down
4 changes: 2 additions & 2 deletions tomee-jnosql-sample/src/main/java/org/soujava/Animal.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.soujava;

import jakarta.nosql.Column;
import jakarta.nosql.Convert;
import jakarta.nosql.Entity;
import jakarta.nosql.Id;
import org.eclipse.jnosql.mapping.Convert;

import java.util.Objects;

Expand Down Expand Up @@ -57,4 +57,4 @@ public String toString() {
", name='" + name + '\'' +
'}';
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.soujava;

import jakarta.data.repository.PageableRepository;
import jakarta.data.repository.BasicRepository;
import jakarta.data.repository.Repository;


@Repository
public interface AnimalRepository extends PageableRepository<Animal, String> {
}
public interface AnimalRepository extends BasicRepository<Animal, String> {
}
Loading

0 comments on commit 153e1d2

Please sign in to comment.