Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ jobs:
- run:
name: 'Build and test examples'
command: |
./mvnw -ntp -B verify -Pexamples -rf :querydsl-examples
./mvnw -ntp -B verify -Pexamples -rf :querydsl-examples -pl -:querydsl-example-hibernate-reactive-quarkus
- save-test-results
buildQuarkusExample:
<<: *defaults
Expand Down Expand Up @@ -226,7 +226,8 @@ jobs:
- run:
name: 'Test'
command: |
./mvnw -ntp -B package -Pci -Dgroups=com.querydsl.core.testutil.PostgreSQL
./mvnw -ntp -B install -Pci -Dgroups=com.querydsl.core.testutil.PostgreSQL
./mvnw -ntp -B verify -Pexamples -pl :querydsl-example-hibernate-reactive-quarkus
- save-test-results
testCUBRID:
<<: *defaults
Expand Down
6 changes: 6 additions & 0 deletions querydsl-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@
<module>querydsl-example-kotlin-mongodb</module>

<module>querydsl-example-r2dbc-sql-codegen</module>
<module>querydsl-example-hibernate-reactive-quarkus</module>
</modules>

<properties>
<quarkus.version>3.14.1</quarkus.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down Expand Up @@ -112,4 +117,5 @@
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!target/*-runner
!target/*-runner.jar
!target/lib/*
!target/quarkus-app/
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
116 changes: 116 additions & 0 deletions querydsl-examples/querydsl-example-hibernate-reactive-quarkus/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.github.openfeign.querydsl</groupId>
<artifactId>querydsl-examples</artifactId>
<version>7.0-SNAPSHOT</version>
</parent>

<artifactId>querydsl-example-hibernate-reactive-quarkus</artifactId>
<name>Querydsl example - Hibernate reactive Quarkus</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus.platform</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.github.openfeign.querydsl</groupId>
<artifactId>querydsl-hibernate-reactive</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive</artifactId>
</dependency>
<!-- Hibernate Reactive uses the reactive-pg-client with PostgreSQL under the hood -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-pg-client</artifactId>
</dependency>

<!-- Vert.x Routes -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-routes</artifactId>
</dependency>

<!-- Testing -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>io.github.openfeign.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${project.version}</version>
<classifier>jpa</classifier>
</annotationProcessorPath>
</annotationProcessorPaths>

<!-- the parameters=true option is critical so that RESTEasy works fine -->
<parameters>true</parameters>
</configuration>
<dependencies>
<dependency>
<groupId>io.github.openfeign.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<!-- you need this specific version to integrate with the other build helpers -->
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
<!-- This is what injects the magic Quarkus bytecode -->
<groupId>io.quarkus.platform</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.querydsl.example.reactive;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;

@Entity
@Table(name = "known_fruits")
@NamedQuery(name = Fruit.FIND_ALL, query = "SELECT f FROM Fruit f ORDER BY f.name")
public class Fruit {
public static final String FIND_ALL = "Fruits.findAll";

@Id
@SequenceGenerator(
name = "fruitsSequence",
sequenceName = "known_fruits_id_seq",
allocationSize = 1,
initialValue = 10)
@GeneratedValue(generator = "fruitsSequence")
private Integer id;

@Column(length = 40, unique = true)
private String name;

public Fruit() {}

public Fruit(String name) {
this.name = name;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "Fruit{" + id + "," + name + '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.querydsl.example.reactive;

import static io.quarkus.vertx.web.Route.HandlerType.FAILURE;
import static io.quarkus.vertx.web.Route.HttpMethod.DELETE;
import static io.quarkus.vertx.web.Route.HttpMethod.GET;
import static io.quarkus.vertx.web.Route.HttpMethod.POST;
import static io.quarkus.vertx.web.Route.HttpMethod.PUT;

import com.querydsl.jpa.hibernate.MutinyQueryFactory;
import io.quarkus.vertx.web.Body;
import io.quarkus.vertx.web.Param;
import io.quarkus.vertx.web.Route;
import io.quarkus.vertx.web.RouteBase;
import io.smallrye.mutiny.Uni;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;
import jakarta.inject.Inject;
import java.util.List;
import java.util.NoSuchElementException;
import org.hibernate.reactive.mutiny.Mutiny;
import org.jboss.logging.Logger;

/** An example using Vert.x Web, Hibernate Reactive and Mutiny. */
@RouteBase(path = "/fruits", produces = "application/json")
public class FruitsRoutes {

private static final Logger LOGGER = Logger.getLogger(FruitsRoutes.class.getName());

private final Mutiny.SessionFactory sf;
private final MutinyQueryFactory qf;

@Inject
public FruitsRoutes(Mutiny.SessionFactory sf) {
this.sf = sf;
qf = new MutinyQueryFactory(sf);
}

private static final QFruit f = new QFruit("f");

@Route(methods = GET, path = "/")
public Uni<List<Fruit>> getAll() {
return qf.withQuery(query -> query.select(f).from(f).orderBy(f.name.asc()).fetch());
}

@Route(methods = GET, path = "/:id")
public Uni<Fruit> getSingle(@Param Integer id) {
return qf.withQuery(query -> query.select(f).from(f).where(f.id.eq(id)).fetchOne());
}

@Route(methods = POST, path = "/")
public Uni<Fruit> create(@Body Fruit fruit, HttpServerResponse response) {
if (fruit == null || fruit.getId() != null) {
return Uni.createFrom()
.failure(new IllegalArgumentException("Fruit id invalidly set on request."));
}
return sf.withTransaction((session, tx) -> session.persist(fruit))
.invoke(() -> response.setStatusCode(201))
.replaceWith(fruit);
}

@Route(methods = PUT, path = "/:id")
public Uni<Fruit> update(@Body Fruit fruit, @Param Integer id) {
if (fruit == null || fruit.getName() == null) {
return Uni.createFrom()
.failure(new IllegalArgumentException("Fruit name was not set on request."));
}
return qf.withUpdate(
f, update -> update.where(f.id.eq(id)).set(f.name, fruit.getName()).execute())
.onItem()
.ifNull()
.fail()
.flatMap(a -> qf.withSelectFrom(f, select -> select.where(f.id.eq(id)).fetchOne()));
}

@Route(methods = DELETE, path = "/:id")
public Uni<Integer> delete(@Param Integer id, HttpServerResponse response) {
return qf.withDelete(f, delete -> delete.where(f.id.eq(id)).execute())
.invoke(() -> response.setStatusCode(204))
.onItem()
.ifNull()
.fail();
}

@Route(path = "/*", type = FAILURE)
public void error(RoutingContext context) {
Throwable t = context.failure();
if (t != null) {
LOGGER.error("Failed to handle request", t);
int status = context.statusCode();
String chunk = "";
if (t instanceof NoSuchElementException) {
status = 404;
} else if (t instanceof IllegalArgumentException) {
status = 422;
chunk =
new JsonObject()
.put("code", status)
.put("exceptionType", t.getClass().getName())
.put("error", t.getMessage())
.encode();
}
context.response().setStatusCode(status).end(chunk);
} else {
// Continue with the default error handler
context.next();
}
}
}
Loading
Loading