Package org.hibernate

Examples of org.hibernate.LockOptions


      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


  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

      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

  }

  public <A> A find(Class<A> entityClass, Object primaryKey, LockModeType lockModeType, Map<String, Object> properties) {
    CacheMode previousCacheMode = getSession().getCacheMode();
    CacheMode cacheMode = determineAppropriateLocalCacheMode( properties );
    LockOptions lockOptions = null;
    try {
      getSession().setCacheMode( cacheMode );
      if ( lockModeType != null ) {
        return ( A ) getSession().get(
            entityClass, ( Serializable ) primaryKey,
View Full Code Here

  public void refresh(Object entity, LockModeType lockModeType, Map<String, Object> properties) {
    checkTransactionNeeded();
    CacheMode previousCacheMode = getSession().getCacheMode();
    CacheMode localCacheMode = determineAppropriateLocalCacheMode( properties );
    LockOptions lockOptions = null;
    try {
      getSession().setCacheMode( localCacheMode );
      if ( !getSession().contains( entity ) ) {
        throw new IllegalArgumentException( "Entity not managed" );
      }
View Full Code Here

  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;
    if ( !isTransactionInProgress() ) {
      throw new TransactionRequiredException( "no transaction is in progress" );
    }

    try {
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

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

  public LockOptions determineLockOptions(NamedQuery namedQueryAnnotation) {
    LockModeType lockModeType = namedQueryAnnotation.lockMode();
    Integer lockTimeoutHint = getInteger( namedQueryAnnotation.name(), "javax.persistence.lock.timeout" );

    LockOptions lockOptions = new LockOptions( LockModeConverter.convertToLockMode( lockModeType ) );
    if ( lockTimeoutHint != null ) {
      lockOptions.setTimeOut( lockTimeoutHint );
    }

    return lockOptions;
  }
View Full Code Here

    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

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.