Add support for shared locks to DB2Dialect

For HHH-14210
This commit is contained in:
Gavin King 2020-09-11 21:59:33 +02:00 committed by Andrea Boriero
parent dc0cabad5d
commit 64338f2bf1
1 changed files with 24 additions and 2 deletions

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.dialect;
import org.hibernate.LockOptions;
import org.hibernate.NullPrecedence;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.CommonFunctionFactory;
@ -57,6 +58,13 @@ public class DB2Dialect extends Dialect {
// * can't select a parameter unless wrapped
// in a cast or function call
private static final String FOR_READ_ONLY_SQL = " for read only with rs";
private static final String FOR_SHARE_SQL = FOR_READ_ONLY_SQL + " use and keep share locks";
private static final String FOR_UPDATE_SQL = FOR_READ_ONLY_SQL + " use and keep update locks";
private static final String SKIP_LOCKED_SQL = " skip locked data";
private static final String FOR_SHARE_SKIP_LOCKED_SQL = FOR_SHARE_SQL + SKIP_LOCKED_SQL;
private static final String FOR_UPDATE_SKIP_LOCKED_SQL = FOR_UPDATE_SQL + SKIP_LOCKED_SQL;
private final int version;
private LimitHandler limitHandler;
@ -323,9 +331,23 @@ public class DB2Dialect extends Dialect {
}
}
@Override
public String getReadLockString(int timeout) {
return timeout==LockOptions.SKIP_LOCKED
? FOR_SHARE_SKIP_LOCKED_SQL
: FOR_SHARE_SQL;
}
@Override
public String getWriteLockString(int timeout) {
return timeout==LockOptions.SKIP_LOCKED
? FOR_UPDATE_SKIP_LOCKED_SQL
: FOR_UPDATE_SQL;
}
@Override
public String getForUpdateString() {
return " for read only with rs use and keep update locks";
return FOR_UPDATE_SQL;
}
@Override
@ -335,7 +357,7 @@ public class DB2Dialect extends Dialect {
@Override
public String getForUpdateSkipLockedString() {
return getForUpdateString() + " skip locked data";
return FOR_UPDATE_SKIP_LOCKED_SQL;
}
@Override
public boolean supportsOuterJoinForUpdate() {