2929import org .hibernate .exception .spi .TemplatedViolatedConstraintNameExtractor ;
3030import org .hibernate .exception .spi .ViolatedConstraintNameExtractor ;
3131import org .hibernate .internal .util .JdbcExceptionHelper ;
32- import org .hibernate .internal .util .config .ConfigurationHelper ;
3332import org .hibernate .query .sqm .IntervalType ;
3433import org .hibernate .query .common .TemporalUnit ;
3534import org .hibernate .service .ServiceRegistry ;
4948import jakarta .persistence .TemporalType ;
5049
5150import static org .hibernate .cfg .DialectSpecificSettings .SYBASE_ANSI_NULL ;
51+ import static org .hibernate .cfg .DialectSpecificSettings .SYBASE_PAGE_SIZE ;
5252import static org .hibernate .exception .spi .TemplatedViolatedConstraintNameExtractor .extractUsingTemplate ;
53+ import static org .hibernate .internal .util .config .ConfigurationHelper .getBoolean ;
54+ import static org .hibernate .internal .util .config .ConfigurationHelper .getInt ;
5355import static org .hibernate .type .SqlTypes .BOOLEAN ;
5456import static org .hibernate .type .SqlTypes .DATE ;
5557import static org .hibernate .type .SqlTypes .NCLOB ;
@@ -65,6 +67,8 @@ public class SybaseASEDialect extends SybaseDialect {
6567
6668 private static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion .make ( 16 , 0 );
6769
70+ public static final int MAX_PAGE_SIZE = 16_384 ;
71+
6872 private final SizeStrategy sizeStrategy = new SizeStrategyImpl () {
6973 @ Override
7074 public Size resolveSize (
@@ -95,6 +99,7 @@ public Size resolveSize(
9599 };
96100
97101 private final boolean ansiNull ;
102+ private final int pageSize ;
98103
99104 public SybaseASEDialect () {
100105 this ( MINIMUM_VERSION );
@@ -103,37 +108,29 @@ public SybaseASEDialect() {
103108 public SybaseASEDialect (DatabaseVersion version ) {
104109 super (version );
105110 ansiNull = false ;
111+ pageSize = MAX_PAGE_SIZE ;
106112 }
107113
108114 public SybaseASEDialect (DialectResolutionInfo info ) {
109115 super (info );
110116 ansiNull = isAnsiNull ( info );
117+ pageSize = pageSize ( info );
111118 }
112119
113120 @ Override
114121 protected String columnType (int sqlTypeCode ) {
115- switch ( sqlTypeCode ) {
116- case BOOLEAN : {
117- // On Sybase ASE, the 'bit' type cannot be null,
118- // and cannot have indexes (while we don't use
119- // tinyint to store signed bytes, we can use it
120- // to store boolean values)
121- return "tinyint" ;
122- }
123- case DATE : {
124- return "date" ;
125- }
126- case TIME : {
127- return "time" ;
128- }
129- case NCLOB : {
130- // Sybase uses `unitext` instead of the T-SQL `ntext` type name
131- return "unitext" ;
132- }
133- default : {
134- return super .columnType ( sqlTypeCode );
135- }
136- }
122+ return switch ( sqlTypeCode ) {
123+ // On Sybase ASE, the 'bit' type cannot be null,
124+ // and cannot have indexes (while we don't use
125+ // tinyint to store signed bytes, we can use it
126+ // to store boolean values)
127+ case BOOLEAN -> "tinyint" ;
128+ case DATE -> "date" ;
129+ case TIME -> "time" ;
130+ // Sybase uses `unitext` instead of the T-SQL `ntext` type name
131+ case NCLOB -> "unitext" ;
132+ default -> super .columnType ( sqlTypeCode );
133+ };
137134 }
138135
139136 @ Override
@@ -175,7 +172,7 @@ public int getMaxVarcharLength() {
175172 // not the individual column length -- anyway, the
176173 // largest possible page size is 16k, so that's a
177174 // hard upper limit
178- return 16_384 ;
175+ return pageSize ;
179176 }
180177
181178 @ Override
@@ -220,7 +217,24 @@ private static boolean isAnsiNull(DialectResolutionInfo info) {
220217 }
221218 }
222219 // default to the dialect-specific configuration setting
223- return ConfigurationHelper .getBoolean ( SYBASE_ANSI_NULL , info .getConfigurationValues (), false );
220+ return getBoolean ( SYBASE_ANSI_NULL , info .getConfigurationValues (), false );
221+ }
222+
223+ private int pageSize (DialectResolutionInfo info ) {
224+ final DatabaseMetaData databaseMetaData = info .getDatabaseMetadata ();
225+ if ( databaseMetaData != null ) {
226+ try (java .sql .Statement s = databaseMetaData .getConnection ().createStatement () ) {
227+ final ResultSet rs = s .executeQuery ( "SELECT @@maxpagesize" );
228+ if ( rs .next () ) {
229+ return rs .getInt ( 1 );
230+ }
231+ }
232+ catch (SQLException ex ) {
233+ // Ignore
234+ }
235+ }
236+ // default to the dialect-specific configuration setting
237+ return getInt ( SYBASE_PAGE_SIZE , info .getConfigurationValues (), MAX_PAGE_SIZE );
224238 }
225239
226240 @ Override
0 commit comments