|
6 | 6 |
|
7 | 7 | import jakarta.persistence.GenerationType;
|
8 | 8 | import jakarta.persistence.TemporalType;
|
| 9 | +import jakarta.persistence.Timeout; |
9 | 10 | import org.checkerframework.checker.nullness.qual.Nullable;
|
10 | 11 | import org.hibernate.Length;
|
11 | 12 | import org.hibernate.LockMode;
|
12 | 13 | import org.hibernate.LockOptions;
|
13 |
| -import org.hibernate.PessimisticLockException; |
14 | 14 | import org.hibernate.QueryTimeoutException;
|
| 15 | +import org.hibernate.Timeouts; |
15 | 16 | import org.hibernate.boot.model.FunctionContributions;
|
16 | 17 | import org.hibernate.boot.model.TypeContributions;
|
17 | 18 | import org.hibernate.community.dialect.identity.GaussDBIdentityColumnSupport;
|
|
39 | 40 | import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
|
40 | 41 | import org.hibernate.engine.spi.SessionFactoryImplementor;
|
41 | 42 | import org.hibernate.exception.LockAcquisitionException;
|
| 43 | +import org.hibernate.exception.LockTimeoutException; |
42 | 44 | import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
|
43 | 45 | import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
|
44 | 46 | import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
|
@@ -810,7 +812,7 @@ public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
|
810 | 812 | return new LockAcquisitionException( message, sqlException, sql );
|
811 | 813 | case "55P03":
|
812 | 814 | // LOCK NOT AVAILABLE
|
813 |
| - return new PessimisticLockException( message, sqlException, sql ); |
| 815 | + return new LockTimeoutException( message, sqlException, sql ); |
814 | 816 | case "57014":
|
815 | 817 | return new QueryTimeoutException( message, sqlException, sql );
|
816 | 818 | }
|
@@ -1039,10 +1041,38 @@ public void appendDateTimeLiteral(
|
1039 | 1041 | }
|
1040 | 1042 | }
|
1041 | 1043 |
|
| 1044 | + private String withTimeout(String lockString, Timeout timeout) { |
| 1045 | + return switch (timeout.milliseconds()) { |
| 1046 | + case Timeouts.NO_WAIT_MILLI -> supportsNoWait() ? lockString + " nowait" : lockString; |
| 1047 | + case Timeouts.SKIP_LOCKED_MILLI -> supportsSkipLocked() ? lockString + " skip locked" : lockString; |
| 1048 | + default -> lockString; |
| 1049 | + }; |
| 1050 | + } |
| 1051 | + |
| 1052 | + @Override |
| 1053 | + public String getWriteLockString(Timeout timeout) { |
| 1054 | + return withTimeout( getForUpdateString(), timeout ); |
| 1055 | + } |
| 1056 | + |
| 1057 | + @Override |
| 1058 | + public String getWriteLockString(String aliases, Timeout timeout) { |
| 1059 | + return withTimeout( getForUpdateString( aliases ), timeout ); |
| 1060 | + } |
| 1061 | + |
| 1062 | + @Override |
| 1063 | + public String getReadLockString(Timeout timeout) { |
| 1064 | + return withTimeout(" for share", timeout ); |
| 1065 | + } |
| 1066 | + |
| 1067 | + @Override |
| 1068 | + public String getReadLockString(String aliases, Timeout timeout) { |
| 1069 | + return withTimeout(" for share of " + aliases, timeout ); |
| 1070 | + } |
| 1071 | + |
1042 | 1072 | private String withTimeout(String lockString, int timeout) {
|
1043 | 1073 | return switch (timeout) {
|
1044 |
| - case LockOptions.NO_WAIT -> supportsNoWait() ? lockString + " nowait" : lockString; |
1045 |
| - case LockOptions.SKIP_LOCKED -> supportsSkipLocked() ? lockString + " skip locked" : lockString; |
| 1074 | + case Timeouts.NO_WAIT_MILLI -> supportsNoWait() ? lockString + " nowait" : lockString; |
| 1075 | + case Timeouts.SKIP_LOCKED_MILLI -> supportsSkipLocked() ? lockString + " skip locked" : lockString; |
1046 | 1076 | default -> lockString;
|
1047 | 1077 | };
|
1048 | 1078 | }
|
|
0 commit comments