Package org.hibernate

Examples of org.hibernate.LockOptions


  public Object get(Class entityClass, Serializable id, LockOptions lockOptions) throws HibernateException {
    return this.byId( entityClass ).with( lockOptions ).load( id );
  }

  public Object get(String entityName, Serializable id, LockMode lockMode) throws HibernateException {
    return this.byId( entityName ).with( new LockOptions( lockMode ) ).load( id );
  }
View Full Code Here


      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() {
            @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

  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;
    }

    if ( dialect.useFollowOnLocking() ) {
      // Dialect prefers to perform locking in a separate step
      LOG.usingFollowOnLocking();

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

    }
  }


  protected void initPersisters(final List associations, final LockMode lockMode) throws MappingException {
    initPersisters( associations, new LockOptions(lockMode));
  }
View Full Code Here

      String sql,
      QueryParameters parameters,
      Dialect dialect,
      List<AfterLoadAction> afterLoadActions) throws QueryException {
    // can't cache this stuff either (per-invocation)
    final LockOptions lockOptions = parameters.getLockOptions();
    final String result;
    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 final LockOptions lockOptions;

  private Serializable entityId;

  public ResolveNaturalIdEvent(Map<String, Object> naturalIdValues, EntityPersister entityPersister, EventSource source) {
    this( naturalIdValues, entityPersister, new LockOptions(), source );
  }
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.