Skip to content

Commit fec95c3

Browse files
author
Tomáš Kraus
committed
Helidon Data documentation fixes.
Signed-off-by: Tomáš Kraus <[email protected]>
1 parent 8e6b683 commit fec95c3

File tree

3 files changed

+96
-25
lines changed

3 files changed

+96
-25
lines changed

data/README.md

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,56 @@ Note that the PU must be of the same type as the Provider
5151

5252
## Configuration
5353

54-
There are the following new nodes of configuration:
54+
There are following new nodes in the configuration:
5555

56-
- `data-sources` - a section for data sources
5756
- `data.sources.sql` - a list of SQL data sources (implement `javax.sql.DataSource`)
58-
- `persistence-units` - a section for persistence units
59-
- `persistence-units.jakarta` - a list of JPA Persistence unit configurations
57+
- `data.persistence-units` - a section for persistence units
58+
- `data.persistence-units.jakarta` - a list of Jakarta Persistence units configurations
6059

60+
### Persistence unit with custom connection
61+
62+
An example of Helidon Data persistence unit with custom database connection.
63+
64+
```yaml
65+
data:
66+
persistence-units:
67+
jakarta:
68+
- connection:
69+
username: "user"
70+
password: "changeit"
71+
url: "jdbc:mysql://localhost:3306/pets"
72+
jdbc-driver-class-name: "com.mysql.cj.jdbc.Driver"
73+
init-script: "init.sql"
74+
properties:
75+
eclipselink.target-database: "MySQL"
76+
eclipselink.target-server: "None"
77+
jakarta.persistence.schema-generation.database.action: "drop-and-create"
78+
```
79+
80+
### Persistence unit with DataSource
81+
82+
An example of Helidon Data persistence unit with DataSource. In this configuration, DataSource is defined in a separate node
83+
and persistence unit references just the name of this DataSource. Configured DataSource is available in the `ServiceRegistry`
84+
and also trough JNDI to be available for Jakarta Persistence provider, such as EclipseLink and Hibernate.
85+
86+
```yaml
87+
data:
88+
sources:
89+
sql:
90+
- name: "example"
91+
provider.hikari:
92+
username: "user"
93+
password: "changeit"
94+
url: "jdbc:mysql://localhost:3306/pets"
95+
jdbc-driver-class-name: "com.mysql.cj.jdbc.Driver"
96+
persistence-units:
97+
jakarta:
98+
- data-source: "example"
99+
init-script: "init.sql"
100+
drop-script: "drop.sql"
101+
properties:
102+
jakarta.persistence.schema-generation.database.action: "drop-and-create"
103+
```
61104

62105
## Services in Service Registry
63106

@@ -80,22 +123,23 @@ This will be supported by defining a single SQL data source, such as:
80123
```yaml
81124
# this section is required for our testcontainer support
82125
test.database:
83-
username: "test" # will be honored
84-
password: "changeit" # will be honored
85-
url: "jdbc:mysql://localhost:3306/testdb" # everything except port is honored
126+
username: "test"
127+
password: "changeit"
128+
url: "jdbc:mysql://localhost:3306/testdb"
86129
87130
# this section is the usual Helidon Data setup of data sources and persistence units
88-
data-sources:
89-
sql:
90-
- name: "test" # arbitrary name
91-
provider.hikari: # any provider that extends `ConnectionConfig`
92-
username: "${test.database.username}"
93-
password: "${test.database.password}"
94-
url: "${test.database.url}"
131+
data:
132+
sources:
133+
sql:
134+
- name: "test"
135+
provider.hikari:
136+
username: "${test.database.username}"
137+
password: "${test.database.password}"
138+
url: "${test.database.url}"
139+
persistence-units:
140+
jakarta:
141+
- data-source: "test"
95142
```
96143

97144
This information will be read by `io.helidon.data.sql.testing.SqlTestContainerConfig.configureContainer(io.helidon.common.config.Config, org.testcontainers.containers.JdbcDatabaseContainer<?>)` and a container will be initialized with it.
98145
The method returns a `TestContainerHandler` that can be used to start and stop the container, and to get the new mapped port. Its method `setConfig()` can be called to register the config instance with updated port numbers in ServiceRegistry
99-
100-
101-

data/sql/datasource/datasource/src/main/java/io/helidon/data/sql/datasource/DataSourceConfigBlueprint.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121

2222
/**
2323
* {@link javax.sql.DataSource} configuration.
24-
* <p>This is the {@code data-source} configuration array member node of the {@code DataSource} configuration with {@code name}
24+
* <p>This is the {@code data.sources} configuration array member node of the {@code DataSource} configuration with {@code name}
2525
* and {@code provider.<provider>} nodes:
2626
* <pre>
27-
* data-source:
27+
* data:
28+
* sources:
29+
* sql:
2830
* - name: something
2931
* provider.ucp:
30-
* # provider configuration
31-
* username: "test"
32-
* password: "changeit"
33-
* ...
32+
* # provider configuration
33+
* username: "test"
34+
* password: "changeit"
35+
* ...
3436
* </pre>
3537
*/
3638
@Prototype.Blueprint

docs/src/main/asciidoc/includes/data.adoc

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ include::{sourcedir}/includes/data/PetRepository.java[tag=listPets_method, inden
120120
121121
You must configure the data repository before using it.
122122
123-
In the example below, Helidon Config sets up the data repository using the EclipseLink
124-
provider and a MySQL database:
123+
In the example below, Helidon Config sets up the data repository using the EclipseLink provider and a MySQL
124+
database as a custom connection:
125125
126126
[source,yaml]
127127
----
@@ -140,6 +140,31 @@ data:
140140
jakarta.persistence.schema-generation.database.action: "none"
141141
----
142142
143+
In the next example, Helidon Config sets up the data repository using the Hibernate provider and a MySQL database
144+
as a Hikari `DataSource`:
145+
146+
[source,yaml]
147+
----
148+
data:
149+
sources:
150+
sql:
151+
- name: "example"
152+
provider.hikari:
153+
username: "user"
154+
password: "changeit"
155+
url: "jdbc:mysql://localhost:3306/pets"
156+
jdbc-driver-class-name: "com.mysql.cj.jdbc.Driver"
157+
persistence-units:
158+
jakarta:
159+
- data-source: "example"
160+
properties:
161+
hibernate.dialect: "org.hibernate.dialect.MySQLDialect"
162+
jakarta.persistence.schema-generation.database.action: "drop-and-create"
163+
----
164+
165+
`DataSource` is defined in a separate node, and its name is set to `"example"`. This name is referenced in the corresponding
166+
`persistence-units` configuration node.
167+
143168
// end::data_config[]
144169
145170
// tag::data_repository_interface[]

0 commit comments

Comments
 (0)