@Override public final boolean setCurrentSession(SharedSessionContractImplementor session) throws HibernateException { if ( session == this.session ) { return false; } else if ( this.session != null ) { final String msg = generateUnexpectedSessionStateMessage( session ); if ( isConnectedToSession() ) { throw new HibernateException( "Illegal attempt to associate a collection with two open sessions. " + msg ); } else { LOG.logUnexpectedSessionInCollectionNotConnected( msg ); } } if ( hasQueuedOperations() ) { LOG.queuedOperationWhenAttachToSession( MessageHelper.collectionInfoString( getRole(), getKey() ) ); } this.session = session; return true; }
@Override public boolean endRead() { //override on some subclasses return afterInitialize(); }
@Override @SuppressWarnings("unchecked") public void beginRead() { super.beginRead(); tempList = new ArrayList(); }
/** * Called by any writer method of the collection interface */ protected final void write() { initialize( true ); dirty(); }
/** * Is this collection in a state that would allow us to * "queue" clear? This is a special case, because of orphan * delete. */ @SuppressWarnings({"JavaDoc"}) protected boolean isClearQueueEnabled() { return !initialized && isConnectedToSession() && isInverseCollectionNoOrphanDelete(); }
@Override public void postAction() { clearOperationQueue(); cachedSize = -1; clearDirty(); }
assertEquals( role, maniesEEOneStateOrig.getRole() ); assertEquals( one.getId(), maniesEEOneStateOrig.getKey() ); assertSame( s, maniesEEOneStateOrig.getSession() ); assertNull( maniesEEOneStateOrig.getKey() ); assertNull( maniesEEOneStateOrig.getRole() ); assertNull( maniesEEOneStateOrig.getSession() ); s.getTransaction().commit(); s.close();
/** * Called by the {@link Collection#size} method */ @SuppressWarnings( {"JavaDoc"}) 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; }
@Override public final boolean unsetSession(SharedSessionContractImplementor currentSession) { prepareForPossibleLoadingOutsideTransaction(); if ( currentSession == this.session ) { if ( !isTempSession ) { if ( hasQueuedOperations() ) { final String collectionInfoString = MessageHelper.collectionInfoString( getRole(), getKey() ); try { final TransactionStatus transactionStatus = LOG.logCannotUnsetUnexpectedSessionInCollection( generateUnexpectedSessionStateMessage( currentSession ) );
@Override public Boolean doWork() { final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); final CollectionPersister persister = entry.getLoadedPersister(); if ( persister.isExtraLazy() ) { if ( hasQueuedOperations() ) { session.flush(); } return persister.indexExists( entry.getLoadedKey(), index, session ); } else { read(); } return null; } }
@Override public boolean afterInitialize() { setInitialized(); //do this bit after setting initialized to true or it will recurse if ( hasQueuedOperations() ) { performQueuedOperations(); cachedSize = -1; return false; } else { return true; } }
@Override @SuppressWarnings({"unchecked"}) public final Collection getQueuedOrphans(String entityName) { if ( hasQueuedOperations() ) { final Collection additions = new ArrayList( operationQueue.size() ); final Collection removals = new ArrayList( operationQueue.size() ); for ( DelayedOperation operation : operationQueue ) { additions.add( operation.getAddedInstance() ); removals.add( operation.getOrphan() ); } return getOrphans( removals, additions, entityName, session ); } else { return Collections.EMPTY_LIST; } }
private void throwLazyInitializationExceptionIfNotConnected() { if ( !isConnectedToSession() ) { throwLazyInitializationException( "no session or session was closed" ); } if ( !session.isConnected() ) { throwLazyInitializationException( "session is disconnected" ); } }
/** * Is this collection in a state that would allow us to * "queue" operations? */ @SuppressWarnings({"JavaDoc"}) protected boolean isOperationQueueEnabled() { return !initialized && isConnectedToSession() && isInverseCollection(); }
/** * Is this collection in a state that would allow us to * "queue" puts? This is a special case, because of orphan * delete. */ @SuppressWarnings({"JavaDoc"}) protected boolean isPutQueueEnabled() { return !initialized && isConnectedToSession() && isInverseOneToManyOrNoOrphanDelete(); }
@Override public final Iterator queuedAdditionIterator() { if ( hasQueuedOperations() ) { return new Iterator() { private int index; @Override public Object next() { return operationQueue.get( index++ ).getAddedInstance(); } @Override public boolean hasNext() { return index < operationQueue.size(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } else { return Collections.emptyIterator(); } }
tempSession = openTemporarySessionForLoading(); throwLazyInitializationException( "could not initialize proxy - no Session" ); tempSession = openTemporarySessionForLoading(); throwLazyInitializationException( "could not initialize proxy - the owning Session was closed" ); tempSession = openTemporarySessionForLoading(); throwLazyInitializationException( "could not initialize proxy - the owning Session is disconnected" ); session.getFactory().getCollectionPersister( getRole() ), this );
public void postInitialize(PersistentCollection collection) throws HibernateException { snapshot = getLoadedPersister().isMutable() ? collection.getSnapshot( getLoadedPersister() ) : null; collection.setSnapshot(loadedKey, role, snapshot); if ( getLoadedPersister().getBatchSize() > 1 ) { ( (AbstractPersistentCollection) collection ).getSession() .getPersistenceContext() .getBatchFetchQueue() .removeBatchLoadableCollection( this ); } }
protected boolean readSize() { if ( !initialized ) { if ( cachedSize != -1 && !hasQueuedOperations() ) { return true; final boolean isExtraLazy = withTemporarySessionIfNeeded( new LazyInitializationWork<Boolean>() { @Override
/** * Called by any read-only method of the collection interface */ protected final void read() { initialize( false ); }