Java Code Examples for org.hibernate.LockMode#UPGRADE_NOWAIT

The following examples show how to use org.hibernate.LockMode#UPGRADE_NOWAIT . 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: LockModeConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convert from the Hibernate specific LockMode to the JPA defined LockModeType.
 *
 * @param lockMode The Hibernate LockMode.
 *
 * @return The JPA LockModeType
 */
public static LockModeType convertToLockModeType(LockMode lockMode) {
	if ( lockMode == LockMode.NONE ) {
		return LockModeType.NONE;
	}
	else if ( lockMode == LockMode.OPTIMISTIC || lockMode == LockMode.READ ) {
		return LockModeType.OPTIMISTIC;
	}
	else if ( lockMode == LockMode.OPTIMISTIC_FORCE_INCREMENT || lockMode == LockMode.WRITE ) {
		return LockModeType.OPTIMISTIC_FORCE_INCREMENT;
	}
	else if ( lockMode == LockMode.PESSIMISTIC_READ ) {
		return LockModeType.PESSIMISTIC_READ;
	}
	else if ( lockMode == LockMode.PESSIMISTIC_WRITE
			|| lockMode == LockMode.UPGRADE
			|| lockMode == LockMode.UPGRADE_NOWAIT
			|| lockMode == LockMode.UPGRADE_SKIPLOCKED) {
		return LockModeType.PESSIMISTIC_WRITE;
	}
	else if ( lockMode == LockMode.PESSIMISTIC_FORCE_INCREMENT
			|| lockMode == LockMode.FORCE ) {
		return LockModeType.PESSIMISTIC_FORCE_INCREMENT;
	}
	throw new AssertionFailure( "unhandled lock mode " + lockMode );
}
 
Example 2
Source File: ResultSetMappingBinder.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static LockMode getLockMode(String lockMode) {
	if ( lockMode == null || "read".equals( lockMode ) ) {
		return LockMode.READ;
	}
	else if ( "none".equals( lockMode ) ) {
		return LockMode.NONE;
	}
	else if ( "upgrade".equals( lockMode ) ) {
		return LockMode.UPGRADE;
	}
	else if ( "upgrade-nowait".equals( lockMode ) ) {
		return LockMode.UPGRADE_NOWAIT;
	}
	else if ( "write".equals( lockMode ) ) {
		return LockMode.WRITE;
	}
	else if ( "force".equals( lockMode ) ) {
		return LockMode.FORCE;
	}
	else {
		throw new MappingException( "unknown lockmode" );
	}
}
 
Example 3
Source File: Dialect.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Given a lock mode, determine the appropriate for update fragment to use.
 *
 * @param lockMode The lock mode to apply.
 * @return The appropriate for update fragment.
 */
public String getForUpdateString(LockMode lockMode) {
	if ( lockMode==LockMode.UPGRADE ) {
		return getForUpdateString();
	}
	else if ( lockMode==LockMode.UPGRADE_NOWAIT ) {
		return getForUpdateNowaitString();
	}
	else if ( lockMode==LockMode.FORCE ) {
		return getForUpdateNowaitString();
	}
	else {
		return "";
	}
}
 
Example 4
Source File: ForUpdateFragment.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ForUpdateFragment(Dialect dialect, Map lockModes, Map keyColumnNames) throws QueryException {
	this( dialect );
	LockMode upgradeType = null;
	Iterator iter = lockModes.entrySet().iterator();
	while ( iter.hasNext() ) {
		final Map.Entry me = ( Map.Entry ) iter.next();
		final LockMode lockMode = ( LockMode ) me.getValue();
		if ( LockMode.READ.lessThan( lockMode ) ) {
			final String tableAlias = ( String ) me.getKey();
			if ( dialect.forUpdateOfColumns() ) {
				String[] keyColumns = ( String[] ) keyColumnNames.get( tableAlias ); //use the id column alias
				if ( keyColumns == null ) {
					throw new IllegalArgumentException( "alias not found: " + tableAlias );
				}
				keyColumns = StringHelper.qualify( tableAlias, keyColumns );
				for ( int i = 0; i < keyColumns.length; i++ ) {
					addTableAlias( keyColumns[i] );
				}
			}
			else {
				addTableAlias( tableAlias );
			}
			if ( upgradeType != null && lockMode != upgradeType ) {
				throw new QueryException( "mixed LockModes" );
			}
			upgradeType = lockMode;
		}
	}

	if ( upgradeType == LockMode.UPGRADE_NOWAIT ) {
		setNowaitEnabled( true );
	}
}