Skip to content

Commit c57a90e

Browse files
committed
cleanup warnings in PersistenceContext
+ code cleanups in CacheEntityLoaderHelper
1 parent 3a4da8d commit c57a90e

File tree

3 files changed

+100
-142
lines changed

3 files changed

+100
-142
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ public EntityEntry addEntry(
699699
return e;
700700
}
701701

702+
@Override
702703
public EntityEntry addReferenceEntry(
703704
final Object entity,
704705
final Status status) {
@@ -885,11 +886,13 @@ public Object narrowProxy(Object proxy, EntityPersister persister, EntityKey key
885886
}
886887

887888
private Object removeProxyByKey(final EntityKey key) {
888-
final EntityHolderImpl entityHolder;
889-
if ( entitiesByKey != null && ( entityHolder = entitiesByKey.get( key ) ) != null ) {
890-
final Object proxy = entityHolder.proxy;
891-
entityHolder.proxy = null;
892-
return proxy;
889+
if ( entitiesByKey != null ) {
890+
final EntityHolderImpl entityHolder = entitiesByKey.get( key );
891+
if ( entityHolder != null ) {
892+
final Object proxy = entityHolder.proxy;
893+
entityHolder.proxy = null;
894+
return proxy;
895+
}
893896
}
894897
return null;
895898
}
@@ -911,11 +914,6 @@ public Object proxyFor(Object impl) throws HibernateException {
911914
return e == null ? impl : proxyFor( e.getPersister(), e.getEntityKey(), impl );
912915
}
913916

914-
@Override
915-
public Object proxyFor(EntityHolder holder) throws HibernateException {
916-
return proxyFor( holder, holder.getDescriptor() );
917-
}
918-
919917
@Override
920918
public Object proxyFor(EntityHolder holder, EntityPersister persister) {
921919
final Object proxy = holder.getProxy();
@@ -2089,7 +2087,7 @@ public boolean wasInsertedDuringTransaction(EntityPersister persister, Object id
20892087
@Override
20902088
public boolean containsNullifiableEntityKey(Supplier<EntityKey> sek) {
20912089
return nullifiableEntityKeys != null
2092-
&& nullifiableEntityKeys.size() != 0
2090+
&& !nullifiableEntityKeys.isEmpty()
20932091
&& nullifiableEntityKeys.contains( sek.get() );
20942092
}
20952093

@@ -2104,7 +2102,7 @@ public void registerNullifiableEntityKey(EntityKey key) {
21042102
@Override
21052103
public boolean isNullifiableEntityKeysEmpty() {
21062104
return nullifiableEntityKeys == null
2107-
|| nullifiableEntityKeys.size() == 0;
2105+
|| nullifiableEntityKeys.isEmpty();
21082106
}
21092107

21102108
@Override

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

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.hibernate.Incubating;
1818
import org.hibernate.Internal;
1919
import org.hibernate.LockMode;
20-
import org.hibernate.query.Query;
2120
import org.hibernate.collection.spi.PersistentCollection;
2221
import org.hibernate.internal.util.MarkerObject;
2322
import org.hibernate.persister.collection.CollectionPersister;
@@ -272,6 +271,10 @@ EntityEntry addEntry(
272271
final EntityPersister persister,
273272
final boolean disableVersionIncrement);
274273

274+
EntityEntry addReferenceEntry(
275+
final Object entity,
276+
final Status status);
277+
275278
/**
276279
* Is the given collection associated with this persistence context?
277280
*/
@@ -354,16 +357,6 @@ EntityEntry addEntry(
354357
*/
355358
Object proxyFor(EntityHolder holder, EntityPersister persister);
356359

357-
/**
358-
* Return the existing {@linkplain EntityHolder#getProxy() proxy} associated with
359-
* the given {@link EntityHolder}, or the {@linkplain EntityHolder#getEntity() entity}
360-
* if it contains no proxy.
361-
*
362-
* @deprecated Use {@link #proxyFor(EntityHolder, EntityPersister)} instead.
363-
*/
364-
@Deprecated( forRemoval = true )
365-
Object proxyFor(EntityHolder holder);
366-
367360
/**
368361
* Cross between {@link #addEntity(EntityKey, Object)} and {@link #addProxy(EntityKey, Object)}
369362
* for use with enhancement-as-proxy
@@ -498,13 +491,6 @@ CollectionEntry addInitializedCollection(
498491
*/
499492
Object removeProxy(EntityKey key);
500493

501-
// /**
502-
// * Retrieve the set of EntityKeys representing nullifiable references
503-
// * @deprecated Use {@link #containsNullifiableEntityKey(Supplier)} or {@link #registerNullifiableEntityKey(EntityKey)} or {@link #isNullifiableEntityKeysEmpty()}
504-
// */
505-
// @Deprecated
506-
// HashSet getNullifiableEntityKeys();
507-
508494
/**
509495
* Return an existing entity holder for the entity key, possibly creating one if necessary.
510496
* Will claim the entity holder by registering the given entity initializer, if it isn't claimed yet.
@@ -675,45 +661,41 @@ EntityHolder claimEntityHolderIfPossible(
675661
/**
676662
* Will entities and proxies that are loaded into this persistence
677663
* context be made read-only by default?
678-
*
679-
* To determine the read-only/modifiable setting for a particular entity
680-
* or proxy:
681-
* @see PersistenceContext#isReadOnly(Object)
682-
* @see org.hibernate.Session#isReadOnly(Object)
664+
* <p>
665+
* To determine the read-only/modifiable setting for a particular
666+
* entity or proxy, call {@link #isReadOnly(Object)}.
683667
*
684668
* @return true, loaded entities/proxies will be made read-only by default;
685669
* false, loaded entities/proxies will be made modifiable by default.
686670
*
687671
* @see org.hibernate.Session#isDefaultReadOnly()
672+
* @see org.hibernate.Session#isReadOnly(Object)
688673
*/
689674
boolean isDefaultReadOnly();
690675

691676
/**
692677
* Change the default for entities and proxies loaded into this persistence
693678
* context from modifiable to read-only mode, or from read-only mode to
694679
* modifiable.
695-
*
680+
* <p>
696681
* Read-only entities are not dirty-checked and snapshots of persistent
697682
* state are not maintained. Read-only entities can be modified, but
698683
* changes are not persisted.
699-
*
684+
* <p>
700685
* When a proxy is initialized, the loaded entity will have the same
701686
* read-only/modifiable setting as the uninitialized
702687
* proxy has, regardless of the persistence context's current setting.
703-
*
688+
* <p>
704689
* To change the read-only/modifiable setting for a particular entity
705-
* or proxy that is already in this session:
706-
+ * @see PersistenceContext#setReadOnly(Object,boolean)
707-
* @see org.hibernate.Session#setReadOnly(Object, boolean)
708-
*
709-
* To override this session's read-only/modifiable setting for entities
710-
* and proxies loaded by a Query:
711-
* @see Query#setReadOnly(boolean)
690+
* or proxy that is already in this session, call
691+
* {@link #setReadOnly(Object,boolean)}.
712692
*
713693
* @param readOnly true, the default for loaded entities/proxies is read-only;
714694
* false, the default for loaded entities/proxies is modifiable
715695
*
716696
* @see org.hibernate.Session#setDefaultReadOnly(boolean)
697+
* @see org.hibernate.query.Query#setReadOnly(boolean)
698+
* @see org.hibernate.Session#isReadOnly(Object)
717699
*/
718700
void setDefaultReadOnly(boolean readOnly);
719701

@@ -733,25 +715,25 @@ EntityHolder claimEntityHolderIfPossible(
733715
/**
734716
* Set an unmodified persistent object to read-only mode, or a read-only
735717
* object to modifiable mode.
736-
*
718+
* <p>
737719
* Read-only entities are not dirty-checked and snapshots of persistent
738720
* state are not maintained. Read-only entities can be modified, but
739721
* changes are not persisted.
740-
*
722+
* <p>
741723
* When a proxy is initialized, the loaded entity will have the same
742724
* read-only/modifiable setting as the uninitialized
743725
* proxy has, regardless of the session's current setting.
744-
*
726+
* <p>
745727
* If the entity or proxy already has the specified read-only/modifiable
746728
* setting, then this method does nothing.
747729
*
748730
* @param entityOrProxy an entity or proxy
749-
* @param readOnly if {@code true}, the entity or proxy is made read-only; otherwise, the entity or proxy is made
750-
* modifiable.
731+
* @param readOnly if {@code true}, the entity or proxy is made read-only;
732+
* otherwise, the entity or proxy is made modifiable.
751733
*
752734
* @see org.hibernate.Session#setDefaultReadOnly
753735
* @see org.hibernate.Session#setReadOnly
754-
* @see Query#setReadOnly
736+
* @see org.hibernate.query.Query#setReadOnly
755737
*/
756738
void setReadOnly(Object entityOrProxy, boolean readOnly);
757739

0 commit comments

Comments
 (0)