/
PersistenceContext.java
808 lines (711 loc) · 26.2 KB
/
PersistenceContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.engine.spi;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.internal.util.MarkerObject;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.sql.results.spi.LoadContexts;
/**
* Represents the state of "stuff" Hibernate is tracking, including (not exhaustive):
* <ul>
* <li>entities</li>
* <li>collections</li>
* <li>snapshots</li>
* <li>proxies</li>
* </ul>
* <p/>
* Often referred to as the "first level cache".
*
* @author Gavin King
* @author Steve Ebersole
*/
@SuppressWarnings( {"JavaDoc"})
public interface PersistenceContext {
/**
* Marker object used to indicate (via reference checking) that no row was returned.
*/
Object NO_ROW = new MarkerObject( "NO_ROW" );
@SuppressWarnings( {"UnusedDeclaration"})
boolean isStateless();
/**
* Get the session to which this persistence context is bound.
*
* @return The session.
*/
SharedSessionContractImplementor getSession();
/**
* Retrieve this persistence context's managed load context.
*
* @return The load context
*/
LoadContexts getLoadContexts();
/**
* Add a collection which has no owner loaded
*
* @param key The collection key under which to add the collection
* @param collection The collection to add
*/
void addUnownedCollection(CollectionKey key, PersistentCollection collection);
/**
* Take ownership of a previously unowned collection, if one. This method returns {@code null} if no such
* collection was previously added () or was previously removed.
* <p/>
* This should indicate the owner is being loaded and we are ready to "link" them.
*
* @param key The collection key for which to locate a collection collection
*
* @return The unowned collection, or {@code null}
*/
PersistentCollection useUnownedCollection(CollectionKey key);
/**
* Get the {@link BatchFetchQueue}, instantiating one if necessary.
*
* @return The batch fetch queue in effect for this persistence context
*/
BatchFetchQueue getBatchFetchQueue();
/**
* Clear the state of the persistence context
*/
void clear();
/**
* @return false if we know for certain that all the entities are read-only
*/
@SuppressWarnings( {"UnusedDeclaration"})
boolean hasNonReadOnlyEntities();
/**
* Set the status of an entry
*
* @param entry The entry for which to set the status
* @param status The new status
*/
void setEntryStatus(EntityEntry entry, Status status);
/**
* Called after transactions end
*/
void afterTransactionCompletion();
/**
* Get the current state of the entity as known to the underlying database, or null if there is no
* corresponding row
*
* @param id The identifier of the entity for which to grab a snapshot
* @param persister The persister of the entity.
*
* @return The entity's (non-cached) snapshot
*
* @see #getCachedDatabaseSnapshot
*/
Object[] getDatabaseSnapshot(Object id, EntityPersister persister);
/**
* Retrieve the cached database snapshot for the requested entity key.
* <p/>
* This differs from {@link #getDatabaseSnapshot} in two important respects:<ol>
* <li>no snapshot is obtained from the database if not already cached</li>
* <li>an entry of {@link #NO_ROW} here is interpreted as an exception</li>
* </ol>
* @param key The entity key for which to retrieve the cached snapshot
* @return The cached snapshot
* @throws IllegalStateException if the cached snapshot was == {@link #NO_ROW}.
*/
Object[] getCachedDatabaseSnapshot(EntityKey key);
/**
* Get the values of the natural id fields as known to the underlying database, or null if the entity has no
* natural id or there is no corresponding row.
*
* @param id The identifier of the entity for which to grab a snapshot
* @param persister The persister of the entity.
*
* @return The current (non-cached) snapshot of the entity's natural id state.
*/
Object getNaturalIdSnapshot(Object id, EntityPersister persister);
/**
* Add a canonical mapping from entity key to entity instance
*
* @param key The key under which to add an entity
* @param entity The entity instance to add
*/
void addEntity(EntityKey key, Object entity);
/**
* Get the entity instance associated with the given key
*
* @param key The key under which to look for an entity
*
* @return The matching entity, or {@code null}
*/
Object getEntity(EntityKey key);
/**
* Is there an entity with the given key in the persistence context
*
* @param key The key under which to look for an entity
*
* @return {@code true} indicates an entity was found; otherwise {@code false}
*/
boolean containsEntity(EntityKey key);
/**
* Remove an entity. Also clears up all other state associated with the entity aside from the {@link EntityEntry}
*
* @param key The key whose matching entity should be removed
*
* @return The matching entity
*/
Object removeEntity(EntityKey key);
/**
* Add an entity to the cache by unique key
*
* @param euk The unique (non-primary) key under which to add an entity
* @param entity The entity instance
*/
void addEntity(EntityUniqueKey euk, Object entity);
/**
* Get an entity cached by unique key
*
* @param euk The unique (non-primary) key under which to look for an entity
*
* @return The located entity
*/
Object getEntity(EntityUniqueKey euk);
/**
* Retrieve the {@link EntityEntry} representation of the given entity.
*
* @param entity The entity instance for which to locate the corresponding entry
* @return The entry
*/
EntityEntry getEntry(Object entity);
/**
* Remove an entity entry from the session cache
*
* @param entity The entity instance for which to remove the corresponding entry
* @return The matching entry
*/
EntityEntry removeEntry(Object entity);
/**
* Is there an {@link EntityEntry} registration for this entity instance?
*
* @param entity The entity instance for which to check for an entry
*
* @return {@code true} indicates a matching entry was found.
*/
boolean isEntryFor(Object entity);
/**
* Get the collection entry for a persistent collection
*
* @param coll The persistent collection instance for which to locate the collection entry
*
* @return The matching collection entry
*/
CollectionEntry getCollectionEntry(PersistentCollection coll);
/**
* Adds an entity to the internal caches.
*/
EntityEntry addEntity(
final Object entity,
final Status status,
final Object[] loadedState,
final EntityKey entityKey,
final Object version,
final LockMode lockMode,
final boolean existsInDatabase,
final EntityPersister persister,
final boolean disableVersionIncrement);
/**
* Generates an appropriate EntityEntry instance and adds it
* to the event source's internal caches.
*/
EntityEntry addEntry(
final Object entity,
final Status status,
final Object[] loadedState,
final Object rowId,
final Object id,
final Object version,
final LockMode lockMode,
final boolean existsInDatabase,
final EntityPersister persister,
final boolean disableVersionIncrement);
/**
* Is the given collection associated with this persistence context?
*/
boolean containsCollection(PersistentCollection collection);
/**
* Is the given proxy associated with this persistence context?
*/
boolean containsProxy(Object proxy);
/**
* Takes the given object and, if it represents a proxy, reassociates it with this event source.
*
* @param value The possible proxy to be reassociated.
* @return Whether the passed value represented an actual proxy which got initialized.
* @throws MappingException
*/
boolean reassociateIfUninitializedProxy(Object value) ;
/**
* If a deleted entity instance is re-saved, and it has a proxy, we need to
* reset the identifier of the proxy
*/
void reassociateProxy(Object value, Object id);
/**
* Get the entity instance underlying the given proxy, throwing
* an exception if the proxy is uninitialized. If the given object
* is not a proxy, simply return the argument.
*/
Object unproxy(Object maybeProxy);
/**
* Possibly unproxy the given reference and reassociate it with the current session.
*
* @param maybeProxy The reference to be unproxied if it currently represents a proxy.
* @return The unproxied instance.
* @throws HibernateException
*/
Object unproxyAndReassociate(Object maybeProxy);
/**
* Attempts to check whether the given key represents an entity already loaded within the
* current session.
*
* @param object The entity reference against which to perform the uniqueness check.
*
* @throws HibernateException
*/
void checkUniqueness(EntityKey key, Object object);
/**
* If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy
* and overwrite the registration of the old one. This breaks == and occurs only for
* "class" proxies rather than "interface" proxies. Also init the proxy to point to
* the given target implementation if necessary.
*
* @param proxy The proxy instance to be narrowed.
* @param persister The persister for the proxied entity.
* @param key The internal cache key for the proxied entity.
* @param object (optional) the actual proxied entity instance.
* @return An appropriately narrowed instance.
* @throws HibernateException
*/
Object narrowProxy(Object proxy, EntityPersister persister, EntityKey key, Object object);
/**
* Return the existing proxy associated with the given <tt>EntityKey</tt>, or the
* third argument (the entity associated with the key) if no proxy exists. Init
* the proxy to the target implementation, if necessary.
*/
Object proxyFor(EntityPersister persister, EntityKey key, Object impl);
/**
* Return the existing proxy associated with the given <tt>EntityKey</tt>, or the
* argument (the entity associated with the key) if no proxy exists.
* (slower than the form above)
*/
Object proxyFor(Object impl);
/**
* Cross between {@link #addEntity(EntityKey, Object)} and {@link #addProxy(EntityKey, Object)}
* for use with enhancement-as-proxy
*/
void addEnhancedProxy(EntityKey key, PersistentAttributeInterceptable entity);
/**
* Get the entity that owns this persistent collection
*/
Object getCollectionOwner(Object key, CollectionPersister collectionPersister);
/**
* Get the entity that owned this persistent collection when it was loaded
*
* @param collection The persistent collection
* @return the owner if its entity ID is available from the collection's loaded key
* and the owner entity is in the persistence context; otherwise, returns null
*/
Object getLoadedCollectionOwnerOrNull(PersistentCollection collection);
/**
* Get the ID for the entity that owned this persistent collection when it was loaded
*
* @param collection The persistent collection
* @return the owner ID if available from the collection's loaded key; otherwise, returns null
*/
Object getLoadedCollectionOwnerIdOrNull(PersistentCollection collection);
/**
* add a collection we just loaded up (still needs initializing)
*/
void addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Object id);
/**
* add a detached uninitialized collection
*/
void addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection collection);
/**
* Add a new collection (ie. a newly created one, just instantiated by the
* application, with no database state or snapshot)
* @param collection The collection to be associated with the persistence context
*/
void addNewCollection(CollectionPersister persister, PersistentCollection collection);
/**
* add an (initialized) collection that was created by another session and passed
* into update() (ie. one with a snapshot and existing state on the database)
*/
void addInitializedDetachedCollection(
CollectionPersister collectionPersister,
PersistentCollection collection);
/**
* add a collection we just pulled out of the cache (does not need initializing)
*/
CollectionEntry addInitializedCollection(
CollectionPersister persister,
PersistentCollection collection,
Object id);
/**
* Get the collection instance associated with the <tt>CollectionKey</tt>
*/
PersistentCollection getCollection(CollectionKey collectionKey);
/**
* Register a collection for non-lazy loading at the end of the
* two-phase load
*/
void addNonLazyCollection(PersistentCollection collection);
/**
* 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)
*/
void initializeNonLazyCollections() throws HibernateException;
/**
* Get the <tt>PersistentCollection</tt> object for an array
*/
PersistentCollection getCollectionHolder(Object array);
/**
* Register a <tt>PersistentCollection</tt> object for an array.
* Associates a holder with an array - MUST be called after loading
* array, since the array instance is not created until endLoad().
*/
void addCollectionHolder(PersistentCollection holder);
/**
* Remove the mapping of collection to holder during eviction
* of the owning entity
*/
PersistentCollection removeCollectionHolder(Object array);
/**
* Get the snapshot of the pre-flush collection state
*/
Serializable getSnapshot(PersistentCollection coll);
/**
* 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.
*
* @deprecated Intended use was in handling Hibernate's legacy
* "collection filter via Query" feature which has been removed
*/
@Deprecated
CollectionEntry getCollectionEntryOrNull(Object collection);
/**
* Get an existing proxy by key
*/
Object getProxy(EntityKey key);
/**
* Add a proxy to the session cache
*/
void addProxy(EntityKey key, Object proxy);
/**
* Remove a proxy from the session cache.
* <p/>
* Additionally, ensure that any load optimization references
* such as batch or subselect loading get cleaned up as well.
*
* @param key The key of the entity proxy to be removed
* @return The proxy reference.
*/
Object removeProxy(EntityKey key);
/**
* Retrieve the set of EntityKeys representing nullifiable references
* @deprecated Use {@link #containsNullifiableEntityKey(Supplier)} or {@link #registerNullifiableEntityKey(EntityKey)} or {@link #isNullifiableEntityKeysEmpty()}
*/
@Deprecated
HashSet getNullifiableEntityKeys();
/**
* Get the mapping from key value to entity instance
* @deprecated this will be removed: it provides too wide access, making it hard to optimise the internals
* for specific access needs. Consider using #iterateEntities instead.
*/
@Deprecated
Map getEntitiesByKey();
/**
* Provides access to the entity/EntityEntry combos associated with the persistence context in a manner that
* is safe from reentrant access. Specifically, it is safe from additions/removals while iterating.
*/
Map.Entry<Object,EntityEntry>[] reentrantSafeEntityEntries();
/**
* Get the mapping from entity instance to entity entry
*
* @deprecated Due to the introduction of EntityEntryContext and bytecode enhancement; only valid really for
* sizing, see {@link #getNumberOfManagedEntities}. For iterating the entity/EntityEntry combos, see
* {@link #reentrantSafeEntityEntries}
*/
@Deprecated
Map getEntityEntries();
int getNumberOfManagedEntities();
/**
* Get the mapping from collection instance to collection entry
* @deprecated use {@link #removeCollectionEntry(PersistentCollection)} or {@link #getCollectionEntriesSize()}, {@link #forEachCollectionEntry(BiConsumer,boolean)}.
*/
@Deprecated
Map getCollectionEntries();
/**
* Execute some action on each entry of the collectionEntries map, optionally iterating on a defensive copy.
* @param action the lambda to apply on each PersistentCollection,CollectionEntry map entry of the PersistenceContext.
* @param concurrent set this to false for improved efficiency, but that would make it illegal to make changes to the underlying collectionEntries map.
*/
void forEachCollectionEntry(BiConsumer<PersistentCollection,CollectionEntry> action, boolean concurrent);
/**
* Get the mapping from collection key to collection instance
* @deprecated this method should be removed; alternative methods are available that better express the intent, allowing
* for better optimisations. Not aggressively removing this as it's an SPI, but also useful for testing and other
* contexts which are not performance sensitive.
* N.B. This might return an immutable map: do not use for mutations!
*/
@Deprecated
Map getCollectionsByKey();
/**
* How deep are we cascaded?
*/
int getCascadeLevel();
/**
* Called before cascading
*/
int incrementCascadeLevel();
/**
* Called after cascading
*/
int decrementCascadeLevel();
/**
* Is a flush cycle currently in process?
*/
@SuppressWarnings( {"UnusedDeclaration"})
boolean isFlushing();
/**
* Called before and after the flush cycle
*/
void setFlushing(boolean flushing);
/**
* Call this before beginning a two-phase load
*/
void beforeLoad();
/**
* Call this after finishing a two-phase load
*/
void afterLoad();
/**
* Is in a two-phase load?
*/
boolean isLoadFinished();
/**
* Returns a string representation of the object.
*
* @return a string representation of the object.
*/
String toString();
/**
* Search <tt>this</tt> persistence context for an associated entity instance which is considered the "owner" of
* the given <tt>childEntity</tt>, and return that owner's id value. This is performed in the scenario of a
* uni-directional, non-inverse one-to-many collection (which means that the collection elements do not maintain
* a direct reference to the owner).
* <p/>
* As such, the processing here is basically to loop over every entity currently associated with this persistence
* context and for those of the correct entity (sub) type to extract its collection role property value and see
* if the child is contained within that collection. If so, we have found the owner; if not, we go on.
* <p/>
* Also need to account for <tt>mergeMap</tt> which acts as a local copy cache managed for the duration of a merge
* operation. It represents a map of the detached entity instances pointing to the corresponding managed instance.
*
* @param entityName The entity name for the entity type which would own the child
* @param propertyName The name of the property on the owning entity type which would name this child association.
* @param childEntity The child entity instance for which to locate the owner instance id.
* @param mergeMap A map of non-persistent instances from an on-going merge operation (possibly null).
*
* @return The id of the entityName instance which is said to own the child; null if an appropriate owner not
* located.
*/
Object getOwnerId(String entityName, String propertyName, Object childEntity, Map mergeMap);
/**
* Search the persistence context for an index of the child object,
* given a collection role
*/
Object getIndexInOwner(String entity, String property, Object childObject, Map mergeMap);
/**
* Record the fact that the association belonging to the keyed
* entity is null.
*/
void addNullProperty(EntityKey ownerKey, String propertyName);
/**
* Is the association property belonging to the keyed entity null?
*/
boolean isPropertyNull(EntityKey ownerKey, String propertyName);
/**
* Will entities and proxies that are loaded into this persistence
* context be made read-only by default?
*
* To determine the read-only/modifiable setting for a particular entity
* or proxy:
* @see PersistenceContext#isReadOnly(Object)
* @see org.hibernate.Session#isReadOnly(Object)
*
* @return true, loaded entities/proxies will be made read-only by default;
* false, loaded entities/proxies will be made modifiable by default.
*
* @see org.hibernate.Session#isDefaultReadOnly()
*/
boolean isDefaultReadOnly();
/**
* Change the default for entities and proxies loaded into this persistence
* context from modifiable to read-only mode, or from modifiable to read-only
* mode.
*
* Read-only entities are not dirty-checked and snapshots of persistent
* state are not maintained. Read-only entities can be modified, but
* changes are not persisted.
*
* When a proxy is initialized, the loaded entity will have the same
* read-only/modifiable setting as the uninitialized
* proxy has, regardless of the persistence context's current setting.
*
* To change the read-only/modifiable setting for a particular entity
* or proxy that is already in this session:
+ * @see PersistenceContext#setReadOnly(Object,boolean)
* @see org.hibernate.Session#setReadOnly(Object, boolean)
*
* To override this session's read-only/modifiable setting for entities
* and proxies loaded by a Query:
* @see org.hibernate.query.Query#setReadOnly(boolean)
*
* @param readOnly true, the default for loaded entities/proxies is read-only;
* false, the default for loaded entities/proxies is modifiable
*
* @see org.hibernate.Session#setDefaultReadOnly(boolean)
*/
void setDefaultReadOnly(boolean readOnly);
/**
* Is the entity or proxy read-only?
* <p/>
* To determine the default read-only/modifiable setting used for entities and proxies that are loaded into the
* session use {@link org.hibernate.Session#isDefaultReadOnly}
*
* @param entityOrProxy an entity or proxy
*
* @return {@code true} if the object is read-only; otherwise {@code false} to indicate that the object is
* modifiable.
*/
boolean isReadOnly(Object entityOrProxy);
/**
* Set an unmodified persistent object to read-only mode, or a read-only
* object to modifiable mode.
*
* Read-only entities are not dirty-checked and snapshots of persistent
* state are not maintained. Read-only entities can be modified, but
* changes are not persisted.
*
* When a proxy is initialized, the loaded entity will have the same
* read-only/modifiable setting as the uninitialized
* proxy has, regardless of the session's current setting.
*
* If the entity or proxy already has the specified read-only/modifiable
* setting, then this method does nothing.
*
* @param entityOrProxy an entity or proxy
* @param readOnly if {@code true}, the entity or proxy is made read-only; otherwise, the entity or proxy is made
* modifiable.
*
* @see org.hibernate.Session#setDefaultReadOnly
* @see org.hibernate.Session#setReadOnly
* @see org.hibernate.query.Query#setReadOnly
*/
void setReadOnly(Object entityOrProxy, boolean readOnly);
void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Object generatedId);
/**
* Add a child/parent relation to cache for cascading op
*
* @param child The child of the relationship
* @param parent The parent of the relationship
*/
void addChildParent(Object child, Object parent);
/**
* Remove child/parent relation from cache
*
* @param child The child to be removed.
*/
void removeChildParent(Object child);
/**
* Register keys inserted during the current transaction
* @param persister The entity persister
* @param id The id
*/
void registerInsertedKey(EntityPersister persister, Object id);
/**
* Allows callers to check to see if the identified entity was inserted during the current transaction.
*
* @param persister The entity persister
* @param id The id
*
* @return True if inserted during this transaction, false otherwise.
*/
boolean wasInsertedDuringTransaction(EntityPersister persister, Object id);
/**
* Checks if a certain {@link EntityKey} was registered as nullifiable on this {@link PersistenceContext}.
*
* @param sek a supplier for the EntityKey; this allows to not always needing to create the key;
* for example if the map is known to be empty there is no need to create one to check.
* @return true if the EntityKey had been registered before using {@link #registerNullifiableEntityKey(EntityKey)}
* @see #registerNullifiableEntityKey(EntityKey)
*/
boolean containsNullifiableEntityKey(Supplier<EntityKey> sek);
/**
* Registers an {@link EntityKey} as nullifiable on this {@link PersistenceContext}.
* @param key
*/
void registerNullifiableEntityKey(EntityKey key);
/**
* @return true if no {@link EntityKey} was registered as nullifiable on this {@link PersistenceContext}.
* @see #registerNullifiableEntityKey(EntityKey)
*/
boolean isNullifiableEntityKeysEmpty();
/**
* The size of the internal map storing all collection entries.
* (The map is not exposed directly, but the size is often useful)
* @return the size
*/
int getCollectionEntriesSize();
/**
* Remove a {@link PersistentCollection} from the {@link PersistenceContext}.
* @param collection the collection to remove
* @return the matching {@link CollectionEntry}, if any was removed.
*/
CollectionEntry removeCollectionEntry(PersistentCollection collection);
/**
* Remove all state of the collections-by-key map.
*/
void clearCollectionsByKey();
/**
* Adds a collection in the collections-by-key map.
* @param collectionKey
* @param persistentCollection
* @return the previous collection, it the key was already mapped.
*/
PersistentCollection addCollectionByKey(CollectionKey collectionKey, PersistentCollection persistentCollection);
/**
* Remove a collection-by-key mapping.
* @param collectionKey the key to clear
*/
void removeCollectionByKey(CollectionKey collectionKey);
/**
* A read-only iterator on all entities managed by this persistence context
*/
Iterator managedEntitiesIterator();
/**
* Access to the natural-id helper for this persistence context
*
* @return This persistence context's natural-id helper
*/
NaturalIdResolutions getNaturalIdResolutions();
}