Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.CollectionEntry


  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() ) {
      final boolean traceEnabled = LOG.isTraceEnabled();
      if ( traceEnabled ) {
        LOG.tracev( "Initializing collection {0}",
            MessageHelper.collectionInfoString( ce.getLoadedPersister(), collection, ce.getLoadedKey(), source ) );
        LOG.trace( "Checking second-level cache" );
      }

      final boolean foundInCache = initializeCollectionFromCache(
          ce.getLoadedKey(),
          ce.getLoadedPersister(),
          collection,
          source
        );

      if ( foundInCache ) {
        if ( traceEnabled ) {
          LOG.trace( "Collection initialized from cache" );
        }
      }
      else {
        if ( traceEnabled ) {
          LOG.trace( "Collection not cached" );
        }
        ce.getLoadedPersister().initialize( ce.getLoadedKey(), source );
        if ( traceEnabled ) {
          LOG.trace( "Collection initialized" );
        }

        if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
          source.getFactory().getStatisticsImplementor().fetchCollection(
              ce.getLoadedPersister().getRole()
            );
        }
      }
    }
  }
View Full Code Here


    LOG.trace( "Processing unreferenced collections" );

    for ( Map.Entry<PersistentCollection,CollectionEntry> me :
        IdentityMap.concurrentEntries( (Map<PersistentCollection,CollectionEntry>) persistenceContext.getCollectionEntries() )) {
      CollectionEntry ce = me.getValue();
      if ( !ce.isReached() && !ce.isIgnore() ) {
        Collections.processUnreachableCollection( me.getKey(), session );
      }
    }

    // Schedule updates to collections:

    LOG.trace( "Scheduling collection removes/(re)creates/updates" );

    ActionQueue actionQueue = session.getActionQueue();
    for ( Map.Entry<PersistentCollection,CollectionEntry> me :
      IdentityMap.concurrentEntries( (Map<PersistentCollection,CollectionEntry>) persistenceContext.getCollectionEntries() )) {
      PersistentCollection coll = me.getKey();
      CollectionEntry ce = me.getValue();

      if ( ce.isDorecreate() ) {
        session.getInterceptor().onCollectionRecreate( coll, ce.getCurrentKey() );
        actionQueue.addAction(
            new CollectionRecreateAction(
                coll,
                ce.getCurrentPersister(),
                ce.getCurrentKey(),
                session
              )
          );
      }
      if ( ce.isDoremove() ) {
        session.getInterceptor().onCollectionRemove( coll, ce.getLoadedKey() );
        actionQueue.addAction(
            new CollectionRemoveAction(
                coll,
                ce.getLoadedPersister(),
                ce.getLoadedKey(),
                ce.isSnapshotEmpty(coll),
                session
              )
          );
      }
      if ( ce.isDoupdate() ) {
        session.getInterceptor().onCollectionUpdate( coll, ce.getLoadedKey() );
        actionQueue.addAction(
            new CollectionUpdateAction(
                coll,
                ce.getLoadedPersister(),
                ce.getLoadedKey(),
                ce.isSnapshotEmpty(coll),
                session
              )
          );
      }
      if ( !coll.wasInitialized() && coll.hasQueuedOperations() ) {
        actionQueue.addAction(
            new QueuedOperationCollectionAction(
                coll,
                ce.getLoadedPersister(),
                ce.getLoadedKey(),
                session
              )
          );
      }
View Full Code Here

    // the database has changed now, so the subselect results need to be invalidated
    // the batch fetching queues should also be cleared - especially the collection batch fetching one
    persistenceContext.getBatchFetchQueue().clear();

    for ( Map.Entry<PersistentCollection, CollectionEntry> me : IdentityMap.concurrentEntries( persistenceContext.getCollectionEntries() ) ) {
      CollectionEntry collectionEntry = me.getValue();
      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()
            .remove(persistentCollection);
      }
      else {
        //otherwise recreate the mapping between the collection and its key
        CollectionKey collectionKey = new CollectionKey(
            collectionEntry.getLoadedPersister(),
            collectionEntry.getLoadedKey()
        );
        persistenceContext.getCollectionsByKey().put(collectionKey, persistentCollection);
      }
    }
View Full Code Here

      boolean shallow) throws HibernateException {
    if ( collection == null ) {
      throw new NullPointerException( "null collection passed to filter" );
    }

    CollectionEntry entry = persistenceContext.getCollectionEntryOrNull( collection );
    final CollectionPersister roleBeforeFlush = (entry == null) ? null : entry.getLoadedPersister();

    FilterQueryPlan plan = null;
    if ( roleBeforeFlush == null ) {
      // if it was previously unreferenced, we need to flush in order to
      // get its state into the database in order to execute query
      flush();
      entry = persistenceContext.getCollectionEntryOrNull( collection );
      CollectionPersister roleAfterFlush = (entry == null) ? null : entry.getLoadedPersister();
      if ( roleAfterFlush == null ) {
        throw new QueryException( "The collection was unreferenced" );
      }
      plan = factory.getQueryPlanCache().getFilterQueryPlan( filter, roleAfterFlush.getRole(), shallow, getEnabledFilters() );
    }
    else {
      // otherwise, we only need to flush if there are in-memory changes
      // to the queried tables
      plan = factory.getQueryPlanCache().getFilterQueryPlan( filter, roleBeforeFlush.getRole(), shallow, getEnabledFilters() );
      if ( autoFlushIfRequired( plan.getQuerySpaces() ) ) {
        // might need to run a different filter entirely after the flush
        // because the collection role may have changed
        entry = persistenceContext.getCollectionEntryOrNull( collection );
        CollectionPersister roleAfterFlush = (entry == null) ? null : entry.getLoadedPersister();
        if ( roleBeforeFlush != roleAfterFlush ) {
          if ( roleAfterFlush == null ) {
            throw new QueryException( "The collection was dereferenced" );
          }
          plan = factory.getQueryPlanCache().getFilterQueryPlan( filter, roleAfterFlush.getRole(), shallow, getEnabledFilters() );
        }
      }
    }

    if ( parameters != null ) {
      parameters.getPositionalParameterValues()[0] = entry.getLoadedKey();
      parameters.getPositionalParameterTypes()[0] = entry.getLoadedPersister().getKeyType();
    }

    return plan;
  }
View Full Code Here

    if ( persister.getCollectionType().hasHolder() ) {
      getLoadContext().getPersistenceContext().addCollectionHolder( lce.getCollection() );
    }

    CollectionEntry ce = getLoadContext().getPersistenceContext().getCollectionEntry( lce.getCollection() );
    if ( ce == null ) {
      ce = getLoadContext().getPersistenceContext().addInitializedCollection( persister, lce.getCollection(), lce.getKey() );
    }
    else {
      ce.postInitialize( lce.getCollection() );
    }

    boolean addToCache = hasNoQueuedAdds && // there were no queued additions
        persister.hasCache() &&             // and the role has a cache
        session.getCacheMode().isPutEnabled() &&
        !ce.isDoremove();                   // and this is not a forced initialization during flush
    if ( addToCache ) {
      addCollectionToCache( lce, persister );
    }

    if ( LOG.isDebugEnabled() ) {
View Full Code Here

   */
  private void deleteOrphans(String entityName, PersistentCollection pc) throws HibernateException {
    //TODO: suck this logic into the collection!
    final Collection orphans;
    if ( pc.wasInitialized() ) {
      CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry(pc);
      orphans = ce==null ?
          java.util.Collections.EMPTY_LIST :
          ce.getOrphans(entityName, pc);
    }
    else {
      orphans = pc.getQueuedOrphans(entityName);
    }

View Full Code Here

   * @return the owner, if its entity ID is available from the collection's loaded key
   * and the owner entity is in the persistence context; otherwise, returns null
   */
  @Override
  public Object getLoadedCollectionOwnerOrNull(PersistentCollection collection) {
    CollectionEntry ce = getCollectionEntry( collection );
    if ( ce.getLoadedPersister() == null ) {
      return null; // early exit...
    }
    Object loadedOwner = null;
    // TODO: an alternative is to check if the owner has changed; if it hasn't then
    // return collection.getOwner()
    Serializable entityId = getLoadedCollectionOwnerIdOrNull( ce );
    if ( entityId != null ) {
      loadedOwner = getCollectionOwner( entityId, ce.getLoadedPersister() );
    }
    return loadedOwner;
  }
View Full Code Here

  /**
   * add a collection we just loaded up (still needs initializing)
   */
  @Override
  public void addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id) {
    CollectionEntry ce = new CollectionEntry(collection, persister, id, flushing);
    addCollection(collection, ce, id);
  }
View Full Code Here

  /**
   * add a detached uninitialized collection
   */
  @Override
  public void addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection collection) {
    CollectionEntry ce = new CollectionEntry( persister, collection.getKey() );
    addCollection( collection, ce, collection.getKey() );
  }
View Full Code Here

   *
   * @param collection The collection for which we are adding an entry.
   * @param persister The collection persister
   */
  private void addCollection(PersistentCollection collection, CollectionPersister persister) {
    CollectionEntry ce = new CollectionEntry( persister, collection );
    collectionEntries.put( collection, ce );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.engine.spi.CollectionEntry

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.