Skip to content
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

Fix CNFE in native mode for Flyway + MSSQL #21615

Closed
wants to merge 1 commit into from

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Nov 22, 2021

Fixes: #21611

@geoand geoand removed the request for review from gsmet November 22, 2021 13:37
Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gastaldi
Copy link
Contributor

I think this may also going to happen with other DBs supported by Flyway Teams edition (where the org.flywaydb.core.internal.FlywayTeamsObjectResolver is used)

@gsmet
Copy link
Member

gsmet commented Nov 22, 2021

Ah ah, funny, I was going to add the same comment.

@gastaldi
Copy link
Contributor

@gsmet great minds think alike 😆

@gastaldi
Copy link
Contributor

Looking at the sources it seems that SQLServerDatabaseType is the only one that uses it, so we're good

@gsmet
Copy link
Member

gsmet commented Nov 22, 2021

I think this is due to the new changes made for the 8.0.5 upgrade. I /think/ I registered all of them in the patch I had locally.

I had something like that to mimic what was done before (we included all the implementations before the upgrade to 8.0.5):

+    @BuildStep
+    void registerDatabaseTypes(CombinedIndexBuildItem combinedIndex,
+            BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
+        for (ClassInfo databaseType : combinedIndex.getIndex().getAllKnownImplementors(DATABASE_TYPE)) {
+            if (ORACLE_DATABASE_TYPE.equals(databaseType.name())) {
+                try {
+                    // Only add the OracleDatabaseType if the driver exists
+                    Class.forName("oracle.jdbc.OracleConnection");
+                } catch (ClassNotFoundException e) {
+                    continue;
+                }
+            } else if (POSTGRESQL_DATABASE_TYPE.equals(databaseType.name())) {
+                try {
+                    // Only add the PostgreSQLDatabaseType if the driver exists
+                    Class.forName("org.postgresql.Driver");
+                } catch (ClassNotFoundException e) {
+                    continue;
+                }
+            }
+
+            System.out.println("Registering for reflection: " + databaseType.name().toString());
+
+            reflectiveClasses.produce(new ReflectiveClassBuildItem(true, true, databaseType.name().toString()));
+        }
+    }

Basically, this was a replacement for what was done before here: https://github.com/quarkusio/quarkus/blob/2.5/extensions/flyway/runtime/src/main/java/io/quarkus/flyway/runtime/graal/DatabaseTypeRegisterSubstitutions.java#L27 (this class was dropped from Flyway to use a ServiceLoader based approach).

@geoand
Copy link
Contributor Author

geoand commented Nov 22, 2021

Looking at the sources it seems that SQLServerDatabaseType is the only one that uses it, so we're good

👍🏼

@gsmet
Copy link
Member

gsmet commented Nov 22, 2021

Now maybe it's not needed, just saying what I did locally before @gastaldi did the work on his side for the 8.0.5 upgrade.

@gastaldi
Copy link
Contributor

gastaldi commented Nov 22, 2021

@gsmet I am not sure this fix needs to be backported. This change happens in 8.0.5 only, and that was not marked to be backported (see #21526)

These are the 8.0.3 sources: https://github.com/flyway/flyway/blob/flyway-8.0.3/flyway-core/src/main/java/org/flywaydb/core/internal/database/sqlserver/SQLServerDatabaseType.java#L92

@gastaldi
Copy link
Contributor

Actually I think an easier solution is to create a @Substitute method that avoids the usage of FlywayTeamsObjectResolver completely, but that can be done in another PR

@gastaldi
Copy link
Contributor

Actually I think an easier solution is to create a @Substitute method that avoids the usage of FlywayTeamsObjectResolver completely, but that can be done in another PR

Done in #21617

@gastaldi
Copy link
Contributor

Superseded by #21617

@gastaldi gastaldi closed this Nov 22, 2021
@quarkus-bot quarkus-bot bot added the triage/invalid This doesn't seem right label Nov 22, 2021
@gastaldi gastaldi deleted the #21611 branch November 22, 2021 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mssql extensions fails in native mode with a ClassNotFoundException
3 participants