Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public interface DialectSpecificSettings {
*/
String SYBASE_ANSI_NULL = "hibernate.dialect.sybase.extended_string_size";

/**
* Specifies the maximum page size on Sybase.
*
* @settingDefault {@value org.hibernate.dialect.SybaseASEDialect#MAX_PAGE_SIZE}
*/
String SYBASE_PAGE_SIZE = "hibernate.dialect.sybase.page_size";

/**
* Specifies the bytes per character to use based on the database's configured
* <a href="https://dev.mysql.com/doc/refman/8.0/en/charset-charsets.html">charset</a>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.query.sqm.IntervalType;
import org.hibernate.query.common.TemporalUnit;
import org.hibernate.service.ServiceRegistry;
Expand All @@ -49,7 +48,10 @@
import jakarta.persistence.TemporalType;

import static org.hibernate.cfg.DialectSpecificSettings.SYBASE_ANSI_NULL;
import static org.hibernate.cfg.DialectSpecificSettings.SYBASE_PAGE_SIZE;
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;
import static org.hibernate.internal.util.config.ConfigurationHelper.getInt;
import static org.hibernate.type.SqlTypes.BOOLEAN;
import static org.hibernate.type.SqlTypes.DATE;
import static org.hibernate.type.SqlTypes.NCLOB;
Expand All @@ -65,6 +67,8 @@ public class SybaseASEDialect extends SybaseDialect {

private static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 16, 0 );

public static final int MAX_PAGE_SIZE = 16_384;

private final SizeStrategy sizeStrategy = new SizeStrategyImpl() {
@Override
public Size resolveSize(
Expand Down Expand Up @@ -95,6 +99,7 @@ public Size resolveSize(
};

private final boolean ansiNull;
private final int pageSize;

public SybaseASEDialect() {
this( MINIMUM_VERSION );
Expand All @@ -103,37 +108,29 @@ public SybaseASEDialect() {
public SybaseASEDialect(DatabaseVersion version) {
super(version);
ansiNull = false;
pageSize = MAX_PAGE_SIZE;
}

public SybaseASEDialect(DialectResolutionInfo info) {
super(info);
ansiNull = isAnsiNull( info );
pageSize = pageSize( info );
}

@Override
protected String columnType(int sqlTypeCode) {
switch ( sqlTypeCode ) {
case BOOLEAN: {
// On Sybase ASE, the 'bit' type cannot be null,
// and cannot have indexes (while we don't use
// tinyint to store signed bytes, we can use it
// to store boolean values)
return "tinyint";
}
case DATE: {
return "date";
}
case TIME: {
return "time";
}
case NCLOB: {
// Sybase uses `unitext` instead of the T-SQL `ntext` type name
return "unitext";
}
default: {
return super.columnType( sqlTypeCode );
}
}
return switch ( sqlTypeCode ) {
// On Sybase ASE, the 'bit' type cannot be null,
// and cannot have indexes (while we don't use
// tinyint to store signed bytes, we can use it
// to store boolean values)
case BOOLEAN -> "tinyint";
case DATE -> "date";
case TIME -> "time";
// Sybase uses `unitext` instead of the T-SQL `ntext` type name
case NCLOB -> "unitext";
default -> super.columnType( sqlTypeCode );
};
}

@Override
Expand Down Expand Up @@ -175,7 +172,7 @@ public int getMaxVarcharLength() {
// not the individual column length -- anyway, the
// largest possible page size is 16k, so that's a
// hard upper limit
return 16_384;
return pageSize;
}

@Override
Expand Down Expand Up @@ -220,7 +217,24 @@ private static boolean isAnsiNull(DialectResolutionInfo info) {
}
}
// default to the dialect-specific configuration setting
return ConfigurationHelper.getBoolean( SYBASE_ANSI_NULL, info.getConfigurationValues(), false );
return getBoolean( SYBASE_ANSI_NULL, info.getConfigurationValues(), false );
}

private int pageSize(DialectResolutionInfo info) {
final DatabaseMetaData databaseMetaData = info.getDatabaseMetadata();
if ( databaseMetaData != null ) {
try (java.sql.Statement s = databaseMetaData.getConnection().createStatement() ) {
final ResultSet rs = s.executeQuery( "SELECT @@maxpagesize" );
if ( rs.next() ) {
return rs.getInt( 1 );
}
}
catch (SQLException ex) {
// Ignore
}
}
// default to the dialect-specific configuration setting
return getInt( SYBASE_PAGE_SIZE, info.getConfigurationValues(), MAX_PAGE_SIZE );
}

@Override
Expand Down
Loading