Package org.hibernate.engine

Examples of org.hibernate.engine.SessionImplementor


   */
  public void onInitializeCollection(InitializeCollectionEvent event)
  throws HibernateException {

    PersistentCollection collection = event.getCollection();
    SessionImplementor source = event.getSession();

    CollectionEntry ce = source.getPersistenceContext().getCollectionEntry(collection);
    if (ce==null) throw new HibernateException("collection was evicted");
    if ( !collection.wasInitialized() ) {
      if ( log.isTraceEnabled() ) {
        log.trace(
            "initializing collection " +
            MessageHelper.collectionInfoString( ce.getLoadedPersister(), ce.getLoadedKey(), source.getFactory() )
          );
      }

      log.trace("checking second-level cache");
      final boolean foundInCache = initializeCollectionFromCache(
          ce.getLoadedKey(),
          ce.getLoadedPersister(),
          collection,
          source
        );

      if (foundInCache) {
        log.trace("collection initialized from cache");
      }
      else {
        log.trace("collection not cached");
        ce.getLoadedPersister().initialize( ce.getLoadedKey(), source );
        log.trace("collection initialized");

        if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
          source.getFactory().getStatisticsImplementor().fetchCollection(
              ce.getLoadedPersister().getRole()
            );
        }
      }
    }
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

   * 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

  }

  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() );
      getSession().registerInsertedKey( getPersister(), generatedId );
    }


    //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

    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.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
      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.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, session.getEntityMode() ),
            nextVersion,
            getSession(),
            instance
        );
        cacheEntry = persister.getCacheEntryStructure().structure( ce );
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);
      }
      getSession().registerInsertedKey( getPersister(), getId() );
    }

    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.getCacheAccessStrategy().insert( ck, cacheEntry, version );
     
      if ( put && factory.getStatistics().isStatisticsEnabled() ) {
View Full Code Here

    public static Object getTargetFromProxy(SessionFactoryImplementor sessionFactoryImplementor, HibernateProxy proxy) {
        if (!proxy.getHibernateLazyInitializer().isUninitialized()) {
            return proxy.getHibernateLazyInitializer().getImplementation();
        }

        SessionImplementor sessionImplementor = proxy.getHibernateLazyInitializer().getSession();
        Session tempSession = sessionImplementor==null
        ? sessionFactoryImplementor.openTemporarySession()
        : sessionImplementor.getFactory().openTemporarySession();
        try {
      Object target = tempSession.get(
          proxy.getHibernateLazyInitializer().getEntityName(),
          proxy.getHibernateLazyInitializer().getIdentifier()
      );
View Full Code Here

          LOG.callingJoinTransactionOnNonJtaEntityManager();
      }
      return;
    }

    final SessionImplementor session = (SessionImplementor) getSession();
    final TransactionCoordinator transactionCoordinator = session.getTransactionCoordinator();
    final TransactionImplementor transaction = transactionCoordinator.getTransaction();

    transaction.markForJoin();
    transactionCoordinator.pulse();
View Full Code Here

    // http://docs.jboss.org/hibernate/stable/entitymanager/api/org/hibernate/ejb/AbstractEntityManagerImpl.html#getDelegate()
    return (Session)entityManager.getDelegate();
  }
 
  private EntityStatus getStatus(Object model){
    SessionImplementor simpl = (SessionImplementor)getSession();
    EntityEntry entry = simpl.getPersistenceContext().getEntry(model);
    if(entry != null){
      //Persistent Object
      logger.debug("current {} is one Entity with entry in PersistenceContext.", model);
      if (entry.getStatus() != Status.DELETED) {
        logger.debug("EntityStatus: {}", EntityStatus.PERSISTENT );
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.