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

          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

    }
    else {
      return; //EARLY EXIT!
    }

    PersistentCollection collection = (PersistentCollection) pc;
    if ( collection.unsetSession( getSession() ) ) evictCollection(collection);
  }
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

   * @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

  @Override
  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

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.