Package org.hibernate.collection

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


  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

  }

  public void execute() throws HibernateException {
    // this method is called when a new non-null collection is persisted
    // or when an existing (non-null) collection is moved to a new owner
    final PersistentCollection collection = getCollection();
   
    preRecreate();

    getPersister().recreate( collection, getKey(), getSession() );
   
View Full Code Here

          //    with the current Session
          //throw new AssertionFailure("bug loading unowned collection");
        }
      }

      PersistentCollection rowCollection = persistenceContext.getLoadContexts()
          .getCollectionLoadContext( rs )
          .getLoadingCollection( persister, collectionRowKey );

      if ( rowCollection != null ) {
        rowCollection.readFrom( rs, persister, descriptor, owner );
      }

    }
    else if ( optionalKey != null ) {
      // we did not find a collection element in the result set, so we
View Full Code Here

    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

    Iterator iter = context.getCollectionEntries().entrySet().iterator(); //TODO: calling entrySet on an IdentityMap is SLOW!!
    while ( iter.hasNext() ) {
      Map.Entry me = (Map.Entry) iter.next();

      CollectionEntry ce = (CollectionEntry) me.getValue();
      PersistentCollection collection = (PersistentCollection) me.getKey();
      if ( !collection.wasInitialized() && ce.getLoadedPersister() == collectionPersister ) {

        if ( checkForEnd && i == end ) {
          return keys; //the first key found after the given key
        }
View Full Code Here

  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

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

   * 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.trace(
            "initializing collection " +
            MessageHelper.collectionInfoString( ce.getLoadedPersister(), ce.getLoadedKey(), source.getFactory() )
          );
View Full Code Here

    EventSource session = getSession();
    CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() );

    final Serializable collectionKey = extractCollectionKeyFromOwner( persister );
    if ( collection!=null && (collection instanceof PersistentCollection) ) {
      PersistentCollection wrapper = (PersistentCollection) collection;
      if ( wrapper.setCurrentSession(session) ) {
        //a "detached" collection!
        if ( !isOwnerUnchanged( wrapper, persister, collectionKey ) ) {
          // if the collection belonged to a different entity,
          // clean up the existing state of the collection
          removeCollection( persister, collectionKey, session );
View Full Code Here

TOP

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