diff --git a/oracle-nosql/src/main/java/org/jnosql/demo/se/App.java b/oracle-nosql/src/main/java/org/jnosql/demo/se/App.java index 747fc6ce..fb6c6494 100644 --- a/oracle-nosql/src/main/java/org/jnosql/demo/se/App.java +++ b/oracle-nosql/src/main/java/org/jnosql/demo/se/App.java @@ -24,12 +24,16 @@ public static void main(String[] args) { Faker faker = new Faker(); try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { DocumentTemplate template = container.select(DocumentTemplate.class).get(); - for (int index = 0; index < 100; index++) { - Beer beer = Beer.of(faker); - template.insert(beer); + for (int index = 0; index < 0; index++) { + Car car = Car.of(faker); + template.insert(car); } - template.select(Beer.class).where("style").eq("Pilsner").orderBy("hop").desc() + // template.select(Car.class).stream().toList().forEach(System.out::println); + template.select(Car.class).where("transmission").eq("Automatic").orderBy("model").desc() + .stream().forEach(System.out::println); + + template.select(Car.class).where("transmission").eq("CVT").orderBy("make").desc() .stream().forEach(System.out::println); } diff --git a/oracle-nosql/src/main/java/org/jnosql/demo/se/App2.java b/oracle-nosql/src/main/java/org/jnosql/demo/se/App2.java index bc221c5d..0848ac9d 100644 --- a/oracle-nosql/src/main/java/org/jnosql/demo/se/App2.java +++ b/oracle-nosql/src/main/java/org/jnosql/demo/se/App2.java @@ -15,12 +15,12 @@ public static void main(String[] args) { Faker faker = new Faker(); try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { KeyValueTemplate template = container.select(KeyValueTemplate.class).get(); - Beer beer = Beer.of(faker); - template.put(beer); + Car car = Car.of(faker); + template.put(car); - System.out.println("The query result: " + template.get(beer.id(), Beer.class)); - template.delete(beer.id()); - System.out.println("The query result: " + template.get(beer.id(), Beer.class)); + System.out.println("The query result: " + template.get(car.id(), Car.class)); + template.delete(car.id()); + System.out.println("The query result: " + template.get(car.id(), Car.class)); } System.exit(0); } diff --git a/oracle-nosql/src/main/java/org/jnosql/demo/se/App3.java b/oracle-nosql/src/main/java/org/jnosql/demo/se/App3.java index fe310e6c..e324b8a1 100644 --- a/oracle-nosql/src/main/java/org/jnosql/demo/se/App3.java +++ b/oracle-nosql/src/main/java/org/jnosql/demo/se/App3.java @@ -7,30 +7,29 @@ import jakarta.enterprise.inject.se.SeContainer; import jakarta.enterprise.inject.se.SeContainerInitializer; import net.datafaker.Faker; +import org.eclipse.jnosql.mapping.DatabaseQualifier; public class App3 { public static void main(String[] args) { Faker faker = new Faker(); try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { - BeerRepository repository = container.select(BeerRepository.class).get(); - for (int index = 0; index < 100; index++) { - Beer beer = Beer.of(faker); - repository.save(beer); - + Garage repository = container.select(Garage.class, DatabaseQualifier.ofDocument()).get(); + for (int index = 0; index < 0; index++) { + Car beer = Car.of(faker); + repository.parking(beer); } - Pageable page = Pageable.ofPage(1).sortBy(Sort.desc("style")); - Page page1 = repository.findAll(page); + Pageable page = Pageable.ofPage(1).size(3).sortBy(Sort.desc("model")); + Page page1 = repository.findByTransmission("CVT", page); System.out.println("The first page"); page1.forEach(System.out::println); System.out.println("The second page"); Pageable secondPage = page.next(); - Page page2 = repository.findAll(secondPage); + Page page2 = repository.findByTransmission("CVT", secondPage); page2.forEach(System.out::println); System.out.println("The query result: "); - repository.query().forEach(System.out::println); } System.exit(0); diff --git a/oracle-nosql/src/main/java/org/jnosql/demo/se/Beer.java b/oracle-nosql/src/main/java/org/jnosql/demo/se/Beer.java deleted file mode 100644 index c27e4c1e..00000000 --- a/oracle-nosql/src/main/java/org/jnosql/demo/se/Beer.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.jnosql.demo.se; - -import jakarta.nosql.Column; -import jakarta.nosql.Entity; -import jakarta.nosql.Id; -import net.datafaker.Faker; - -import java.util.Objects; -import java.util.UUID; - -@Entity -public class Beer { - - @Id - private String id; - - @Column - private String style; - - @Column - private String hop; - - @Column - private String malt; - - - public String id() { - return id; - } - - public String style() { - return style; - } - - public String hop() { - return hop; - } - - public String malt() { - return malt; - } - - @Override - public String toString() { - return "Beer{" + - "id='" + id + '\'' + - ", style='" + style + '\'' + - ", hop='" + hop + '\'' + - ", malt='" + malt + '\'' + - '}'; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object == null || getClass() != object.getClass()) { - return false; - } - Beer beer = (Beer) object; - return Objects.equals(id, beer.id); - } - - @Override - public int hashCode() { - return Objects.hashCode(id); - } - - public static Beer of(Faker faker){ - var beer = faker.beer(); - Beer entity = new Beer(); - entity.hop = beer.hop(); - entity.malt = beer.malt(); - entity.style = beer.style(); - entity.id= UUID.randomUUID().toString(); - return entity; - } - -} diff --git a/oracle-nosql/src/main/java/org/jnosql/demo/se/BeerRepository.java b/oracle-nosql/src/main/java/org/jnosql/demo/se/BeerRepository.java deleted file mode 100644 index 4fa19f2e..00000000 --- a/oracle-nosql/src/main/java/org/jnosql/demo/se/BeerRepository.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.jnosql.demo.se; - -import jakarta.data.repository.Query; -import jakarta.data.repository.Repository; -import org.eclipse.jnosql.databases.oracle.mapping.OracleNoSQLRepository; - -import java.util.Set; - -@Repository -public interface BeerRepository extends OracleNoSQLRepository { - - Set findByStyle(String style); - - @Query("select * from Beer") - Set query(); - -} diff --git a/oracle-nosql/src/main/java/org/jnosql/demo/se/Car.java b/oracle-nosql/src/main/java/org/jnosql/demo/se/Car.java new file mode 100644 index 00000000..a0d67258 --- /dev/null +++ b/oracle-nosql/src/main/java/org/jnosql/demo/se/Car.java @@ -0,0 +1,86 @@ +package org.jnosql.demo.se; + +import jakarta.nosql.Column; +import jakarta.nosql.Entity; +import jakarta.nosql.Id; +import net.datafaker.Faker; +import net.datafaker.providers.base.Vehicle; + +import java.util.Objects; +import java.util.UUID; + +@Entity +public class Car { + + + @Id + private String id; + + @Column + private String vin; + @Column + private String model; + @Column + private String make; + @Column + private String transmission; + + public String id() { + return id; + } + + public String vin() { + return vin; + } + + public String model() { + return model; + } + + public String make() { + return make; + } + + public String transmission() { + return transmission; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Car car = (Car) o; + return Objects.equals(id, car.id); + } + + @Override + public int hashCode() { + return Objects.hashCode(id); + } + + @Override + public String toString() { + return "Car{" + + "id='" + id + '\'' + + ", vin='" + vin + '\'' + + ", model='" + model + '\'' + + ", make='" + make + '\'' + + ", transmission='" + transmission + '\'' + + '}'; + } + + public static Car of(Faker faker){ + Vehicle vehicle = faker.vehicle(); + Car car = new Car(); + car.id = UUID.randomUUID().toString(); + car.vin = vehicle.vin(); + car.model = vehicle.model(); + car.make = vehicle.make(); + car.transmission = vehicle.transmission(); + return car; + } +} diff --git a/oracle-nosql/src/main/java/org/jnosql/demo/se/Garage.java b/oracle-nosql/src/main/java/org/jnosql/demo/se/Garage.java new file mode 100644 index 00000000..50c23624 --- /dev/null +++ b/oracle-nosql/src/main/java/org/jnosql/demo/se/Garage.java @@ -0,0 +1,20 @@ +package org.jnosql.demo.se; + +import jakarta.data.page.Page; +import jakarta.data.page.Pageable; +import jakarta.data.repository.DataRepository; +import jakarta.data.repository.Delete; +import jakarta.data.repository.Repository; +import jakarta.data.repository.Save; + +@Repository +public interface Garage extends DataRepository{ + + @Save + Car parking(Car car); + + @Delete + void departure(Car car); + + Page findByTransmission(String transmission, Pageable page); +}