Skip to content

Commit f01bcc0

Browse files
ejannettbeikov
authored andcommitted
HHH-17404 fix regression on OracleDialect on timeouts
1 parent f56ab6f commit f01bcc0

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
import jakarta.persistence.GenerationType;
88
import jakarta.persistence.TemporalType;
9+
import jakarta.persistence.Timeout;
910
import org.hibernate.Length;
1011
import org.hibernate.QueryTimeoutException;
12+
import org.hibernate.Timeouts;
13+
import org.hibernate.QueryTimeoutException;
1114
import org.hibernate.boot.model.FunctionContributions;
1215
import org.hibernate.boot.model.TypeContributions;
1316
import org.hibernate.dialect.aggregate.AggregateSupport;
@@ -117,9 +120,6 @@
117120
import org.jboss.logging.Logger;
118121

119122
import static java.util.regex.Pattern.CASE_INSENSITIVE;
120-
import static org.hibernate.LockOptions.NO_WAIT;
121-
import static org.hibernate.LockOptions.SKIP_LOCKED;
122-
import static org.hibernate.LockOptions.WAIT_FOREVER;
123123
import static org.hibernate.cfg.DialectSpecificSettings.ORACLE_USE_BINARY_FLOATS;
124124
import static org.hibernate.cfg.DialectSpecificSettings.ORACLE_OSON_DISABLED;
125125
import static org.hibernate.dialect.type.OracleJdbcHelper.getArrayJdbcTypeConstructor;
@@ -1470,7 +1470,7 @@ public RowLockStrategy getWriteRowLockStrategy() {
14701470
}
14711471

14721472
@Override
1473-
public String getForUpdateNowaitString() {
1473+
public String getForUpdateNowaitString(){
14741474
return " for update nowait";
14751475
}
14761476

@@ -1494,12 +1494,36 @@ public String getForUpdateSkipLockedString(String aliases) {
14941494
return " for update of " + aliases + " skip locked";
14951495
}
14961496

1497+
private String withTimeout(String lockString, Timeout timeout) {
1498+
return withTimeout( lockString, timeout.milliseconds() );
1499+
}
1500+
1501+
@Override
1502+
public String getWriteLockString(Timeout timeout) {
1503+
return withTimeout( getForUpdateString(), timeout );
1504+
}
1505+
1506+
@Override
1507+
public String getWriteLockString(String aliases, Timeout timeout) {
1508+
return withTimeout( getForUpdateString(aliases), timeout );
1509+
}
1510+
1511+
@Override
1512+
public String getReadLockString(Timeout timeout) {
1513+
return getWriteLockString( timeout );
1514+
}
1515+
1516+
@Override
1517+
public String getReadLockString(String aliases, Timeout timeout) {
1518+
return getWriteLockString( aliases, timeout );
1519+
}
1520+
14971521
private String withTimeout(String lockString, int timeout) {
14981522
return switch (timeout) {
1499-
case NO_WAIT -> supportsNoWait() ? lockString + " nowait" : lockString;
1500-
case SKIP_LOCKED -> supportsSkipLocked() ? lockString + " skip locked" : lockString;
1501-
case WAIT_FOREVER -> lockString;
1502-
default -> supportsWait() ? lockString + " wait " + getTimeoutInSeconds( timeout ) : lockString;
1523+
case Timeouts.NO_WAIT_MILLI -> supportsNoWait() ? lockString + " nowait" : lockString;
1524+
case Timeouts.SKIP_LOCKED_MILLI -> supportsSkipLocked() ? lockString + " skip locked" : lockString;
1525+
case Timeouts.WAIT_FOREVER_MILLI -> lockString;
1526+
default -> supportsWait() ? lockString + " wait " + Timeouts.getTimeoutInSeconds( timeout ) : lockString;
15031527
};
15041528
}
15051529

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/unit/locktimeout/OracleLockTimeoutTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.hibernate.dialect.DatabaseVersion;
1010
import org.hibernate.dialect.Dialect;
1111
import org.hibernate.dialect.OracleDialect;
12-
12+
import org.hibernate.testing.RequiresDialect;
1313
import org.hibernate.testing.junit4.BaseUnitTestCase;
1414
import org.junit.Test;
1515

@@ -18,6 +18,7 @@
1818
/**
1919
* @author Vlad Mihalcea
2020
*/
21+
@RequiresDialect(OracleDialect.class)
2122
public class OracleLockTimeoutTest extends BaseUnitTestCase {
2223

2324
private final Dialect dialect = new OracleDialect( DatabaseVersion.make( 12 ) );

0 commit comments

Comments
 (0)