You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/src/main/asciidoc/datasource.adoc
+49-46
Original file line number
Diff line number
Diff line change
@@ -296,16 +296,15 @@ Because of this, you can also use `javax.sql.DataSource` as the injected type.
296
296
297
297
===== Oracle considerations
298
298
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.
301
301
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.
303
304
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.
306
307
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.
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.
445
444
446
445
To deactivate a datasource at runtime, either:
447
446
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`.
450
449
451
450
If a datasource is not active:
452
451
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.
458
457
+
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].
461
460
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.
463
462
464
-
For example, with the following configuration:
463
+
.An example of configuring multiple datasources for runtime selection:
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.
478
478
479
479
[TIP]
480
480
====
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
`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`.
486
484
487
485
[source,properties]
488
486
----
489
487
%pg.quarkus.hibernate-orm."pg".active=true
490
488
%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."
# Add any pg-related runtime configuration here, prefixed with "%pg."
493
+
# Add any Oracle-related runtime configuration here, prefixed with "%oracle."
496
494
----
497
495
====
498
496
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()`].
501
499
502
500
[source,java]
503
501
----
@@ -515,7 +513,9 @@ public class MyConsumer {
515
513
}
516
514
----
517
515
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:
519
519
520
520
[source,java,indent=0]
521
521
----
@@ -551,13 +551,14 @@ public class MyConsumer {
551
551
}
552
552
}
553
553
----
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.
556
556
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
+
561
562
562
563
[[datasource-multiple-single-transaction]]
563
564
=== Use multiple datasources in a single transaction
@@ -604,18 +605,19 @@ To do so, use xref:transaction.adoc#programmatic-approach[`QuarkusTransaction.re
604
605
605
606
[CAUTION]
606
607
====
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.
608
609
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.
610
612
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:
612
614
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.
615
617
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.
619
621
====
620
622
621
623
== Datasource integrations
@@ -693,7 +695,8 @@ You will usually specify the `db-kind` property or explicitly enable Dev Service
693
695
694
696
Some databases like H2 and Derby are commonly used in the _embedded mode_ as a facility to run integration tests quickly.
695
697
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.
697
700
However, it is also possible to use JVM-powered databases for scenarios when the ability to run simple integration tests is required.
0 commit comments