Package org.hibernate.engine

Examples of org.hibernate.engine.CollectionEntry


    if (session==this.session) {
      return false;
    }
    else {
      if ( isConnectedToSession() ) {
        CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(this);
        if (ce==null) {
          throw new HibernateException(
              "Illegal attempt to associate a collection with two open sessions"
            );
        }
        else {
          throw new HibernateException(
              "Illegal attempt to associate a collection with two open sessions: " +
              MessageHelper.collectionInfoString(
                  ce.getLoadedPersister(),
                  ce.getLoadedKey(),
                  session.getFactory()
                )
            );
        }
      }
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( em ) ) {
      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

    if ( persister.getCollectionType().hasHolder( em ) ) {
      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

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

  }
 
  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

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.