Package org.hibernate.collection.spi

Examples of org.hibernate.collection.spi.PersistentCollection


          //    with the current Session
          //throw new AssertionFailure("bug loading unowned collection");
        }
      }

      PersistentCollection rowCollection = persistenceContext.getLoadContexts()
          .getCollectionLoadContext( rs )
          .getLoadingCollection( persister, collectionRowKey );

      if ( rowCollection != null ) {
        rowCollection.readFrom(
            rs,
            persister,
            descriptor,
            owner );
      }
View Full Code Here


          MessageHelper.collectionInfoString( persister.getRole(), key ) );
    }
    final LoadingCollectionEntry loadingCollectionEntry = loadContexts.locateLoadingCollectionEntry( collectionKey );
    if ( loadingCollectionEntry == null ) {
      // look for existing collection as part of the persistence context
      PersistentCollection collection = loadContexts.getPersistenceContext().getCollection( collectionKey );
      if ( collection != null ) {
        if ( collection.wasInitialized() ) {
          LOG.trace( "Collection already initialized; ignoring" );
          // ignore this row of results! Note the early exit
          return null;
        }
        LOG.trace( "Collection not yet initialized; initializing" );
      }
      else {
        final Object owner = loadContexts.getPersistenceContext().getCollectionOwner( key, persister );
        final boolean newlySavedEntity = owner != null
            && loadContexts.getPersistenceContext().getEntry( owner ).getStatus() != Status.LOADING;
        if ( newlySavedEntity ) {
          // important, to account for newly saved entities in query
          // todo : some kind of check for new status...
          LOG.trace( "Owning entity already loaded; ignoring" );
          return null;
        }
        // create one
        LOG.tracev( "Instantiating new collection [key={0}, rs={1}]", key, resultSet );
        collection = persister.getCollectionType().instantiate(
            loadContexts.getPersistenceContext().getSession(), persister, key );
      }
      collection.beforeInitialize( persister, -1 );
      collection.beginRead();
      localLoadingCollectionKeys.add( collectionKey );
      loadContexts.registerLoadingCollectionXRef( collectionKey, new LoadingCollectionEntry( resultSet, persister, key, collection ) );
      return collection;
    }
    if ( loadingCollectionEntry.getResultSet() == resultSet ) {
View Full Code Here

    // One thing to be careful of here is a "bare" original collection
    // in which case we should never ever ever reset the dirty flag
    // on the target because we simply do not know...
    if ( original instanceof PersistentCollection ) {
      if ( result instanceof PersistentCollection ) {
        final PersistentCollection originalPersistentCollection = (PersistentCollection) original;
        final PersistentCollection resultPersistentCollection = (PersistentCollection) result;

        preserveSnapshot( originalPersistentCollection, resultPersistentCollection, elemType, owner, copyCache, session );

        if ( ! originalPersistentCollection.isDirty() ) {
          resultPersistentCollection.clearDirty();
        }
      }
    }

    return result;
View Full Code Here

    CollectionPersister persister = getPersister( session );
    final PersistenceContext persistenceContext = session.getPersistenceContext();
    final EntityMode entityMode = persister.getOwnerEntityPersister().getEntityMode();

    // check if collection is currently being loaded
    PersistentCollection collection = persistenceContext.getLoadContexts().locateLoadingCollection( persister, key );
   
    if ( collection == null ) {
     
      // check if it is already completely loaded, but unowned
      collection = persistenceContext.useUnownedCollection( new CollectionKey(persister, key, entityMode) );
     
      if ( collection == null ) {
        // create a new collection wrapper, to be initialized later
        collection = instantiate( session, persister, key );
       
        collection.setOwner(owner);
 
        persistenceContext.addUninitializedCollection( persister, collection, key );
 
        // some collections are not lazy:
        if ( initializeImmediately() ) {
          session.initializeCollection( collection, false );
        }
        else if ( !persister.isLazy() ) {
          persistenceContext.addNonLazyCollection( collection );
        }
 
        if ( hasHolder() ) {
          session.getPersistenceContext().addCollectionHolder( collection );
        }
       
      }
     
      if ( LOG.isTraceEnabled() ) {
        LOG.tracef( "Created collection wrapper: %s",
            MessageHelper.collectionInfoString( persister, collection,
                key, session ) );
      }
     
    }
   
    collection.setOwner(owner);

    return collection.getValue();
  }
View Full Code Here

          //    with the current Session
          //throw new AssertionFailure("bug loading unowned collection");
        }
      }

      PersistentCollection rowCollection = persistenceContext.getLoadContexts()
          .getCollectionLoadContext( rs )
          .getLoadingCollection( persister, collectionRowKey );

      if ( rowCollection != null ) {
        rowCollection.readFrom( rs, persister, descriptor, owner );
      }

    }
    else if ( optionalKey != null ) {
      // we did not find a collection element in the result set, so we
View Full Code Here

          );
        }

        Object collectionOwner = findCollectionOwner( collectionRowKey, resultSet, context );

        PersistentCollection rowCollection = persistenceContext.getLoadContexts()
            .getCollectionLoadContext( resultSet )
            .getLoadingCollection( collectionReference.getCollectionPersister(), collectionRowKey );

        if ( rowCollection != null ) {
          rowCollection.readFrom(
              resultSet,
              collectionReference.getCollectionPersister(),
              aliases.getCollectionColumnAliases(),
              collectionOwner
          );
View Full Code Here

      // (if the collection is uninitialized, hibernate has no way of
      // knowing if the collection is actually empty without querying the db)
      getPersister().remove( getKey(), getSession() );
    }
   
    final PersistentCollection collection = getCollection();
    if ( collection != null ) {
      getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection );
    }

    evict();
View Full Code Here

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

    preUpdate();

    if ( !collection.wasInitialized() ) {
      if ( !collection.hasQueuedOperations() ) {
        throw new AssertionFailure( "no queued adds" );
      }
      //do nothing - we only need to notify the cache...
    }
    else if ( !affectedByFilters && collection.empty() ) {
      if ( !emptySnapshot ) {
        persister.remove( id, session );
      }
    }
    else if ( collection.needsRecreate( persister ) ) {
      if ( affectedByFilters ) {
        throw new HibernateException(
            "cannot recreate collection while filter is enabled: " +
                MessageHelper.collectionInfoString( persister, collection, id, session )
        );
View Full Code Here

  @Override
  public void execute() throws HibernateException {
    // this method is called when a new non-null collection is persisted
    // or when an existing (non-null) collection is moved to a new owner
    final PersistentCollection collection = getCollection();
   
    preRecreate();
    getPersister().recreate( collection, getKey(), getSession() );
    getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection );
    evict();
View Full Code Here

          //    with the current Session
          //throw new AssertionFailure("bug loading unowned collection");
        }
      }

      PersistentCollection rowCollection = persistenceContext.getLoadContexts()
          .getCollectionLoadContext( rs )
          .getLoadingCollection( persister, collectionRowKey );

      if ( rowCollection != null ) {
        rowCollection.readFrom( rs, persister, descriptor, owner );
      }

    }
    else if ( optionalKey != null ) {
      // we did not find a collection element in the result set, so we
View Full Code Here

TOP

Related Classes of org.hibernate.collection.spi.PersistentCollection

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.