/** * Get the pre-flush identifier of the collection */ public Serializable getLoadedCollectionKey(PersistentCollection coll) { return getCollectionEntry(coll).getLoadedKey(); }
/** * Get the snapshot of the pre-flush collection state */ public Serializable getSnapshot(PersistentCollection coll) { return getCollectionEntry(coll).getSnapshot(); }
/** * Is this the "inverse" end of a bidirectional association? */ public boolean isInverseCollection(PersistentCollection collection) { CollectionEntry ce = getCollectionEntry(collection); return ce != null && ce.getLoadedPersister().isInverse(); }
/** * Delete any entities that were removed from the collection */ private static void deleteOrphans(String entityName, PersistentCollection pc, SessionImplementor session) throws HibernateException { if ( pc.wasInitialized() ) { //can't be any orphans if it was not initialized! CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(pc); if (ce!=null) { Iterator orphanIter = ce.getOrphans(entityName, pc).iterator(); while ( orphanIter.hasNext() ) { Object orphan = orphanIter.next(); if (orphan!=null) { if ( log.isTraceEnabled() ) log.trace("deleting orphaned: " + entityName); session.delete(entityName, orphan, false); } } } } }
/** * Is this the "inverse" end of a bidirectional association? */ private boolean isInverseCollection() { CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(this); return ce != null && ce.getLoadedPersister().isInverse(); }
/** * Delete any entities that were removed from the collection */ 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); } final Iterator orphanIter = orphans.iterator(); while ( orphanIter.hasNext() ) { Object orphan = orphanIter.next(); if (orphan!=null) { if ( log.isTraceEnabled() ) { log.trace("deleting orphaned entity instance: " + entityName); } eventSource.delete( entityName, orphan, false, null ); } } }
/** * 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; } } } } return (coll == null) ? null : getCollectionEntry(coll); }
/** * 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(); }
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; }
/** * 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() ); }
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; }
private static void processNeverReferencedCollection(PersistentCollection coll, SessionImplementor session) throws HibernateException { final PersistenceContext persistenceContext = session.getPersistenceContext(); CollectionEntry entry = persistenceContext.getCollectionEntry(coll); log.debug( "Found collection with unloaded owner: " + MessageHelper.collectionInfoString( entry.getLoadedPersister(), entry.getLoadedKey(), session.getFactory() ) ); entry.setCurrentPersister( entry.getLoadedPersister() ); entry.setCurrentKey( entry.getLoadedKey() ); prepareCollectionForUpdate( coll, entry, session.getEntityMode(), session.getFactory() ); }
Object processCollection(Object collection, CollectionType type) throws HibernateException { if (collection!=null) { SessionImplementor session = getSession(); final PersistentCollection coll; if ( type.isArrayType() ) { coll = session.getPersistenceContext().getCollectionHolder(collection); // if no array holder we found an unwrappered array (this can't occur, // because we now always call wrap() before getting to here) // return (ah==null) ? true : searchForDirtyCollections(ah, type); } else { // if not wrappered yet, its dirty (this can't occur, because // we now always call wrap() before getting to here) // return ( ! (obj instanceof PersistentCollection) ) ? //true : searchForDirtyCollections( (PersistentCollection) obj, type ); coll = (PersistentCollection) collection; } if ( session.getPersistenceContext().getCollectionEntry(coll).isInitializedAndDirty() ) { dirty=true; return null; //NOTE: EARLY EXIT! } } return null; }
private static void processNeverReferencedCollection(PersistentCollection coll, SessionImplementor session) throws HibernateException { final PersistenceContext persistenceContext = session.getPersistenceContext(); CollectionEntry entry = persistenceContext.getCollectionEntry(coll); log.debug( "Found collection with unloaded owner: " + MessageHelper.collectionInfoString( entry.getLoadedPersister(), entry.getLoadedKey(), session.getFactory() ) ); entry.setCurrentPersister( entry.getLoadedPersister() ); entry.setCurrentKey( entry.getLoadedKey() ); prepareCollectionForUpdate( coll, entry, session.getEntityMode(), session.getFactory() ); }
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; }
SessionImplementor source = event.getSession(); CollectionEntry ce = source.getPersistenceContext().getCollectionEntry(collection); if (ce==null) throw new HibernateException("collection was evicted"); if ( !ce.isInitialized() ) {
/** * Called by the <tt>size()</tt> method */ protected boolean readSize() { if (!initialized) { 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(); return false; }
CollectionEntry ce = context.getCollectionEntry(lce.collection); if ( ce==null ) { ce = context.addInitializedCollection(lce.collection, persister, lce.key, em);
public void execute() throws HibernateException { final PersistentCollection collection = getCollection(); getPersister().recreate( collection, getKey(), getSession() ); getSession().getPersistenceContext() .getCollectionEntry(collection) .afterAction(collection); evict(); if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) { getSession().getFactory().getStatisticsImplementor() .recreateCollection( getPersister().getRole() ); } }
public void execute() throws HibernateException { if ( !emptySnapshot ) getPersister().remove( getKey(), getSession() ); final PersistentCollection collection = getCollection(); if (collection!=null) { getSession().getPersistenceContext() .getCollectionEntry(collection) .afterAction(collection); } evict(); if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) { getSession().getFactory().getStatisticsImplementor() .removeCollection( getPersister().getRole() ); } }