Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.CollectionEntry


        .clearSubselects(); //the database has changed now, so the subselect results need to be invalidated

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


   * @param collection The persistent collection
   * @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
   */
  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)
   */
  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
   */
  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

    if ( collection.isUnreferenced() ) {
      //treat it just like a new collection
      addCollection( collection, collectionPersister );
    }
    else {
      CollectionEntry ce = new CollectionEntry( collection, session.getFactory() );
      addCollection( collection, ce, collection.getKey() );
    }
  }
View Full Code Here

  /**
   * add a collection we just pulled out of the cache (does not need initializing)
   */
  public CollectionEntry addInitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id)
  throws HibernateException {
    CollectionEntry ce = new CollectionEntry(collection, persister, id, flushing);
    ce.postInitialize(collection);
    addCollection(collection, ce, id);
    return ce;
  }
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();
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

   */
  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 ?
          CollectionHelper.EMPTY_COLLECTION :
          ce.getOrphans(entityName, pc);
    }
    else {
      orphans = pc.getQueuedOrphans(entityName);
    }

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.