Package org.hibernate.engine

Examples of org.hibernate.engine.CollectionEntry


    PersistentCollection collection = (PersistentCollection) pc;
    if ( collection.unsetSession( getSession() ) ) evictCollection(collection);
  }

  private void evictCollection(PersistentCollection collection) {
    CollectionEntry ce = (CollectionEntry) getSession().getPersistenceContext().getCollectionEntries().remove(collection);
    if ( log.isDebugEnabled() )
      log.debug(
          "evicting collection: " +
          MessageHelper.collectionInfoString( ce.getLoadedPersister(), ce.getLoadedKey(), getSession().getFactory() )
      );
    if ( ce.getLoadedPersister() != null && ce.getLoadedKey() != null ) {
      //TODO: is this 100% correct?
      getSession().getPersistenceContext().getCollectionsByKey().remove(
          new CollectionKey( ce.getLoadedPersister(), ce.getLoadedKey(), getSession().getEntityMode() )
      );
    }
  }
View Full Code Here


      if ( cachedSize!=-1 && !hasQueuedOperations() ) {
        return true;
      }
      else {
        throwLazyInitializationExceptionIfNotConnected();
        CollectionEntry entry = session.getPersistenceContext().getCollectionEntry(this);
        CollectionPersister persister = entry.getLoadedPersister();
        if ( persister.isExtraLazy() ) {
          if ( hasQueuedOperations() ) {
            session.flush();
          }
          cachedSize = persister.getSize( entry.getLoadedKey(), session );
          return true;
        }
      }
    }
    read();
View Full Code Here

    List list = IdentityMap.entries( session.getPersistenceContext().getCollectionEntries() );
    int size = list.size();
    for ( int i = 0; i < size; i++ ) {
      Map.Entry me = ( Map.Entry ) list.get( i );
      CollectionEntry ce = (CollectionEntry) me.getValue();
      if ( !ce.isReached() && !ce.isIgnore() ) {
        Collections.processUnreachableCollection( (PersistentCollection) me.getKey(), session );
      }
    }

    // Schedule updates to collections:

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

    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(
            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
              )
          );
      }
View Full Code Here

  }
 
  protected Boolean readIndexExistence(Object index) {
    if (!initialized) {
      throwLazyInitializationExceptionIfNotConnected();
      CollectionEntry entry = session.getPersistenceContext().getCollectionEntry(this);
      CollectionPersister persister = entry.getLoadedPersister();
      if ( persister.isExtraLazy() ) {
        if ( hasQueuedOperations() ) {
          session.flush();
        }
        return new Boolean( persister.indexExists( entry.getLoadedKey(), index, session ) );
      }
    }
    read();
    return null;
   
View Full Code Here

  }
 
  protected Boolean readElementExistence(Object element) {
    if (!initialized) {
      throwLazyInitializationExceptionIfNotConnected();
      CollectionEntry entry = session.getPersistenceContext().getCollectionEntry(this);
      CollectionPersister persister = entry.getLoadedPersister();
      if ( persister.isExtraLazy() ) {
        if ( hasQueuedOperations() ) {
          session.flush();
        }
        return new Boolean( persister.elementExists( entry.getLoadedKey(), element, session ) );
      }
    }
    read();
    return null;
   
View Full Code Here

  protected static final Object UNKNOWN = new MarkerObject("UNKNOWN");
 
  protected Object readElementByIndex(Object index) {
    if (!initialized) {
      throwLazyInitializationExceptionIfNotConnected();
      CollectionEntry entry = session.getPersistenceContext().getCollectionEntry(this);
      CollectionPersister persister = entry.getLoadedPersister();
      if ( persister.isExtraLazy() ) {
        if ( hasQueuedOperations() ) {
          session.flush();
        }
        return persister.getElementByIndex( entry.getLoadedKey(), index, session, owner );
      }
    }
    read();
    return UNKNOWN;
   
View Full Code Here

  /**
   * Is this the "inverse" end of a bidirectional association?
   */
  private boolean isInverseCollection() {
    CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(this);
    return ce != null && ce.getLoadedPersister().isInverse();
  }
View Full Code Here

  /**
   * Is this the "inverse" end of a bidirectional association with
   * no orphan delete enabled?
   */
  private boolean isInverseCollectionNoOrphanDelete() {
    CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(this);
    return ce != null &&
        ce.getLoadedPersister().isInverse() &&
        !ce.getLoadedPersister().hasOrphanDelete();
  }
View Full Code Here

  /**
   * Is this the "inverse" end of a bidirectional one-to-many, or
   * of a collection with no orphan delete?
   */
  private boolean isInverseOneToManyOrNoOrphanDelete() {
    CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(this);
    return ce != null && ce.getLoadedPersister().isInverse() && (
        ce.getLoadedPersister().isOneToMany() ||
        !ce.getLoadedPersister().hasOrphanDelete()
      );
  }
View Full Code Here

        .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(),
            session.getEntityMode()
          );
        persistenceContext.getCollectionsByKey()
            .put(collectionKey, persistentCollection);
      }
View Full Code Here

TOP

Related Classes of org.hibernate.engine.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.