-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#577] Guide: Integrating with a PostgreSQL database #625
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The basic structure of this looks good; my comments are all just copy editing.
If we do a MariaDB or other DB variant of this we'd likely refactor much of this out into separate files for inclusion.
_data/guides.yaml
Outdated
guides: | ||
- title: Integrating with a PostgreSQL database | ||
url: /guides/database-integrating-with-postgresql | ||
description: Learn how to configure a datasource to connect a PostgreSQL database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/connect a/connect to a/g
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
:postgre-docker-image: docker.io/library/postgres | ||
:postgre-sql-kubernetes-service-name: postgres-service | ||
|
||
In this guide, you will learn how to configure WildFly to connect to a PostgreSQL database. You will create a simple Book Store API application to manage books stored in the database using a https://jakarta.ee/specifications/restful-ws/[Jakarta RESTful Web Services (JAX-RS), window=_blank]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a missing word after "(JAX-RS)", or you can change "using a" to just "using".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Replaced with "using"
|
||
=== PostgreSQL | ||
|
||
We will use PostgreSQL as database server in its containerized version: see https://hub.docker.com/_/postgres[PostgreSQL Official Image, window=_blank]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/as database/as the database/g
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
{postgre-docker-image} | ||
---- | ||
|
||
NOTE: we started the container with the `--rm` so it can be disposed automatically when we stop it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/disposed/disposed of/g
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/the --rm
/the --rm
flag/g
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done both
|
||
=== Create a new Maven project | ||
|
||
We are going to use the *WildFly Getting Started Archetype* to create the base structure of our Book Store API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/API/API application/g
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
---- | ||
NOTE: We don't need to specify the name of the Datasource by using `<jta-data-source>`. In absence of this property, JPA will use the default datasource configured in the server. | ||
|
||
=== Configure RESTful Web Services (JAX-RS) application |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Configure/Configure the Jakarta/g
I think you should drop the "(JAX-RS)". Mentioning it once is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Jakarta
|
||
=== Configure RESTful Web Services (JAX-RS) application | ||
|
||
The `BookStoreApplication` class acts as a configuration class for the JAX-RS application. It essentially tells the JAX-RS runtime that this is a JAX-RS application and provides the base path for the application's RESTful web services. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jakarta REST.
We should not use the term JAX-RS beyond the very first "Jakarta RESTful Web Services (JAX-RS)" above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/tells the JAX-RS runtime/tells the WildFly runtime/g
The fact that it's the jax-rs subsystem that detects this is an internal detail of the WildFly runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jakarta REST.
We should not use the term JAX-RS beyond the very first "Jakarta RESTful Web Services (JAX-RS)" above.
Not sure if I am following you here. Should not we use JAX-RS to avoid writing the full name? I understand that in the title of a section makes more sense to use the full name "Jakarta RESTful Web Services" (with or without the JAX-RS since it has been already mentioned before), and then in the paragraph use JAX-RS to avoid using the full name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yersan JAX-RS is a Java EE trademark that was not transferred by Oracle to the Eclipse foundation when Jakarta was created. We should avoid using it as a shorthand -- use Jakarta REST. Similar things apply to all the old Java EE shorthands, JAX-WS etc. We are not required or willing to break our software to deal with this change (e.g. renaming subsystems) but for purely documentation things like this we should avoid the old shorthands.
TBH, we shouldn't use JAX-RS even once. This shift from Java EE to Jakarta EE is many years old now; we don't need to remind people who are actually using these technologies.
I thought that you were trying to remind people of the old term by using it, but I think now you were more just trying to use a short form. Don't use JAX-RS as a short form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bstansberry ok, I've have updated it accordingly, take another look when you have a chance, thanks!
---- | ||
|
||
=== BookResource | ||
The `BookResource` is the web service that exposes the book records as JSon objects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/JSon/JSON
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
mvn clean package | ||
---- | ||
|
||
Notice how WildFly Glow gives us information about the Feature packs and Galleon layers discovered. It also provides some hints about required environment variables: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Feature packs/feature packs/g
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// Always keep a what's next? section to let the user know what could be achieved next | ||
== What's next? | ||
|
||
In this guide we have learnt how to configure a WildFly server to access to a PostgreSQL database and how to easily trim the server capabilities using WildFly Glow. Seamlessly, you can adapt the same application to use other databases by changing the Galleon Layers used by the WildFly server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/learnt/learned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing this @bstansberry , all fixed but added a small note about JAX-RS usage
_data/guides.yaml
Outdated
guides: | ||
- title: Integrating with a PostgreSQL database | ||
url: /guides/database-integrating-with-postgresql | ||
description: Learn how to configure a datasource to connect a PostgreSQL database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
:postgre-docker-image: docker.io/library/postgres | ||
:postgre-sql-kubernetes-service-name: postgres-service | ||
|
||
In this guide, you will learn how to configure WildFly to connect to a PostgreSQL database. You will create a simple Book Store API application to manage books stored in the database using a https://jakarta.ee/specifications/restful-ws/[Jakarta RESTful Web Services (JAX-RS), window=_blank]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Replaced with "using"
|
||
=== PostgreSQL | ||
|
||
We will use PostgreSQL as database server in its containerized version: see https://hub.docker.com/_/postgres[PostgreSQL Official Image, window=_blank]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
{postgre-docker-image} | ||
---- | ||
|
||
NOTE: we started the container with the `--rm` so it can be disposed automatically when we stop it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done both
|
||
=== Create a new Maven project | ||
|
||
We are going to use the *WildFly Getting Started Archetype* to create the base structure of our Book Store API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
|
||
=== Configure RESTful Web Services (JAX-RS) application | ||
|
||
The `BookStoreApplication` class acts as a configuration class for the JAX-RS application. It essentially tells the JAX-RS runtime that this is a JAX-RS application and provides the base path for the application's RESTful web services. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jakarta REST.
We should not use the term JAX-RS beyond the very first "Jakarta RESTful Web Services (JAX-RS)" above.
Not sure if I am following you here. Should not we use JAX-RS to avoid writing the full name? I understand that in the title of a section makes more sense to use the full name "Jakarta RESTful Web Services" (with or without the JAX-RS since it has been already mentioned before), and then in the paragraph use JAX-RS to avoid using the full name.
---- | ||
NOTE: We don't need to specify the name of the Datasource by using `<jta-data-source>`. In absence of this property, JPA will use the default datasource configured in the server. | ||
|
||
=== Configure RESTful Web Services (JAX-RS) application |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Jakarta
---- | ||
|
||
=== BookResource | ||
The `BookResource` is the web service that exposes the book records as JSon objects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
mvn clean package | ||
---- | ||
|
||
Notice how WildFly Glow gives us information about the Feature packs and Galleon layers discovered. It also provides some hints about required environment variables: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// Always keep a what's next? section to let the user know what could be achieved next | ||
== What's next? | ||
|
||
In this guide we have learnt how to configure a WildFly server to access to a PostgreSQL database and how to easily trim the server capabilities using WildFly Glow. Seamlessly, you can adapt the same application to use other databases by changing the Galleon Layers used by the WildFly server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took another round, I'll squash all the commits when we are done
|
||
=== Configure RESTful Web Services (JAX-RS) application | ||
|
||
The `BookStoreApplication` class acts as a configuration class for the JAX-RS application. It essentially tells the JAX-RS runtime that this is a JAX-RS application and provides the base path for the application's RESTful web services. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bstansberry ok, I've have updated it accordingly, take another look when you have a chance, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yersan Just a few more things.
|
||
=== Create a new Maven project | ||
|
||
We are going to use the *WildFly Getting Started Archetype* to create the base structure of our Book Store API application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps make this a link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
---- | ||
|
||
==== Configure WildFly Datasource and trimming server capabilities: | ||
To connect to the database we need to configure the https://docs.wildfly.org/32/Admin_Guide.html#DataSource[WildFly Datasource Subsystem,window=_blank] and install the PostgreSQL driver into the WildFly server. The https://github.com/wildfly-extras/wildfly-datasources-galleon-pack[WildFly Datasource Galleon Pack, window=_blank] contains a set of https://github.com/wildfly-extras/wildfly-datasources-galleon-pack/blob/main/doc/postgresql/README.md[Galleon Layers, window=_blank] that provide *JDBC drivers* and *WildFly Datasource Subsystem* configurations for various databases. For this guide, we will use the `postgresql-default-datasource` Galleon layer that will configure a PostgreSQL datasource as the default datasource for the server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/WildFly Datasource Galleon Pack/WildFly Datasources Galleon Pack/g
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Replaced all the occurrences.
In the above configuration, behind the scenes the `wildfly-maven-plugin` is using https://docs.wildfly.org/wildfly-glow/[WildFly Glow, window=_blank] to discover automatically the required Galleon Layers for our application. The `discover-provisioning-info` configuration tells the plugin to discover the required layers by inspecting our application code. By using the `postgresql:default` addon, we are specifying we want to use a PostgreSQL database, and we want to configure it as the default datasource for the server. | ||
|
||
=== persistence.xml | ||
This file is used to configure the Jakarta Persistence API (JPA) persistence unit and its database schema generation strategy. In this guide, we are using the `drop-and-create` strategy to drop the existing schema and create a new one every time the application starts. For a production environment, you should use a more appropriate strategy to avoid data loss. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're dealing with the abbreviations, 'JPA' is another one we should drop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, no "API".
It's just Jakarta Persistence. https://jakarta.ee/specifications/persistence/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. It leads to "This file is used to configure the Jakarta Persistence persistence unit", which indeed seems to be correct.
</persistence-unit> | ||
</persistence> | ||
---- | ||
NOTE: We don't need to specify the name of the Datasource by using `<jta-data-source>`. In absence of this property, JPA will use the default datasource configured in the server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/JPA/Jakarta Persistence/g
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bstansberry , I've applied all the suggestions, take another look. Thanks for the review!
|
||
=== Create a new Maven project | ||
|
||
We are going to use the *WildFly Getting Started Archetype* to create the base structure of our Book Store API application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
---- | ||
|
||
==== Configure WildFly Datasource and trimming server capabilities: | ||
To connect to the database we need to configure the https://docs.wildfly.org/32/Admin_Guide.html#DataSource[WildFly Datasource Subsystem,window=_blank] and install the PostgreSQL driver into the WildFly server. The https://github.com/wildfly-extras/wildfly-datasources-galleon-pack[WildFly Datasource Galleon Pack, window=_blank] contains a set of https://github.com/wildfly-extras/wildfly-datasources-galleon-pack/blob/main/doc/postgresql/README.md[Galleon Layers, window=_blank] that provide *JDBC drivers* and *WildFly Datasource Subsystem* configurations for various databases. For this guide, we will use the `postgresql-default-datasource` Galleon layer that will configure a PostgreSQL datasource as the default datasource for the server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Replaced all the occurrences.
In the above configuration, behind the scenes the `wildfly-maven-plugin` is using https://docs.wildfly.org/wildfly-glow/[WildFly Glow, window=_blank] to discover automatically the required Galleon Layers for our application. The `discover-provisioning-info` configuration tells the plugin to discover the required layers by inspecting our application code. By using the `postgresql:default` addon, we are specifying we want to use a PostgreSQL database, and we want to configure it as the default datasource for the server. | ||
|
||
=== persistence.xml | ||
This file is used to configure the Jakarta Persistence API (JPA) persistence unit and its database schema generation strategy. In this guide, we are using the `drop-and-create` strategy to drop the existing schema and create a new one every time the application starts. For a production environment, you should use a more appropriate strategy to avoid data loss. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. It leads to "This file is used to configure the Jakarta Persistence persistence unit", which indeed seems to be correct.
</persistence-unit> | ||
</persistence> | ||
---- | ||
NOTE: We don't need to specify the name of the Datasource by using `<jta-data-source>`. In absence of this property, JPA will use the default datasource configured in the server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Thanks @yersan |
Fixes #577