Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions documentation/decision-service-framework.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ toc::[]
We need to choose which framework(s) we want to use for building services. For the devonfw, we focus on a standard API, if available. However, we also want to recommend an implementation. While projects would still be able to choose whatever they want, we want to suggest the best, most robust, and established solution. This way, projects do not have to worry about the decision and can rely on a production-ready framework without running into any trouble. Also, besides the standard, the configuration of the implementation framework differs, so we want to give instructions in the documentation and by our sample application. This is why, in the end, the implementation also matters. If a project has a customer demand to use something else, the project has to take care of it. We will always suggest and "support" ONE solution.

== REST Services
For REST services, devonfw relies on the JAX-RS standard (and NOT on spring-mvc with its proprietary annotations). https://github.com/eclipse-ee4j/jaxrs-api[JAX-RS] (Jakarta RESTful Web Services) is a Java programming language API to develop web services following the Representational State Transfer (REST) architectural pattern.

For link:guide-rest.asciidoc[REST] services, devonfw relies on the JAX-RS standard (and NOT on spring-mvc with its proprietary annotations). https://github.com/eclipse-ee4j/jaxrs-api[JAX-RS] (Jakarta RESTful Web Services) is a Java programming language API to develop web services following the Representational State Transfer (REST) architectural pattern.
For https://cxf.apache.org/[Apache CXF], the spring container was the first choice, but container abstraction has been properly introduced by design, so it can be used in JEE application servers. Apache CXF is a services framework that helps to build and develop services using frontend programming APIs, such as JAX-RS. Everything works smoothly in our sample application, and in addition, we collected feedback from various projects utilizing CXF, either with XML or JSON, with reported success in production. Therefore, we decided to use Apache CXF for Spring.
For Quarkus applications, devon4j recommends to use https://github.com/resteasy/resteasy[RESTEasy], which is a JAX-RS implementation aimed at providing productivity frameworks for developing client and server RESTful applications and services in Java.


== WebServices
For WebServices we rely on the JAX-WS standard. On our short list we have https://metro.java.net[Metro2] and http://cxf.apache.org[Apache CXF]. Here a collection of facts and considerations:

Expand Down
69 changes: 64 additions & 5 deletions documentation/guide-jpa-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,59 @@ SELECT line FROM OrderLineEntity line WHERE line.order.id = :orderId
----

== Dynamic Queries
For dynamic queries we use http://www.querydsl.com/[QueryDSL]. It allows to implement queries in a powerful but readable and type-safe way (unlike Criteria API). If you already know JPQL you will quickly be able to read and write QueryDSL code. It feels like JPQL but implemented in Java instead of plain text.
For dynamic queries, we use the http://querydsl.com/static/querydsl/latest/reference/html/ch02.html[JPA] module for http://www.querydsl.com/[Querydsl]. Querydsl also supports other modules such as http://querydsl.com/static/querydsl/latest/reference/html/ch02s07.html[MongoDB], and http://querydsl.com/static/querydsl/latest/reference/html/ch02s05.html[Apache Lucene]. It allows to implement queries in a powerful but readable and type-safe way (unlike Criteria API). If you already know JPQL, you will quickly be able to read and write Querydsl code. It feels like JPQL but implemented in Java instead of plain text.

To use Querydsl in your Maven project, add the following dependencies:

[source,xml]
----
<dependencies>

<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl.version}</version>
</dependency>

</dependencies>
----

Next, configure the annotation processing tool (APT) plugin:

[source,xml]
----
<project>
<build>
<plugins>
...
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
</project>
----

Here is an example from our sample application:

Expand All @@ -49,13 +101,20 @@ Here is an example from our sample application:
if ((name != null) && (!name.isEmpty())) {
query.where(dish.name.eq(name));
}
query.orderBy(dish.price.asc(), dish.name.asc());
return query.fetch();
}
----

In this example we use the so called Q-types (`QDishEntity`). These are classes generated at build time by the QueryDSL annotation processor from entity classes. The Q-type classes can be used as static types representative of the original entity class.
In this example, we use the so called Q-types (`QDishEntity`). These are classes generated at build time by the Querydsl annotation processor from entity classes. The Q-type classes can be used as static types representative of the original entity class.

The `query.from(dish)` method call defines the query source, in this case the `dish` table. The `where` method defines a filter. For example, The first call uses the `goe` operator to filter out any dishes that are not greater or equal to the minimal price. Further operators can be found https://querydsl.com/static/querydsl/latest/apidocs/com/querydsl/core/types/dsl/ComparableExpression.html[here].

The `orderBy` method is used to sort the query results according to certain criteria. Here, we sort the results first by their price and then by their name, both in ascending order. To sort in descending order, use `.desc()`. To partition query results into groups of rows, see the https://querydsl.com/static/querydsl/latest/reference/html_single/#d0e377[groupBy] method.

For spring, devon4j provides another approach that you can use for your Spring applications to implement Querydsl logic without having to use these metaclasses. An example can be found link:spring/guide-querydsl-spring.asciidoc[here].


For spring, devon4j provides another approach that you can use for your Spring applications to implement QueryDSL logic without having to use these metaclasses. An example can be found link:spring/guide-querydsl-spring.asciidoc[here].

== Using Wildcards
For flexible queries it is often required to allow wildcards (especially in xref:dynamic_queries[dynamic queries]). While users intuitively expect glob syntax the SQL and JPQL standards work different. Therefore a mapping is required. devonfw provides this on a lower level by https://github.com/devonfw/devon4j/blob/develop/modules/basic/src/main/java/com/devonfw/module/basic/common/api/query/LikePatternSyntax.java[LikePatternSyntax] and on a high level by https://github.com/devonfw/devon4j/blob/develop/modules/jpa-basic/src/main/java/com/devonfw/module/jpa/dataaccess/api/QueryUtil.java#L54[QueryUtil] (see https://github.com/devonfw/devon4j/blob/develop/modules/jpa-basic/src/main/java/com/devonfw/module/jpa/dataaccess/api/QueryHelper.java#L199[QueryHelper.newStringClause(...)]).
Expand All @@ -81,9 +140,9 @@ Pageable pageable = PageRequest.of(page, size);
Page<DishEntity> dishes = dishRepository.findAll(pageable);
----

=== Paging with QueryDSL
=== Paging with Querydsl

Pagination is also supported for dynamic queries with QueryDSL:
Pagination is also supported for dynamic queries with Querydsl:
Comment thread
maybeec marked this conversation as resolved.

[source,java]
----
Expand Down
2 changes: 1 addition & 1 deletion documentation/guide-service-client.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ For Spring, follow the link:spring/guide-service-client-spring.asciidoc[Spring r

*Quarkus*

For Quarkus, we recommend to follow the the official link:https://quarkus.io/guides/rest-client[Quarkus rest-client guide]
For Quarkus, we recommend to follow the official link:https://quarkus.io/guides/rest-client[Quarkus rest-client guide]