Skip to content

Commit 89ccee1

Browse files
DavideDSanne
authored andcommitted
[#1596] Allow use of Sql Server dialect 11+
Vert.x 4.2.2 add a partial implementation of SSVARIANTTYPE decoding, just enough to support querying metadata about integer MSSQL sequences.
1 parent 4f24eef commit 89ccee1

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/adaptor/impl/ResultSetAdaptor.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.time.LocalTime;
3030
import java.util.Calendar;
3131
import java.util.Map;
32+
import java.util.NoSuchElementException;
3233
import java.util.function.Function;
3334

3435
import org.hibernate.engine.jdbc.BlobProxy;
@@ -191,8 +192,19 @@ public InputStream getBinaryStream(int columnIndex) {
191192

192193
@Override
193194
public String getString(String columnLabel) {
194-
String string = row.getString( columnLabel );
195-
return ( wasNull = string == null ) ? null : string;
195+
String result = caseInsensitiveGet( columnLabel, row::getString );
196+
wasNull = result == null;
197+
return result;
198+
}
199+
200+
private <T> T caseInsensitiveGet(String columnLabel, Function<String, T> produce) {
201+
for ( String columnName : rows.columnsNames() ) {
202+
if ( columnName.equalsIgnoreCase( columnLabel ) ) {
203+
return produce.apply( columnName );
204+
}
205+
}
206+
// Same error thrown by io.vertx.sqlclient.Row when it doesn't find the label
207+
throw new NoSuchElementException( "Column " + columnLabel + " does not exist" );
196208
}
197209

198210
@Override
@@ -239,7 +251,7 @@ public int getInt(String columnLabel) {
239251

240252
@Override
241253
public long getLong(String columnLabel) {
242-
Long aLong = row.getLong( columnLabel );
254+
Long aLong = caseInsensitiveGet( columnLabel, row::getLong );
243255
wasNull = aLong == null;
244256
return wasNull ? 0 : aLong;
245257
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/provider/service/NoJdbcEnvironmentInitiator.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,12 @@
99
import java.util.concurrent.CompletionStage;
1010

1111
import org.hibernate.boot.registry.StandardServiceInitiator;
12-
import org.hibernate.dialect.DatabaseVersion;
1312
import org.hibernate.dialect.Dialect;
14-
import org.hibernate.dialect.SQLServerDialect;
1513
import org.hibernate.engine.jdbc.dialect.spi.DialectFactory;
1614
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
1715
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
1816
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
1917
import org.hibernate.reactive.engine.jdbc.env.internal.ReactiveJdbcEnvironment;
20-
import org.hibernate.reactive.logging.impl.Log;
21-
import org.hibernate.reactive.logging.impl.LogCategory;
2218
import org.hibernate.reactive.pool.ReactiveConnection;
2319
import org.hibernate.reactive.pool.ReactiveConnectionPool;
2420
import org.hibernate.reactive.provider.Settings;
@@ -29,7 +25,6 @@
2925
import io.vertx.sqlclient.spi.DatabaseMetadata;
3026

3127
import static java.util.function.Function.identity;
32-
import static org.hibernate.reactive.logging.impl.LoggerFactory.make;
3328
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
3429

3530
/**
@@ -39,11 +34,6 @@
3934
*/
4035
public class NoJdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEnvironment> {
4136

42-
/**
43-
* I'm using the same logger category used in {@link org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl}.
44-
*/
45-
private static final Log LOG = make( Log.class, new LogCategory( "SQL dialect" ) );
46-
4737
public static final NoJdbcEnvironmentInitiator INSTANCE = new NoJdbcEnvironmentInitiator();
4838

4939
@Override
@@ -75,24 +65,7 @@ public DialectBuilder(Map<String, Object> configurationValues, ServiceRegistry r
7565

7666
public Dialect build() {
7767
DialectFactory dialectFactory = registry.getService( DialectFactory.class );
78-
Dialect dialect = dialectFactory.buildDialect( configurationValues, this::dialectResolutionInfo );
79-
return checkDialect( dialect );
80-
}
81-
82-
/**
83-
* Workaround for <a href="https://github.com/eclipse-vertx/vertx-sql-client/issues/1312">vertx-sql-client#1312</a>
84-
* <p>
85-
* For extracting the information about sequences, the Sql Server dialect 11+ uses the following query:
86-
* <pre>{@code select * from INFORMATION_SCHEMA.SEQUENCES}</pre>
87-
* But, the Vert.x MSSQL client throws an exception when running it.
88-
*/
89-
private static Dialect checkDialect(Dialect dialect) {
90-
if ( dialect instanceof SQLServerDialect && dialect.getVersion().isSameOrAfter( 11 ) ) {
91-
SQLServerDialect sqlServerDialect = new SQLServerDialect( DatabaseVersion.make( 10 ) );
92-
LOG.replacingDialect( dialect, sqlServerDialect );
93-
return sqlServerDialect;
94-
}
95-
return dialect;
68+
return dialectFactory.buildDialect( configurationValues, this::dialectResolutionInfo );
9669
}
9770

9871
private DialectResolutionInfo dialectResolutionInfo() {

0 commit comments

Comments
 (0)