Skip to content

Commit 11139c2

Browse files
committed
HHH-13969 query the page size on Sybase ASE
1 parent b36641f commit 11139c2

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/DialectSpecificSettings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public interface DialectSpecificSettings {
4343
*/
4444
String SYBASE_ANSI_NULL = "hibernate.dialect.sybase.extended_string_size";
4545

46+
/**
47+
* Specifies the maximum page size on Sybase.
48+
*
49+
* @settingDefault {@value org.hibernate.dialect.SybaseASEDialect#MAX_PAGE_SIZE}
50+
*/
51+
String SYBASE_PAGE_SIZE = "hibernate.dialect.sybase.page_size";
52+
4653
/**
4754
* Specifies the bytes per character to use based on the database's configured
4855
* <a href="https://dev.mysql.com/doc/refman/8.0/en/charset-charsets.html">charset</a>.

hibernate-core/src/main/java/org/hibernate/dialect/SybaseASEDialect.java

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
3030
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
3131
import org.hibernate.internal.util.JdbcExceptionHelper;
32-
import org.hibernate.internal.util.config.ConfigurationHelper;
3332
import org.hibernate.query.sqm.IntervalType;
3433
import org.hibernate.query.common.TemporalUnit;
3534
import org.hibernate.service.ServiceRegistry;
@@ -49,7 +48,10 @@
4948
import jakarta.persistence.TemporalType;
5049

5150
import static org.hibernate.cfg.DialectSpecificSettings.SYBASE_ANSI_NULL;
51+
import static org.hibernate.cfg.DialectSpecificSettings.SYBASE_PAGE_SIZE;
5252
import 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;
5355
import static org.hibernate.type.SqlTypes.BOOLEAN;
5456
import static org.hibernate.type.SqlTypes.DATE;
5557
import 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

Comments
 (0)