diff --git a/extensions/jdbc/jdbc-mssql/runtime/src/main/java/io/quarkus/jdbc/mssql/runtime/graal/com/microsoft/sqlserver/jdbc/SQLServerJDBCSubstitutions.java b/extensions/jdbc/jdbc-mssql/runtime/src/main/java/io/quarkus/jdbc/mssql/runtime/graal/com/microsoft/sqlserver/jdbc/SQLServerJDBCSubstitutions.java index dbb21c9ab934e..b5da254262cee 100644 --- a/extensions/jdbc/jdbc-mssql/runtime/src/main/java/io/quarkus/jdbc/mssql/runtime/graal/com/microsoft/sqlserver/jdbc/SQLServerJDBCSubstitutions.java +++ b/extensions/jdbc/jdbc-mssql/runtime/src/main/java/io/quarkus/jdbc/mssql/runtime/graal/com/microsoft/sqlserver/jdbc/SQLServerJDBCSubstitutions.java @@ -8,6 +8,8 @@ import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.SQLServerStatement; +import com.oracle.svm.core.annotate.AlwaysInline; +import com.oracle.svm.core.annotate.Delete; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; @@ -60,6 +62,50 @@ static KeyManager[] getKeyManagerFromFile(String certPath, String keyPath, Strin } } +@TargetClass(className = "com.microsoft.sqlserver.jdbc.SQLServerLexer") +@Delete //Deleting this one explicitly, so to help with maintenance with the substitutions of SQLServerFMTQuery +final class SQLServerLexerRemove { + +} + +/** + * This will make sure the ANTLR4 Lexer included in the driver is not reachable; this was mostly + * prevented by not allowing to explicitly set the useFmtOnly connection property, but this code + * path would also get activated on very old SQL Server versions being detected on a connection. + * Since that's not a constant that the compiler can rely on, we need one more substitution. + */ +@TargetClass(className = "com.microsoft.sqlserver.jdbc.SQLServerFMTQuery") +final class SQLServerFMTQuery { + + @Substitute + SQLServerFMTQuery(String userSql) throws SQLServerException { + throw new IllegalStateException("It is not supported to connect to SQL Server versions older than 2012"); + } + +} + +/** + * This substitution is not strictly necessary, but it helps by providing a better error message to our users. + */ +@TargetClass(className = "com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement") +final class DisableFMTRemove { + + @Substitute + @AlwaysInline("We need this to be constant folded") + public final boolean getUseFmtOnly() throws SQLServerException { + return false;//Important for this to be disabled via a constant + } + + @Substitute + public final void setUseFmtOnly(boolean useFmtOnly) throws SQLServerException { + if (useFmtOnly) { + throw new IllegalStateException( + "It is not possible to enable the useFmtOnly option on Quarkus: this option is only useful on SQL Server version 2008 (which is not supported) and introduces several other problems."); + } + } + +} + class SQLServerJDBCSubstitutions { }