-
Notifications
You must be signed in to change notification settings - Fork 3k
Prevent startup failing when having mismatched datasource types #51159
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
Open
lucamolteni
wants to merge
1
commit into
quarkusio:main
Choose a base branch
from
lucamolteni:50634-bis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+241
−68
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateDataSourceUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package io.quarkus.hibernate.orm.deployment; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.function.Function; | ||
|
|
||
| import io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil; | ||
|
|
||
| public class HibernateDataSourceUtil { | ||
| public static <T> Optional<T> findDataSourceWithNameDefault(String persistenceUnitName, | ||
| List<T> datasSources, | ||
| Function<T, String> nameExtractor, | ||
| Function<T, Boolean> defaultExtractor, | ||
| Optional<String> datasource) { | ||
| if (datasource.isPresent()) { | ||
| String dataSourceName = datasource.get(); | ||
| return datasSources.stream() | ||
| .filter(i -> dataSourceName.equals(nameExtractor.apply(i))) | ||
| .findFirst(); | ||
| } else if (PersistenceUnitUtil.isDefaultPersistenceUnit(persistenceUnitName)) { | ||
| return datasSources.stream() | ||
| .filter(i -> defaultExtractor.apply(i)) | ||
| .findFirst(); | ||
| } else { | ||
| // if it's not the default persistence unit, we mandate an explicit datasource to prevent common errors | ||
| return Optional.empty(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
.../reactive/compatibility/ORMReactiveCompatibilityNamedReactiveDefaultBlockingUnitTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package io.quarkus.hibernate.reactive.compatibility; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.hibernate.reactive.mutiny.Mutiny; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| import io.quarkus.builder.Version; | ||
| import io.quarkus.hibernate.orm.PersistenceUnit; | ||
| import io.quarkus.hibernate.reactive.entities.Hero; | ||
| import io.quarkus.maven.dependency.Dependency; | ||
| import io.quarkus.test.QuarkusUnitTest; | ||
| import io.quarkus.test.vertx.RunOnVertxContext; | ||
| import io.quarkus.test.vertx.UniAsserter; | ||
|
|
||
| public class ORMReactiveCompatibilityNamedReactiveDefaultBlockingUnitTest extends CompatibilityUnitTestBase { | ||
|
|
||
| @RegisterExtension | ||
| static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
| .withApplicationRoot((jar) -> jar | ||
| .addClasses(Hero.class) | ||
| .addAsResource("complexMultilineImports.sql", "import.sql")) | ||
| .setForcedDependencies(List.of( | ||
| Dependency.of("io.quarkus", "quarkus-jdbc-postgresql-deployment", Version.getVersion()) // this triggers Agroal | ||
| )) | ||
| .withConfigurationResource("application-unittest-both-named-reactive-and-default-blocking.properties") | ||
| // If we want the named PU to be reactive only we need to explicitly disable the blocking the JDBC data source | ||
| .overrideConfigKey("quarkus.datasource.\"named-datasource\".jdbc", "false") | ||
| .overrideConfigKey("quarkus.datasource.\"named-datasource\".reactive", "true") | ||
| .overrideConfigKey("quarkus.hibernate-orm.\"named-pu\".schema-management.strategy", SCHEMA_MANAGEMENT_STRATEGY) | ||
| .overrideConfigKey("quarkus.hibernate-orm.\"named-pu\".datasource", "named-datasource") | ||
| .overrideConfigKey("quarkus.hibernate-orm.\"named-pu\".packages", "io.quarkus.hibernate.reactive.entities") | ||
| .overrideConfigKey("quarkus.datasource.\"named-datasource\".db-kind", POSTGRES_KIND) | ||
| .overrideConfigKey("quarkus.datasource.\"named-datasource\".username", USERNAME_PWD) | ||
| .overrideConfigKey("quarkus.datasource.\"named-datasource\".password", USERNAME_PWD) | ||
|
|
||
| // In this test we want the default PU as blocking only, so we need to disable reactive on the datasource. | ||
| // JDBC is enabled by default. | ||
| .overrideConfigKey("quarkus.datasource.reactive", "false") | ||
| // In this case packages for the default PU should be explicit as well | ||
| .overrideConfigKey("quarkus.hibernate-orm.packages", "io.quarkus.hibernate.reactive.entities") | ||
| .overrideConfigKey("quarkus.datasource.username", USERNAME_PWD) | ||
| .overrideConfigKey("quarkus.datasource.password", USERNAME_PWD) | ||
| .overrideConfigKey("quarkus.datasource.db-kind", POSTGRES_KIND) | ||
| .overrideConfigKey("quarkus.log.category.\"io.quarkus.hibernate\".level", "DEBUG"); | ||
|
|
||
| @PersistenceUnit("named-pu") | ||
| Mutiny.SessionFactory namedMutinySessionFactory; | ||
|
|
||
| @Test | ||
| @RunOnVertxContext | ||
| public void test(UniAsserter uniAsserter) { | ||
| testReactiveWorks(namedMutinySessionFactory, uniAsserter); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBlocking() { | ||
| testBlockingWorks(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.