Examples of PersistentCollection


Examples of org.hibernate.collection.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 );
      }

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

Examples of org.hibernate.collection.PersistentCollection

      log.trace( "starting attempt to find loading collection [" + 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" );
          return null; // ignore this row of results! Note the early exit
        }
        else {
          // initialize this collection
          log.trace( "collection not yet initialized; initializing" );
        }
      }
      else {
        Object owner = loadContexts.getPersistenceContext().getCollectionOwner( key, persister );
        final boolean newlySavedEntity = owner != null
            && loadContexts.getPersistenceContext().getEntry( owner ).getStatus() != Status.LOADING
            && em != EntityMode.DOM4J;
        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;
        }
        else {
          // create one
          if ( log.isTraceEnabled() ) {
            log.trace( "instantiating new collection [key=" + key + ", rs=" + 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;
    }
    else {
View Full Code Here

Examples of org.hibernate.collection.PersistentCollection

   * called by a collection that wants to initialize itself
   */
  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() )
          );
View Full Code Here

Examples of org.hibernate.collection.PersistentCollection

  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();

    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, id, persister.getFactory() )
        );
View Full Code Here

Examples of org.hibernate.collection.PersistentCollection

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

    final Serializable collectionKey = extractCollectionKeyFromOwner( persister );
    if ( collection!=null && (collection instanceof PersistentCollection) ) {
      PersistentCollection wrapper = (PersistentCollection) collection;
      if ( wrapper.setCurrentSession(session) ) {
        //a "detached" collection!
        if ( !isOwnerUnchanged( wrapper, persister, collectionKey ) ) {
          // if the collection belonged to a different entity,
          // clean up the existing state of the collection
          removeCollection( persister, collectionKey, session );
View Full Code Here

Examples of org.hibernate.collection.PersistentCollection

    if ( collection == null ) {
      //do nothing
    }
    else if ( collection instanceof PersistentCollection ) {
      PersistentCollection persistentCollection = ( PersistentCollection ) collection;
      if ( persistentCollection.setCurrentSession( session ) ) {
        if ( isOwnerUnchanged( persistentCollection, persister, extractCollectionKeyFromOwner( persister ) ) ) {
          // a "detached" collection that originally belonged to the same entity
          if ( persistentCollection.isDirty() ) {
            throw new HibernateException( "reassociated object has dirty collection" );
          }
          reattachCollection( persistentCollection, type );
        }
        else {
View Full Code Here

Examples of org.hibernate.collection.PersistentCollection

  }

  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() );
   
View Full Code Here

Examples of org.hibernate.collection.PersistentCollection

    Iterator iter = context.getCollectionEntries().entrySet().iterator(); //TODO: calling entrySet on an IdentityMap is SLOW!!
    while ( iter.hasNext() ) {
      Map.Entry me = (Map.Entry) iter.next();

      CollectionEntry ce = (CollectionEntry) me.getValue();
      PersistentCollection collection = (PersistentCollection) me.getKey();
      if ( !collection.wasInitialized() && ce.getLoadedPersister() == collectionPersister ) {

        if ( checkForEnd && i == end ) {
          return keys; //the first key found after the given key
        }
View Full Code Here

Examples of org.hibernate.collection.PersistentCollection

      // (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);
    }
View Full Code Here

Examples of org.hibernate.collection.PersistentCollection

    }
    else {
      return; //EARLY EXIT!
    }

    PersistentCollection collection = (PersistentCollection) pc;
    if ( collection.unsetSession( getSession() ) ) evictCollection(collection);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.