Package org.hibernate

Examples of org.hibernate.LockOptions


  public void lock(Object entity, LockModeType lockMode) {
    lock( entity, lockMode, null );
  }

  public void lock(Object entity, LockModeType lockModeType, Map<String, Object> properties) {
    LockOptions lockOptions = null;
    try {
      if ( !isTransactionInProgress() ) {
        throw new TransactionRequiredException( "no transaction is in progress" );
      }
      if ( !contains( entity ) ) {
View Full Code Here


      throw convert( he, lockOptions );
    }
  }

  public LockOptions getLockRequest(LockModeType lockModeType, Map<String, Object> properties) {
    LockOptions lockOptions = new LockOptions();
    LockOptions.copy( this.lockOptions, lockOptions );
    lockOptions.setLockMode( getLockMode( lockModeType ) );
    if ( properties != null ) {
      setLockOptions( properties, lockOptions );
    }
    return lockOptions;
  }
View Full Code Here

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

    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 ) {
          keyColumnNames.put( rootSqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
        }
      }
    }
View Full Code Here

    }
  }


  protected void initPersisters(final List associations, final LockMode lockMode) throws MappingException {
    initPersisters( associations, new LockOptions(lockMode));
  }
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.UPGRADE);
    lockOptions.setAliasSpecificLockMode( alias, LockMode.UPGRADE );
    Map updateTargetColumnsMap = Collections.singletonMap( alias, new String[] { valueColumnName } );
    return dialect.applyLocksToSql( query, lockOptions, updateTargetColumnsMap );
  }
View Full Code Here

      return sql;
    }

    // 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 keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null;

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

    final Iterator itr = sqlAliasByEntityAlias.entrySet().iterator();
    while ( itr.hasNext() ) {
      final Map.Entry entry = (Map.Entry) itr.next();
      final String userAlias = (String) entry.getKey();
      final String drivingSqlAlias = (String) 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() );
      }
    }
View Full Code Here

  public CriteriaImpl getRootCriteria() {
    return rootCriteria;
  }

  public QueryParameters getQueryParameters() {
    LockOptions lockOptions = new LockOptions();
    RowSelection selection = new RowSelection();
    selection.setFirstRow( rootCriteria.getFirstResult() );
    selection.setMaxRows( rootCriteria.getMaxResults() );
    selection.setTimeout( rootCriteria.getTimeout() );
    selection.setFetchSize( rootCriteria.getFetchSize() );

    Iterator iter = rootCriteria.getLockModes().entrySet().iterator();
    while ( iter.hasNext() ) {
      Map.Entry me = ( Map.Entry ) iter.next();
      final Criteria subcriteria = getAliasedCriteria( ( String ) me.getKey() );
      lockOptions.setAliasSpecificLockMode( getSQLAlias( subcriteria ), (LockMode)me.getValue() );
    }
    List values = new ArrayList();
    List types = new ArrayList();
    iter = rootCriteria.iterateSubcriteria();
    while ( iter.hasNext() ) {
      CriteriaImpl.Subcriteria subcriteria = ( CriteriaImpl.Subcriteria ) iter.next();
      LockMode lm = subcriteria.getLockMode();
      if ( lm != null ) {
        lockOptions.setAliasSpecificLockMode( getSQLAlias( subcriteria ), lm );
      }
      if ( subcriteria.getWithClause() != null )
      {
        TypedValue[] tv = subcriteria.getWithClause().getTypedValues( subcriteria, this );
        for ( int i = 0; i < tv.length; i++ ) {
View Full Code Here

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

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

      log.trace( "Bound [" + col + "] parameters total" );
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

      Map properties) {
    this.entityManagerFactory = entityManagerFactory;
    this.persistenceContextType = type;
    this.transactionType = transactionType;

    this.lockOptions = new LockOptions();
    this.properties = new HashMap<String, Object>();
    if ( properties != null ) {
      for ( String key : entityManagerSpecificProperties ) {
        if ( properties.containsKey( key ) ) {
          this.properties.put( key, properties.get( key ) );
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.