Examples of PersistentCollection


Examples of org.hibernate.collection.PersistentCollection

  throws HibernateException {

    if ( collection!=null && (collection instanceof PersistentCollection) ) {

      final SessionImplementor session = getSession();
      PersistentCollection coll = (PersistentCollection) collection;
      if ( coll.setCurrentSession(session) ) {
        reattachCollection( coll, collectionType );
      }
      return null;

    }
View Full Code Here

Examples of org.hibernate.collection.PersistentCollection

      //TODO: move into collection type, so we can use polymorphism!
      if ( collectionType.hasHolder( session.getEntityMode() ) ) {
       
        if (collection==CollectionType.UNFETCHED_COLLECTION) return null;

        PersistentCollection ah = persistenceContext.getCollectionHolder(collection);
        if (ah==null) {
          ah = collectionType.wrap(session, collection);
          persistenceContext.addNewCollection( persister, ah );
          persistenceContext.addCollectionHolder(ah);
        }
        return null;
      }
      else {

        PersistentCollection persistentCollection = collectionType.wrap(session, collection);
        persistenceContext.addNewCollection( persister, persistentCollection );

        if ( log.isTraceEnabled() ) log.trace( "Wrapped collection in role: " + collectionType.getRole() );

        return persistentCollection; //Force a substitution!
View Full Code Here

Examples of org.hibernate.collection.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, session.getEntityMode() );
    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

Examples of org.hibernate.collection.PersistentCollection

   * 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

Examples of org.hibernate.collection.PersistentCollection

      count = ois.readInt();
      log.trace( "staring 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();
      log.trace( "staring deserialization of [" + count + "] arrayHolders entries" );
View Full Code Here

Examples of org.hibernate.collection.PersistentCollection

    if ( isUpdate ) {
      removeCollection( persister, extractCollectionKeyFromOwner( persister ), session );
    }
    if ( collection != null && ( collection instanceof PersistentCollection ) ) {
      PersistentCollection wrapper = ( PersistentCollection ) collection;
      wrapper.setCurrentSession( session );
      if ( wrapper.wasInitialized() ) {
        session.getPersistenceContext().addNewCollection( persister, wrapper );
      }
      else {
        reattachCollection( wrapper, type );
      }
View Full Code Here

Examples of org.hibernate.collection.PersistentCollection

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

Examples of org.hibernate.collection.PersistentCollection

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

Examples of org.hibernate.collection.PersistentCollection

    if (entityMode==EntityMode.DOM4J && !isEmbeddedInXML) {
      return UNFETCHED_COLLECTION;
    }
   
    // check if collection is currently being loaded
    PersistentCollection collection = persistenceContext.getLoadContexts().locateLoadingCollection( persister, key );
   
    if ( collection == null ) {
     
      // check if it is already completely loaded, but unowned
      collection = persistenceContext.useUnownedCollection( new CollectionKey(persister, key, entityMode) );
     
      if ( collection == null ) {
        // create a new collection wrapper, to be initialized later
        collection = instantiate( session, persister, key );
        collection.setOwner(owner);
 
        persistenceContext.addUninitializedCollection( persister, collection, key );
 
        // some collections are not lazy:
        if ( initializeImmediately( entityMode ) ) {
          session.initializeCollection( collection, false );
        }
        else if ( !persister.isLazy() ) {
          persistenceContext.addNonLazyCollection( collection );
        }
 
        if ( hasHolder( entityMode ) ) {
          session.getPersistenceContext().addCollectionHolder( collection );
        }
       
      }
     
    }
   
    collection.setOwner(owner);

    return collection.getValue();
  }
View Full Code Here

Examples of org.hibernate.collection.PersistentCollection

    if (entityMode==EntityMode.DOM4J && !isEmbeddedInXML) {
      return UNFETCHED_COLLECTION;
    }
   
    // check if collection is currently being loaded
    PersistentCollection collection = persistenceContext.getLoadContexts().locateLoadingCollection( persister, key );
   
    if ( collection == null ) {
     
      // check if it is already completely loaded, but unowned
      collection = persistenceContext.useUnownedCollection( new CollectionKey(persister, key, entityMode) );
     
      if ( collection == null ) {
        // create a new collection wrapper, to be initialized later
        collection = instantiate( session, persister, key );
        collection.setOwner(owner);
 
        persistenceContext.addUninitializedCollection( persister, collection, key );
 
        // some collections are not lazy:
        if ( initializeImmediately( entityMode ) ) {
          session.initializeCollection( collection, false );
        }
        else if ( !persister.isLazy() ) {
          persistenceContext.addNonLazyCollection( collection );
        }
 
        if ( hasHolder( entityMode ) ) {
          session.getPersistenceContext().addCollectionHolder( collection );
        }
       
      }
     
    }
   
    collection.setOwner(owner);

    return collection.getValue();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.