@@ -151,7 +151,13 @@ public Object insert(String entityName, Object entity) {
151151}
152152persister .setIdentifier ( entity , id , this );
153153forEachOwnedCollection ( entity , id , persister ,
154- (descriptor , collection ) -> descriptor .recreate ( collection , id , this ) );
154+ (descriptor , collection ) -> {
155+ descriptor .recreate ( collection , id , this );
156+ final StatisticsImplementor statistics = getFactory ().getStatistics ();
157+ if ( statistics .isStatisticsEnabled () ) {
158+ statistics .recreateCollection ( descriptor .getRole () );
159+ }
160+ } );
155161firePostInsert (entity , id , state , persister );
156162final StatisticsImplementor statistics = getFactory ().getStatistics ();
157163if ( statistics .isStatisticsEnabled () ) {
@@ -178,7 +184,13 @@ public void delete(String entityName, Object entity) {
178184getInterceptor ()
179185.onDelete ( entity , id , persister .getPropertyNames (), persister .getPropertyTypes () );
180186forEachOwnedCollection ( entity , id , persister ,
181- (descriptor , collection ) -> descriptor .remove (id , this ) );
187+ (descriptor , collection ) -> {
188+ descriptor .remove ( id , this );
189+ final StatisticsImplementor statistics = getFactory ().getStatistics ();
190+ if ( statistics .isStatisticsEnabled () ) {
191+ statistics .removeCollection ( descriptor .getRole () );
192+ }
193+ } );
182194persister .getDeleteCoordinator ().delete ( entity , id , version , this );
183195firePostDelete (entity , id , persister );
184196final StatisticsImplementor statistics = getFactory ().getStatistics ();
@@ -223,11 +235,16 @@ public void update(String entityName, Object entity) {
223235getInterceptor ()
224236.onUpdate ( entity , id , state , persister .getPropertyNames (), persister .getPropertyTypes () );
225237persister .getUpdateCoordinator ().update ( entity , id , null , state , oldVersion , null , null , false , this );
226- // TODO: can we do better here?
227- forEachOwnedCollection ( entity , id , persister ,
228- (descriptor , collection ) -> descriptor .remove (id , this ) );
229238forEachOwnedCollection ( entity , id , persister ,
230- (descriptor , collection ) -> descriptor .recreate ( collection , id , this ) );
239+ (descriptor , collection ) -> {
240+ // TODO: can we do better here?
241+ descriptor .remove ( id , this );
242+ descriptor .recreate ( collection , id , this );
243+ final StatisticsImplementor statistics = getFactory ().getStatistics ();
244+ if ( statistics .isStatisticsEnabled () ) {
245+ statistics .updateCollection ( descriptor .getRole () );
246+ }
247+ } );
231248firePostUpdate (entity , id , state , persister );
232249final StatisticsImplementor statistics = getFactory ().getStatistics ();
233250if ( statistics .isStatisticsEnabled () ) {
@@ -247,11 +264,17 @@ public void upsert(String entityName, Object entity) {
247264.onUpsert ( entity , id , state , persister .getPropertyNames (), persister .getPropertyTypes () );
248265final Object oldVersion = versionToUpsert ( entity , persister , state );
249266persister .getMergeCoordinator ().update ( entity , id , null , state , oldVersion , null , null , false , this );
250- // TODO: can we do better here?
251- forEachOwnedCollection ( entity , id , persister ,
252- (descriptor , collection ) -> descriptor .remove (id , this ) );
267+ // TODO: statistics for upsert!
253268forEachOwnedCollection ( entity , id , persister ,
254- (descriptor , collection ) -> descriptor .recreate ( collection , id , this ) );
269+ (descriptor , collection ) -> {
270+ // TODO: can we do better here?
271+ descriptor .remove ( id , this );
272+ descriptor .recreate ( collection , id , this );
273+ final StatisticsImplementor statistics = getFactory ().getStatistics ();
274+ if ( statistics .isStatisticsEnabled () ) {
275+ statistics .updateCollection ( descriptor .getRole () );
276+ }
277+ } );
255278firePostUpsert (entity , id , state , persister );
256279}
257280}
@@ -562,11 +585,10 @@ public void initializeCollection(PersistentCollection<?> collection, boolean wri
562585if ( LOG .isTraceEnabled () ) {
563586LOG .trace ( "Collection initialized" );
564587}
565- //TODO: statistics!
566- // final StatisticsImplementor statistics = getFactory().getStatistics();
567- // if ( statistics.isStatisticsEnabled() ) {
568- // statistics.fetchCollection( loadedPersister.getRole() );
569- // }
588+ final StatisticsImplementor statistics = getFactory ().getStatistics ();
589+ if ( statistics .isStatisticsEnabled () ) {
590+ statistics .fetchCollection ( loadedPersister .getRole () );
591+ }
570592}
571593}
572594
@@ -710,6 +732,7 @@ else if ( isPersistentAttributeInterceptable( association ) ) {
710732proxyInterceptor .setSession ( this );
711733try {
712734proxyInterceptor .forceInitialize ( association , null );
735+ // TODO: statistics?? call statistics.fetchEntity()
713736}
714737finally {
715738proxyInterceptor .unsetSession ();
@@ -731,6 +754,10 @@ else if ( association instanceof PersistentCollection ) {
731754collectionDescriptor .initialize ( key , this );
732755handlePotentiallyEmptyCollection ( persistentCollection , getPersistenceContextInternal (), key ,
733756collectionDescriptor );
757+ final StatisticsImplementor statistics = getFactory ().getStatistics ();
758+ if ( statistics .isStatisticsEnabled () ) {
759+ statistics .fetchCollection ( collectionDescriptor .getRole () );
760+ }
734761}
735762finally {
736763persistentCollection .unsetSession ( this );
0 commit comments