|
9 | 9 | import java.util.concurrent.CompletionStage;
|
10 | 10 |
|
11 | 11 | import org.hibernate.boot.registry.StandardServiceInitiator;
|
| 12 | +import org.hibernate.dialect.DatabaseVersion; |
12 | 13 | import org.hibernate.dialect.Dialect;
|
| 14 | +import org.hibernate.dialect.SQLServerDialect; |
13 | 15 | import org.hibernate.engine.jdbc.dialect.spi.DialectFactory;
|
14 | 16 | import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
|
15 | 17 | import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
16 | 18 | import org.hibernate.reactive.engine.jdbc.env.internal.ReactiveJdbcEnvironment;
|
| 19 | +import org.hibernate.reactive.logging.impl.Log; |
| 20 | +import org.hibernate.reactive.logging.impl.LogCategory; |
17 | 21 | import org.hibernate.reactive.pool.ReactiveConnection;
|
18 | 22 | import org.hibernate.reactive.pool.ReactiveConnectionPool;
|
19 | 23 | import org.hibernate.reactive.provider.Settings;
|
|
23 | 27 |
|
24 | 28 | import io.vertx.sqlclient.spi.DatabaseMetadata;
|
25 | 29 |
|
| 30 | +import static org.hibernate.reactive.logging.impl.LoggerFactory.make; |
26 | 31 | import static org.hibernate.reactive.util.impl.CompletionStages.failedFuture;
|
27 | 32 |
|
28 | 33 | /**
|
|
32 | 37 | */
|
33 | 38 | public class NoJdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEnvironment> {
|
34 | 39 |
|
| 40 | + /** |
| 41 | + * I'm using the same logger category used in {@link org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl} |
| 42 | + */ |
| 43 | + private static final Log LOG = make( Log.class, new LogCategory( "SQL dialect" ) ); |
| 44 | + |
35 | 45 | public static final NoJdbcEnvironmentInitiator INSTANCE = new NoJdbcEnvironmentInitiator();
|
36 | 46 |
|
37 | 47 | @Override
|
@@ -63,7 +73,25 @@ public DialectBuilder(Map<String, Object> configurationValues, ServiceRegistry r
|
63 | 73 |
|
64 | 74 | public Dialect build() {
|
65 | 75 | DialectFactory dialectFactory = registry.getService( DialectFactory.class );
|
66 |
| - return dialectFactory.buildDialect( configurationValues, this::dialectResolutionInfo ); |
| 76 | + Dialect dialect = dialectFactory.buildDialect( configurationValues, this::dialectResolutionInfo ); |
| 77 | + dialect = checkDialect( dialect ); |
| 78 | + return dialect; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Workaround for <a href="https://github.com/eclipse-vertx/vertx-sql-client/issues/1312">vertx-sql-client#1312</a> |
| 83 | + * <p> |
| 84 | + * For extracting the information about sequences, the Sql Server dialect 11+ uses the following query: |
| 85 | + * <pre>{@code select * from INFORMATION_SCHEMA.SEQUENCES}</pre> |
| 86 | + * But, the Vert.x MSSQL client throws an exception when running it. |
| 87 | + */ |
| 88 | + private static Dialect checkDialect(Dialect dialect) { |
| 89 | + if ( dialect instanceof SQLServerDialect && dialect.getVersion().isSameOrAfter( 11 ) ) { |
| 90 | + SQLServerDialect sqlServerDialect = new SQLServerDialect( DatabaseVersion.make( 10 ) ); |
| 91 | + LOG.replacingDialect( dialect, sqlServerDialect ); |
| 92 | + return sqlServerDialect; |
| 93 | + } |
| 94 | + return dialect; |
67 | 95 | }
|
68 | 96 |
|
69 | 97 | private DialectResolutionInfo dialectResolutionInfo() {
|
|
0 commit comments