Skip to content

Commit 35c4cea

Browse files
committed
Add Jakarta Data quickstart
1 parent 9655c48 commit 35c4cea

File tree

23 files changed

+1598
-0
lines changed

23 files changed

+1598
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ See [CONTRIBUTING](CONTRIBUTING.md) for how to build these examples.
5656
* [Hibernate ORM REST Data with Panache](./hibernate-orm-rest-data-panache-quickstart): Automatically generate the CRUD endpoints for your entities and repositories using Hibernate ORM with Panache.
5757
* [Hibernate ORM Multitenancy Database](./hibernate-orm-multi-tenancy-database-quickstart): Multitenant CRUD service over REST using Hibernate ORM to connect to multiple PostgreSQL databases (database approach)
5858
* [Hibernate ORM Multitenancy Schema](./hibernate-orm-multi-tenancy-schema-quickstart): Multitenant CRUD service over REST using Hibernate ORM to connect to a PostgreSQL database (schema approach)
59+
* [Hibernate Data Repositories (Jakarta Data) and RESTEasy](./hibernate-orm-quickstart): Exposing a CRUD service over REST using Hibernate Data Repositories (Jakarta Data) to connect to a PostgreSQL database
5960
* [Hibernate Search + Elasticsearch](./hibernate-search-orm-elasticsearch-quickstart): Index your Hibernate entities in Elasticsearch to get full text search
6061
* [Infinispan Client](./infinispan-client-quickstart): How to use Infinispan Client. Covers creating caches and simple get/put
6162
* [Artemis JMS](./jms-quickstart): How to use the Artemis JMS extension
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!target/*-runner
3+
!target/*-runner.jar
4+
!target/lib/*
5+
!target/quarkus-app/
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Eclipse
2+
.project
3+
.classpath
4+
.settings/
5+
bin/
6+
7+
# IntelliJ
8+
.idea
9+
*.ipr
10+
*.iml
11+
*.iws
12+
13+
# NetBeans
14+
nb-configuration.xml
15+
16+
# Visual Studio Code
17+
.vscode
18+
19+
# OSX
20+
.DS_Store
21+
22+
# Vim
23+
*.swp
24+
*.swo
25+
26+
# patch
27+
*.orig
28+
*.rej
29+
30+
# Maven
31+
target/
32+
pom.xml.tag
33+
pom.xml.releaseBackup
34+
pom.xml.versionsBackup
35+
release.properties
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
wrapperVersion=3.3.2
18+
distributionType=bin
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
20+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Quarkus demo: Hibernate Data Repositories (Jakarta Data) and RESTEasy
2+
3+
This is a minimal CRUD service exposing a couple of endpoints over REST,
4+
with a front-end based on Angular so you can play with it from your browser.
5+
6+
While the code is surprisingly simple, under the hood this is using:
7+
- [Hibernate Data Repositories (Jakarta Data)](https://hibernate.org/repositories/) to perform the CRUD operations on the database
8+
- RESTEasy to expose the REST endpoints
9+
- A PostgreSQL database; see below to run one via Docker
10+
- ArC, the CDI inspired dependency injection tool with zero overhead
11+
- The high performance Agroal connection pool
12+
- Infinispan based caching
13+
- All safely coordinated by the Narayana Transaction Manager
14+
15+
## Requirements
16+
17+
To compile and run this demo you will need:
18+
19+
- JDK 17+
20+
- GraalVM
21+
22+
In addition, you will need either a PostgreSQL database, or Docker to run one.
23+
24+
### Configuring GraalVM and JDK 17+
25+
26+
Make sure that both the `GRAALVM_HOME` and `JAVA_HOME` environment variables have
27+
been set, and that a JDK 17+ `java` command is on the path.
28+
29+
See the [Building a Native Executable guide](https://quarkus.io/guides/building-native-image)
30+
for help setting up your environment.
31+
32+
## Building the demo
33+
34+
Launch the Maven build on the checked out sources of this demo:
35+
36+
> ./mvnw package
37+
38+
## Running the demo
39+
40+
### Live coding with Quarkus
41+
42+
The Maven Quarkus plugin provides a development mode that supports
43+
live coding. To try this out:
44+
45+
> ./mvnw quarkus:dev
46+
47+
In this mode you can make changes to the code and have the changes immediately applied, by just refreshing your browser.
48+
49+
Hot reload works even when modifying your JPA entities or Jakarta Data repositories.
50+
Try it! Even the database schema will be updated on the fly.
51+
52+
### Run Quarkus in JVM mode
53+
54+
When you're done iterating in developer mode, you can run the application as a
55+
conventional jar file.
56+
57+
First compile it:
58+
59+
> ./mvnw package
60+
61+
Next we need to make sure you have a PostgreSQL instance running (Quarkus automatically starts one for dev and test mode). To set up a PostgreSQL database with Docker:
62+
63+
> docker run --rm=true --name quarkus_test -e POSTGRES_USER=quarkus_test -e POSTGRES_PASSWORD=quarkus_test -e POSTGRES_DB=quarkus_test -p 5432:5432 postgres:17
64+
65+
Connection properties for the Agroal datasource are defined in the standard Quarkus configuration file,
66+
`src/main/resources/application.properties`.
67+
68+
Then run it:
69+
70+
> java -jar ./target/quarkus-app/quarkus-run.jar
71+
72+
Have a look at how fast it boots.
73+
Or measure total native memory consumption...
74+
75+
### Run Quarkus as a native application
76+
77+
You can also create a native executable from this application without making any
78+
source code changes. A native executable removes the dependency on the JVM:
79+
everything needed to run the application on the target platform is included in
80+
the executable, allowing the application to run with minimal resource overhead.
81+
82+
Compiling a native executable takes a bit longer, as GraalVM performs additional
83+
steps to remove unnecessary codepaths. Use the `native` profile to compile a
84+
native executable:
85+
86+
> ./mvnw package -Dnative
87+
88+
After getting a cup of coffee, you'll be able to run this binary directly:
89+
90+
> ./target/hibernate-orm-jakarta-data-quickstart-1.0.0-SNAPSHOT-runner
91+
92+
Please brace yourself: don't choke on that fresh cup of coffee you just got.
93+
94+
Now observe the time it took to boot, and remember: that time was mostly spent to generate the tables in your database and import the initial data.
95+
96+
Next, maybe you're ready to measure how much memory this service is consuming.
97+
98+
N.B. This implies all dependencies have been compiled to native;
99+
that's a whole lot of stuff: from the bytecode enhancements that Hibernate ORM
100+
applies to your entities, to the lower level essential components such as the PostgreSQL JDBC driver, the Undertow webserver.
101+
102+
## See the demo in your browser
103+
104+
Navigate to:
105+
106+
<http://localhost:8080/index.html>
107+
108+
Have fun, and join the team of contributors!
109+
110+
## Running the demo in Kubernetes
111+
112+
This section provides extra information for running both the database and the demo on Kubernetes.
113+
As well as running the DB on Kubernetes, a service needs to be exposed for the demo to connect to the DB.
114+
115+
Then, rebuild demo docker image with a system property that points to the DB.
116+
117+
```bash
118+
-Dquarkus.datasource.jdbc.url=jdbc:postgresql://<DB_SERVICE_NAME>/quarkus_test
119+
```

0 commit comments

Comments
 (0)