Java Code Examples for org.hibernate.LockOptions#SKIP_LOCKED

The following examples show how to use org.hibernate.LockOptions#SKIP_LOCKED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MySQL8Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getWriteLockString(int timeout) {
	if ( timeout == LockOptions.NO_WAIT ) {
		return getForUpdateNowaitString();
	}
	else if ( timeout == LockOptions.SKIP_LOCKED ) {
		return getForUpdateSkipLockedString();
	}
	return super.getWriteLockString( timeout );
}
 
Example 2
Source File: MySQL8Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getWriteLockString(String aliases, int timeout) {
	if ( timeout == LockOptions.NO_WAIT ) {
		return getForUpdateNowaitString(aliases);
	}
	else if ( timeout == LockOptions.SKIP_LOCKED ) {
		return getForUpdateSkipLockedString(aliases);
	}
	return super.getWriteLockString( aliases, timeout );
}
 
Example 3
Source File: MySQL8Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getReadLockString(int timeout) {
	String readLockString =  " for share";
	if ( timeout == LockOptions.NO_WAIT ) {
		return readLockString + " nowait ";
	}
	else if ( timeout == LockOptions.SKIP_LOCKED ) {
		return readLockString + " skip locked ";
	}
	return readLockString;
}
 
Example 4
Source File: MySQL8Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getReadLockString(String aliases, int timeout) {
	String readLockString = String.format( " for share of %s ", aliases );
	if ( timeout == LockOptions.NO_WAIT ) {
		return readLockString + " nowait ";
	}
	else if ( timeout == LockOptions.SKIP_LOCKED ) {
		return readLockString + " skip locked ";
	}
	return readLockString;
}
 
Example 5
Source File: PostgreSQL95Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getWriteLockString(int timeout) {
	if ( timeout == LockOptions.SKIP_LOCKED ) {
		return getForUpdateSkipLockedString();
	}
	else {
		return super.getWriteLockString( timeout );
	}
}
 
Example 6
Source File: PostgreSQL95Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getWriteLockString(String aliases, int timeout) {
	if ( timeout == LockOptions.SKIP_LOCKED ) {
		return getForUpdateSkipLockedString( aliases );
	}
	else {
		return super.getWriteLockString( aliases, timeout );
	}
}
 
Example 7
Source File: PostgreSQL95Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getReadLockString(int timeout) {
	if ( timeout == LockOptions.SKIP_LOCKED ) {
		return " for share skip locked";
	}
	else {
		return super.getReadLockString( timeout );
	}
}
 
Example 8
Source File: PostgreSQL95Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getReadLockString(String aliases, int timeout) {
	if ( timeout == LockOptions.SKIP_LOCKED ) {
		return String.format( " for share of %s skip locked", aliases );
	}
	else {
		return super.getReadLockString( aliases, timeout );
	}
}
 
Example 9
Source File: Oracle10gDialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getWriteLockString(int timeout) {
	if ( timeout == LockOptions.SKIP_LOCKED ) {
		return  getForUpdateSkipLockedString();
	}
	else {
		return super.getWriteLockString( timeout );
	}
}
 
Example 10
Source File: Oracle10gDialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getWriteLockString(String aliases, int timeout) {
	if ( timeout == LockOptions.SKIP_LOCKED ) {
		return getForUpdateSkipLockedString( aliases );
	}
	else {
		return super.getWriteLockString( aliases, timeout );
	}
}
 
Example 11
Source File: AbstractSelectLockingStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected String determineSql(int timeout) {
	if ( timeout == LockOptions.WAIT_FOREVER) {
		return waitForeverSql;
	}
	else if ( timeout == LockOptions.NO_WAIT) {
		return getNoWaitSql();
	}
	else if ( timeout == LockOptions.SKIP_LOCKED) {
		return getSkipLockedSql();
	}
	else {
		return generateLockString( timeout );
	}
}
 
Example 12
Source File: SQLServer2005Dialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String appendLockHint(LockOptions lockOptions, String tableName) {

	LockMode lockMode = lockOptions.getAliasSpecificLockMode( tableName );
	if(lockMode == null) {
		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 UPGRADE:
		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;
		}
	}
}
 
Example 13
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void setLockOptions(Map<String, Object> props, LockOptions options) {
	Object lockScope = props.get( JPA_LOCK_SCOPE );
	if ( lockScope instanceof String && PessimisticLockScope.valueOf( ( String ) lockScope ) == PessimisticLockScope.EXTENDED ) {
		options.setScope( true );
	}
	else if ( lockScope instanceof PessimisticLockScope ) {
		boolean extended = PessimisticLockScope.EXTENDED.equals( lockScope );
		options.setScope( extended );
	}
	else if ( lockScope != null ) {
		throw new PersistenceException( "Unable to parse " + JPA_LOCK_SCOPE + ": " + lockScope );
	}

	Object lockTimeout = props.get( JPA_LOCK_TIMEOUT );
	int timeout = 0;
	boolean timeoutSet = false;
	if ( lockTimeout instanceof String ) {
		timeout = Integer.parseInt( ( String ) lockTimeout );
		timeoutSet = true;
	}
	else if ( lockTimeout instanceof Number ) {
		timeout = ( (Number) lockTimeout ).intValue();
		timeoutSet = true;
	}
	else if ( lockTimeout != null ) {
		throw new PersistenceException( "Unable to parse " + JPA_LOCK_TIMEOUT + ": " + lockTimeout );
	}

	if ( timeoutSet ) {
		if ( timeout == LockOptions.SKIP_LOCKED ) {
			options.setTimeOut( LockOptions.SKIP_LOCKED );
		}
		else if ( timeout < 0 ) {
			options.setTimeOut( LockOptions.WAIT_FOREVER );
		}
		else if ( timeout == 0 ) {
			options.setTimeOut( LockOptions.NO_WAIT );
		}
		else {
			options.setTimeOut( timeout );
		}
	}
}