Package org.hibernate

Examples of org.hibernate.LockMode


  private void checkVersion(
      ResultSet resultSet,
      ResultSetProcessingContext context,
      EntityKey entityKey,
      Object existing) {
    final LockMode requestedLockMode = context.resolveLockMode( entityReference );
    if ( requestedLockMode != LockMode.NONE ) {
      final LockMode currentLockMode = context.getSession().getPersistenceContext().getEntry( existing ).getLockMode();
      final boolean isVersionCheckNeeded = entityReference.getEntityPersister().isVersioned()
          && currentLockMode.lessThan( requestedLockMode );

      // we don't need to worry about existing version being uninitialized because this block isn't called
      // by a re-entrant load (re-entrant loads *always* have lock mode NONE)
      if ( isVersionCheckNeeded ) {
        //we only check the version when *upgrading* lock modes
View Full Code Here


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

    if ( dialect.useFollowOnLocking() ) {
            final LockMode lockMode = determineFollowOnLockMode( lockOptions );
            if( lockMode != LockMode.UPGRADE_SKIPLOCKED ) {
        // Dialect prefers to perform locking in a separate step
        LOG.usingFollowOnLocking();

        final LockOptions lockOptionsToUse = new LockOptions( lockMode );
        lockOptionsToUse.setTimeOut( lockOptions.getTimeOut() );
        lockOptionsToUse.setScope( lockOptions.getScope() );

        afterLoadActions.add(
            new AfterLoadAction() {
                @Override
                public void afterLoad(SessionImplementor session, Object entity, Loadable persister) {
                  ( (Session) session ).buildLockRequest( lockOptionsToUse )
                    .lock( persister.getEntityName(), entity );
                }
                }
        );
        parameters.setLockOptions( new LockOptions() );
        return sql;
      }
    }
    final LockOptions locks = new LockOptions(lockOptions.getLockMode());
    locks.setScope( lockOptions.getScope());
    locks.setTimeOut( lockOptions.getTimeOut());

    final Map keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null;
    final String[] drivingSqlAliases = getAliases();
    for ( int i = 0; i < drivingSqlAliases.length; i++ ) {
      final LockMode lockMode = lockOptions.getAliasSpecificLockMode( drivingSqlAliases[i] );
      if ( lockMode != null ) {
        final Lockable drivingPersister = ( Lockable ) getEntityPersisters()[i];
        final String rootSqlAlias = drivingPersister.getRootTableAlias( drivingSqlAliases[i] );
        locks.setAliasSpecificLockMode( rootSqlAlias, lockMode );
        if ( keyColumnNames != null ) {
View Full Code Here

  }


  @Override
  protected LockMode determineFollowOnLockMode(LockOptions lockOptions) {
    final LockMode lockModeToUse = lockOptions.findGreatestLockMode();

    if ( lockOptions.getAliasLockCount() > 1 ) {
      // > 1 here because criteria always uses alias map for the root lock mode (under 'this_')
      LOG.aliasSpecificLockingWithFollowOnLocking( lockModeToUse );
    }
View Full Code Here

      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;
  }
View Full Code Here

        if ( canApplyAliasSpecificLockModeHints() ) {
          // extract the alias
          final String alias = hintName.substring( AvailableSettings.ALIAS_SPECIFIC_LOCK_MODE.length() + 1 );
          // determine the LockMode
          try {
            final LockMode lockMode = LockModeTypeHelper.interpretLockMode( value );
            applyAliasSpecificLockModeHint( alias, lockMode );
          }
          catch ( Exception e ) {
            LOG.unableToDetermineLockModeValue( hintName, value );
            applied = false;
View Full Code Here

            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;
View Full Code Here

      Dialect dialect,
      List<AfterLoadAction> afterLoadActions) {
    if ( dialect.useFollowOnLocking() ) {
      LOG.usingFollowOnLocking();
      // currently only one lock mode is allowed in follow-on locking
      final LockMode lockMode = determineFollowOnLockMode( parameters.getLockOptions() );
      final LockOptions lockOptions = new LockOptions( lockMode );
      lockOptions.setTimeOut( parameters.getLockOptions().getTimeOut() );
      lockOptions.setScope( parameters.getLockOptions().getScope() );
      afterLoadActions.add(
          new AfterLoadAction() {
View Full Code Here

    }
    return false;
  }

  protected LockMode determineFollowOnLockMode(LockOptions lockOptions) {
    final LockMode lockModeToUse = lockOptions.findGreatestLockMode();

    if ( lockOptions.hasAliasSpecificLockModes() ) {
      LOG.aliasSpecificLockingWithFollowOnLocking( lockModeToUse );
    }
View Full Code Here

    //need to hydrate it.

    // grab its state from the ResultSet and keep it in the Session
    // (but don't yet initialize the object itself)
    // note that we acquire LockMode.READ even if it was not requested
    LockMode acquiredLockMode = lockMode == LockMode.NONE ? LockMode.READ : lockMode;
    loadFromResultSet(
        rs,
        i,
        object,
        instanceClass,
View Full Code Here

    String entityName = HbmBinder.getEntityName(returnElem, mappings);
    if(entityName==null) {
      throw new MappingException( "<return alias='" + alias + "'> must specify either a class or entity-name");
    }
    LockMode lockMode = getLockMode( returnElem.attributeValue( "lock-mode" ) );

    PersistentClass pc = mappings.getClass( entityName );
    java.util.Map propertyResults = bindPropertyResults(alias, returnElem, pc, mappings );

    return new NativeSQLQueryRootReturn(
View Full Code Here

TOP

Related Classes of org.hibernate.LockMode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.