Skip to content

Commit eed1cf1

Browse files
SweetWuXiaoMeibeikov
authored andcommitted
HHH-19652 - GaussDB locking support
1 parent c0cb619 commit eed1cf1

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/GaussDBDialect.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.hibernate.boot.model.FunctionContributions;
1717
import org.hibernate.boot.model.TypeContributions;
1818
import org.hibernate.community.dialect.identity.GaussDBIdentityColumnSupport;
19+
import org.hibernate.community.dialect.lock.internal.GaussDBLockingSupport;
1920
import org.hibernate.community.dialect.sequence.GaussDBSequenceSupport;
2021
import org.hibernate.dialect.BooleanDecoder;
2122
import org.hibernate.dialect.Dialect;
@@ -29,6 +30,7 @@
2930
import org.hibernate.dialect.TimeZoneSupport;
3031
import org.hibernate.dialect.aggregate.AggregateSupport;
3132
import org.hibernate.dialect.identity.IdentityColumnSupport;
33+
import org.hibernate.dialect.lock.spi.LockingSupport;
3234
import org.hibernate.dialect.pagination.LimitHandler;
3335
import org.hibernate.dialect.pagination.LimitLimitHandler;
3436
import org.hibernate.dialect.sequence.SequenceSupport;
@@ -148,6 +150,7 @@
148150
* <a href="https://support.huaweicloud.com/function-gaussdb/index.html">GaussDB documentation</a>.
149151
*
150152
* @author liubao
153+
* @author chen zhida
151154
*
152155
* Notes: Original code of this class is based on PostgreSQLDialect.
153156
*/
@@ -1121,6 +1124,11 @@ public String getReadLockString(String aliases, int timeout) {
11211124
return withTimeout(" for share of " + aliases, timeout );
11221125
}
11231126

1127+
@Override
1128+
public LockingSupport getLockingSupport() {
1129+
return GaussDBLockingSupport.LOCKING_SUPPORT;
1130+
}
1131+
11241132
@Override
11251133
public String getForUpdateNowaitString() {
11261134
return supportsNoWait()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.community.dialect.lock.internal;
6+
7+
import jakarta.persistence.Timeout;
8+
import org.hibernate.dialect.RowLockStrategy;
9+
import org.hibernate.dialect.lock.spi.ConnectionLockTimeoutStrategy;
10+
import org.hibernate.dialect.lock.spi.LockTimeoutType;
11+
import org.hibernate.dialect.lock.spi.LockingSupport;
12+
import org.hibernate.dialect.lock.spi.OuterJoinLockingType;
13+
14+
15+
import static org.hibernate.Timeouts.NO_WAIT_MILLI;
16+
import static org.hibernate.Timeouts.SKIP_LOCKED_MILLI;
17+
import static org.hibernate.Timeouts.WAIT_FOREVER_MILLI;
18+
import static org.hibernate.dialect.lock.spi.LockTimeoutType.QUERY;
19+
20+
/**
21+
* @author chen zhida
22+
*
23+
* Notes: Original code of this class is based on PostgreSQLLockingSupport.
24+
*/
25+
public class GaussDBLockingSupport implements LockingSupport, LockingSupport.Metadata, ConnectionLockTimeoutStrategy {
26+
public static final LockingSupport LOCKING_SUPPORT = new GaussDBLockingSupport();
27+
private final boolean supportsNoWait;
28+
private final boolean supportsSkipLocked;
29+
30+
public GaussDBLockingSupport() {
31+
this( true, true );
32+
}
33+
34+
public GaussDBLockingSupport(boolean supportsNoWait, boolean supportsSkipLocked) {
35+
this.supportsNoWait = supportsNoWait;
36+
this.supportsSkipLocked = supportsSkipLocked;
37+
}
38+
39+
@Override
40+
public Metadata getMetadata() {
41+
return this;
42+
}
43+
44+
@Override
45+
public RowLockStrategy getWriteRowLockStrategy() {
46+
return RowLockStrategy.TABLE;
47+
}
48+
49+
@Override
50+
public LockTimeoutType getLockTimeoutType(Timeout timeout) {
51+
return switch ( timeout.milliseconds() ) {
52+
case NO_WAIT_MILLI -> supportsNoWait ? QUERY : LockTimeoutType.NONE;
53+
case SKIP_LOCKED_MILLI -> supportsSkipLocked ? QUERY : LockTimeoutType.NONE;
54+
case WAIT_FOREVER_MILLI -> LockTimeoutType.NONE;
55+
// we can apply a timeout via the connection
56+
default -> LockTimeoutType.CONNECTION;
57+
};
58+
}
59+
60+
@Override
61+
public OuterJoinLockingType getOuterJoinLockingType() {
62+
return OuterJoinLockingType.UNSUPPORTED;
63+
}
64+
65+
@Override
66+
public ConnectionLockTimeoutStrategy getConnectionLockTimeoutStrategy() {
67+
return this;
68+
}
69+
70+
@Override
71+
public Level getSupportedLevel() {
72+
return Level.NONE;
73+
}
74+
}

0 commit comments

Comments
 (0)