Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.SessionFactoryImplementor


      );
    }
  }

  protected String generateLockString() {
    SessionFactoryImplementor factory = lockable.getFactory();
    Update update = new Update( factory.getDialect() );
    update.setTableName( lockable.getRootTableName() );
    update.addPrimaryKeyColumns( lockable.getRootTableIdentifierColumnNames() );
    update.setVersionColumnName( lockable.getVersionColumnName() );
    update.addColumn( lockable.getVersionColumnName() );
    if ( factory.getSettings().isCommentsEnabled() ) {
      update.setComment( lockMode + " lock " + lockable.getEntityName() );
    }
    return update.toStatementString();
  }
View Full Code Here


      Object version,
      Object object,
      int timeout,
      SessionImplementor session) throws StaleObjectStateException, JDBCException {
    final String sql = determineSql( timeout );
    SessionFactoryImplementor factory = session.getFactory();
    try {
      PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
      try {
        getLockable().getIdentifierType().nullSafeSet( st, id, 1, session );
        if ( getLockable().isVersioned() ) {
          getLockable().getVersionType().nullSafeSet(
              st,
              version,
              getLockable().getIdentifierType().getColumnSpan( factory ) + 1,
              session
          );
        }

        ResultSet rs = st.executeQuery();
        try {
          if ( !rs.next() ) {
            if ( factory.getStatistics().isStatisticsEnabled() ) {
              factory.getStatisticsImplementor()
                  .optimisticFailure( getLockable().getEntityName() );
            }
            throw new StaleObjectStateException( getLockable().getEntityName(), id );
          }
        }
View Full Code Here

      throw new PessimisticLockException( "could not obtain pessimistic lock", e, object );
    }
  }

  protected String generateLockString(int lockTimeout) {
    SessionFactoryImplementor factory = getLockable().getFactory();
    LockOptions lockOptions = new LockOptions( getLockMode() );
    lockOptions.setTimeOut( lockTimeout );
    SimpleSelect select = new SimpleSelect( factory.getDialect() )
        .setLockOptions( lockOptions )
        .setTableName( getLockable().getRootTableName() )
        .addColumn( getLockable().getRootTableIdentifierColumnNames()[0] )
        .addCondition( getLockable().getRootTableIdentifierColumnNames(), "=?" );
    if ( getLockable().isVersioned() ) {
      select.addCondition( getLockable().getVersionColumnName(), "=?" );
    }
    if ( factory.getSettings().isCommentsEnabled() ) {
      select.setComment( getLockMode() + " lock " + getLockable().getEntityName() );
    }
    return select.toStatementString();
  }
View Full Code Here

      Object object,
      int timeout, SessionImplementor session) throws StaleObjectStateException, JDBCException {
    if ( !lockable.isVersioned() ) {
      throw new HibernateException( "write locks via update not supported for non-versioned entities [" + lockable.getEntityName() + "]" );
    }
    SessionFactoryImplementor factory = session.getFactory();
    try {
      PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
      try {
        lockable.getVersionType().nullSafeSet( st, version, 1, session );
        int offset = 2;

        lockable.getIdentifierType().nullSafeSet( st, id, offset, session );
        offset += lockable.getIdentifierType().getColumnSpan( factory );

        if ( lockable.isVersioned() ) {
          lockable.getVersionType().nullSafeSet( st, version, offset, session );
        }

        int affected = st.executeUpdate();
        if ( affected < 0 ) {  // todo:  should this instead check for exactly one row modified?
          factory.getStatisticsImplementor().optimisticFailure( lockable.getEntityName() );
          throw new StaleObjectStateException( lockable.getEntityName(), id );
        }

      }
      finally {
View Full Code Here

      throw new PessimisticLockException("could not obtain pessimistic lock", e, object);
    }
  }

  protected String generateLockString() {
    SessionFactoryImplementor factory = lockable.getFactory();
    Update update = new Update( factory.getDialect() );
    update.setTableName( lockable.getRootTableName() );
    update.addPrimaryKeyColumns( lockable.getRootTableIdentifierColumnNames() );
    update.setVersionColumnName( lockable.getVersionColumnName() );
    update.addColumn( lockable.getVersionColumnName() );
    if ( factory.getSettings().isCommentsEnabled() ) {
      update.setComment( lockMode + " lock " + lockable.getEntityName() );
    }
    return update.toStatementString();
  }
View Full Code Here

          Object version,
          Object object,
          int timeout,
          SessionImplementor session) throws StaleObjectStateException, JDBCException {
    final String sql = determineSql( timeout );
    SessionFactoryImplementor factory = session.getFactory();
    try {
      PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
      try {
        getLockable().getIdentifierType().nullSafeSet( st, id, 1, session );
        if ( getLockable().isVersioned() ) {
          getLockable().getVersionType().nullSafeSet(
              st,
              version,
              getLockable().getIdentifierType().getColumnSpan( factory ) + 1,
              session
          );
        }

        ResultSet rs = st.executeQuery();
        try {
          if ( !rs.next() ) {
            if ( factory.getStatistics().isStatisticsEnabled() ) {
              factory.getStatisticsImplementor()
                  .optimisticFailure( getLockable().getEntityName() );
            }
            throw new StaleObjectStateException( getLockable().getEntityName(), id );
          }
        }
View Full Code Here

        );
    }
  }

  protected String generateLockString(int timeout) {
    SessionFactoryImplementor factory = getLockable().getFactory();
    LockOptions lockOptions = new LockOptions( getLockMode() );
    lockOptions.setTimeOut( timeout );
    SimpleSelect select = new SimpleSelect( factory.getDialect() )
        .setLockOptions( lockOptions )
        .setTableName( getLockable().getRootTableName() )
        .addColumn( getLockable().getRootTableIdentifierColumnNames()[0] )
        .addCondition( getLockable().getRootTableIdentifierColumnNames(), "=?" );
    if ( getLockable().isVersioned() ) {
      select.addCondition( getLockable().getVersionColumnName(), "=?" );
    }
    if ( factory.getSettings().isCommentsEnabled() ) {
      select.setComment( getLockMode() + " lock " + getLockable().getEntityName() );
    }
    return select.toStatementString();
  }
View Full Code Here

      Object object,
      int timeout, SessionImplementor session) throws StaleObjectStateException, JDBCException {
    if ( !lockable.isVersioned() ) {
      throw new HibernateException( "write locks via update not supported for non-versioned entities [" + lockable.getEntityName() + "]" );
    }
    SessionFactoryImplementor factory = session.getFactory();
    try {
      PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
      try {
        lockable.getVersionType().nullSafeSet( st, version, 1, session );
        int offset = 2;

        lockable.getIdentifierType().nullSafeSet( st, id, offset, session );
        offset += lockable.getIdentifierType().getColumnSpan( factory );

        if ( lockable.isVersioned() ) {
          lockable.getVersionType().nullSafeSet( st, version, offset, session );
        }

        int affected = st.executeUpdate();
        if ( affected < 0 ) {  // todo:  should this instead check for exactly one row modified?
          factory.getStatisticsImplementor().optimisticFailure( lockable.getEntityName() );
          throw new StaleObjectStateException( lockable.getEntityName(), id );
        }

      }
      finally {
View Full Code Here

      throw new PessimisticLockException("could not obtain pessimistic lock", e, object);
    }
  }

  protected String generateLockString() {
    SessionFactoryImplementor factory = lockable.getFactory();
    Update update = new Update( factory.getDialect() );
    update.setTableName( lockable.getRootTableName() );
    update.addPrimaryKeyColumns( lockable.getRootTableIdentifierColumnNames() );
    update.setVersionColumnName( lockable.getVersionColumnName() );
    update.addColumn( lockable.getVersionColumnName() );
    if ( factory.getSettings().isCommentsEnabled() ) {
      update.setComment( lockMode + " lock " + lockable.getEntityName() );
    }
    return update.toStatementString();
  }
View Full Code Here

    SessionImplementor session = getSession();
    Object instance = getInstance();

    boolean veto = preUpdate();

    final SessionFactoryImplementor factory = getSession().getFactory();
    Object previousVersion = this.previousVersion;
    if ( persister.isVersionPropertyGenerated() ) {
      // we need to grab the version value from the entity, otherwise
      // we have issues with generated-version entities that may have
      // multiple actions queued during the same flush
      previousVersion = persister.getVersion( instance );
    }
   
    final CacheKey ck;
    if ( persister.hasCache() ) {
      ck = session.generateCacheKey(
          id,
          persister.getIdentifierType(),
          persister.getRootEntityName()
      );
      lock = persister.getCacheAccessStrategy().lockItem( ck, previousVersion );
    }
    else {
      ck = null;
    }

    if ( !veto ) {
      persister.update(
          id,
          state,
          dirtyFields,
          hasDirtyCollection,
          previousState,
          previousVersion,
          instance,
          rowId,
          session
      );
    }

    EntityEntry entry = getSession().getPersistenceContext().getEntry( instance );
    if ( entry == null ) {
      throw new AssertionFailure( "possible nonthreadsafe access to session" );
    }
   
    if ( entry.getStatus()==Status.MANAGED || persister.isVersionPropertyGenerated() ) {
      // get the updated snapshot of the entity state by cloning current state;
      // it is safe to copy in place, since by this time no-one else (should have)
      // has a reference  to the array
      TypeHelper.deepCopy(
          state,
          persister.getPropertyTypes(),
          persister.getPropertyCheckability(),
          state,
          session
      );
      if ( persister.hasUpdateGeneratedProperties() ) {
        // this entity defines proeprty generation, so process those generated
        // values...
        persister.processUpdateGeneratedProperties( id, instance, state, session );
        if ( persister.isVersionPropertyGenerated() ) {
          nextVersion = Versioning.getVersion( state, persister );
        }
      }
      // have the entity entry doAfterTransactionCompletion post-update processing, passing it the
      // update state and the new version (if one).
      entry.postUpdate( instance, state, nextVersion );
    }

    if ( persister.hasCache() ) {
      if ( persister.isCacheInvalidationRequired() || entry.getStatus()!= Status.MANAGED ) {
        persister.getCacheAccessStrategy().remove( ck );
      }
      else {
        //TODO: inefficient if that cache is just going to ignore the updated state!
        CacheEntry ce = new CacheEntry(
            state,
            persister,
            persister.hasUninitializedLazyProperties( instance ),
            nextVersion,
            getSession(),
            instance
        );
        cacheEntry = persister.getCacheEntryStructure().structure( ce );
        boolean put = persister.getCacheAccessStrategy().update( ck, cacheEntry, nextVersion, previousVersion );
        if ( put && factory.getStatistics().isStatisticsEnabled() ) {
          factory.getStatisticsImplementor().secondLevelCachePut( getPersister().getCacheAccessStrategy().getRegion().getName() );
        }
      }
    }

    postUpdate();

    if ( factory.getStatistics().isStatisticsEnabled() && !veto ) {
      factory.getStatisticsImplementor()
          .updateEntity( getPersister().getEntityName() );
    }
  }
View Full Code Here

TOP

Related Classes of org.hibernate.engine.spi.SessionFactoryImplementor

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.