当前位置: 首页>>代码示例>>Java>>正文


Java LockOptions.getLockMode方法代码示例

本文整理汇总了Java中org.hibernate.LockOptions.getLockMode方法的典型用法代码示例。如果您正苦于以下问题:Java LockOptions.getLockMode方法的具体用法?Java LockOptions.getLockMode怎么用?Java LockOptions.getLockMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.LockOptions的用法示例。


在下文中一共展示了LockOptions.getLockMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldUseFollowOnLocking

import org.hibernate.LockOptions; //导入方法依赖的package包/类
protected boolean shouldUseFollowOnLocking(
		QueryParameters parameters,
		Dialect dialect,
		List<AfterLoadAction> afterLoadActions) {
	if ( dialect.useFollowOnLocking() ) {
		// currently only one lock mode is allowed in follow-on locking
		final LockMode lockMode = determineFollowOnLockMode( parameters.getLockOptions() );
		final LockOptions lockOptions = new LockOptions( lockMode );
		if ( lockOptions.getLockMode() != LockMode.UPGRADE_SKIPLOCKED ) {
			LOG.usingFollowOnLocking();
			lockOptions.setTimeOut( parameters.getLockOptions().getTimeOut() );
			lockOptions.setScope( parameters.getLockOptions().getScope() );
			afterLoadActions.add(
					new AfterLoadAction() {
						@Override
						public void afterLoad(SessionImplementor session, Object entity, Loadable persister) {
							( (Session) session ).buildLockRequest( lockOptions ).lock( persister.getEntityName(), entity );
						}
					}
			);
			parameters.setLockOptions( new LockOptions() );
			return true;
		}
	}
	return false;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:Loader.java

示例2: cascade

import org.hibernate.LockOptions; //导入方法依赖的package包/类
@Override
public void cascade(
		EventSource session,
		Object child,
		String entityName,
		Object anything,
		boolean isCascadeDeleteEnabled) {
	LOG.tracev( "Cascading to lock: {0}", entityName );
	LockMode lockMode = LockMode.NONE;
	LockOptions lr = new LockOptions();
	if ( anything instanceof LockOptions ) {
		LockOptions lockOptions = (LockOptions) anything;
		lr.setTimeOut( lockOptions.getTimeOut() );
		lr.setScope( lockOptions.getScope() );
		if ( lockOptions.getScope() ) {
			lockMode = lockOptions.getLockMode();
		}
	}
	lr.setLockMode( lockMode );
	session.buildLockRequest( lr ).lock( entityName, child );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:CascadingActions.java

示例3: getForUpdateString

import org.hibernate.LockOptions; //导入方法依赖的package包/类
@Override
public String getForUpdateString(final String aliases, final LockOptions lockOptions) {
	LockMode lockMode = lockOptions.getLockMode();
	final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator();
	while ( itr.hasNext() ) {
		// seek the highest lock mode
		final Map.Entry<String, LockMode> entry = itr.next();
		final LockMode lm = entry.getValue();
		if ( lm.greaterThan( lockMode ) ) {
			lockMode = lm;
		}
	}

	// not sure why this is sometimes empty
	if ( aliases == null || "".equals( aliases ) ) {
		return getForUpdateString( lockMode );
	}

	return getForUpdateString( lockMode ) + " of " + aliases;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:AbstractHANADialect.java

示例4: appendLockHint

import org.hibernate.LockOptions; //导入方法依赖的package包/类
@Override
public String appendLockHint(LockOptions lockOptions, String tableName) {
	final LockMode mode = lockOptions.getLockMode();
	switch ( mode ) {
		case UPGRADE:
		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;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:SQLServerDialect.java

示例5: appendLockHint

import org.hibernate.LockOptions; //导入方法依赖的package包/类
@Override
public String appendLockHint(LockOptions lockOptions, String tableName) {
	// NOTE : since SQLServer2005 the nowait hint is supported
	if ( lockOptions.getLockMode() == LockMode.UPGRADE_NOWAIT ) {
		return tableName + " with (updlock, rowlock, nowait)";
	}

	final LockMode mode = lockOptions.getLockMode();
	final boolean isNoWait = lockOptions.getTimeOut() == LockOptions.NO_WAIT;
	final String noWaitStr = isNoWait ? ", nowait" : "";
	switch ( mode ) {
		case UPGRADE_NOWAIT:
			return tableName + " with (updlock, rowlock, nowait)";
		case UPGRADE:
		case PESSIMISTIC_WRITE:
		case WRITE:
			return tableName + " with (updlock, rowlock" + noWaitStr + " )";
		case PESSIMISTIC_READ:
			return tableName + " with (holdlock, rowlock" + noWaitStr + " )";
		default:
			return tableName;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:SQLServer2005Dialect.java

示例6: getForUpdateString

import org.hibernate.LockOptions; //导入方法依赖的package包/类
/**
 * Get the <tt>FOR UPDATE OF column_list</tt> fragment appropriate for this
 * dialect given the aliases of the columns to be write locked.
 *
 * @param aliases The columns to be write locked.
 * @param lockOptions the lock options to apply
 * @return The appropriate <tt>FOR UPDATE OF column_list</tt> clause string.
 */
@SuppressWarnings({"unchecked", "UnusedParameters"})
public String getForUpdateString(String aliases, LockOptions lockOptions) {
	LockMode lockMode = lockOptions.getLockMode();
	final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator();
	while ( itr.hasNext() ) {
		// seek the highest lock mode
		final Map.Entry<String, LockMode>entry = itr.next();
		final LockMode lm = entry.getValue();
		if ( lm.greaterThan( lockMode ) ) {
			lockMode = lm;
		}
	}
	lockOptions.setLockMode( lockMode );
	return getForUpdateString( lockOptions );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:Dialect.java

示例7: DynamicEntityLoader

import org.hibernate.LockOptions; //导入方法依赖的package包/类
public DynamicEntityLoader(
		OuterJoinLoadable persister,
		int maxBatchSize,
		LockOptions lockOptions,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) {
	this( persister, maxBatchSize, lockOptions.getLockMode(), factory, loadQueryInfluencers );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:DynamicBatchingEntityLoaderBuilder.java

示例8: getLockModes

import org.hibernate.LockOptions; //导入方法依赖的package包/类
@Override
protected LockMode[] getLockModes(LockOptions lockOptions) {
	final String[] entityAliases = getAliases();
	if ( entityAliases == null ) {
		return null;
	}
	final int size = entityAliases.length;
	LockMode[] lockModesArray = new LockMode[size];
	for ( int i=0; i<size; i++ ) {
		LockMode lockMode = lockOptions.getAliasSpecificLockMode( entityAliases[i] );
		lockModesArray[i] = lockMode==null ? lockOptions.getLockMode() : lockMode;
	}
	return lockModesArray;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:CriteriaLoader.java

示例9: applyLocks

import org.hibernate.LockOptions; //导入方法依赖的package包/类
@Override
protected String applyLocks(
		String sql,
		QueryParameters parameters,
		Dialect dialect,
		List<AfterLoadAction> afterLoadActions) throws QueryException {
	final LockOptions lockOptions = parameters.getLockOptions();
	if ( lockOptions == null ||
			( lockOptions.getLockMode() == LockMode.NONE && lockOptions.getAliasLockCount() == 0 ) ) {
		return sql;
	}

	// user is request locking, lets see if we can apply locking directly to the SQL...

	// 		some dialects wont allow locking with paging...
	afterLoadActions.add(
			new AfterLoadAction() {
				private final LockOptions originalLockOptions = lockOptions.makeCopy();
				@Override
				public void afterLoad(SessionImplementor session, Object entity, Loadable persister) {
					( (Session) session ).buildLockRequest( originalLockOptions ).lock( persister.getEntityName(), entity );
				}
			}
	);
	parameters.getLockOptions().setLockMode( LockMode.READ );

	return sql;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:CustomLoader.java

示例10: getLockModes

import org.hibernate.LockOptions; //导入方法依赖的package包/类
/**
 * @param lockOptions a collection of lock modes specified dynamically via the Query interface
 */
@Override
protected LockMode[] getLockModes(LockOptions lockOptions) {
	if ( lockOptions == null ) {
		return defaultLockModes;
	}

	if ( lockOptions.getAliasLockCount() == 0
			&& ( lockOptions.getLockMode() == null || LockMode.NONE.equals( lockOptions.getLockMode() ) ) ) {
		return defaultLockModes;
	}

	// unfortunately this stuff can't be cached because
	// it is per-invocation, not constant for the
	// QueryTranslator instance

	LockMode[] lockModesArray = new LockMode[entityAliases.length];
	for ( int i = 0; i < entityAliases.length; i++ ) {
		LockMode lockMode = lockOptions.getEffectiveLockMode( entityAliases[i] );
		if ( lockMode == null ) {
			//NONE, because its the requested lock mode, not the actual!
			lockMode = LockMode.NONE;
		}
		lockModesArray[i] = lockMode;
	}

	return lockModesArray;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:QueryLoader.java

示例11: LoadEvent

import org.hibernate.LockOptions; //导入方法依赖的package包/类
private LoadEvent(
		Serializable entityId,
		String entityClassName,
		Object instanceToLoad,
		LockOptions lockOptions,
		boolean isAssociationFetch,
		EventSource source) {

	super(source);

	if ( entityId == null ) {
		throw new IllegalArgumentException("id to load is required for loading");
	}

	if ( lockOptions.getLockMode() == LockMode.WRITE ) {
		throw new IllegalArgumentException("Invalid lock mode for loading");
	}
	else if ( lockOptions.getLockMode() == null ) {
		lockOptions.setLockMode(DEFAULT_LOCK_MODE);
	}

	this.entityId = entityId;
	this.entityClassName = entityClassName;
	this.instanceToLoad = instanceToLoad;
	this.lockOptions = lockOptions;
	this.isAssociationFetch = isAssociationFetch;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:LoadEvent.java

示例12: getLockModes

import org.hibernate.LockOptions; //导入方法依赖的package包/类
@Override
   protected LockMode[] getLockModes(LockOptions lockOptions) {

	// unfortunately this stuff can't be cached because
	// it is per-invocation, not constant for the
	// QueryTranslator instance
	HashMap nameLockOptions = new HashMap();
	if ( lockOptions == null) {
		lockOptions = LockOptions.NONE;
	}

	if ( lockOptions.getAliasLockCount() > 0 ) {
		Iterator iter = lockOptions.getAliasLockIterator();
		while ( iter.hasNext() ) {
			Map.Entry me = ( Map.Entry ) iter.next();
			nameLockOptions.put( getAliasName( ( String ) me.getKey() ),
					me.getValue() );
		}
	}
	LockMode[] lockModesArray = new LockMode[names.length];
	for ( int i = 0; i < names.length; i++ ) {
		LockMode lm = ( LockMode ) nameLockOptions.get( names[i] );
		//if ( lm == null ) lm = LockOptions.NONE;
		if ( lm == null ) lm = lockOptions.getLockMode();
		lockModesArray[i] = lm;
	}
	return lockModesArray;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:QueryTranslatorImpl.java

示例13: applyLocks

import org.hibernate.LockOptions; //导入方法依赖的package包/类
@Override
protected String applyLocks(
		String sql,
		QueryParameters parameters,
		Dialect dialect,
		List<AfterLoadAction> afterLoadActions) throws QueryException {
	// can't cache this stuff either (per-invocation)
	// we are given a map of user-alias -> lock mode
	// create a new map of sql-alias -> lock mode

	final LockOptions lockOptions = parameters.getLockOptions();

	if ( lockOptions == null ||
		( lockOptions.getLockMode() == LockMode.NONE && lockOptions.getAliasLockCount() == 0 ) ) {
		return sql;
	}


	// user is request locking, lets see if we can apply locking directly to the SQL...

	// 		some dialects wont allow locking with paging...
	if ( shouldUseFollowOnLocking( parameters, dialect, afterLoadActions ) ) {
		return sql;
	}

	//		there are other conditions we might want to add here, such as checking the result types etc
	//		but those are better served after we have redone the SQL generation to use ASTs.


	// we need both the set of locks and the columns to reference in locks
	// as the ultimate output of this section...
	final LockOptions locks = new LockOptions( lockOptions.getLockMode() );
	final Map<String, String[]> keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap<String, String[]>() : null;

	locks.setScope( lockOptions.getScope() );
	locks.setTimeOut( lockOptions.getTimeOut() );

	for ( Map.Entry<String, String> entry : sqlAliasByEntityAlias.entrySet() ) {
		final String userAlias =  entry.getKey();
		final String drivingSqlAlias = entry.getValue();
		if ( drivingSqlAlias == null ) {
			throw new IllegalArgumentException( "could not locate alias to apply lock mode : " + userAlias );
		}
		// at this point we have (drivingSqlAlias) the SQL alias of the driving table
		// corresponding to the given user alias.  However, the driving table is not
		// (necessarily) the table against which we want to apply locks.  Mainly,
		// the exception case here is joined-subclass hierarchies where we instead
		// want to apply the lock against the root table (for all other strategies,
		// it just happens that driving and root are the same).
		final QueryNode select = (QueryNode) queryTranslator.getSqlAST();
		final Lockable drivingPersister = (Lockable) select.getFromClause()
				.findFromElementByUserOrSqlAlias( userAlias, drivingSqlAlias )
				.getQueryable();
		final String sqlAlias = drivingPersister.getRootTableAlias( drivingSqlAlias );

		final LockMode effectiveLockMode = lockOptions.getEffectiveLockMode( userAlias );
		locks.setAliasSpecificLockMode( sqlAlias, effectiveLockMode );

		if ( keyColumnNames != null ) {
			keyColumnNames.put( sqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
		}
	}

	// apply the collected locks and columns
	return dialect.applyLocksToSql( sql, locks, keyColumnNames );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:67,代码来源:QueryLoader.java

示例14: ResolveNaturalIdEvent

import org.hibernate.LockOptions; //导入方法依赖的package包/类
public ResolveNaturalIdEvent(
		Map<String, Object> naturalIdValues,
		EntityPersister entityPersister,
		LockOptions lockOptions,
		EventSource source) {
	super( source );

	if ( entityPersister == null ) {
		throw new IllegalArgumentException( "EntityPersister is required for loading" );
	}

	if ( ! entityPersister.hasNaturalIdentifier() ) {
		throw new HibernateException( "Entity did not define a natural-id" );
	}

	if ( naturalIdValues == null || naturalIdValues.isEmpty() ) {
		throw new IllegalArgumentException( "natural-id to load is required" );
	}

	if ( entityPersister.getNaturalIdentifierProperties().length != naturalIdValues.size() ) {
		throw new HibernateException(
				String.format(
					"Entity [%s] defines its natural-id with %d properties but only %d were specified",
					entityPersister.getEntityName(),
					entityPersister.getNaturalIdentifierProperties().length,
					naturalIdValues.size()
				)
		);
	}

	if ( lockOptions.getLockMode() == LockMode.WRITE ) {
		throw new IllegalArgumentException( "Invalid lock mode for loading" );
	}
	else if ( lockOptions.getLockMode() == null ) {
		lockOptions.setLockMode( DEFAULT_LOCK_MODE );
	}

	this.entityPersister = entityPersister;
	this.naturalIdValues = naturalIdValues;
	this.lockOptions = lockOptions;

	int[] naturalIdPropertyPositions = entityPersister.getNaturalIdentifierProperties();
	orderedNaturalIdValues = new Object[naturalIdPropertyPositions.length];
	int i = 0;
	for ( int position : naturalIdPropertyPositions ) {
		final String propertyName = entityPersister.getPropertyNames()[position];
		if ( ! naturalIdValues.containsKey( propertyName ) ) {
			throw new HibernateException(
					String.format( "No value specified for natural-id property %s#%s", getEntityName(), propertyName )
			);
		}
		orderedNaturalIdValues[i++] = naturalIdValues.get( entityPersister.getPropertyNames()[position] );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:55,代码来源:ResolveNaturalIdEvent.java

示例15: upgradeLock

import org.hibernate.LockOptions; //导入方法依赖的package包/类
/**
 * Performs a pessimistic lock upgrade on a given entity, if needed.
 *
 * @param object The entity for which to upgrade the lock.
 * @param entry The entity's EntityEntry instance.
 * @param lockOptions contains the requested lock mode.
 * @param source The session which is the source of the event being processed.
 */
protected void upgradeLock(Object object, EntityEntry entry, LockOptions lockOptions, EventSource source) {

	LockMode requestedLockMode = lockOptions.getLockMode();
	if ( requestedLockMode.greaterThan( entry.getLockMode() ) ) {
		// The user requested a "greater" (i.e. more restrictive) form of
		// pessimistic lock

		if ( entry.getStatus() != Status.MANAGED ) {
			throw new ObjectDeletedException(
					"attempted to lock a deleted instance",
					entry.getId(),
					entry.getPersister().getEntityName()
			);
		}

		final EntityPersister persister = entry.getPersister();

		if ( log.isTraceEnabled() ) {
			log.tracev(
					"Locking {0} in mode: {1}",
					MessageHelper.infoString( persister, entry.getId(), source.getFactory() ),
					requestedLockMode
			);
		}

		final SoftLock lock;
		final CacheKey ck;
		if ( persister.hasCache() ) {
			ck = source.generateCacheKey( entry.getId(), persister.getIdentifierType(), persister.getRootEntityName() );
			lock = persister.getCacheAccessStrategy().lockItem( ck, entry.getVersion() );
		}
		else {
			ck = null;
			lock = null;
		}

		try {
			if ( persister.isVersioned() && requestedLockMode == LockMode.FORCE  ) {
				// todo : should we check the current isolation mode explicitly?
				Object nextVersion = persister.forceVersionIncrement(
						entry.getId(), entry.getVersion(), source
				);
				entry.forceLocked( object, nextVersion );
			}
			else {
				persister.lock( entry.getId(), entry.getVersion(), object, lockOptions, source );
			}
			entry.setLockMode(requestedLockMode);
		}
		finally {
			// the database now holds a lock + the object is flushed from the cache,
			// so release the soft lock
			if ( persister.hasCache() ) {
				persister.getCacheAccessStrategy().unlockItem( ck, lock );
			}
		}

	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:68,代码来源:AbstractLockUpgradeEventListener.java


注:本文中的org.hibernate.LockOptions.getLockMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。