Package org.hibernate.collection.spi

Examples of org.hibernate.collection.spi.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


  }

  Object processCollection(Object collection, CollectionType type) throws HibernateException {
    if ( collection != null ) {
      final 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 {
        // if not wrappered yet, its dirty (this can't occur, because
        // we now always call wrap() before getting to here)
        // return ( ! (obj instanceof PersistentCollection) ) ?
        //true : searchForDirtyCollections( (PersistentCollection) obj, type );
        persistentCollection = (PersistentCollection) collection;
      }

      if ( persistentCollection.isDirty() ) { //we need to check even if it was not initialized, because of delayed adds!
        dirty = true;
        return null; //NOTE: EARLY EXIT!
      }
    }
View Full Code Here

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

    if ( collection instanceof PersistentCollection ) {
      final 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

    final LinkedHashMap<CollectionEntry, PersistentCollection> map =  batchLoadableCollections.get( collectionPersister.getRole() );
    if ( map != null ) {
      for ( Entry<CollectionEntry, PersistentCollection> me : map.entrySet() ) {
        final CollectionEntry ce = me.getKey();
        final PersistentCollection collection = me.getValue();
       
        if ( ce.getLoadedKey() == null ) {
          // the loadedKey of the collectionEntry might be null as it might have been reset to null
          // (see for example Collections.processDereferencedCollection()
          // and CollectionEntry.afterAction())
          // though we clear the queue on flush, it seems like a good idea to guard
          // against potentially null loadedKeys (which leads to various NPEs as demonstrated in HHH-7821).
          continue;
        }

        if ( collection.wasInitialized() ) {
          // should never happen
          LOG.warn( "Encountered initialized collection in BatchFetchQueue, this should not happen." );
          continue;
        }
View Full Code Here

        //Hibernate cannot determine every single time the owner especially in case detached objects are involved
        // or property-ref is used
        //Should log really but we don't know if we're interested in this collection for indexing
        return;
      }
      PersistentCollection persistentCollection = event.getCollection();
      final String collectionRole;
      if ( persistentCollection != null ) {
        if ( ! persistentCollection.wasInitialized() ) {
          // non-initialized collections will still trigger events, but we want to skip them
          // as they won't contain new values affecting the index state
          return;
        }
        collectionRole = persistentCollection.getRole();
      }
      else {
        collectionRole = null;
      }
      AbstractDocumentBuilder<?> documentBuilder = getDocumentBuilder( entity );
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" );
          return null; // ignore this row of results! Note the early exit
        }
        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;
        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

   * 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.tracev( "Initializing collection {0}",
            MessageHelper.collectionInfoString( ce.getLoadedPersister(), ce.getLoadedKey(),
            source.getFactory() ) );
      }
View Full Code Here

    list = IdentityMap.entries( session.getPersistenceContext().getCollectionEntries() );
    size = list.size();
    ActionQueue actionQueue = session.getActionQueue();
    for ( int i = 0; i < size; i++ ) {
      Map.Entry me = (Map.Entry) list.get(i);
      PersistentCollection coll = (PersistentCollection) me.getKey();
      CollectionEntry ce = (CollectionEntry) me.getValue();

      if ( ce.isDorecreate() ) {
        session.getInterceptor().onCollectionRecreate( coll, ce.getCurrentKey() );
        actionQueue.addAction(
View Full Code Here

    Iterator iter = persistenceContext.getCollectionEntries().entrySet().iterator();
    while ( iter.hasNext() ) {
      Map.Entry me = (Map.Entry) iter.next();
      CollectionEntry collectionEntry = (CollectionEntry) me.getValue();
      PersistentCollection persistentCollection = (PersistentCollection) me.getKey();
      collectionEntry.postFlush(persistentCollection);
      if ( collectionEntry.getLoadedPersister() == null ) {
        //if the collection is dereferenced, remove from the session cache
        //iter.remove(); //does not work, since the entrySet is not backed by the set
        persistenceContext.getCollectionEntries()
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.