Data Source integration with Quarkus

Dependencies

        <dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>

Configuration

#quarkus.datasource.url=jdbc:postgresql:employee_db
quarkus.datasource.driver=org.postgresql.Driver
quarkus.datasource.username=quarkus
quarkus.datasource.password=quarkus

Panache

  • PanacheEntity
  • PanancheRepository

PanacheEntity

@Entity
public class Employee extends PanacheEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@NotBlank
private String firstName;
private String lastName;
private int age;
private int salary;
public Employee findById(int id) {
return findById(id);
}
public static void deleteById(int id) {
deleteById(id);
}
public static void deleteByFirstname(String name) {
delete("firstName", name);
}
public static void persist(Employee employee) {
persist(employee);
}
public static void update(Employee employee) {
update(employee);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
}

list("age", 25); // JPQL
list("age = ?1 and firstName like ?2", 25, "%"+word+"%");
find("age = ?1 and firstName like ?2", 25, "%"+word+"%")
.page(pageIndex, 3).list();
@GET
public List<Employee> getAll() {
return Employee.listAll(Sort.by("firstName"));
}article
    @DELETE
@Path("/{id}")
@Produces(MediaType.TEXT_PLAIN)
@Transactional
public ResponseEntity delete(@PathParam("id")int id) {
Employee.deleteById(id);
return new ResponseEntity(HttpStatus.NO_CONTENT);
}

Panache Repository

@ApplicationScoped
public class EmployeeRepository implements PanacheRepository<Employee> {
public Employee findById(int id) {
return findById(id);
}
public void deleteById(int id) {
deleteById(id);
}
public void deleteByFirstname(String name) {
delete("firstName", name);
}
public void persist(Employee employee) {
persist(employee);
}
public void update(Employee employee) {
update(employee);
}
}

--

--

--

Full stack developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why is Cloud Call Center Better than On-Premise?

E-book: Android™ Notes for Professionals Book

The Surprising Truth About Promotions

The FilDA Report

How To: Use Diffcheck to Check a New Farm’s MasterChef Contract

How to create a Static Libraries for C programs

Strategic Domain-Driven Design — WalkingTree Technologies

NETWORKING AND ROUTE TABLE

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rohan Aggarwal

Rohan Aggarwal

Full stack developer

More from Medium

Queue in Java

Creating Virtual Machines using Vagrant — 1

Orchestrating in Kubernetes using Spring Boot

Rest API