Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alternative possible mitigation for Oracle fetch size issue #9635

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -11,6 +11,7 @@
import java.sql.Types;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import java.util.Properties;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -19,6 +20,7 @@
import org.hibernate.QueryTimeoutException;
import org.hibernate.boot.model.FunctionContributions;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.cfg.JdbcSettings;
import org.hibernate.dialect.aggregate.AggregateSupport;
import org.hibernate.dialect.aggregate.OracleAggregateSupport;
import org.hibernate.dialect.function.CommonFunctionFactory;
Expand Down Expand Up @@ -212,6 +214,8 @@ protected void applyAggregateColumnCheck(StringBuilder buf, AggregateColumn aggr

protected final int driverMinorVersion;

private final int defaultFetchSize;


public OracleDialect() {
this( MINIMUM_VERSION );
Expand All @@ -222,6 +226,7 @@ public OracleDialect(DatabaseVersion version) {
autonomous = false;
extended = false;
applicationContinuity = false;
defaultFetchSize = -1;
driverMajorVersion = 19;
driverMinorVersion = 0;
}
Expand All @@ -235,6 +240,7 @@ public OracleDialect(DialectResolutionInfo info, OracleServerConfiguration serve
autonomous = serverConfiguration.isAutonomous();
extended = serverConfiguration.isExtended();
applicationContinuity = serverConfiguration.isApplicationContinuity();
defaultFetchSize = serverConfiguration.getDefaultFetchSize();
this.driverMinorVersion = serverConfiguration.getDriverMinorVersion();
this.driverMajorVersion = serverConfiguration.getDriverMajorVersion();
}
Expand Down Expand Up @@ -290,6 +296,15 @@ protected DatabaseVersion getMinimumSupportedVersion() {
return MINIMUM_VERSION;
}

@Override
public Properties getDefaultProperties() {
final Properties defaultProperties = super.getDefaultProperties();
if ( defaultFetchSize > 0 && defaultFetchSize < 200 ) {
defaultProperties.setProperty( JdbcSettings.STATEMENT_FETCH_SIZE, Integer.toString( 1024 ) );
}
return defaultProperties;
}

@Override
public int getPreferredSqlTypeCodeForBoolean() {
// starting 23c we support Boolean type natively
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class OracleServerConfiguration {
private final boolean autonomous;
private final boolean extended;
private final boolean applicationContinuity;
private final int defaultFetchSize;
private final int driverMajorVersion;
private final int driverMinorVersion;

Expand All @@ -53,27 +54,33 @@ public int getDriverMinorVersion() {
return driverMinorVersion;
}

public int getDefaultFetchSize() {
return defaultFetchSize;
}

public OracleServerConfiguration(boolean autonomous, boolean extended) {
this( autonomous, extended, false, 19, 0 );
this( autonomous, extended, false, -1, 19, 0 );
}

public OracleServerConfiguration(
boolean autonomous,
boolean extended,
int driverMajorVersion,
int driverMinorVersion) {
this(autonomous, extended, false, driverMajorVersion, driverMinorVersion);
this(autonomous, extended, false, -1, driverMajorVersion, driverMinorVersion);
}

public OracleServerConfiguration(
boolean autonomous,
boolean extended,
boolean applicationContinuity,
int defaultFetchSize,
int driverMajorVersion,
int driverMinorVersion) {
this.autonomous = autonomous;
this.extended = extended;
this.applicationContinuity = applicationContinuity;
this.defaultFetchSize = defaultFetchSize;
this.driverMajorVersion = driverMajorVersion;
this.driverMinorVersion = driverMinorVersion;
}
Expand All @@ -82,6 +89,7 @@ public static OracleServerConfiguration fromDialectResolutionInfo(DialectResolut
Boolean extended = null;
Boolean autonomous = null;
Boolean applicationContinuity = null;
int defaultFetchSize = -1;
Integer majorVersion = null;
Integer minorVersion = null;
final DatabaseMetaData databaseMetaData = info.getDatabaseMetadata();
Expand All @@ -95,6 +103,8 @@ public static OracleServerConfiguration fromDialectResolutionInfo(DialectResolut

try (final Statement statement = c.createStatement()) {

defaultFetchSize = statement.getFetchSize();

// Use Oracle JDBC replay statistics information to determine if this
// connection is protected by Application Continuity
try {
Expand Down Expand Up @@ -185,7 +195,8 @@ public static OracleServerConfiguration fromDialectResolutionInfo(DialectResolut
}

}
return new OracleServerConfiguration( autonomous, extended, applicationContinuity, majorVersion, minorVersion );
return new OracleServerConfiguration( autonomous, extended, applicationContinuity, defaultFetchSize,
majorVersion, minorVersion );
}

private static boolean isAutonomous(String cloudServiceParam) {
Expand Down
Loading