LOG.trace( "Deserializing persistence-context" ); final StatefulPersistenceContext rtn = new StatefulPersistenceContext( session ); SessionFactoryImplementor sfi = session.getFactory();
@Override public void addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id) { final CollectionEntry ce = new CollectionEntry( collection, persister, id, flushing ); addCollection( collection, ce, id ); if ( persister.getBatchSize() > 1 ) { getBatchFetchQueue().addBatchLoadableCollection( collection, ce ); } }
@Override public void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Serializable generatedId) { final Object entity = entitiesByKey.remove( oldKey ); final EntityEntry oldEntry = entityEntryContext.removeEntityEntry( entity ); parentsByChild.clear(); final EntityKey newKey = session.generateEntityKey( generatedId, oldEntry.getPersister() ); addEntity( newKey, entity ); addEntry( entity, oldEntry.getStatus(), oldEntry.getLoadedState(), oldEntry.getRowId(), generatedId, oldEntry.getVersion(), oldEntry.getLockMode(), oldEntry.isExistsInDatabase(), oldEntry.getPersister(), oldEntry.isBeingReplicated() ); }
@Override public String getEntityName(Object object) { checkOpen(); // checkTransactionSynchStatus(); if ( object instanceof HibernateProxy ) { if ( !persistenceContext.containsProxy( object ) ) { throw new TransientObjectException( "proxy was not associated with the session" ); } object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation(); } EntityEntry entry = persistenceContext.getEntry( object ); if ( entry == null ) { throwTransientObjectException( object ); } return entry.getPersister().getEntityName(); }
private void replacePersistenceContext(StatefulPersistenceContext persistenceContextNew) { if ( persistenceContextNew.getSession() != null ) { throw new IllegalStateException( "new persistence context is already connected to a session " ); } persistenceContext.clear(); ObjectInputStream ois = null; try { ois = new ObjectInputStream( new ByteArrayInputStream( serializePersistenceContext( persistenceContextNew ) ) ); this.persistenceContext = StatefulPersistenceContext.deserialize( ois, this ); } catch (IOException ex) { throw new SerializationException( "could not deserialize the persistence context", ex ); } catch (ClassNotFoundException ex) { throw new SerializationException( "could not deserialize the persistence context", ex ); } finally { try { if (ois != null) ois.close(); } catch (IOException ignore) { } } }
@Override public void addNewCollection(CollectionPersister persister, PersistentCollection collection) throws HibernateException { addCollection( collection, persister ); }
/** * clear all the internal collections, just * to help the garbage collector, does not * clear anything that is needed during the * afterTransactionCompletion() phase */ @Override protected void cleanupOnClose() { persistenceContext.clear(); }
persistenceContext = StatefulPersistenceContext.deserialize( ois, this ); actionQueue = ActionQueue.deserialize( ois, this );
@Override public void afterTransactionCompletion() { cleanUpInsertedKeysAfterTransaction(); entityEntryContext.downgradeLocks(); // // Downgrade locks // for ( EntityEntry o : entityEntries.values() ) { // o.setLockMode( LockMode.NONE ); // } }
@Override public void initializeNonLazyCollections() throws HibernateException { if ( loadCounter == 0 ) { if ( TRACE_ENABLED ) { LOG.trace( "Initializing non-lazy collections" ); } //do this work only at the very highest level of the load //don't let this method be called recursively loadCounter++; try { int size; while ( ( size = nonlazyCollections.size() ) > 0 ) { //note that each iteration of the loop may add new elements nonlazyCollections.remove( size - 1 ).forceInitialization(); } } finally { loadCounter--; clearNullProperties(); } } }
@Override public void afterTransactionCompletion(boolean successful, boolean delayed) { log.tracef( "SessionImpl#afterTransactionCompletion(successful=%s, delayed=%s)", successful, delayed ); if ( !isClosed() || waitingForAutoClose ) { if ( autoClear ||!successful ) { internalClear(); } } persistenceContext.afterTransactionCompletion(); actionQueue.afterTransactionCompletion( successful ); getEventListenerManager().transactionCompletion( successful ); if ( getFactory().getStatistics().isStatisticsEnabled() ) { getFactory().getStatistics().endTransaction( successful ); } try { getInterceptor().afterTransactionCompletion( getCurrentTransaction() ); } catch (Throwable t) { log.exceptionInAfterTransactionCompletionInterceptor( t ); } if ( !delayed ) { if ( shouldAutoClose() && (!isClosed() || waitingForAutoClose) ) { managedClose(); } } super.afterTransactionCompletion( successful, delayed ); }
private void replacePersistenceContext(StatefulPersistenceContext persistenceContextNew) { if ( persistenceContextNew.getSession() != null ) { throw new IllegalStateException( "new persistence context is already connected to a session " ); } persistenceContext.clear(); ObjectInputStream ois = null; try { ois = new ObjectInputStream( new ByteArrayInputStream( serializePersistenceContext( persistenceContextNew ) ) ); this.persistenceContext = StatefulPersistenceContext.deserialize( ois, this ); } catch (IOException ex) { throw new SerializationException( "could not deserialize the persistence context", ex ); } catch (ClassNotFoundException ex) { throw new SerializationException( "could not deserialize the persistence context", ex ); } finally { try { if (ois != null) ois.close(); } catch (IOException ignore) { } } }
@Override public void addInitializedDetachedCollection(CollectionPersister collectionPersister, PersistentCollection collection) throws HibernateException { if ( collection.isUnreferenced() ) { //treat it just like a new collection addCollection( collection, collectionPersister ); } else { final CollectionEntry ce = new CollectionEntry( collection, session.getFactory() ); addCollection( collection, ce, collection.getKey() ); } }
@Override public String getEntityName(Object object) { checkOpen(); // checkTransactionSynchStatus(); if ( object instanceof HibernateProxy ) { if ( !persistenceContext.containsProxy( object ) ) { throw new TransientObjectException( "proxy was not associated with the session" ); } object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation(); } EntityEntry entry = persistenceContext.getEntry( object ); if ( entry == null ) { throwTransientObjectException( object ); } return entry.getDescriptor().getEntityName(); }
private void internalClear() { persistenceContext.clear(); actionQueue.clear(); final ClearEvent event = new ClearEvent( this ); for ( ClearEventListener listener : listeners( EventType.CLEAR ) ) { listener.onClear( event ); } }
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { LOG.trace( "Deserializing NonFlushedChangesImpl" ); ois.defaultReadObject(); persistenceContext = StatefulPersistenceContext.deserialize( ois, null ); actionQueue = ActionQueue.deserialize( ois, null ); }
@Override public void afterTransactionCompletion() { cleanUpInsertedKeysAfterTransaction(); // Downgrade locks for ( EntityEntry o : entityEntries.values() ) { o.setLockMode( LockMode.NONE ); } }
/** * Force initialization of all non-lazy collections encountered during * the current two-phase load (actually, this is a no-op, unless this * is the "outermost" load) */ @Override public void initializeNonLazyCollections() throws HibernateException { if ( loadCounter == 0 ) { LOG.debug( "Initializing non-lazy collections" ); //do this work only at the very highest level of the load loadCounter++; //don't let this method be called recursively try { int size; while ( ( size = nonlazyCollections.size() ) > 0 ) { //note that each iteration of the loop may add new elements nonlazyCollections.remove( size - 1 ).forceInitialization(); } } finally { loadCounter--; clearNullProperties(); } } }
@Override public void afterTransactionCompletion(TransactionImplementor hibernateTransaction, boolean successful) { LOG.trace( "after transaction completion" ); persistenceContext.afterTransactionCompletion(); actionQueue.afterTransactionCompletion( successful ); if ( hibernateTransaction != null ) { try { interceptor.afterTransactionCompletion( hibernateTransaction ); } catch (Throwable t) { LOG.exceptionInAfterTransactionCompletionInterceptor( t ); } } if ( autoClear ) { clear(); } }