Package org.hibernate.collection.spi

Examples of org.hibernate.collection.spi.PersistentCollection


   * @param key The key of the collection's entry.
   */
  private void addCollection(PersistentCollection coll, CollectionEntry entry, Serializable key) {
    collectionEntries.put( coll, entry );
    CollectionKey collectionKey = new CollectionKey( entry.getLoadedPersister(), key );
    PersistentCollection old = ( PersistentCollection ) collectionsByKey.put( collectionKey, coll );
    if ( old != null ) {
      if ( old == coll ) {
        throw new AssertionFailure("bug adding collection twice");
      }
      // or should it actually throw an exception?
      old.unsetSession( session );
      collectionEntries.remove( old );
      // watch out for a case where old is still referenced
      // somewhere in the object graph! (which is a user error)
    }
  }
View Full Code Here


   * Get the collection entry for a collection passed to filter,
   * which might be a collection wrapper, an array, or an unwrapped
   * collection. Return null if there is no entry.
   */
  public CollectionEntry getCollectionEntryOrNull(Object collection) {
    PersistentCollection coll;
    if ( collection instanceof PersistentCollection ) {
      coll = (PersistentCollection) collection;
      //if (collection==null) throw new TransientObjectException("Collection was not yet persistent");
    }
    else {
      coll = getCollectionHolder(collection);
      if ( coll == null ) {
        //it might be an unwrapped collection reference!
        //try to find a wrapper (slowish)
        Iterator wrappers = IdentityMap.keyIterator(collectionEntries);
        while ( wrappers.hasNext() ) {
          PersistentCollection pc = (PersistentCollection) wrappers.next();
          if ( pc.isWrapper(collection) ) {
            coll = pc;
            break;
          }
        }
      }
View Full Code Here

      count = ois.readInt();
      if ( tracing ) LOG.trace("Starting deserialization of [" + count + "] collectionEntries entries");
      rtn.collectionEntries = IdentityMap.instantiateSequenced( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count );
      for ( int i = 0; i < count; i++ ) {
        final PersistentCollection pc = ( PersistentCollection ) ois.readObject();
        final CollectionEntry ce = CollectionEntry.deserialize( ois, session );
        pc.setCurrentSession( session );
        rtn.collectionEntries.put( pc, ce );
      }

      count = ois.readInt();
      if ( tracing ) LOG.trace("Starting deserialization of [" + count + "] arrayHolders entries");
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

   * @param key The key of the collection's entry.
   */
  private void addCollection(PersistentCollection coll, CollectionEntry entry, Serializable key) {
    collectionEntries.put( coll, entry );
    CollectionKey collectionKey = new CollectionKey( entry.getLoadedPersister(), key );
    PersistentCollection old = collectionsByKey.put( collectionKey, coll );
    if ( old != null ) {
      if ( old == coll ) {
        throw new AssertionFailure("bug adding collection twice");
      }
      // or should it actually throw an exception?
      old.unsetSession( session );
      collectionEntries.remove( old );
      // watch out for a case where old is still referenced
      // somewhere in the object graph! (which is a user error)
    }
  }
View Full Code Here

   * which might be a collection wrapper, an array, or an unwrapped
   * collection. Return null if there is no entry.
   */
  @Override
  public CollectionEntry getCollectionEntryOrNull(Object collection) {
    PersistentCollection coll;
    if ( collection instanceof PersistentCollection ) {
      coll = (PersistentCollection) collection;
      //if (collection==null) throw new TransientObjectException("Collection was not yet persistent");
    }
    else {
      coll = getCollectionHolder(collection);
      if ( coll == null ) {
        //it might be an unwrapped collection reference!
        //try to find a wrapper (slowish)
        Iterator<PersistentCollection> wrappers = collectionEntries.keyIterator();
        while ( wrappers.hasNext() ) {
          PersistentCollection pc = wrappers.next();
          if ( pc.isWrapper(collection) ) {
            coll = pc;
            break;
          }
        }
      }
View Full Code Here

      count = ois.readInt();
      if ( tracing ) LOG.trace("Starting deserialization of [" + count + "] collectionEntries entries");
      rtn.collectionEntries = IdentityMap.instantiateSequenced( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count );
      for ( int i = 0; i < count; i++ ) {
        final PersistentCollection pc = ( PersistentCollection ) ois.readObject();
        final CollectionEntry ce = CollectionEntry.deserialize( ois, session );
        pc.setCurrentSession( session );
        rtn.collectionEntries.put( pc, ce );
      }

      count = ois.readInt();
      if ( tracing ) LOG.trace("Starting deserialization of [" + count + "] arrayHolders entries");
View Full Code Here

    final LinkedHashMap<CollectionEntry, PersistentCollection> map =  batchLoadableCollections.get( collectionPersister.getRole() );
    if ( map != null ) {
      for ( Map.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

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

    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

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.