Package org.hibernate

Examples of org.hibernate.LockOptions


  }

  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

  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

      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

  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 event.getResult();
  }

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

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

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

  public Object load(String entityName, Serializable id, LockOptions lockOptions) throws HibernateException {
    return this.byId( entityName ).with( lockOptions ).getReference( id );
  }

  public Object get(Class entityClass, Serializable id, LockMode lockMode) throws HibernateException {
    return this.byId( entityClass ).with( new LockOptions( lockMode ) ).load( id );
  }
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.