Skip to content

Commit 5f4c6de

Browse files
authored
Merge pull request #46128 from MichalMaler/datasource-reveiw
Once-a-while grammar and style review for the Datasource guide
2 parents 5e2dd8c + 0658918 commit 5f4c6de

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

docs/src/main/asciidoc/datasource.adoc

+49-46
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,15 @@ Because of this, you can also use `javax.sql.DataSource` as the injected type.
296296

297297
===== Oracle considerations
298298

299-
As documented in https://github.com/quarkusio/quarkus/issues/36265[issue #36265],
300-
Oracle has a very weird behavior of committing the uncommitted transactions on connection closing.
299+
As documented in link:https://github.com/quarkusio/quarkus/issues/36265[issue #36265], Oracle unexpectedly commits uncommitted transactions when closing a connection.
300+
This means that when stopping Quarkus, in-progress transactions might be committed even if they are incomplete.
301301

302-
Which means that when stopping Quarkus for instance, in progress transactions might be committed even if incomplete.
302+
Because this behavior is unexpected and can lead to data loss, an interceptor rolls back any unfinished transactions when closing a connection.
303+
However, if you use XA transactions, the transaction manager handles the rollback.
303304

304-
Given that is not the expected behavior and that it could lead to data loss, we added an interceptor that rolls back any unfinished transactions at connection close,
305-
provided you are not using XA (in which case the transaction manager handles things for you).
305+
If the behavior introduced in 3.18 causes issues for your workload, disable it by setting the `-Dquarkus-oracle-no-automatic-rollback-on-connection-close` system property to `true`.
306+
Make sure to report your use case in our link:https://github.com/quarkusio/quarkus/issues[issue tracker] so we can adjust this behavior if needed, for example, with more permanent settings.
306307

307-
If this behavior introduced in 3.18 causes issues for your specific workload, you can disable it by setting the `-Dquarkus-oracle-no-automatic-rollback-on-connection-close` system property to `true`.
308-
Please take the time to report your use case in our https://github.com/quarkusio/quarkus/issues[issue tracker] so that we can adjust this behavior if needed.
309308

310309
[[reactive-datasource]]
311310
==== Reactive datasource
@@ -440,28 +439,28 @@ AgroalDataSource inventoryDataSource;
440439
[[datasource-active]]
441440
=== Activate or deactivate datasources
442441

443-
When a datasource is configured at build time and its URL is set at runtime, it is active by default.
444-
This means that Quarkus will start the corresponding JDBC connection pool or reactive client when the application starts.
442+
When a datasource is configured at build time, and its URL is set at runtime, it is active by default.
443+
Quarkus starts the corresponding JDBC connection pool or reactive client when the application starts.
445444

446445
To deactivate a datasource at runtime, either:
447446

448-
* Do not set `quarkus.datasource[.optional name].jdbc.url`/`quarkus.datasource[.optional name].reactive.url`.
449-
* Or set `quarkus.datasource[.optional name].active` to `false`.
447+
* Do not set `quarkus.datasource[.optional name].jdbc.url` or `quarkus.datasource[.optional name].reactive.url`.
448+
* Set `quarkus.datasource[.optional name].active` to `false`.
450449

451450
If a datasource is not active:
452451

453-
* The datasource will not attempt to connect to the database during application startup.
454-
* The datasource will not contribute a <<datasource-health-check,health check>>.
455-
* Static CDI injection points involving the datasource (`@Inject DataSource ds` or `@Inject Pool pool`) will cause application startup to fail.
456-
* Dynamic retrieval of the datasource (e.g. through `CDI.getBeanContainer()`/`Arc.instance()`, or by injecting an `Instance<DataSource>`) will cause an exception to be thrown.
457-
* Other Quarkus extensions consuming the datasource may cause application startup to fail.
452+
* The datasource does not attempt to connect to the database during application startup.
453+
* The datasource does not contribute a <<datasource-health-check,health check>>.
454+
* Static CDI injection points involving the datasource, such as `@Inject DataSource ds` or `@Inject Pool pool`, cause application startup to fail.
455+
* Dynamic retrieval of the datasource, such as through `CDI.getBeanContainer()`, `Arc.instance()`, or by injecting an `Instance<DataSource>`, causes an exception to be thrown.
456+
* Other Quarkus extensions that consume the datasource may cause application startup to fail.
458457
+
459-
In such a case, you will also need to deactivate those other extensions.
460-
For an example of this scenario, see xref:hibernate-orm.adoc#persistence-unit-active[this section of the Hibernate ORM guide].
458+
In this case, you must also deactivate those other extensions.
459+
To see an example of this scenario, refer to xref:hibernate-orm.adoc#persistence-unit-active[this section of the Hibernate ORM guide].
461460

462-
This feature is especially useful when you need the application to select one datasource from a predefined set at runtime.
461+
This feature is especially useful when the application must select one datasource from a predefined set at runtime.
463462

464-
For example, with the following configuration:
463+
.An example of configuring multiple datasources for runtime selection:
465464

466465
[source,properties]
467466
----
@@ -474,30 +473,29 @@ quarkus.datasource."oracle".active=false
474473
quarkus.datasource."oracle".jdbc.url=jdbc:oracle:///your_database
475474
----
476475

477-
Setting `quarkus.datasource."pg".active=true` xref:config-reference.adoc#configuration-sources[at runtime] will make only the PostgreSQL datasource available, and setting `quarkus.datasource."oracle".active=true` at runtime will make only the Oracle datasource available.
476+
Setting `quarkus.datasource."pg".active=true` xref:config-reference.adoc#configuration-sources[at runtime] makes only the PostgreSQL datasource available.
477+
Setting `quarkus.datasource."oracle".active=true` at runtime makes only the Oracle datasource available.
478478

479479
[TIP]
480480
====
481-
xref:config-reference.adoc#custom-profiles[Custom configuration profiles] can help simplify such a setup.
482-
By appending the following profile-specific configuration to the one above,
483-
you can select a persistence unit/datasource at runtime simply by
484-
xref:config-reference.adoc#multiple-profiles[setting `quarkus.profile`]:
485-
`quarkus.profile=prod,pg` or `quarkus.profile=prod,oracle`.
481+
xref:config-reference.adoc#custom-profiles[Custom configuration profiles] simplify this setup.
482+
By appending the following profile-specific configuration to the one above, you can select a persistence unit or datasource at runtime by xref:config-reference.adoc#multiple-profiles[setting `quarkus.profile`].
483+
For example, use `quarkus.profile=prod,pg` or `quarkus.profile=prod,oracle`.
486484
487485
[source,properties]
488486
----
489487
%pg.quarkus.hibernate-orm."pg".active=true
490488
%pg.quarkus.datasource."pg".active=true
491-
# Add any pg-related runtime configuration here, prefixed with "%pg."
489+
# Add any PostgreSQL-related runtime configuration here, prefixed with "%pg."
492490
493491
%oracle.quarkus.hibernate-orm."oracle".active=true
494492
%oracle.quarkus.datasource."oracle".active=true
495-
# Add any pg-related runtime configuration here, prefixed with "%pg."
493+
# Add any Oracle-related runtime configuration here, prefixed with "%oracle."
496494
----
497495
====
498496

499-
With such a setup, you will need to take care to only ever access the _active_ datasource.
500-
To do so, you can inject an `InjectableInstance<DataSource>` or `InjectableInstance<Pool>` with an `@Any` qualifier, and call xref:cdi-integration.adoc#inactive-synthetic-beans[`getActive()`]:
497+
With this setup, ensure that only the _active_ datasource is accessed.
498+
To achieve this, inject an `InjectableInstance<DataSource>` or `InjectableInstance<Pool>` with an `@Any` qualifier and call xref:cdi-integration.adoc#inactive-synthetic-beans[`getActive()`].
501499

502500
[source,java]
503501
----
@@ -515,7 +513,9 @@ public class MyConsumer {
515513
}
516514
----
517515

518-
Alternatively, you may define a xref:cdi.adoc#ok-you-said-that-there-are-several-kinds-of-beans[CDI bean producer] for the default datasource redirecting to the currently active named datasource, so that it can be injected directly, like this:
516+
Alternatively, you can define a xref:cdi.adoc#ok-you-said-that-there-are-several-kinds-of-beans[CDI bean producer] for the default datasource.
517+
This bean producer redirects to the currently active named datasource.
518+
This allows it to be injected directly, as shown below:
519519

520520
[source,java,indent=0]
521521
----
@@ -551,13 +551,14 @@ public class MyConsumer {
551551
}
552552
}
553553
----
554-
<1> Don't inject a `DataSource` or `AgroalDatasource` directly,
555-
because that would lead to a failure on startup (can't inject inactive beans).
554+
<1> Do not inject a `DataSource` or `AgroalDatasource` directly.
555+
Injecting inactive beans causes a startup failure.
556556
Instead, inject `InjectableInstance<DataSource>` or `InjectableInstance<AgroalDataSource>`.
557-
<2> Declare a CDI producer method that will define the default datasource
558-
as either PostgreSQL or Oracle, depending on what is active.
559-
<3> Check whether beans are active before retrieving them.
560-
<4> This will get injected with the (only) active datasource.
557+
<2> Declare a CDI producer method to define the default datasource.
558+
It selects either PostgreSQL or Oracle, depending on which one is active.
559+
<3> Check if a bean is active before retrieving it.
560+
<4> Injects the only active datasource.
561+
561562

562563
[[datasource-multiple-single-transaction]]
563564
=== Use multiple datasources in a single transaction
@@ -604,18 +605,19 @@ To do so, use xref:transaction.adoc#programmatic-approach[`QuarkusTransaction.re
604605

605606
[CAUTION]
606607
====
607-
If no other solution works, and to maintain compatibility with Quarkus 3.8 and earlier, set `quarkus.transaction-manager.unsafe-multiple-last-resources` to `allow` to enable unsafe transaction handling across multiple non-XA datasources.
608+
If no other solution works and compatibility with Quarkus 3.8 or earlier is required, set `quarkus.transaction-manager.unsafe-multiple-last-resources` to `allow` to enable unsafe transaction handling across multiple non-XA datasources.
608609
609-
With this property set to allow, it might happen that a transaction rollback will only be applied to the last non-XA datasource, while other non-XA datasources have already committed their changes, potentially leaving your overall system in an inconsistent state.
610+
With this property set to `allow`, a transaction rollback might only apply to the last non-XA datasource, while other non-XA datasources may have already committed their changes.
611+
This can leave the system in an inconsistent state.
610612
611-
Alternatively, you can allow the same unsafe behavior, but with warnings when it takes effect:
613+
Alternatively, allow the same unsafe behavior but with warnings when it occurs:
612614
613-
* Setting the property to `warn-each` results in logging a warning on *each* offending transaction.
614-
* Setting the property to `warn-first` results in logging a warning on the *first* offending transaction.
615+
* Setting the property to `warn-each` logs a warning for *each* offending transaction.
616+
* Setting the property to `warn-first` logs a warning for the *first* offending transaction.
615617
616-
We do not recommend using this configuration property, and we plan to remove it in the future, so you should fix your application accordingly.
617-
If you think your use case of this feature is valid and this option should be kept around, open an issue in the link:https://github.com/quarkusio/quarkus/issues/new?assignees=&labels=kind%2Fenhancement&projects=&template=feature_request.yml[Quarkus tracker]
618-
explaining why.
618+
We do not recommend using this configuration property and plan to remove it in the future.
619+
You should update your application accordingly.
620+
If you believe your use case justifies keeping this option, open an issue in the link:https://github.com/quarkusio/quarkus/issues/new?assignees=&labels=kind%2Fenhancement&projects=&template=feature_request.yml[Quarkus tracker] explaining why.
619621
====
620622

621623
== Datasource integrations
@@ -693,7 +695,8 @@ You will usually specify the `db-kind` property or explicitly enable Dev Service
693695

694696
Some databases like H2 and Derby are commonly used in the _embedded mode_ as a facility to run integration tests quickly.
695697

696-
The recommended approach is to use the real database you intend to use in production, especially when xref:databases-dev-services.adoc[Dev Services provide a zero-config database for testing], and running tests against a container is relatively quick and produces expected results on an actual environment.
698+
The recommended approach is to use the database intended for production to get results as close as possible to a production environment.
699+
This is made easier by xref:databases-dev-services.adoc[Dev Services] because they require no configuration and start relatively quickly.
697700
However, it is also possible to use JVM-powered databases for scenarios when the ability to run simple integration tests is required.
698701

699702
==== Support and limitations

0 commit comments

Comments
 (0)