Package org.hibernate.engine

Examples of org.hibernate.engine.SessionImplementor


  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


  }

  final Object processArrayOrNewCollection(Object collection, CollectionType collectionType)
  throws HibernateException {

    final SessionImplementor session = getSession();

    if (collection==null) {
      //do nothing
      return null;
    }
    else {
      CollectionPersister persister = session.getFactory().getCollectionPersister( collectionType.getRole() );

      final PersistenceContext persistenceContext = session.getPersistenceContext();
      //TODO: move into collection type, so we can use polymorphism!
      if ( collectionType.hasHolder( session.getEntityMode() ) ) {
       
        if (collection==CollectionType.UNFETCHED_COLLECTION) return null;

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

      ( (Validatable) entity ).validate();
    }
  }
 
  protected boolean handleInterception(FlushEntityEvent event) {
    SessionImplementor session = event.getSession();
    EntityEntry entry = event.getEntityEntry();
    EntityPersister persister = entry.getPersister();
    Object entity = event.getEntity();
   
    //give the Interceptor a chance to modify property values
View Full Code Here

   */
  protected void dirtyCheck(FlushEntityEvent event) throws HibernateException {
   
    final Object entity = event.getEntity();
    final Object[] values = event.getPropertyValues();
    final SessionImplementor session = event.getSession();
    final EntityEntry entry = event.getEntityEntry();
    final EntityPersister persister = entry.getPersister();
    final Serializable id = entry.getId();
    final Object[] loadedState = entry.getLoadedState();

    int[] dirtyProperties = session.getInterceptor().findDirty(
        entity,
        id,
        values,
        loadedState,
        persister.getPropertyNames(),
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

   * @param event The load event to be handled.
   * @throws HibernateException
   */
  public void onLoad(LoadEvent event, LoadEventListener.LoadType loadType) throws HibernateException {

    final SessionImplementor source = event.getSession();

    EntityPersister persister;
    if ( event.getInstanceToLoad() != null ) {
      persister = source.getEntityPersister( null, event.getInstanceToLoad() ); //the load() which takes an entity does not pass an entityName
      event.setEntityClassName( event.getInstanceToLoad().getClass().getName() );
    }
    else {
      persister = source.getFactory().getEntityPersister( event.getEntityClassName() );
    }

    if ( persister == null ) {
      throw new HibernateException(
          "Unable to locate persister: " +
          event.getEntityClassName()
        );
    }

    if ( persister.getIdentifierType().isComponentType() && EntityMode.DOM4J == event.getSession().getEntityMode() ) {
      // skip this check for composite-ids relating to dom4j entity-mode;
      // alternatively, we could add a check to make sure the incoming id value is
      // an instance of Element...
    }
    else {
      Class idClass = persister.getIdentifierType().getReturnedClass();
      if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
        throw new TypeMismatchException(
            "Provided id of the wrong type. Expected: " + idClass + ", got " + event.getEntityId().getClass()
        );
      }
    }

    EntityKey keyToLoad = new EntityKey( event.getEntityId(), persister, source.getEntityMode()  );

    try {
      if ( loadType.isNakedEntityReturned() ) {
        //do not return a proxy!
        //(this option indicates we are initializing a proxy)
View Full Code Here

  protected Object loadFromDatasource(
      final LoadEvent event,
      final EntityPersister persister,
      final EntityKey keyToLoad,
      final LoadEventListener.LoadType options) {
    final SessionImplementor source = event.getSession();
    Object entity = persister.load(
        event.getEntityId(),
        event.getInstanceToLoad(),
        event.getLockMode(),
        source
    );

    if ( event.isAssociationFetch() && source.getFactory().getStatistics().isStatisticsEnabled() ) {
      source.getFactory().getStatisticsImplementor().fetchEntity( event.getEntityClassName() );
    }

    return entity;
  }
View Full Code Here

  protected Object loadFromSessionCache(
      final LoadEvent event,
      final EntityKey keyToLoad,
      final LoadEventListener.LoadType options) throws HibernateException {

    SessionImplementor session = event.getSession();
    Object old = session.getEntityUsingInterceptor( keyToLoad );

    if ( old != null ) {
      // this object was already loaded
      EntityEntry oldEntry = session.getPersistenceContext().getEntry( old );
      if ( options.isCheckDeleted() ) {
        Status status = oldEntry.getStatus();
        if ( status == Status.DELETED || status == Status.GONE ) {
          return REMOVED_ENTITY_MARKER;
        }
View Full Code Here

  protected Object loadFromSecondLevelCache(
      final LoadEvent event,
      final EntityPersister persister,
      final LoadEventListener.LoadType options) {

    final SessionImplementor source = event.getSession();

    final boolean useCache = persister.hasCache()
        && source.getCacheMode().isGetEnabled()
        && event.getLockMode().lessThan(LockMode.READ);

    if ( useCache ) {

      final SessionFactoryImplementor factory = source.getFactory();

      final CacheKey ck = new CacheKey(
          event.getEntityId(),
          persister.getIdentifierType(),
          persister.getRootEntityName(),
          source.getEntityMode(),
          source.getFactory()
      );
      Object ce = persister.getCacheAccessStrategy().get( ck, source.getTimestamp() );
      if ( factory.getStatistics().isStatisticsEnabled() ) {
        if ( ce == null ) {
          factory.getStatisticsImplementor().secondLevelCacheMiss(
              persister.getCacheAccessStrategy().getRegion().getName()
          );
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.