Package org.hibernate

Examples of org.hibernate.LockOptions


    }
  }


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


    }
  }

  protected String generateLockString(int timeout) {
    final SessionFactoryImplementor factory = getLockable().getFactory();
    final LockOptions lockOptions = new LockOptions( getLockMode() );
    lockOptions.setTimeOut( timeout );
    final SimpleSelect select = new SimpleSelect( factory.getDialect() )
        .setLockOptions( lockOptions )
        .setTableName( getLockable().getRootTableName() )
        .addColumn( getLockable().getRootTableIdentifierColumnNames()[0] )
        .addCondition( getLockable().getRootTableIdentifierColumnNames(), "=?" );
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() ) {
            final LockMode lockMode = determineFollowOnLockMode( lockOptions );
            if( lockMode != LockMode.UPGRADE_SKIPLOCKED ) {
        // Dialect prefers to perform locking in a separate step
        LOG.usingFollowOnLocking();

        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

    }
  }

  protected String generateLockString(int lockTimeout) {
    final SessionFactoryImplementor factory = getLockable().getFactory();
    final LockOptions lockOptions = new LockOptions( getLockMode() );
    lockOptions.setTimeOut( lockTimeout );
    final SimpleSelect select = new SimpleSelect( factory.getDialect() )
        .setLockOptions( lockOptions )
        .setTableName( getLockable().getRootTableName() )
        .addColumn( getLockable().getRootTableIdentifierColumnNames()[0] )
        .addCondition( getLockable().getRootTableIdentifierColumnNames(), "=?" );
View Full Code Here

    this.entityManagerFactory = entityManagerFactory;
    this.persistenceContextType = type;
    this.synchronizationType = synchronizationType;
    this.transactionType = transactionType;

    this.lockOptions = new LockOptions();
    this.properties = new HashMap<String, Object>();
    for ( String key : entityManagerSpecificProperties ) {
      if ( entityManagerFactory.getProperties().containsKey( key ) ) {
        this.properties.put( key, entityManagerFactory.getProperties().get( key ) );
      }
View Full Code Here

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

    checkTransactionNeeded();

    Session session = internalGetSession();
    CacheMode previousCacheMode = session.getCacheMode();
    CacheMode localCacheMode = determineAppropriateLocalCacheMode( properties );
    LockOptions lockOptions = null;
    try {
      session.setCacheMode( localCacheMode );
      if ( !session.contains( entity ) ) {
        throw new IllegalArgumentException( "Entity not managed" );
      }
View Full Code Here

  }

  public void lock(Object entity, LockModeType lockModeType, Map<String, Object> properties) {
    checkOpen();

    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

      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

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.