Skip to content

Commit 42959cc

Browse files
committed
javadoc and code comment clean ups
1 parent cc05847 commit 42959cc

File tree

4 files changed

+53
-59
lines changed

4 files changed

+53
-59
lines changed

hibernate-core/src/main/java/org/hibernate/Interceptor.java

+30-21
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ default void onCollectionRemove(Object collection, Object key) {
215215
*/
216216
default void onCollectionUpdate(Object collection, Object key) {
217217
}
218+
218219
/**
219220
* Called before a flush.
220221
*
@@ -223,32 +224,37 @@ default void onCollectionUpdate(Object collection, Object key) {
223224
default void preFlush(Iterator<Object> entities) {}
224225

225226
/**
226-
* Called after a flush that actually ends in execution of the SQL statements required to synchronize
227-
* in-memory state with the database.
227+
* Called after a flush that actually ends in execution of the SQL statements
228+
* required to synchronize in-memory state with the database.
228229
*
229230
* @param entities The entities that were flushed.
230231
*/
231232
default void postFlush(Iterator<Object> entities) {}
232233

233234
/**
234-
* Called to distinguish between transient and detached entities. The return value determines the
235-
* state of the entity with respect to the current session.
235+
* Called to distinguish between transient and detached entities. The return
236+
* value determines the state of the entity with respect to the current session.
237+
* This method should return:
236238
* <ul>
237-
* <li>{@code Boolean.TRUE} - the entity is transient
238-
* <li>{@code Boolean.FALSE} - the entity is detached
239-
* <li>{@code null} - Hibernate uses the {@code unsaved-value} mapping and other heuristics to
240-
* determine if the object is unsaved
239+
* <li>{@code Boolean.TRUE} if the entity is transient,
240+
* <li>{@code Boolean.FALSE} if the entity is detached, or
241+
* <li>{@code null} to signal that the usual heuristics should be used to determine
242+
* if the instance is transient
241243
* </ul>
244+
* Heuristics used when this method returns null are based on the value of the
245+
* {@linkplain jakarta.persistence.GeneratedValue generated} id field, or the
246+
* {@linkplain jakarta.persistence.Version version} field, if any.
242247
*
243248
* @param entity a transient or detached entity
244-
* @return Boolean or {@code null} to choose default behaviour
249+
* @return {@link Boolean} or {@code null} to choose default behaviour
245250
*/
246251
default Boolean isTransient(Object entity) {
247252
return null;
248253
}
249254

250255
/**
251-
* Called from {@code flush()}. The return value determines whether the entity is updated
256+
* Called from {@code flush()}. The return value determines whether the entity
257+
* is updated
252258
* <ul>
253259
* <li>an array of property indices - the entity is dirty
254260
* <li>an empty array - the entity is not dirty
@@ -258,11 +264,13 @@ default Boolean isTransient(Object entity) {
258264
* @param entity The entity for which to find dirty properties.
259265
* @param id The identifier of the entity
260266
* @param currentState The current entity state as taken from the entity instance
261-
* @param previousState The state of the entity when it was last synchronized (generally when it was loaded)
267+
* @param previousState The state of the entity when it was last synchronized
268+
* (generally when it was loaded)
262269
* @param propertyNames The names of the entity properties.
263270
* @param types The types of the entity properties
264271
*
265-
* @return array of dirty property indices or {@code null} to indicate Hibernate should perform default behaviour
272+
* @return array of dirty property indices or {@code null} to indicate Hibernate
273+
* should perform default behaviour
266274
*/
267275
default int[] findDirty(
268276
Object entity,
@@ -275,9 +283,9 @@ default int[] findDirty(
275283
}
276284

277285
/**
278-
* Instantiate the entity. Return {@code null} to indicate that Hibernate should use
279-
* the default constructor of the class. The identifier property of the returned instance
280-
* should be initialized with the given identifier.
286+
* Instantiate the entity. Return {@code null} to indicate that Hibernate should
287+
* use the default constructor of the class. The identifier property of the
288+
* returned instance should be initialized with the given identifier.
281289
*/
282290
default Object instantiate(
283291
String entityName,
@@ -287,9 +295,9 @@ default Object instantiate(
287295
}
288296

289297
/**
290-
* Instantiate the entity. Return {@code null} to indicate that Hibernate should use
291-
* the default constructor of the class. The identifier property of the returned instance
292-
* should be initialized with the given identifier.
298+
* Instantiate the entity. Return {@code null} to indicate that Hibernate should
299+
* use the default constructor of the class. The identifier property of the
300+
* returned instance should be initialized with the given identifier.
293301
*/
294302
default Object instantiate(
295303
String entityName,
@@ -324,9 +332,10 @@ default Object getEntity(String entityName, Object id) {
324332
}
325333

326334
/**
327-
* Called when a Hibernate transaction is begun via the Hibernate {@code Transaction}
328-
* API. Will not be called if transactions are being controlled via some other
329-
* mechanism (CMT, for example).
335+
* Called when a Hibernate transaction is begun via the JPA-standard
336+
* {@link jakarta.persistence.EntityTransaction} API, or via {@link Transaction}.
337+
* This method is not be called if transactions are being controlled via some
338+
* other mechanism, for example, if transactions are managed by a container.
330339
*
331340
* @param tx The Hibernate transaction facade object
332341
*/

hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java

+9-15
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.hibernate.event.spi.PostLoadEvent;
5555
import org.hibernate.event.spi.PostLoadEventListener;
5656
import org.hibernate.internal.CoreMessageLogger;
57-
import org.hibernate.internal.util.collections.CollectionHelper;
5857
import org.hibernate.internal.util.collections.InstanceIdentityMap;
5958
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
6059
import org.hibernate.persister.collection.CollectionPersister;
@@ -78,6 +77,7 @@
7877
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
7978
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
8079
import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize;
80+
import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize;
8181
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
8282

8383
/**
@@ -324,12 +324,6 @@ public void afterTransactionCompletion() {
324324
entityEntryContext.downgradeLocks();
325325
}
326326

327-
/**
328-
* Get the current state of the entity as known to the underlying
329-
* database, or null if there is no corresponding row
330-
* <p>
331-
* {@inheritDoc}
332-
*/
333327
@Override
334328
public Object[] getDatabaseSnapshot(Object id, EntityPersister persister) throws HibernateException {
335329
final EntityKey key = session.generateEntityKey( id, persister );
@@ -1193,14 +1187,13 @@ public void initializeNonLazyCollections() throws HibernateException {
11931187
public void initializeNonLazyCollections(Consumer<PersistentCollection<?>> initializeAction ) {
11941188
if ( loadCounter == 0 ) {
11951189
LOG.trace( "Initializing non-lazy collections" );
1196-
1197-
//do this work only at the very highest level of the load
1198-
//don't let this method be called recursively
1190+
// do this work only at the very highest level of the load
1191+
// don't let this method be called recursively
11991192
loadCounter++;
12001193
try {
1201-
int size;
1202-
while ( nonlazyCollections != null && ( size = nonlazyCollections.size() ) > 0 ) {
1203-
//note that each iteration of the loop may add new elements
1194+
while ( nonlazyCollections != null && !nonlazyCollections.isEmpty() ) {
1195+
final int size = nonlazyCollections.size();
1196+
// note that each iteration of the loop may add new elements
12041197
initializeAction.accept( nonlazyCollections.remove( size - 1 ) );
12051198
}
12061199
}
@@ -1733,14 +1726,15 @@ private Object getIndexInParent(
17331726
@Override
17341727
public void addNullProperty(EntityKey ownerKey, String propertyName) {
17351728
if ( nullAssociations == null ) {
1736-
nullAssociations = CollectionHelper.setOfSize( INIT_COLL_SIZE );
1729+
nullAssociations = setOfSize( INIT_COLL_SIZE );
17371730
}
17381731
nullAssociations.add( new AssociationKey( ownerKey, propertyName ) );
17391732
}
17401733

17411734
@Override
17421735
public boolean isPropertyNull(EntityKey ownerKey, String propertyName) {
1743-
return nullAssociations != null && nullAssociations.contains( new AssociationKey( ownerKey, propertyName ) );
1736+
return nullAssociations != null
1737+
&& nullAssociations.contains( new AssociationKey( ownerKey, propertyName ) );
17441738
}
17451739

17461740
private void clearNullProperties() {

hibernate-core/src/main/java/org/hibernate/engine/spi/PersistenceContext.java

+11-20
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ default boolean hasLoadContext() {
6767
return true;
6868
}
6969

70-
// /**
71-
// * Add a collection which has no owner loaded
72-
// *
73-
// * @param key The collection key under which to add the collection
74-
// * @param collection The collection to add
75-
// */
76-
// void addUnownedCollection(CollectionKey key, PersistentCollection<?> collection);
77-
7870
/**
7971
* Take ownership of a previously unowned collection, if one. This method returns {@code null} if no such
8072
* collection was previously added () or was previously removed.
@@ -99,11 +91,6 @@ default boolean hasLoadContext() {
9991
*/
10092
void clear();
10193

102-
// /**
103-
// * @return false if we know for certain that all the entities are read-only
104-
// */
105-
// boolean hasNonReadOnlyEntities();
106-
10794
/**
10895
* Set the status of an entry
10996
*
@@ -118,8 +105,9 @@ default boolean hasLoadContext() {
118105
void afterTransactionCompletion();
119106

120107
/**
121-
* Get the current state of the entity as known to the underlying database, or null if there is no
122-
* corresponding row
108+
* Get the current state of the entity as known to the underlying database,
109+
* or {@code null} if there is no corresponding row. This operation might
110+
* result in a {@code select} query being executed against the database.
123111
*
124112
* @param id The identifier of the entity for which to grab a snapshot
125113
* @param persister The persister of the entity.
@@ -133,13 +121,16 @@ default boolean hasLoadContext() {
133121
/**
134122
* Retrieve the cached database snapshot for the requested entity key.
135123
* <p>
136-
* This differs from {@link #getDatabaseSnapshot} in two important respects:<ol>
137-
* <li>no snapshot is obtained from the database if not already cached</li>
138-
* <li>an entry of {@link #NO_ROW} here is interpreted as an exception</li>
124+
* This differs from {@link #getDatabaseSnapshot} in two important ways:
125+
* <ol>
126+
* <li>no snapshot is obtained from the database if not already cached,
127+
* and
128+
* <li>an entry of {@link #NO_ROW} here results in an exception.
139129
* </ol>
130+
*
140131
* @param key The entity key for which to retrieve the cached snapshot
141132
* @return The cached snapshot
142-
* @throws IllegalStateException if the cached snapshot was == {@link #NO_ROW}.
133+
* @throws IllegalStateException if the cached snapshot was {@link #NO_ROW}.
143134
*/
144135
Object[] getCachedDatabaseSnapshot(EntityKey key);
145136

@@ -657,7 +648,7 @@ EntityHolder claimEntityHolderIfPossible(
657648
* if the child is contained within that collection. If so, we have found the owner; if not, we go on.
658649
* <p>
659650
* Also need to account for {@code mergeMap} which acts as a local copy cache managed for the duration of a merge
660-
* operation. It represents a map of the detached entity instances pointing to the corresponding managed instance.
651+
* operation. It represents a map of the detached entity instances pointing to the corresponding managed instance.
661652
*
662653
* @param entityName The entity name for the entity type which would own the child
663654
* @param propertyName The name of the property on the owning entity type which would name this child association.

hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ public Serializable disassemble(Object value, SessionFactoryImplementor sessionF
149149
@Override
150150
public Object assemble(Serializable oid, SharedSessionContractImplementor session, Object owner)
151151
throws HibernateException {
152-
//this should be a call to resolve(), not resolveIdentifier(),
153-
//because it might be a property-ref, and we did not cache the
154-
//referenced value
152+
// this should be a call to resolve(), not resolveIdentifier(),
153+
// because it might be a property-ref, and we did not cache the
154+
// referenced value
155155
return resolve( session.getContextEntityIdentifier( owner ), session, owner );
156156
}
157157

0 commit comments

Comments
 (0)