FileDocCategorySizeDatePackage
ForUpdateFragment.javaAPI DocHibernate 3.2.52244Tue Mar 20 05:51:10 GMT 2007org.hibernate.sql

ForUpdateFragment

public class ForUpdateFragment extends Object
author
Gavin King

Fields Summary
private final StringBuffer
aliases
private boolean
isNowaitEnabled
private final org.hibernate.dialect.Dialect
dialect
Constructors Summary
public ForUpdateFragment(org.hibernate.dialect.Dialect dialect)


	   
		this.dialect = dialect;
	
public ForUpdateFragment(org.hibernate.dialect.Dialect dialect, Map lockModes, Map keyColumnNames)

		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 );
		}
	
Methods Summary
public org.hibernate.sql.ForUpdateFragmentaddTableAlias(java.lang.String alias)

		if ( aliases.length() > 0 ) {
			aliases.append( ", " );
		}
		aliases.append( alias );
		return this;
	
public org.hibernate.sql.ForUpdateFragmentsetNowaitEnabled(boolean nowait)

		isNowaitEnabled = nowait;
		return this;
	
public java.lang.StringtoFragmentString()

		if ( aliases.length() == 0 ) {
			return "";
		}
		return isNowaitEnabled ?
				dialect.getForUpdateNowaitString( aliases.toString() ) :
				dialect.getForUpdateString( aliases.toString() );