Package org.hibernate.engine

Examples of org.hibernate.engine.SessionImplementor


  }

  public void execute() throws HibernateException {
    Serializable id = getId();
    EntityPersister persister = getPersister();
    SessionImplementor session = getSession();
    Object instance = getInstance();

    boolean veto = preDelete();

    Object version = this.version;
    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
      version = persister.getVersion( instance, session.getEntityMode() );
    }

    final CacheKey ck;
    if ( persister.hasCache() ) {
      ck = new CacheKey(
          id,
          persister.getIdentifierType(),
          persister.getRootEntityName(),
          session.getEntityMode(),
          session.getFactory()
        );
      lock = persister.getCache().lock(ck, version);
    }
    else {
      ck = null;
    }

    if ( !isCascadeDeleteEnabled && !veto ) {
      persister.delete( id, version, instance, session );
    }
   
    //postDelete:
    // After actually deleting a row, record the fact that the instance no longer
    // exists on the database (needed for identity-column key generation), and
    // remove it from the session cache
    final PersistenceContext persistenceContext = session.getPersistenceContext();
    EntityEntry entry = persistenceContext.removeEntry( instance );
    if ( entry == null ) {
      throw new AssertionFailure( "possible nonthreadsafe access to session" );
    }
    entry.postDelete();

    EntityKey key = new EntityKey( entry.getId(), entry.getPersister(), session.getEntityMode() );
    persistenceContext.removeEntity(key);
    persistenceContext.removeProxy(key);
   
    if ( persister.hasCache() ) persister.getCache().evict(ck);
View Full Code Here


  }

  public void execute() throws HibernateException {
   
    final EntityPersister persister = getPersister();
    final SessionImplementor session = getSession();
    final Object instance = getInstance();
   
    boolean veto = preInsert();

    // Don't need to lock the cache here, since if someone
    // else inserted the same pk first, the insert would fail

    if ( !veto ) {
      generatedId = persister.insert( state, instance, session );
      if ( persister.hasInsertGeneratedProperties() ) {
        persister.processInsertGeneratedProperties( generatedId, instance, state, session );
      }
      //need to do that here rather than in the save event listener to let
      //the post insert events to have a id-filled entity when IDENTITY is used (EJB3)
      persister.setIdentifier( instance, generatedId, session.getEntityMode() );
    }


    //TODO: this bit actually has to be called after all cascades!
    //      but since identity insert is called *synchronously*,
    //      instead of asynchronously as other actions, it isn't
    /*if ( persister.hasCache() && !persister.isCacheInvalidationRequired() ) {
      cacheEntry = new CacheEntry(object, persister, session);
      persister.getCache().insert(generatedId, cacheEntry);
    }*/
   
    postInsert();

    if ( session.getFactory().getStatistics().isStatisticsEnabled() && !veto ) {
      session.getFactory().getStatisticsImplementor()
          .insertEntity( getPersister().getEntityName() );
    }

  }
View Full Code Here

    return state;
  }

  public void execute() throws HibernateException {
    EntityPersister persister = getPersister();
    SessionImplementor session = getSession();
    Object instance = getInstance();
    Serializable id = getId();

    boolean veto = preInsert();

    // Don't need to lock the cache here, since if someone
    // else inserted the same pk first, the insert would fail

    if ( !veto ) {
     
      persister.insert( id, state, instance, session );
   
      EntityEntry entry = session.getPersistenceContext().getEntry( instance );
      if ( entry == null ) {
        throw new AssertionFailure( "possible nonthreadsafe access to session" );
      }
     
      entry.postInsert();
 
      if ( persister.hasInsertGeneratedProperties() ) {
        persister.processInsertGeneratedProperties( id, instance, state, session );
        if ( persister.isVersionPropertyGenerated() ) {
          version = Versioning.getVersion(state, persister);
        }
        entry.postUpdate(instance, state, version);
      }
     
    }

    final SessionFactoryImplementor factory = getSession().getFactory();

    if ( isCachePutEnabled( persister, session ) ) {
     
      CacheEntry ce = new CacheEntry(
          state,
          persister,
          persister.hasUninitializedLazyProperties( instance, session.getEntityMode() ),
          version,
          session,
          instance
        );
     
      cacheEntry = persister.getCacheEntryStructure().structure(ce);
      final CacheKey ck = new CacheKey(
          id,
          persister.getIdentifierType(),
          persister.getRootEntityName(),
          session.getEntityMode(),
          session.getFactory()
        );
//      boolean put = persister.getCache().insert(ck, cacheEntry);
      boolean put = persister.getCache().insert( ck, cacheEntry, version );
     
      if ( put && factory.getStatistics().isStatisticsEnabled() ) {
View Full Code Here

    this.emptySnapshot = emptySnapshot;
  }

  public void execute() throws HibernateException {
    final Serializable id = getKey();
    final SessionImplementor session = getSession();
    final CollectionPersister persister = getPersister();
    final PersistentCollection collection = getCollection();
    boolean affectedByFilters = persister.isAffectedByEnabledFilters(session);

    preUpdate();
View Full Code Here

  }

  public void execute() throws HibernateException {
    Serializable id = getId();
    EntityPersister persister = getPersister();
    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, session.getEntityMode() );
    }
   
    final CacheKey ck;
    if ( persister.hasCache() ) {
      ck = new CacheKey(
          id,
          persister.getIdentifierType(),
          persister.getRootEntityName(),
          session.getEntityMode(),
          session.getFactory()
        );
      lock = persister.getCache().lock(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
      TypeFactory.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 perform 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.getCache().evict(ck);
      }
      else {
        //TODO: inefficient if that cache is just going to ignore the updated state!
        CacheEntry ce = new CacheEntry(
            state,
            persister,
            persister.hasUninitializedLazyProperties( instance, session.getEntityMode() ),
            nextVersion,
            getSession(),
            instance
        );
        cacheEntry = persister.getCacheEntryStructure().structure(ce);
View Full Code Here

   * Handle the given update event.
   *
   * @param event The update event to be handled.
   */
  public void onSaveOrUpdate(SaveOrUpdateEvent event) {
    final SessionImplementor source = event.getSession();
    final Object object = event.getObject();
    final Serializable requestedId = event.getRequestedId();

    if ( requestedId != null ) {
      //assign the requested id to the proxy, *before*
      //reassociating the proxy
      if ( object instanceof HibernateProxy ) {
        ( ( HibernateProxy ) object ).getHibernateLazyInitializer().setIdentifier( requestedId );
      }
    }

    if ( reassociateIfUninitializedProxy( object, source ) ) {
      log.trace( "reassociated uninitialized proxy" );
      // an uninitialized proxy, noop, don't even need to
      // return an id, since it is never a save()
    }
    else {
      //initialize properties of the event:
      final Object entity = source.getPersistenceContext().unproxyAndReassociate( object );
      event.setEntity( entity );
      event.setEntry( source.getPersistenceContext().getEntry( entity ) );
      //return the id in the event object
      event.setResultId( performSaveOrUpdate( event ) );
    }

  }
View Full Code Here

  Object processCollection(Object collection, CollectionType type)
    throws HibernateException {

    if (collection!=null) {

      SessionImplementor session = getSession();

      final PersistentCollection persistentCollection;
      if ( type.isArrayType() ) {
         persistentCollection = session.getPersistenceContext().getCollectionHolder(collection);
        // if no array holder we found an unwrappered array (this can't occur,
        // because we now always call wrap() before getting to here)
        // return (ah==null) ? true : searchForDirtyCollections(ah, type);
      }
      else {
View Full Code Here

    super( session, key, owner );
  }

  Object processCollection(Object collection, CollectionType type) throws HibernateException {

    SessionImplementor session = getSession();
    CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() );

    if ( collection == null ) {
      //do nothing
    }
    else if ( collection instanceof PersistentCollection ) {
View Full Code Here

    if ( event.getLockMode() == LockMode.WRITE ) {
      throw new HibernateException( "Invalid lock mode for lock()" );
    }

    SessionImplementor source = event.getSession();
   
    Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
    //TODO: if object was an uninitialized proxy, this is inefficient,
    //      resulting in two SQL selects
   
    EntityEntry entry = source.getPersistenceContext().getEntry(entity);
    if (entry==null) {
      final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
      final Serializable id = persister.getIdentifier( entity, source.getEntityMode() );
      if ( !ForeignKeys.isNotTransient( event.getEntityName(), entity, Boolean.FALSE, source ) ) {
        throw new TransientObjectException(
            "cannot lock an unsaved transient instance: " +
            persister.getEntityName()
        );
View Full Code Here

  Object processCollection(Object collection, CollectionType collectionType)
  throws HibernateException {

    if ( collection!=null && (collection instanceof PersistentCollection) ) {

      final SessionImplementor session = getSession();
      PersistentCollection coll = (PersistentCollection) collection;
      if ( coll.setCurrentSession(session) ) {
        reattachCollection( coll, collectionType );
      }
      return null;
View Full Code Here

TOP

Related Classes of org.hibernate.engine.SessionImplementor

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.