5757import org .hibernate .exception .spi .SQLExceptionConversionDelegate ;
5858import org .hibernate .exception .spi .TemplatedViolatedConstraintNameExtractor ;
5959import org .hibernate .exception .spi .ViolatedConstraintNameExtractor ;
60- import org .hibernate .internal .util .config .ConfigurationHelper ;
6160import org .hibernate .mapping .AggregateColumn ;
6261import org .hibernate .mapping .CheckConstraint ;
6362import org .hibernate .mapping .Column ;
103102import static org .hibernate .internal .util .JdbcExceptionHelper .extractSqlState ;
104103import static org .hibernate .internal .util .StringHelper .isBlank ;
105104import static org .hibernate .internal .util .StringHelper .isNotEmpty ;
105+ import static org .hibernate .internal .util .config .ConfigurationHelper .getInteger ;
106106import static org .hibernate .query .common .TemporalUnit .NANOSECOND ;
107107import static org .hibernate .query .sqm .produce .function .FunctionParameterType .INTEGER ;
108108import static org .hibernate .type .SqlTypes .BLOB ;
@@ -176,11 +176,9 @@ public Size resolveSize(
176176 @ Override
177177 protected void applyAggregateColumnCheck (StringBuilder buf , AggregateColumn aggregateColumn ) {
178178 final JdbcType jdbcType = aggregateColumn .getType ().getJdbcType ();
179- if ( jdbcType .isXml () ) {
180- // XML columns can't have check constraints
181- return ;
179+ if ( !jdbcType .isXml () ) { // XML columns can't have check constraints
180+ super .applyAggregateColumnCheck ( buf , aggregateColumn );
182181 }
183- super .applyAggregateColumnCheck ( buf , aggregateColumn );
184182 }
185183 };
186184
@@ -190,7 +188,7 @@ public SQLServerDialect() {
190188
191189 public SQLServerDialect (DatabaseVersion version ) {
192190 super (version );
193- exporter = createSequenceExporter ( version );
191+ exporter = new SqlServerSequenceExporter ( this );
194192 }
195193
196194 public SQLServerDialect (DialectResolutionInfo info ) {
@@ -217,10 +215,11 @@ private static DatabaseVersion staticDetermineDatabaseVersion(DialectResolutionI
217215 private static Integer getCompatibilityLevel (DialectResolutionInfo info ) {
218216 final DatabaseMetaData databaseMetaData = info .getDatabaseMetadata ();
219217 if ( databaseMetaData != null ) {
220- try ( java .sql .Statement statement = databaseMetaData .getConnection ().createStatement () ) {
221- final ResultSet rs = statement .executeQuery ( "SELECT compatibility_level FROM sys.databases where name = db_name();" );
222- if ( rs .next () ) {
223- return rs .getInt ( 1 );
218+ try ( var statement = databaseMetaData .getConnection ().createStatement () ) {
219+ final ResultSet resultSet =
220+ statement .executeQuery ( "SELECT compatibility_level FROM sys.databases where name = db_name();" );
221+ if ( resultSet .next () ) {
222+ return resultSet .getInt ( 1 );
224223 }
225224 }
226225 catch (SQLException e ) {
@@ -229,11 +228,7 @@ private static Integer getCompatibilityLevel(DialectResolutionInfo info) {
229228 }
230229
231230 // default to the dialect-specific configuration setting
232- return ConfigurationHelper .getInteger ( SQL_SERVER_COMPATIBILITY_LEVEL , info .getConfigurationValues () );
233- }
234-
235- private StandardSequenceExporter createSequenceExporter (DatabaseVersion version ) {
236- return new SqlServerSequenceExporter (this );
231+ return getInteger ( SQL_SERVER_COMPATIBILITY_LEVEL , info .getConfigurationValues () );
237232 }
238233
239234 @ Override
@@ -350,14 +345,10 @@ public int getMaxIdentifierLength() {
350345 @ Override
351346 public void contributeTypes (TypeContributions typeContributions , ServiceRegistry serviceRegistry ) {
352347 super .contributeTypes ( typeContributions , serviceRegistry );
353-
354348 // Need to bind as java.sql.Timestamp because reading OffsetDateTime from a "datetime2" column fails
355349 typeContributions .contributeJdbcType ( TimestampUtcAsJdbcTimestampJdbcType .INSTANCE );
356-
357- typeContributions .getTypeConfiguration ().getJdbcTypeRegistry ().addDescriptor (
358- Types .TINYINT ,
359- TinyIntAsSmallIntJdbcType .INSTANCE
360- );
350+ typeContributions .getTypeConfiguration ().getJdbcTypeRegistry ()
351+ .addDescriptor ( Types .TINYINT , TinyIntAsSmallIntJdbcType .INSTANCE );
361352 typeContributions .contributeJdbcType ( SQLServerCastingXmlJdbcType .INSTANCE );
362353 typeContributions .contributeJdbcType ( UUIDJdbcType .INSTANCE );
363354 typeContributions .contributeJdbcTypeConstructor ( SQLServerCastingXmlArrayJdbcTypeConstructor .INSTANCE );
@@ -367,12 +358,13 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
367358 public void initializeFunctionRegistry (FunctionContributions functionContributions ) {
368359 super .initializeFunctionRegistry (functionContributions );
369360
370- final BasicTypeRegistry basicTypeRegistry = functionContributions .getTypeConfiguration ().getBasicTypeRegistry ();
371- BasicType <Date > dateType = basicTypeRegistry .resolve ( StandardBasicTypes .DATE );
372- BasicType <Date > timeType = basicTypeRegistry .resolve ( StandardBasicTypes .TIME );
373- BasicType <Date > timestampType = basicTypeRegistry .resolve ( StandardBasicTypes .TIMESTAMP );
361+ final BasicTypeRegistry basicTypeRegistry =
362+ functionContributions .getTypeConfiguration ().getBasicTypeRegistry ();
363+ final BasicType <Date > dateType = basicTypeRegistry .resolve ( StandardBasicTypes .DATE );
364+ final BasicType <Date > timeType = basicTypeRegistry .resolve ( StandardBasicTypes .TIME );
365+ final BasicType <Date > timestampType = basicTypeRegistry .resolve ( StandardBasicTypes .TIMESTAMP );
374366
375- CommonFunctionFactory functionFactory = new CommonFunctionFactory (functionContributions );
367+ final CommonFunctionFactory functionFactory = new CommonFunctionFactory (functionContributions );
376368
377369 // For SQL-Server we need to cast certain arguments to varchar(max) to be able to concat them
378370 functionContributions .getFunctionRegistry ().register (
0 commit comments