Package org.hibernate

Examples of org.hibernate.LockOptions


    if ( lockOptions == null ||
      ( lockOptions.getLockMode() == LockMode.NONE && lockOptions.getAliasLockCount() == 0 ) ) {
      return sql;
    }
    else {
      LockOptions locks = new LockOptions();
      locks.setLockMode(lockOptions.getLockMode());
      locks.setTimeOut(lockOptions.getTimeOut());
      locks.setScope(lockOptions.getScope());
      Iterator iter = lockOptions.getAliasLockIterator();
      while ( iter.hasNext() ) {
        Map.Entry me = ( Map.Entry ) iter.next();
        locks.setAliasSpecificLockMode( getAliasName( ( String ) me.getKey() ), (LockMode) me.getValue() );
      }
      Map keyColumnNames = null;
      if ( dialect.forUpdateOfColumns() ) {
        keyColumnNames = new HashMap();
        for ( int i = 0; i < names.length; i++ ) {
View Full Code Here


  }

  private class LockRequestImpl implements LockRequest {
    private final LockOptions lockOptions;
    private LockRequestImpl(LockOptions lo) {
      lockOptions = new LockOptions();
      LockOptions.copy(lo, lockOptions);
    }
View Full Code Here

  protected String buildSelectQuery(Dialect dialect) {
    final String alias = "tbl";
    String query = "select " + StringHelper.qualify( alias, valueColumnName ) +
        " from " + tableName + ' ' + alias +
        " where " + StringHelper.qualify( alias, segmentColumnName ) + "=?";
    LockOptions lockOptions = new LockOptions( LockMode.PESSIMISTIC_WRITE );
    lockOptions.setAliasSpecificLockMode( alias, LockMode.PESSIMISTIC_WRITE );
    Map updateTargetColumnsMap = Collections.singletonMap( alias, new String[] { valueColumnName } );
    return dialect.applyLocksToSql( query, lockOptions, updateTargetColumnsMap );
  }
View Full Code Here

   * @return The table with any required lock hints.
   * @deprecated use {@code appendLockHint(LockOptions,String)} instead
   */
  @Deprecated
  public String appendLockHint(LockMode mode, String tableName) {
    return appendLockHint( new LockOptions( mode ), tableName );
  }
View Full Code Here

  /**
   * Load an instance using either the <tt>forUpdateLoader</tt> or the outer joining <tt>loader</tt>,
   * depending upon the value of the <tt>lock</tt> parameter
   */
  public Object load(Serializable id, Object optionalObject, LockMode lockMode, SessionImplementor session) {
    return load( id, optionalObject, new LockOptions().setLockMode(lockMode), session );
  }
View Full Code Here

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

          st.setFetchSize( selection.getFetchSize() );
        }
      }

      // handle lock timeout...
      LockOptions lockOptions = queryParameters.getLockOptions();
      if ( lockOptions != null ) {
        if ( lockOptions.getTimeOut() != LockOptions.WAIT_FOREVER ) {
          if ( !dialect.supportsLockTimeouts() ) {
            if ( LOG.isDebugEnabled() ) {
              LOG.debugf(
                  "Lock timeout [%s] requested but dialect reported to not support lock timeouts",
                  lockOptions.getTimeOut()
              );
            }
          }
          else if ( dialect.isLockTimeoutParameterized() ) {
            st.setInt( col++, lockOptions.getTimeOut() );
          }
        }
      }

      if ( LOG.isTraceEnabled() )
View Full Code Here

  /**
   * Load an instance using either the <tt>forUpdateLoader</tt> or the outer joining <tt>loader</tt>,
   * depending upon the value of the <tt>lock</tt> parameter
   */
  public Object load(Serializable id, Object optionalObject, LockMode lockMode, SessionImplementor session) {
    return load( id, optionalObject, new LockOptions().setLockMode(lockMode), session );
  }
View Full Code Here

    selection.setFirstRow( rootCriteria.getFirstResult() );
    selection.setMaxRows( rootCriteria.getMaxResults() );
    selection.setTimeout( rootCriteria.getTimeout() );
    selection.setFetchSize( rootCriteria.getFetchSize() );

    final LockOptions lockOptions = new LockOptions();
    final Map<String, LockMode> lockModeMap = rootCriteria.getLockModes();
    for ( final String key : lockModeMap.keySet() ) {
      final Criteria subcriteria = getAliasedCriteria( key );
      lockOptions.setAliasSpecificLockMode( getSQLAlias( subcriteria ), lockModeMap.get( key ) );
    }

    final List<Object> values = new ArrayList<Object>();
    final List<Type> types = new ArrayList<Type>();
    final Iterator<CriteriaImpl.Subcriteria> subcriteriaIterator = rootCriteria.iterateSubcriteria();
    while ( subcriteriaIterator.hasNext() ) {
      final CriteriaImpl.Subcriteria subcriteria = subcriteriaIterator.next();
      final LockMode lm = subcriteria.getLockMode();
      if ( lm != null ) {
        lockOptions.setAliasSpecificLockMode( getSQLAlias( subcriteria ), lm );
      }
      if ( subcriteria.getWithClause() != null ) {
        final TypedValue[] tv = subcriteria.getWithClause().getTypedValues( subcriteria, this );
        for ( TypedValue aTv : tv ) {
          values.add( aTv.getValue() );
View Full Code Here

          st.setFetchSize( selection.getFetchSize() );
        }
      }

      // handle lock timeout...
      final LockOptions lockOptions = queryParameters.getLockOptions();
      if ( lockOptions != null ) {
        if ( lockOptions.getTimeOut() != LockOptions.WAIT_FOREVER ) {
          if ( !dialect.supportsLockTimeouts() ) {
            if ( log.isDebugEnabled() ) {
              log.debugf(
                  "Lock timeout [%s] requested but dialect reported to not support lock timeouts",
                  lockOptions.getTimeOut()
              );
            }
          }
          else if ( dialect.isLockTimeoutParameterized() ) {
            st.setInt( col++, lockOptions.getTimeOut() );
          }
        }
      }

      if ( log.isTraceEnabled() ) {
View Full Code Here

TOP

Related Classes of org.hibernate.LockOptions

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.