|
4 | 4 | */ |
5 | 5 | package org.hibernate.event.spi; |
6 | 6 |
|
7 | | -import org.hibernate.collection.spi.PersistentCollection; |
| 7 | +import org.hibernate.Internal;import org.hibernate.collection.spi.PersistentCollection; |
8 | 8 | import org.hibernate.persister.collection.CollectionPersister; |
9 | 9 |
|
10 | 10 | /** |
11 | 11 | * Defines a base class for events involving collections. |
12 | 12 | * |
13 | 13 | * @author Gail Badner |
| 14 | + * @author Steve Ebersole |
| 15 | + * |
| 16 | + * @apiNote AbstractCollectionEvent and its implementations are defined |
| 17 | + * as SPI for consumption; their constructors are defined as |
| 18 | + * {@linkplain Internal internal} |
14 | 19 | */ |
15 | 20 | public abstract class AbstractCollectionEvent extends AbstractSessionEvent { |
16 | | - |
17 | 21 | private final PersistentCollection<?> collection; |
18 | | - private final Object affectedOwner; |
19 | | - private final Object affectedOwnerId; |
20 | | - private final String affectedOwnerEntityName; |
| 22 | + private final CollectionPersister collectionPersister; |
| 23 | + private final Object owner; |
| 24 | + private final Object ownerId; |
| 25 | + private final String ownerEntityName; |
21 | 26 |
|
22 | 27 | /** |
23 | 28 | * Constructs an instance for a stateful session. |
24 | | - * @param collection - the collection |
25 | | - * @param source - the Session source |
26 | | - * @param affectedOwner - the owner that is affected by this event; |
27 | | - * can be null if unavailable |
28 | | - * @param affectedOwnerId - the ID for the owner that is affected |
29 | | - * by this event; can be null if unavailable |
| 29 | + * |
| 30 | + * @param collectionPersister The descriptor for the collection mapping. |
| 31 | + * @param collection - The (wrapped) collection instance. |
| 32 | + * @param source - The {@linkplain org.hibernate.Session session} |
| 33 | + * @param owner - The entity instance that "owns" the {@code collection} |
| 34 | + * affected by this event; can be {@code null} if unavailable. |
| 35 | + * @param ownerId - The identifier value for the {@code owner}; can be |
| 36 | + * {@code null} if unavailable. |
30 | 37 | */ |
| 38 | + @Internal |
31 | 39 | public AbstractCollectionEvent( |
32 | 40 | CollectionPersister collectionPersister, |
33 | 41 | PersistentCollection<?> collection, |
34 | 42 | EventSource source, |
35 | | - Object affectedOwner, |
36 | | - Object affectedOwnerId) { |
| 43 | + Object owner, |
| 44 | + Object ownerId) { |
37 | 45 | super( source ); |
38 | 46 | this.collection = collection; |
39 | | - this.affectedOwner = affectedOwner; |
40 | | - this.affectedOwnerId = affectedOwnerId; |
41 | | - this.affectedOwnerEntityName = |
42 | | - getAffectedOwnerEntityName( collectionPersister, affectedOwner, source ); |
| 47 | + this.collectionPersister = collectionPersister; |
| 48 | + this.owner = owner; |
| 49 | + this.ownerId = ownerId; |
| 50 | + this.ownerEntityName = getAffectedOwnerEntityName( collectionPersister, owner, source ); |
43 | 51 | } |
44 | 52 |
|
45 | 53 | /** |
46 | 54 | * Constructs an instance for a stateless session. |
47 | | - * @param collection - the collection |
48 | | - * @param entityName - the name of the owning entity |
49 | | - * @param affectedOwner - the owner that is affected by this event; |
50 | | - * can be null if unavailable |
51 | | - * @param affectedOwnerId - the ID for the owner that is affected |
52 | | - * by this event; can be null if unavailable |
| 55 | + * |
| 56 | + * @param collectionPersister The descriptor for the collection mapping. |
| 57 | + * @param collection - The (wrapped) collection instance. |
| 58 | + * @param ownerEntityName - The entity-name of the {@code owner}. |
| 59 | + * @param owner - The entity instance that "owns" the {@code collection} |
| 60 | + * affected by this event; can be {@code null} if unavailable. |
| 61 | + * @param ownerId - The identifier value for the {@code owner}; can be |
| 62 | + * {@code null} if unavailable. |
53 | 63 | */ |
| 64 | + @Internal |
54 | 65 | public AbstractCollectionEvent( |
| 66 | + CollectionPersister collectionPersister, |
55 | 67 | PersistentCollection<?> collection, |
56 | | - String entityName, |
57 | | - Object affectedOwner, |
58 | | - Object affectedOwnerId) { |
| 68 | + String ownerEntityName, |
| 69 | + Object owner, |
| 70 | + Object ownerId) { |
59 | 71 | super( null ); |
60 | 72 | this.collection = collection; |
61 | | - this.affectedOwner = affectedOwner; |
62 | | - this.affectedOwnerId = affectedOwnerId; |
63 | | - this.affectedOwnerEntityName = entityName; |
| 73 | + this.owner = owner; |
| 74 | + this.ownerId = ownerId; |
| 75 | + this.ownerEntityName = ownerEntityName; |
| 76 | + this.collectionPersister = collectionPersister; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * The descriptor for the {@linkplain #getCollection() collection} mapping. |
| 81 | + */ |
| 82 | + public CollectionPersister getCollectionPersister() { |
| 83 | + return collectionPersister; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * The (wrapped) collection instance affected by this event. |
| 88 | + */ |
| 89 | + public PersistentCollection<?> getCollection() { |
| 90 | + return collection; |
64 | 91 | } |
65 | 92 |
|
66 | | - protected static CollectionPersister getLoadedCollectionPersister( PersistentCollection<?> collection, EventSource source ) { |
| 93 | + /** |
| 94 | + * Get the collection owner entity that is affected by this event. |
| 95 | + * |
| 96 | + * @return the affected owner; returns null if the entity is not in the persistence context |
| 97 | + * (e.g., because the collection from a detached entity was moved to a new owner) |
| 98 | + */ |
| 99 | + public Object getAffectedOwnerOrNull() { |
| 100 | + return owner; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Get the ID for the collection owner entity that is affected by this event. |
| 105 | + * |
| 106 | + * @return the affected owner ID; returns null if the ID cannot be obtained |
| 107 | + * from the collection's loaded key (e.g., a property-ref is used for the |
| 108 | + * collection and does not include the entity's ID) |
| 109 | + */ |
| 110 | + public Object getAffectedOwnerIdOrNull() { |
| 111 | + return ownerId; |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Get the entity name for the collection owner entity that is affected by this event. |
| 116 | + * |
| 117 | + * @return the entity name; if the owner is not in the PersistenceContext, the |
| 118 | + * returned value may be a superclass name, instead of the actual class name |
| 119 | + */ |
| 120 | + public String getAffectedOwnerEntityName() { |
| 121 | + return ownerEntityName; |
| 122 | + } |
| 123 | + |
| 124 | + protected static CollectionPersister getLoadedCollectionPersister(PersistentCollection<?> collection, EventSource source) { |
67 | 125 | final var entry = source.getPersistenceContextInternal().getCollectionEntry( collection ); |
68 | 126 | return entry == null ? null : entry.getLoadedPersister(); |
69 | 127 | } |
@@ -102,39 +160,4 @@ protected static String getAffectedOwnerEntityName( |
102 | 160 | : null; |
103 | 161 | } |
104 | 162 |
|
105 | | - public PersistentCollection<?> getCollection() { |
106 | | - return collection; |
107 | | - } |
108 | | - |
109 | | - /** |
110 | | - * Get the collection owner entity that is affected by this event. |
111 | | - * |
112 | | - * @return the affected owner; returns null if the entity is not in the persistence context |
113 | | - * (e.g., because the collection from a detached entity was moved to a new owner) |
114 | | - */ |
115 | | - public Object getAffectedOwnerOrNull() { |
116 | | - return affectedOwner; |
117 | | - } |
118 | | - |
119 | | - /** |
120 | | - * Get the ID for the collection owner entity that is affected by this event. |
121 | | - * |
122 | | - * @return the affected owner ID; returns null if the ID cannot be obtained |
123 | | - * from the collection's loaded key (e.g., a property-ref is used for the |
124 | | - * collection and does not include the entity's ID) |
125 | | - */ |
126 | | - public Object getAffectedOwnerIdOrNull() { |
127 | | - return affectedOwnerId; |
128 | | - } |
129 | | - |
130 | | - /** |
131 | | - * Get the entity name for the collection owner entity that is affected by this event. |
132 | | - * |
133 | | - * @return the entity name; if the owner is not in the PersistenceContext, the |
134 | | - * returned value may be a superclass name, instead of the actual class name |
135 | | - */ |
136 | | - public String getAffectedOwnerEntityName() { |
137 | | - return affectedOwnerEntityName; |
138 | | - } |
139 | | - |
140 | 163 | } |
0 commit comments