Skip to content

Commit

Permalink
feat: update sample using car instead of beer
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <[email protected]>
  • Loading branch information
otaviojava committed Jan 28, 2024
1 parent 1676788 commit 86566f7
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 115 deletions.
12 changes: 8 additions & 4 deletions oracle-nosql/src/main/java/org/jnosql/demo/se/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Expand Down
10 changes: 5 additions & 5 deletions oracle-nosql/src/main/java/org/jnosql/demo/se/App2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 8 additions & 9 deletions oracle-nosql/src/main/java/org/jnosql/demo/se/App3.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Beer> page1 = repository.findAll(page);
Pageable page = Pageable.ofPage(1).size(3).sortBy(Sort.desc("model"));
Page<Car> 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<Beer> page2 = repository.findAll(secondPage);
Page<Car> 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);
Expand Down
80 changes: 0 additions & 80 deletions oracle-nosql/src/main/java/org/jnosql/demo/se/Beer.java

This file was deleted.

17 changes: 0 additions & 17 deletions oracle-nosql/src/main/java/org/jnosql/demo/se/BeerRepository.java

This file was deleted.

86 changes: 86 additions & 0 deletions oracle-nosql/src/main/java/org/jnosql/demo/se/Car.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
20 changes: 20 additions & 0 deletions oracle-nosql/src/main/java/org/jnosql/demo/se/Garage.java
Original file line number Diff line number Diff line change
@@ -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<Car, String>{

@Save
Car parking(Car car);

@Delete
void departure(Car car);

Page<Car> findByTransmission(String transmission, Pageable page);
}

0 comments on commit 86566f7

Please sign in to comment.