Skip to content

Commit

Permalink
feat: create app6 guest and hotel
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <[email protected]>
  • Loading branch information
otaviojava committed Nov 7, 2024
1 parent 52598d5 commit 841cbad
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
24 changes: 24 additions & 0 deletions oracle-nosql/src/main/java/org/jnosql/demo/se/beer/App6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.jnosql.demo.se.beer;

import jakarta.enterprise.inject.se.SeContainer;
import jakarta.enterprise.inject.se.SeContainerInitializer;
import net.datafaker.Faker;
import org.eclipse.jnosql.mapping.DatabaseQualifier;

public class App6 {

public static void main(String[] args) {
var faker = new Faker();
try (SeContainer container = SeContainerInitializer.newInstance().initialize()) {

var guest = new Guest(faker.cpf().valid(), faker.name().name());
var room = new Room(12, guest);
var repository = container.select(Hotel.class, DatabaseQualifier.ofDocument()).get();
var roomUpdated = repository.checkIn(room);
System.out.println("Room updated: " + roomUpdated);

}

System.exit(0);
}
}
8 changes: 8 additions & 0 deletions oracle-nosql/src/main/java/org/jnosql/demo/se/beer/Guest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jnosql.demo.se.beer;

import jakarta.nosql.Column;
import jakarta.nosql.Embeddable;

@Embeddable
public record Guest (@Column String documentNumber, @Column String name) {
}
26 changes: 26 additions & 0 deletions oracle-nosql/src/main/java/org/jnosql/demo/se/beer/Hotel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jnosql.demo.se.beer;

import jakarta.data.page.Page;
import jakarta.data.page.PageRequest;
import jakarta.data.repository.By;
import jakarta.data.repository.Delete;
import jakarta.data.repository.Find;
import jakarta.data.repository.Repository;
import jakarta.data.repository.Save;

import java.util.Optional;

@Repository
public interface Hotel {

@Save
Room checkIn(Room room);

@Delete
void checkOut(Room room);

@Find
Optional<Room> reservation(@By("_id") String number);

Page<Room> findBy(PageRequest pageRequest);
}
9 changes: 9 additions & 0 deletions oracle-nosql/src/main/java/org/jnosql/demo/se/beer/Room.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jnosql.demo.se.beer;

import jakarta.nosql.Column;
import jakarta.nosql.Entity;
import jakarta.nosql.Id;

@Entity
public record Room (@Id int number, @Column Guest guest) {
}

0 comments on commit 841cbad

Please sign in to comment.