Skip to content
Merged
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 @@ -991,38 +991,21 @@ public String getForUpdateString(String aliases, LockOptions lockOptions) {
if (lockMode == null ) {
lockMode = lockOptions.getLockMode();
}
switch ( lockMode ) {
case PESSIMISTIC_READ: {
return getReadLockString( aliases, lockOptions.getTimeOut() );
}
case PESSIMISTIC_WRITE: {
return getWriteLockString( aliases, lockOptions.getTimeOut() );
}
case UPGRADE_NOWAIT:
case PESSIMISTIC_FORCE_INCREMENT: {
return getForUpdateNowaitString(aliases);
}
case UPGRADE_SKIPLOCKED: {
return getForUpdateSkipLockedString(aliases);
}
default: {
return "";
}
}
return switch ( lockMode ) {
case PESSIMISTIC_READ -> getReadLockString( aliases, lockOptions.getTimeOut() );
case PESSIMISTIC_WRITE -> getWriteLockString( aliases, lockOptions.getTimeOut() );
case UPGRADE_NOWAIT, PESSIMISTIC_FORCE_INCREMENT -> getForUpdateNowaitString( aliases );
case UPGRADE_SKIPLOCKED -> getForUpdateSkipLockedString( aliases );
default -> "";
};
}

private String withTimeout(String lockString, int timeout) {
switch (timeout) {
case LockOptions.NO_WAIT: {
return supportsNoWait() ? lockString + " nowait" : lockString;
}
case LockOptions.SKIP_LOCKED: {
return supportsSkipLocked() ? lockString + " skip locked" : lockString;
}
default: {
return lockString;
}
}
return switch ( timeout ) {
case LockOptions.NO_WAIT -> supportsNoWait() ? lockString + " nowait" : lockString;
case LockOptions.SKIP_LOCKED -> supportsSkipLocked() ? lockString + " skip locked" : lockString;
default -> lockString;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,26 +684,14 @@ public String getForUpdateString(final String aliases, final LockOptions lockOpt
return getForUpdateString( aliases, lockMode, lockOptions.getTimeOut() );
}

@SuppressWarnings({ "deprecation" })
private String getForUpdateString(String aliases, LockMode lockMode, int timeout) {
switch ( lockMode ) {
case PESSIMISTIC_READ: {
return getReadLockString( aliases, timeout );
}
case PESSIMISTIC_WRITE: {
return getWriteLockString( aliases, timeout );
}
case UPGRADE_NOWAIT:
case PESSIMISTIC_FORCE_INCREMENT: {
return getForUpdateNowaitString( aliases );
}
case UPGRADE_SKIPLOCKED: {
return getForUpdateSkipLockedString( aliases );
}
default: {
return "";
}
}
return switch ( lockMode ) {
case PESSIMISTIC_READ -> getReadLockString( aliases, timeout );
case PESSIMISTIC_WRITE -> getWriteLockString( aliases, timeout );
case UPGRADE_NOWAIT, PESSIMISTIC_FORCE_INCREMENT -> getForUpdateNowaitString( aliases );
case UPGRADE_SKIPLOCKED -> getForUpdateSkipLockedString( aliases );
default -> "";
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1325,16 +1325,12 @@ public static Replacer datetimeFormat(String format) {
}

private String withTimeout(String lockString, int timeout) {
switch (timeout) {
case LockOptions.NO_WAIT:
return supportsNoWait() ? lockString + " nowait" : lockString;
case LockOptions.SKIP_LOCKED:
return supportsSkipLocked() ? lockString + " skip locked" : lockString;
case LockOptions.WAIT_FOREVER:
return lockString;
default:
return supportsWait() ? lockString + " wait " + getTimeoutInSeconds( timeout ) : lockString;
}
return switch ( timeout ) {
case LockOptions.NO_WAIT -> supportsNoWait() ? lockString + " nowait" : lockString;
case LockOptions.SKIP_LOCKED -> supportsSkipLocked() ? lockString + " skip locked" : lockString;
case LockOptions.WAIT_FOREVER -> lockString;
default -> supportsWait() ? lockString + " wait " + getTimeoutInSeconds( timeout ) : lockString;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1411,16 +1411,12 @@ public String getForUpdateSkipLockedString(String aliases) {
}

private String withTimeout(String lockString, int timeout) {
switch (timeout) {
case LockOptions.NO_WAIT:
return supportsNoWait() ? lockString + " nowait" : lockString;
case LockOptions.SKIP_LOCKED:
return supportsSkipLocked() ? lockString + " skip locked" : lockString;
case LockOptions.WAIT_FOREVER:
return lockString;
default:
return supportsWait() ? lockString + " wait " + getTimeoutInSeconds( timeout ) : lockString;
}
return switch ( timeout ) {
case LockOptions.NO_WAIT -> supportsNoWait() ? lockString + " nowait" : lockString;
case LockOptions.SKIP_LOCKED -> supportsSkipLocked() ? lockString + " skip locked" : lockString;
case LockOptions.WAIT_FOREVER -> lockString;
default -> supportsWait() ? lockString + " wait " + getTimeoutInSeconds( timeout ) : lockString;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -886,24 +886,13 @@ public String getForUpdateString(String aliases, LockOptions lockOptions) {
if (lockMode == null ) {
lockMode = lockOptions.getLockMode();
}
switch ( lockMode ) {
case PESSIMISTIC_READ: {
return getReadLockString( aliases, lockOptions.getTimeOut() );
}
case PESSIMISTIC_WRITE: {
return getWriteLockString( aliases, lockOptions.getTimeOut() );
}
case UPGRADE_NOWAIT:
case PESSIMISTIC_FORCE_INCREMENT: {
return getForUpdateNowaitString(aliases);
}
case UPGRADE_SKIPLOCKED: {
return getForUpdateSkipLockedString(aliases);
}
default: {
return "";
}
}
return switch ( lockMode ) {
case PESSIMISTIC_READ -> getReadLockString( aliases, lockOptions.getTimeOut() );
case PESSIMISTIC_WRITE -> getWriteLockString( aliases, lockOptions.getTimeOut() );
case UPGRADE_NOWAIT, PESSIMISTIC_FORCE_INCREMENT -> getForUpdateNowaitString( aliases );
case UPGRADE_SKIPLOCKED -> getForUpdateSkipLockedString( aliases );
default -> "";
};
}

@Override
Expand Down Expand Up @@ -1319,14 +1308,11 @@ public void appendDateTimeLiteral(
}

private String withTimeout(String lockString, int timeout) {
switch (timeout) {
case LockOptions.NO_WAIT:
return supportsNoWait() ? lockString + " nowait" : lockString;
case LockOptions.SKIP_LOCKED:
return supportsSkipLocked() ? lockString + " skip locked" : lockString;
default:
return lockString;
}
return switch ( timeout ) {
case LockOptions.NO_WAIT -> supportsNoWait() ? lockString + " nowait" : lockString;
case LockOptions.SKIP_LOCKED -> supportsSkipLocked() ? lockString + " skip locked" : lockString;
default -> lockString;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,39 +649,31 @@ public String appendLockHint(LockOptions lockOptions, String tableName) {
lockMode = lockOptions.getLockMode();
}

final String writeLockStr = lockOptions.getTimeOut() == LockOptions.SKIP_LOCKED ? "updlock" : "updlock,holdlock";
final String readLockStr = lockOptions.getTimeOut() == LockOptions.SKIP_LOCKED ? "updlock" : "holdlock";

final String noWaitStr = lockOptions.getTimeOut() == LockOptions.NO_WAIT ? ",nowait" : "";
final String skipLockStr = lockOptions.getTimeOut() == LockOptions.SKIP_LOCKED ? ",readpast" : "";

switch ( lockMode ) {
case PESSIMISTIC_WRITE:
case WRITE:
return tableName + " with (" + writeLockStr + ",rowlock" + noWaitStr + skipLockStr + ")";
case PESSIMISTIC_READ:
return tableName + " with (" + readLockStr + ",rowlock" + noWaitStr + skipLockStr + ")";
case UPGRADE_SKIPLOCKED:
return tableName + " with (updlock,rowlock,readpast" + noWaitStr + ")";
case UPGRADE_NOWAIT:
return tableName + " with (updlock,holdlock,rowlock,nowait)";
default:
return tableName;
}
final int timeOut = lockOptions.getTimeOut();

final String writeLockStr = timeOut == LockOptions.SKIP_LOCKED ? "updlock" : "updlock,holdlock";
final String readLockStr = timeOut == LockOptions.SKIP_LOCKED ? "updlock" : "holdlock";

final String noWaitStr = timeOut == LockOptions.NO_WAIT ? ",nowait" : "";
final String skipLockStr = timeOut == LockOptions.SKIP_LOCKED ? ",readpast" : "";

return switch ( lockMode ) {
case PESSIMISTIC_WRITE, WRITE ->
tableName + " with (" + writeLockStr + ",rowlock" + noWaitStr + skipLockStr + ")";
case PESSIMISTIC_READ ->
tableName + " with (" + readLockStr + ",rowlock" + noWaitStr + skipLockStr + ")";
case UPGRADE_SKIPLOCKED -> tableName + " with (updlock,rowlock,readpast" + noWaitStr + ")";
case UPGRADE_NOWAIT -> tableName + " with (updlock,holdlock,rowlock,nowait)";
default -> tableName;
};
}
else {
switch ( lockOptions.getLockMode() ) {
case UPGRADE_NOWAIT:
case PESSIMISTIC_WRITE:
case WRITE:
return tableName + " with (updlock,rowlock)";
case PESSIMISTIC_READ:
return tableName + " with (holdlock,rowlock)";
case UPGRADE_SKIPLOCKED:
return tableName + " with (updlock,rowlock,readpast)";
default:
return tableName;
}
return switch ( lockOptions.getLockMode() ) {
case UPGRADE_NOWAIT, PESSIMISTIC_WRITE, WRITE -> tableName + " with (updlock,rowlock)";
case PESSIMISTIC_READ -> tableName + " with (holdlock,rowlock)";
case UPGRADE_SKIPLOCKED -> tableName + " with (updlock,rowlock,readpast)";
default -> tableName;
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,11 @@ public String getReadLockString(String aliases, int timeout) {


private String withTimeout(String lockString, int timeout) {
switch (timeout) {
case LockOptions.NO_WAIT:
return supportsNoWait() ? lockString + " nowait" : lockString;
case LockOptions.SKIP_LOCKED:
case LockOptions.WAIT_FOREVER:
return lockString;
default:
return supportsWait() ? lockString + " wait " + getTimeoutInSeconds( timeout ) : lockString;
}
return switch ( timeout ) {
case LockOptions.NO_WAIT -> supportsNoWait() ? lockString + " nowait" : lockString;
case LockOptions.SKIP_LOCKED, LockOptions.WAIT_FOREVER -> lockString;
default -> supportsWait() ? lockString + " wait " + getTimeoutInSeconds( timeout ) : lockString;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class LockOptions implements FindOption, RefreshOption, Serializable {
* @see #getTimeOut()
* @deprecated use {@link LockMode#UPGRADE_SKIPLOCKED}
*/
@Deprecated
@Deprecated(since = "6.2", forRemoval = true)
public static final int SKIP_LOCKED = -2;

private final boolean immutable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2270,8 +2270,8 @@ public String getWriteLockString(int timeout) {
* @return The appropriate {@code LOCK} clause string.
*/
public String getWriteLockString(String aliases, int timeout) {
// by default we simply return the getWriteLockString(timeout) result since
// the default is to say no support for "FOR UPDATE OF ..."
// by default, we simply return getWriteLockString(timeout),
// since the default is no support for "FOR UPDATE OF ..."
return getWriteLockString( timeout );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,26 +693,14 @@ public String getForUpdateString(final String aliases, final LockOptions lockOpt
return getForUpdateString( aliases, lockMode, lockOptions.getTimeOut() );
}

@SuppressWarnings({ "deprecation" })
private String getForUpdateString(String aliases, LockMode lockMode, int timeout) {
switch ( lockMode ) {
case PESSIMISTIC_READ: {
return getReadLockString( aliases, timeout );
}
case PESSIMISTIC_WRITE: {
return getWriteLockString( aliases, timeout );
}
case UPGRADE_NOWAIT:
case PESSIMISTIC_FORCE_INCREMENT: {
return getForUpdateNowaitString( aliases );
}
case UPGRADE_SKIPLOCKED: {
return getForUpdateSkipLockedString( aliases );
}
default: {
return "";
}
}
return switch ( lockMode ) {
case PESSIMISTIC_READ -> getReadLockString( aliases, timeout );
case PESSIMISTIC_WRITE -> getWriteLockString( aliases, timeout );
case UPGRADE_NOWAIT, PESSIMISTIC_FORCE_INCREMENT -> getForUpdateNowaitString( aliases );
case UPGRADE_SKIPLOCKED -> getForUpdateSkipLockedString( aliases );
default -> "";
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,27 +643,29 @@ public char openQuote() {

@Override
public String appendLockHint(LockOptions lockOptions, String tableName) {
LockMode lockMode = lockOptions.getAliasSpecificLockMode( tableName );
if ( lockMode == null ) {
lockMode = lockOptions.getLockMode();
}
final LockMode lockMode = lockModeForAlias( lockOptions, tableName );
final int timeOut = lockOptions.getTimeOut();

final String writeLockStr = lockOptions.getTimeOut() == LockOptions.SKIP_LOCKED ? "updlock" : "updlock,holdlock";
final String readLockStr = lockOptions.getTimeOut() == LockOptions.SKIP_LOCKED ? "updlock" : "holdlock";
final String writeLockStr = timeOut == LockOptions.SKIP_LOCKED ? "updlock" : "updlock,holdlock";
final String readLockStr = timeOut == LockOptions.SKIP_LOCKED ? "updlock" : "holdlock";

final String noWaitStr = lockOptions.getTimeOut() == LockOptions.NO_WAIT ? ",nowait" : "";
final String skipLockStr = lockOptions.getTimeOut() == LockOptions.SKIP_LOCKED ? ",readpast" : "";
final String noWaitStr = timeOut == LockOptions.NO_WAIT ? ",nowait" : "";
final String skipLockStr = timeOut == LockOptions.SKIP_LOCKED ? ",readpast" : "";

return switch (lockMode) {
case PESSIMISTIC_WRITE, WRITE ->
tableName + " with (" + writeLockStr + ",rowlock" + noWaitStr + skipLockStr + ")";
case PESSIMISTIC_READ -> tableName + " with (" + readLockStr + ",rowlock" + noWaitStr + skipLockStr + ")";
case UPGRADE_SKIPLOCKED -> tableName + " with (updlock,rowlock,readpast" + noWaitStr + ")";
case UPGRADE_NOWAIT -> tableName + " with (updlock,holdlock,rowlock,nowait)";
default -> tableName;
return tableName + switch (lockMode) {
case PESSIMISTIC_WRITE, WRITE -> " with (" + writeLockStr + ",rowlock" + noWaitStr + skipLockStr + ")";
case PESSIMISTIC_READ -> " with (" + readLockStr + ",rowlock" + noWaitStr + skipLockStr + ")";
case UPGRADE_SKIPLOCKED -> " with (updlock,rowlock,readpast" + noWaitStr + ")";
case UPGRADE_NOWAIT -> " with (updlock,holdlock,rowlock,nowait)";
default -> "";
};
}

private static LockMode lockModeForAlias(LockOptions lockOptions, String tableName) {
final LockMode lockMode = lockOptions.getAliasSpecificLockMode( tableName );
return lockMode == null ? lockOptions.getLockMode() : lockMode;
}


/**
* The current_timestamp is more accurate, but only known to be supported in SQL Server 7.0 and later and
Expand Down