clean up yet more warnings, and remove some obsolete code

This commit is contained in:
Gavin King 2022-01-23 02:56:07 +01:00
parent 24627b214f
commit b7802f5eb6
26 changed files with 280 additions and 355 deletions

View File

@ -355,7 +355,7 @@ public final class Cascade {
}
else {
// Else, we must delete after the updates.
eventSource.delete( entityName, loadedValue, isCascadeDeleteEnabled, new HashSet() );
eventSource.delete( entityName, loadedValue, isCascadeDeleteEnabled, new HashSet<>() );
}
}
}
@ -537,7 +537,7 @@ public final class Cascade {
LOG.tracev( "Cascade {0} for collection: {1}", action, collectionType.getRole() );
}
final Iterator itr = action.getCascadableChildrenIterator( eventSource, collectionType, child );
final Iterator<?> itr = action.getCascadableChildrenIterator( eventSource, collectionType, child );
while ( itr.hasNext() ) {
cascadeProperty(
action,
@ -564,7 +564,7 @@ public final class Cascade {
&& elemType.isEntityType()
&& child instanceof PersistentCollection
// a newly instantiated collection can't have orphans
&& ! ( (PersistentCollection) child ).isNewlyInstantiated();
&& ! ( (PersistentCollection<?>) child ).isNewlyInstantiated();
if ( deleteOrphans ) {
final boolean traceEnabled = LOG.isTraceEnabled();
@ -575,7 +575,7 @@ public final class Cascade {
// 1. newly instantiated collections
// 2. arrays (we can't track orphans for detached arrays)
final String entityName = collectionType.getAssociatedEntityName( eventSource.getFactory() );
deleteOrphans( eventSource, entityName, (PersistentCollection) child );
deleteOrphans( eventSource, entityName, (PersistentCollection<?>) child );
if ( traceEnabled ) {
LOG.tracev( "Done deleting orphans for collection: {0}", collectionType.getRole() );
@ -586,9 +586,9 @@ public final class Cascade {
/**
* Delete any entities that were removed from the collection
*/
private static void deleteOrphans(EventSource eventSource, String entityName, PersistentCollection pc) throws HibernateException {
private static void deleteOrphans(EventSource eventSource, String entityName, PersistentCollection<?> pc) {
//TODO: suck this logic into the collection!
final Collection orphans;
final Collection<?> orphans;
if ( pc.wasInitialized() ) {
final CollectionEntry ce = eventSource.getPersistenceContextInternal().getCollectionEntry( pc );
orphans = ce==null
@ -602,7 +602,7 @@ public final class Cascade {
for ( Object orphan : orphans ) {
if ( orphan != null ) {
LOG.tracev( "Deleting orphaned entity instance: {0}", entityName );
eventSource.delete( entityName, orphan, false, new HashSet() );
eventSource.delete( entityName, orphan, false, new HashSet<>() );
}
}
}

View File

@ -41,7 +41,7 @@ public final class Collections {
* @param coll The collection to be updated by un-reachability.
* @param session The session
*/
public static void processUnreachableCollection(PersistentCollection coll, SessionImplementor session) {
public static void processUnreachableCollection(PersistentCollection<?> coll, SessionImplementor session) {
if ( coll.getOwner() == null ) {
processNeverReferencedCollection( coll, session );
}
@ -50,7 +50,7 @@ public final class Collections {
}
}
private static void processDereferencedCollection(PersistentCollection coll, SessionImplementor session) {
private static void processDereferencedCollection(PersistentCollection<?> coll, SessionImplementor session) {
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final CollectionEntry entry = persistenceContext.getCollectionEntry( coll );
final CollectionPersister loadedPersister = entry.getLoadedPersister();
@ -107,7 +107,7 @@ public final class Collections {
}
private static void processNeverReferencedCollection(PersistentCollection coll, SessionImplementor session)
private static void processNeverReferencedCollection(PersistentCollection<?> coll, SessionImplementor session)
throws HibernateException {
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final CollectionEntry entry = persistenceContext.getCollectionEntry( coll );
@ -140,7 +140,7 @@ public final class Collections {
* @param session The session from which this request originates
*/
public static void processReachableCollection(
PersistentCollection collection,
PersistentCollection<?> collection,
CollectionType type,
Object entity,
SessionImplementor session) {
@ -234,9 +234,8 @@ public final class Collections {
* 2. decide if the collection needs deleting/creating/updating (but
* don't actually schedule the action yet)
*/
@SuppressWarnings( {"JavaDoc"})
private static void prepareCollectionForUpdate(
PersistentCollection collection,
PersistentCollection<?> collection,
CollectionEntry entry,
SessionFactoryImplementor factory) {
if ( entry.isProcessed() ) {

View File

@ -51,7 +51,7 @@ public class EntityEntryContext {
private transient IdentityHashMap<Object,ManagedEntity> nonEnhancedEntityXref;
@SuppressWarnings( {"unchecked"})
@SuppressWarnings("unchecked")
private transient Map.Entry<Object,EntityEntry>[] reentrantSafeEntries = new Map.Entry[0];
private transient boolean dirty;
@ -76,14 +76,13 @@ public class EntityEntryContext {
// any addition (even the double one described above) should invalidate the cross-ref array
dirty = true;
assert AbstractEntityEntry.class.isInstance( entityEntry );
assert entityEntry instanceof AbstractEntityEntry;
// We only need to check a mutable EntityEntry is associated with the same PersistenceContext.
// Immutable EntityEntry can be associated with multiple PersistenceContexts, so no need to check.
// ImmutableEntityEntry#getPersistenceContext() throws an exception (HHH-10251).
if ( entityEntry.getPersister().isMutable() ) {
assert AbstractEntityEntry.class.cast( entityEntry ).getPersistenceContext() == persistenceContext;
}
assert !entityEntry.getPersister().isMutable()
|| ( (AbstractEntityEntry) entityEntry ).getPersistenceContext() == persistenceContext;
// Determine the appropriate ManagedEntity instance to use based on whether the entity is enhanced or not.
// Throw an exception if entity is a mutable ManagedEntity that is associated with a different
@ -91,7 +90,7 @@ public class EntityEntryContext {
ManagedEntity managedEntity = getAssociatedManagedEntity( entity );
final boolean alreadyAssociated = managedEntity != null;
if ( !alreadyAssociated ) {
if ( ManagedEntity.class.isInstance( entity ) ) {
if (entity instanceof ManagedEntity) {
if ( entityEntry.getPersister().isMutable() ) {
managedEntity = (ManagedEntity) entity;
// We know that managedEntity is not associated with the same PersistenceContext.
@ -150,7 +149,7 @@ public class EntityEntryContext {
}
private ManagedEntity getAssociatedManagedEntity(Object entity) {
if ( ManagedEntity.class.isInstance( entity ) ) {
if (entity instanceof ManagedEntity) {
final ManagedEntity managedEntity = (ManagedEntity) entity;
if ( managedEntity.$$_hibernate_getEntityEntry() == null ) {
// it is not associated
@ -247,12 +246,12 @@ public class EntityEntryContext {
dirty = true;
if ( ImmutableManagedEntityHolder.class.isInstance( managedEntity ) ) {
if (managedEntity instanceof ImmutableManagedEntityHolder) {
assert entity == ( (ImmutableManagedEntityHolder) managedEntity ).managedEntity;
immutableManagedEntityXref.remove( entity );
}
else if ( !ManagedEntity.class.isInstance( entity ) ) {
else if ( !(entity instanceof ManagedEntity) ) {
nonEnhancedEntityXref.remove( entity );
}
@ -488,10 +487,14 @@ public class EntityEntryContext {
EntityEntry entry = null;
final String entityEntryClassName = new String( entityEntryClassNameArr );
final Class entityEntryClass = rtn.getSession().getFactory().getServiceRegistry().getService( ClassLoaderService.class ).classForName( entityEntryClassName );
final Class<?> entityEntryClass =
rtn.getSession().getFactory().getServiceRegistry()
.getService( ClassLoaderService.class )
.classForName( entityEntryClassName );
try {
final Method deserializeMethod = entityEntryClass.getDeclaredMethod( "deserialize", ObjectInputStream.class, PersistenceContext.class );
final Method deserializeMethod =
entityEntryClass.getDeclaredMethod( "deserialize", ObjectInputStream.class, PersistenceContext.class );
entry = (EntityEntry) deserializeMethod.invoke( null, ois, rtn );
}
catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
@ -556,7 +559,7 @@ public class EntityEntryContext {
}
private static class ImmutableManagedEntityHolder implements ManagedEntity {
private ManagedEntity managedEntity;
private final ManagedEntity managedEntity;
private ManagedEntity previous;
private ManagedEntity next;
@ -627,21 +630,10 @@ public class EntityEntryContext {
/*
Check instance type of EntityEntry and if type is ImmutableEntityEntry, check to see if entity is referenced cached in the second level cache
*/
private boolean canClearEntityEntryReference(){
if( managedEntity.$$_hibernate_getEntityEntry() == null ) {
return true;
}
if( !(managedEntity.$$_hibernate_getEntityEntry() instanceof ImmutableEntityEntry) ) {
return true;
}
else if( managedEntity.$$_hibernate_getEntityEntry().getPersister().canUseReferenceCacheEntries() ) {
return false;
}
return true;
private boolean canClearEntityEntryReference() {
EntityEntry entityEntry = managedEntity.$$_hibernate_getEntityEntry();
return !(entityEntry instanceof ImmutableEntityEntry)
|| !entityEntry.getPersister().canUseReferenceCacheEntries();
}
}

View File

@ -38,7 +38,7 @@ public class EntityEntryExtraStateHolder implements EntityEntryExtraState {
}
}
@Override
@Override @SuppressWarnings("unchecked")
public <T extends EntityEntryExtraState> T getExtraState(Class<T> extraStateType) {
if ( next == null ) {
return null;

View File

@ -144,7 +144,7 @@ public final class ForeignKeys {
// or 2) returnedValue was initialized, but not nullified.
// When bytecode-enhancement is used for dirty-checking, the change should
// only be tracked when returnedValue was nullified (1)).
if ( value != returnedValue && returnedValue == null && SelfDirtinessTracker.class.isInstance( self ) ) {
if ( value != returnedValue && returnedValue == null && self instanceof SelfDirtinessTracker ) {
( (SelfDirtinessTracker) self ).$$_hibernate_trackChange( propertyName );
}
return returnedValue;
@ -214,7 +214,7 @@ public final class ForeignKeys {
// case we definitely need to nullify
if ( object == self ) {
return isEarlyInsert
|| ( isDelete && session.getFactory().getDialect().hasSelfReferentialForeignKeyBug() );
|| ( isDelete && session.getFactory().getDialect().hasSelfReferentialForeignKeyBug() );
}
// See if the entity is already bound to this session, if not look at the

View File

@ -39,8 +39,7 @@ public final class ImmutableEntityEntry extends AbstractEntityEntry {
final LockMode lockMode,
final boolean existsInDatabase,
final EntityPersister persister,
final boolean disableVersionIncrement,
final PersistenceContext persistenceContext) {
final boolean disableVersionIncrement) {
super(
status,
@ -60,7 +59,6 @@ public final class ImmutableEntityEntry extends AbstractEntityEntry {
/**
* This for is used during custom deserialization handling
*/
@SuppressWarnings( {"JavaDoc"})
private ImmutableEntityEntry(
final SessionFactoryImplementor factory,
final String entityName,

View File

@ -51,8 +51,7 @@ public class ImmutableEntityEntryFactory implements EntityEntryFactory {
lockMode,
existsInDatabase,
persister,
disableVersionIncrement,
persistenceContext
disableVersionIncrement
);
}
}

View File

@ -8,11 +8,9 @@ package org.hibernate.engine.internal;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.persister.entity.Joinable;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.persister.entity.PropertyMapping;
import org.hibernate.type.AssociationType;
/**

View File

@ -25,27 +25,6 @@ import org.hibernate.persister.entity.EntityPersister;
* @author <a href="mailto:sanne@hibernate.org">Sanne Grinovero </a>
*/
public final class MutableEntityEntry extends AbstractEntityEntry {
/**
* @deprecated the tenantId and entityMode parameters where removed: this constructor accepts but ignores them.
* Use the other constructor!
*/
@Deprecated
public MutableEntityEntry(
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 String tenantId,
final boolean disableVersionIncrement,
final PersistenceContext persistenceContext) {
this( status, loadedState, rowId, id, version, lockMode, existsInDatabase,
persister,disableVersionIncrement, persistenceContext
);
}
public MutableEntityEntry(
final Status status,
@ -66,7 +45,6 @@ public final class MutableEntityEntry extends AbstractEntityEntry {
/**
* This for is used during custom deserialization handling
*/
@SuppressWarnings( {"JavaDoc"})
private MutableEntityEntry(
final SessionFactoryImplementor factory,
final String entityName,

View File

@ -717,12 +717,7 @@ public class NaturalIdResolutionsImpl implements NaturalIdResolutions, Serializa
return false;
}
final Resolution initial = pkToNaturalIdMap.get( pk );
if ( initial != null ) {
if ( initial.isSame( naturalIdValues ) ) {
return true;
}
}
return false;
return initial != null && initial.isSame( naturalIdValues );
}
public boolean cache(Object pk, Object naturalIdValues) {

View File

@ -153,7 +153,7 @@ public final class Nullability {
if ( collectionElementType.isComponentType() ) {
// check for all components values in the collection
final CompositeType componentType = (CompositeType) collectionElementType;
final Iterator itr = CascadingActions.getLoadedElementsIterator( session, collectionType, value );
final Iterator<?> itr = CascadingActions.getLoadedElementsIterator( session, collectionType, value );
while ( itr.hasNext() ) {
final Object compositeElement = itr.next();
if ( compositeElement != null ) {

View File

@ -35,10 +35,10 @@ public class SessionEventListenerManagerImpl implements SessionEventListenerMana
}
else {
// Resize our existing array and add the new listeners
final SessionEventListener[] newlist = new SessionEventListener[ existing.length + additionalListeners.length ];
System.arraycopy( existing, 0, newlist, 0, existing.length );
System.arraycopy( additionalListeners, 0, newlist, existing.length, additionalListeners.length );
this.listeners = newlist;
final SessionEventListener[] newList = new SessionEventListener[ existing.length + additionalListeners.length ];
System.arraycopy( existing, 0, newList, 0, existing.length );
System.arraycopy( additionalListeners, 0, newList, existing.length, additionalListeners.length );
this.listeners = newList;
}
}

View File

@ -91,7 +91,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
Eagerly Initialized Fields
the following fields are used in all circumstances, and are not worth (or not suited) to being converted into lazy
*/
private SharedSessionContractImplementor session;
private final SharedSessionContractImplementor session;
private EntityEntryContext entityEntryContext;
/*
@ -116,13 +116,13 @@ public class StatefulPersistenceContext implements PersistenceContext {
private HashMap<EntityKey, Object> entitySnapshotsByKey;
// Identity map of array holder ArrayHolder instances, by the array instance
private IdentityHashMap<Object, PersistentCollection> arrayHolders;
private IdentityHashMap<Object, PersistentCollection<?>> arrayHolders;
// Identity map of CollectionEntry instances, by the collection wrapper
private IdentityMap<PersistentCollection, CollectionEntry> collectionEntries;
private IdentityMap<PersistentCollection<?>, CollectionEntry> collectionEntries;
// Collection wrappers, by the CollectionKey
private HashMap<CollectionKey, PersistentCollection> collectionsByKey;
private HashMap<CollectionKey, PersistentCollection<?>> collectionsByKey;
// Set of EntityKeys of deleted objects
private HashSet<EntityKey> nullifiableEntityKeys;
@ -132,11 +132,11 @@ public class StatefulPersistenceContext implements PersistenceContext {
// A list of collection wrappers that were instantiating during result set
// processing, that we will need to initialize at the end of the query
private ArrayList<PersistentCollection> nonlazyCollections;
private ArrayList<PersistentCollection<?>> nonlazyCollections;
// A container for collections we load up when the owning entity is not
// yet loaded ... for now, this is purely transient!
private HashMap<CollectionKey,PersistentCollection> unownedCollections;
private HashMap<CollectionKey,PersistentCollection<?>> unownedCollections;
// Parent entities cache by their child for cascading
// May be empty or not contains all relation
@ -165,7 +165,6 @@ public class StatefulPersistenceContext implements PersistenceContext {
private ConcurrentMap<EntityKey, Object> getOrInitializeProxiesByKey() {
if ( proxiesByKey == null ) {
//noinspection unchecked
proxiesByKey = new ConcurrentReferenceHashMap<>(
INIT_COLL_SIZE,
.75f,
@ -196,16 +195,16 @@ public class StatefulPersistenceContext implements PersistenceContext {
return loadContexts;
}
// @Override
// public void addUnownedCollection(CollectionKey key, PersistentCollection collection) {
// if ( unownedCollections == null ) {
// unownedCollections = CollectionHelper.mapOfSize( INIT_COLL_SIZE );
// }
// unownedCollections.put( key, collection );
// }
//
@Override
public void addUnownedCollection(CollectionKey key, PersistentCollection collection) {
if ( unownedCollections == null ) {
unownedCollections = CollectionHelper.mapOfSize( INIT_COLL_SIZE );
}
unownedCollections.put( key, collection );
}
@Override
public PersistentCollection useUnownedCollection(CollectionKey key) {
public PersistentCollection<?> useUnownedCollection(CollectionKey key) {
return ( unownedCollections == null ) ? null : unownedCollections.remove( key );
}
@ -274,10 +273,10 @@ public class StatefulPersistenceContext implements PersistenceContext {
this.defaultReadOnly = defaultReadOnly;
}
@Override
public boolean hasNonReadOnlyEntities() {
return hasNonReadOnlyEntities;
}
// @Override
// public boolean hasNonReadOnlyEntities() {
// return hasNonReadOnlyEntities;
// }
@Override
public void setEntryStatus(EntityEntry entry, Status status) {
@ -409,7 +408,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
if ( entitiesByKey != null ) {
entity = entitiesByKey.remove( key );
if ( entitiesByUniqueKey != null ) {
final Iterator itr = entitiesByUniqueKey.values().iterator();
final Iterator<?> itr = entitiesByUniqueKey.values().iterator();
while ( itr.hasNext() ) {
if ( itr.next() == entity ) {
itr.remove();
@ -466,7 +465,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public CollectionEntry getCollectionEntry(PersistentCollection coll) {
public CollectionEntry getCollectionEntry(PersistentCollection<?> coll) {
return collectionEntries == null ? null : collectionEntries.get( coll );
}
@ -563,7 +562,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
return e;
}
public EntityEntry addReferenceEntry(
public void addReferenceEntry(
final Object entity,
final Status status) {
@ -571,11 +570,10 @@ public class StatefulPersistenceContext implements PersistenceContext {
entityEntryContext.addEntityEntry( entity, ((ManagedEntity)entity).$$_hibernate_getEntityEntry() );
setHasNonReadOnlyEnties( status );
return ((ManagedEntity)entity).$$_hibernate_getEntityEntry();
}
@Override
public boolean containsCollection(PersistentCollection collection) {
public boolean containsCollection(PersistentCollection<?> collection) {
return collectionEntries != null && collectionEntries.containsKey( collection );
}
@ -690,11 +688,10 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
@SuppressWarnings("unchecked")
public Object narrowProxy(Object proxy, EntityPersister persister, EntityKey key, Object object)
throws HibernateException {
final Class concreteProxyClass = persister.getConcreteProxyClass();
final Class<?> concreteProxyClass = persister.getConcreteProxyClass();
final boolean alreadyNarrow = concreteProxyClass.isInstance( proxy );
if ( !alreadyNarrow ) {
@ -834,7 +831,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public Object getLoadedCollectionOwnerOrNull(PersistentCollection collection) {
public Object getLoadedCollectionOwnerOrNull(PersistentCollection<?> collection) {
final CollectionEntry ce = getCollectionEntry( collection );
if ( ce == null || ce.getLoadedPersister() == null ) {
return null;
@ -851,7 +848,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public Object getLoadedCollectionOwnerIdOrNull(PersistentCollection collection) {
public Object getLoadedCollectionOwnerIdOrNull(PersistentCollection<?> collection) {
return getLoadedCollectionOwnerIdOrNull( getCollectionEntry( collection ) );
}
@ -871,7 +868,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public void addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Object id) {
public void addUninitializedCollection(CollectionPersister persister, PersistentCollection<?> collection, Object id) {
final CollectionEntry ce = new CollectionEntry( collection, persister, id, flushing );
addCollection( collection, ce, id );
if ( persister.getBatchSize() > 1 ) {
@ -880,7 +877,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public void addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection collection) {
public void addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection<?> collection) {
final CollectionEntry ce = new CollectionEntry( persister, collection.getKey() );
addCollection( collection, ce, collection.getKey() );
if ( persister.getBatchSize() > 1 ) {
@ -889,7 +886,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public void addNewCollection(CollectionPersister persister, PersistentCollection collection)
public void addNewCollection(CollectionPersister persister, PersistentCollection<?> collection)
throws HibernateException {
addCollection( collection, persister );
}
@ -901,10 +898,10 @@ public class StatefulPersistenceContext implements PersistenceContext {
* @param entry The entry representing the collection.
* @param key The key of the collection's entry.
*/
private void addCollection(PersistentCollection coll, CollectionEntry entry, Object key) {
private void addCollection(PersistentCollection<?> coll, CollectionEntry entry, Object key) {
getOrInitializeCollectionEntries().put( coll, entry );
final CollectionKey collectionKey = new CollectionKey( entry.getLoadedPersister(), key );
final PersistentCollection old = addCollectionByKey( collectionKey, coll );
final PersistentCollection<?> old = addCollectionByKey( collectionKey, coll );
if ( old != null ) {
if ( old == coll ) {
throw new AssertionFailure( "bug adding collection twice" );
@ -919,7 +916,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
}
private IdentityMap<PersistentCollection, CollectionEntry> getOrInitializeCollectionEntries() {
private IdentityMap<PersistentCollection<?>, CollectionEntry> getOrInitializeCollectionEntries() {
if ( this.collectionEntries == null ) {
this.collectionEntries = IdentityMap.instantiateSequenced( INIT_COLL_SIZE );
}
@ -932,13 +929,13 @@ public class StatefulPersistenceContext implements PersistenceContext {
* @param collection The collection for which we are adding an entry.
* @param persister The collection persister
*/
private void addCollection(PersistentCollection collection, CollectionPersister persister) {
private void addCollection(PersistentCollection<?> collection, CollectionPersister persister) {
final CollectionEntry ce = new CollectionEntry( persister, collection );
getOrInitializeCollectionEntries().put( collection, ce );
}
@Override
public void addInitializedDetachedCollection(CollectionPersister collectionPersister, PersistentCollection collection)
public void addInitializedDetachedCollection(CollectionPersister collectionPersister, PersistentCollection<?> collection)
throws HibernateException {
if ( collection.isUnreferenced() ) {
//treat it just like a new collection
@ -951,7 +948,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public CollectionEntry addInitializedCollection(CollectionPersister persister, PersistentCollection collection, Object id)
public CollectionEntry addInitializedCollection(CollectionPersister persister, PersistentCollection<?> collection, Object id)
throws HibernateException {
final CollectionEntry ce = new CollectionEntry( collection, persister, id, flushing );
ce.postInitialize( collection );
@ -960,12 +957,12 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public PersistentCollection getCollection(CollectionKey collectionKey) {
public PersistentCollection<?> getCollection(CollectionKey collectionKey) {
return collectionsByKey == null ? null : collectionsByKey.get( collectionKey );
}
@Override
public void addNonLazyCollection(PersistentCollection collection) {
public void addNonLazyCollection(PersistentCollection<?> collection) {
if ( nonlazyCollections == null ) {
nonlazyCollections = new ArrayList<>( INIT_COLL_SIZE );
}
@ -977,7 +974,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
initializeNonLazyCollections( PersistentCollection::forceInitialization );
}
protected void initializeNonLazyCollections(Consumer<PersistentCollection> initializeAction ) {
protected void initializeNonLazyCollections(Consumer<PersistentCollection<?>> initializeAction ) {
if ( loadCounter == 0 ) {
LOG.trace( "Initializing non-lazy collections" );
@ -999,12 +996,12 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public PersistentCollection getCollectionHolder(Object array) {
public PersistentCollection<?> getCollectionHolder(Object array) {
return arrayHolders == null ? null : arrayHolders.get( array );
}
@Override
public void addCollectionHolder(PersistentCollection holder) {
public void addCollectionHolder(PersistentCollection<?> holder) {
//TODO:refactor + make this method private
if ( arrayHolders == null ) {
arrayHolders = new IdentityHashMap<>( INIT_COLL_SIZE );
@ -1013,40 +1010,40 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public PersistentCollection removeCollectionHolder(Object array) {
public PersistentCollection<?> removeCollectionHolder(Object array) {
return arrayHolders != null ? arrayHolders.remove( array ) : null;
}
@Override
public Serializable getSnapshot(PersistentCollection coll) {
public Serializable getSnapshot(PersistentCollection<?> coll) {
return getCollectionEntry( coll ).getSnapshot();
}
@Override
public CollectionEntry getCollectionEntryOrNull(Object collection) {
PersistentCollection coll;
if ( collection instanceof PersistentCollection ) {
coll = (PersistentCollection) collection;
//if (collection==null) throw new TransientObjectException("Collection was not yet persistent");
}
else {
coll = getCollectionHolder( collection );
if ( coll == null && collectionEntries != null ) {
//it might be an unwrapped collection reference!
//try to find a wrapper (slowish)
final Iterator<PersistentCollection> wrappers = collectionEntries.keyIterator();
while ( wrappers.hasNext() ) {
final PersistentCollection pc = wrappers.next();
if ( pc.isWrapper( collection ) ) {
coll = pc;
break;
}
}
}
}
return (coll == null) ? null : getCollectionEntry( coll );
}
// @Override
// public CollectionEntry getCollectionEntryOrNull(Object collection) {
// PersistentCollection<?> coll;
// if ( collection instanceof PersistentCollection ) {
// coll = (PersistentCollection<?>) collection;
// //if (collection==null) throw new TransientObjectException("Collection was not yet persistent");
// }
// else {
// coll = getCollectionHolder( collection );
// if ( coll == null && collectionEntries != null ) {
// //it might be an unwrapped collection reference!
// //try to find a wrapper (slowish)
// final Iterator<PersistentCollection<?>> wrappers = collectionEntries.keyIterator();
// while ( wrappers.hasNext() ) {
// final PersistentCollection<?> pc = wrappers.next();
// if ( pc.isWrapper( collection ) ) {
// coll = pc;
// break;
// }
// }
// }
// }
//
// return (coll == null) ? null : getCollectionEntry( coll );
// }
@Override
public Object getProxy(EntityKey key) {
@ -1068,13 +1065,13 @@ public class StatefulPersistenceContext implements PersistenceContext {
return removeProxyByKey( key );
}
@Override
public HashSet getNullifiableEntityKeys() {
if ( nullifiableEntityKeys == null ) {
nullifiableEntityKeys = new HashSet<>();
}
return nullifiableEntityKeys;
}
// @Override
// public HashSet getNullifiableEntityKeys() {
// if ( nullifiableEntityKeys == null ) {
// nullifiableEntityKeys = new HashSet<>();
// }
// return nullifiableEntityKeys;
// }
/**
* @deprecated this will be removed: it provides too wide access, making it hard to optimise the internals
@ -1082,18 +1079,13 @@ public class StatefulPersistenceContext implements PersistenceContext {
*/
@Deprecated
@Override
public Map getEntitiesByKey() {
public Map<EntityKey,Object> getEntitiesByKey() {
return entitiesByKey == null ? Collections.emptyMap() : entitiesByKey;
}
@Override
public Iterator managedEntitiesIterator() {
if ( entitiesByKey == null ) {
return Collections.emptyIterator();
}
else {
return entitiesByKey.values().iterator();
}
public Iterator<Object> managedEntitiesIterator() {
return entitiesByKey == null ? Collections.emptyIterator() : entitiesByKey.values().iterator();
}
@Override
@ -1101,10 +1093,10 @@ public class StatefulPersistenceContext implements PersistenceContext {
return entityEntryContext.getNumberOfManagedEntities();
}
@Override
public Map getEntityEntries() {
return null;
}
// @Override
// public Map getEntityEntries() {
// return null;
// }
/**
* @deprecated We should not expose this directly: the other accessors that have been created as a replacement
@ -1113,15 +1105,15 @@ public class StatefulPersistenceContext implements PersistenceContext {
*/
@Override
@Deprecated
public Map getCollectionEntries() {
public Map<PersistentCollection<?>,CollectionEntry> getCollectionEntries() {
return getOrInitializeCollectionEntries();
}
@Override
public void forEachCollectionEntry(BiConsumer<PersistentCollection, CollectionEntry> action, boolean concurrent) {
public void forEachCollectionEntry(BiConsumer<PersistentCollection<?>, CollectionEntry> action, boolean concurrent) {
if ( collectionEntries != null ) {
if ( concurrent ) {
for ( Entry<PersistentCollection,CollectionEntry> entry : IdentityMap.concurrentEntries( collectionEntries ) ) {
for ( Entry<PersistentCollection<?>,CollectionEntry> entry : IdentityMap.concurrentEntries( collectionEntries ) ) {
action.accept( entry.getKey(), entry.getValue() );
}
}
@ -1132,13 +1124,8 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public Map getCollectionsByKey() {
if ( collectionsByKey == null ) {
return Collections.emptyMap();
}
else {
return collectionsByKey;
}
public Map<CollectionKey,PersistentCollection<?>> getCollectionsByKey() {
return collectionsByKey == null ? Collections.emptyMap() : collectionsByKey;
}
@Override
@ -1308,7 +1295,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
// of the loop-in-loop especially considering this is far more likely the 'edge case'
if ( mergeMap != null ) {
for ( Object o : mergeMap.entrySet() ) {
final Entry mergeMapEntry = (Entry) o;
final Entry<?,?> mergeMapEntry = (Entry<?,?>) o;
if ( mergeMapEntry.getKey() instanceof HibernateProxy ) {
final HibernateProxy proxy = (HibernateProxy) mergeMapEntry.getKey();
if ( persister.isSubclassEntityName( proxy.getHibernateLazyInitializer().getEntityName() ) ) {
@ -1677,7 +1664,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
if ( LOG.isTraceEnabled() ) {
LOG.trace( "Starting deserialization of [" + count + "] entitiesByKey entries" );
}
rtn.entitiesByKey = CollectionHelper.mapOfSize( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count );
rtn.entitiesByKey = CollectionHelper.mapOfSize(Math.max(count, INIT_COLL_SIZE));
for ( int i = 0; i < count; i++ ) {
rtn.entitiesByKey.put( EntityKey.deserialize( ois, sfi ), ois.readObject() );
}
@ -1687,7 +1674,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
LOG.trace( "Starting deserialization of [" + count + "] entitiesByUniqueKey entries" );
}
if ( count != 0 ) {
rtn.entitiesByUniqueKey = CollectionHelper.mapOfSize( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count );
rtn.entitiesByUniqueKey = CollectionHelper.mapOfSize(Math.max(count, INIT_COLL_SIZE));
for ( int i = 0; i < count; i++ ) {
rtn.entitiesByUniqueKey.put( EntityUniqueKey.deserialize( ois, session ), ois.readObject() );
}
@ -1716,7 +1703,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
if ( LOG.isTraceEnabled() ) {
LOG.trace( "Starting deserialization of [" + count + "] entitySnapshotsByKey entries" );
}
rtn.entitySnapshotsByKey = CollectionHelper.mapOfSize( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count );
rtn.entitySnapshotsByKey = CollectionHelper.mapOfSize(Math.max(count, INIT_COLL_SIZE));
for ( int i = 0; i < count; i++ ) {
rtn.entitySnapshotsByKey.put( EntityKey.deserialize( ois, sfi ), ois.readObject() );
}
@ -1727,9 +1714,12 @@ public class StatefulPersistenceContext implements PersistenceContext {
if ( LOG.isTraceEnabled() ) {
LOG.trace( "Starting deserialization of [" + count + "] collectionsByKey entries" );
}
rtn.collectionsByKey = CollectionHelper.mapOfSize( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count );
rtn.collectionsByKey = CollectionHelper.mapOfSize(Math.max(count, INIT_COLL_SIZE));
for ( int i = 0; i < count; i++ ) {
rtn.collectionsByKey.put( CollectionKey.deserialize( ois, session ), (PersistentCollection) ois.readObject() );
rtn.collectionsByKey.put(
CollectionKey.deserialize( ois, session ),
(PersistentCollection<?>) ois.readObject()
);
}
count = ois.readInt();
@ -1737,7 +1727,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
LOG.trace( "Starting deserialization of [" + count + "] collectionEntries entries" );
}
for ( int i = 0; i < count; i++ ) {
final PersistentCollection pc = (PersistentCollection) ois.readObject();
final PersistentCollection<?> pc = (PersistentCollection<?>) ois.readObject();
final CollectionEntry ce = CollectionEntry.deserialize( ois, session );
pc.setCurrentSession( session );
rtn.getOrInitializeCollectionEntries().put( pc, ce );
@ -1748,9 +1738,9 @@ public class StatefulPersistenceContext implements PersistenceContext {
LOG.trace( "Starting deserialization of [" + count + "] arrayHolders entries" );
}
if ( count != 0 ) {
rtn.arrayHolders = new IdentityHashMap<>( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count );
rtn.arrayHolders = new IdentityHashMap<>(Math.max(count, INIT_COLL_SIZE));
for ( int i = 0; i < count; i++ ) {
rtn.arrayHolders.put( ois.readObject(), (PersistentCollection) ois.readObject() );
rtn.arrayHolders.put( ois.readObject(), (PersistentCollection<?>) ois.readObject() );
}
}
@ -1850,7 +1840,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public CollectionEntry removeCollectionEntry(PersistentCollection collection) {
public CollectionEntry removeCollectionEntry(PersistentCollection<?> collection) {
if ( collectionEntries == null ) {
return null;
}
@ -1870,11 +1860,11 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
@Override
public PersistentCollection addCollectionByKey(CollectionKey collectionKey, PersistentCollection persistentCollection) {
public PersistentCollection<?> addCollectionByKey(CollectionKey collectionKey, PersistentCollection<?> persistentCollection) {
if ( collectionsByKey == null ) {
collectionsByKey = CollectionHelper.mapOfSize( INIT_COLL_SIZE );
}
final PersistentCollection old = collectionsByKey.put( collectionKey, persistentCollection );
final PersistentCollection<?> old = collectionsByKey.put( collectionKey, persistentCollection );
return old;
}

View File

@ -11,7 +11,6 @@ import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.Status;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.EntityType;
/**
* Functionality relating to the Hibernate two-phase loading process, that may be reused by persisters

View File

@ -12,12 +12,9 @@ import java.util.function.Supplier;
import org.hibernate.InstantiationException;
import org.hibernate.MappingException;
import org.hibernate.engine.spi.IdentifierValue;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.VersionValue;
import org.hibernate.mapping.KeyValue;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.type.BasicType;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.VersionJavaType;
import org.hibernate.type.descriptor.java.spi.PrimitiveJavaType;
@ -39,8 +36,7 @@ public class UnsavedValueFactory {
KeyValue bootIdMapping,
JavaType<?> idJtd,
Getter getter,
Supplier<?> templateInstanceAccess,
SessionFactoryImplementor sessionFactory) {
Supplier<?> templateInstanceAccess) {
final String unsavedValue = bootIdMapping.getNullValue();
if ( unsavedValue == null ) {
@ -80,21 +76,20 @@ public class UnsavedValueFactory {
* unsaved value by instantiating an instance of the entity and reading the value of its
* version property, or if that is not possible, using the java default value for the type
*/
public static VersionValue getUnsavedVersionValue(
public static <T> VersionValue getUnsavedVersionValue(
KeyValue bootVersionMapping,
VersionJavaType jtd,
VersionJavaType<T> jtd,
Getter getter,
Supplier<?> templateInstanceAccess,
SessionFactoryImplementor sessionFactory) {
Supplier<?> templateInstanceAccess) {
final String unsavedValue = bootVersionMapping.getNullValue();
if ( unsavedValue == null ) {
if ( getter != null && templateInstanceAccess != null ) {
final Object templateInstance = templateInstanceAccess.get();
final Object defaultValue = getter.get( templateInstance );
@SuppressWarnings("unchecked")
final T defaultValue = (T) getter.get( templateInstanceAccess.get() );
// if the version of a newly instantiated object is not the same
// as the version seed value, use that as the unsaved-value
final Object seedValue = jtd.seed( null );
final T seedValue = jtd.seed( null );
return jtd.areEqual( seedValue, defaultValue )
? VersionValue.UNDEFINED
: new VersionValue( defaultValue );
@ -128,7 +123,7 @@ public class UnsavedValueFactory {
*
* @throws InstantiationException if something went wrong
*/
private static Object instantiate(Constructor constructor) {
private static Object instantiate(Constructor<?> constructor) {
try {
return constructor.newInstance();
}
@ -154,7 +149,7 @@ public class UnsavedValueFactory {
String versionUnsavedValue,
Getter versionGetter,
VersionJavaType<X> versionType,
Constructor constructor) {
Constructor<?> constructor) {
if ( versionUnsavedValue == null ) {
if ( constructor!=null ) {

View File

@ -53,7 +53,7 @@ public class Fetch {
private final String name;
private Style(String name) {
Style(String name) {
this.name = name;
}

View File

@ -26,7 +26,7 @@ public class FetchProfile {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( FetchProfile.class );
private final String name;
private Map<String,Fetch> fetches = new HashMap<>();
private final Map<String,Fetch> fetches = new HashMap<>();
private boolean containsJoinFetchedCollection;
private boolean containsJoinFetchedBag;
@ -78,7 +78,7 @@ public class FetchProfile {
if ( Fetch.Style.JOIN == fetch.getStyle() ) {
// first, if this is a bag we need to ignore it if we previously
// processed collection join fetches
if ( BagType.class.isInstance( associationType ) ) {
if ( associationType instanceof BagType ) {
if ( containsJoinFetchedCollection ) {
LOG.containsJoinFetchedCollection( fetchAssociactionRole );
// EARLY EXIT!!!

View File

@ -13,9 +13,7 @@ import java.util.List;
import java.util.Map;
import org.hibernate.engine.query.ParameterRecognitionException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.query.sql.internal.ParameterParser;
import org.hibernate.query.sql.spi.ParameterRecognizer;
/**
@ -26,8 +24,8 @@ import org.hibernate.query.sql.spi.ParameterRecognizer;
*/
public class ParamLocationRecognizer implements ParameterRecognizer {
private Map<String, NamedParameterDescriptor> namedParameterDescriptors;
private Map<Integer, OrdinalParameterDescriptor> ordinalParameterDescriptors;
private Map<String, NamedParameterDescriptor<?>> namedParameterDescriptors;
private Map<Integer, OrdinalParameterDescriptor<?>> ordinalParameterDescriptors;
private Map<String, InFlightNamedParameterState> inFlightNamedStateMap;
private Map<Integer, InFlightOrdinalParameterState> inFlightOrdinalStateMap;
@ -36,26 +34,22 @@ public class ParamLocationRecognizer implements ParameterRecognizer {
private final int jdbcStyleOrdinalCountBase;
private int jdbcStyleOrdinalCount;
public ParamLocationRecognizer() {
this( 1 );
}
public ParamLocationRecognizer(int jdbcStyleOrdinalCountBase) {
this.jdbcStyleOrdinalCountBase = jdbcStyleOrdinalCountBase;
this.jdbcStyleOrdinalCount = jdbcStyleOrdinalCountBase;
}
/**
* Convenience method for creating a param location recognizer and
* initiating the parse.
*/
public static ParamLocationRecognizer parseLocations(
String query,
SessionFactoryImplementor sessionFactory) {
final ParamLocationRecognizer recognizer = new ParamLocationRecognizer( 1 );
ParameterParser.parse( query, recognizer );
return recognizer;
}
// /**
// * Convenience method for creating a param location recognizer and
// * initiating the parse.
// */
// public static ParamLocationRecognizer parseLocations(
// String query,
// SessionFactoryImplementor sessionFactory) {
// final ParamLocationRecognizer recognizer = new ParamLocationRecognizer( 1 );
// ParameterParser.parse( query, recognizer );
// return recognizer;
// }
public void validate() {
if ( inFlightNamedStateMap != null && ( inFlightOrdinalStateMap != null || inFlightJpaOrdinalStateMap != null ) ) {
@ -69,7 +63,7 @@ public class ParamLocationRecognizer implements ParameterRecognizer {
}
if ( inFlightNamedStateMap != null ) {
final Map<String, NamedParameterDescriptor> tmp = new HashMap<>();
final Map<String, NamedParameterDescriptor<?>> tmp = new HashMap<>();
for ( InFlightNamedParameterState inFlightState : inFlightNamedStateMap.values() ) {
tmp.put( inFlightState.name, inFlightState.complete() );
}
@ -83,7 +77,7 @@ public class ParamLocationRecognizer implements ParameterRecognizer {
ordinalParameterDescriptors = Collections.emptyMap();
}
else {
final Map<Integer, OrdinalParameterDescriptor> tmp = new HashMap<>();
final Map<Integer, OrdinalParameterDescriptor<?>> tmp = new HashMap<>();
if ( inFlightOrdinalStateMap != null ) {
for ( InFlightOrdinalParameterState state : inFlightOrdinalStateMap.values() ) {
tmp.put( state.identifier, state.complete() );
@ -102,11 +96,11 @@ public class ParamLocationRecognizer implements ParameterRecognizer {
throw new ParameterRecognitionException( "Mixed parameter strategies - use just one of named, positional or JPA-ordinal strategy" );
}
public Map<String, NamedParameterDescriptor> getNamedParameterDescriptionMap() {
public Map<String, NamedParameterDescriptor<?>> getNamedParameterDescriptionMap() {
return namedParameterDescriptors;
}
public Map<Integer, OrdinalParameterDescriptor> getOrdinalParameterDescriptionMap() {
public Map<Integer, OrdinalParameterDescriptor<?>> getOrdinalParameterDescriptionMap() {
return ordinalParameterDescriptors;
}
@ -193,8 +187,8 @@ public class ParamLocationRecognizer implements ParameterRecognizer {
sourcePositions.add( position );
}
private NamedParameterDescriptor complete() {
return new NamedParameterDescriptor(
private NamedParameterDescriptor<?> complete() {
return new NamedParameterDescriptor<>(
name,
null,
ArrayHelper.toIntArray( sourcePositions )
@ -217,8 +211,8 @@ public class ParamLocationRecognizer implements ParameterRecognizer {
this.sourcePosition = sourcePosition;
}
private OrdinalParameterDescriptor complete() {
return new OrdinalParameterDescriptor(
private OrdinalParameterDescriptor<?> complete() {
return new OrdinalParameterDescriptor<>(
identifier,
valuePosition,
null,
@ -243,8 +237,8 @@ public class ParamLocationRecognizer implements ParameterRecognizer {
sourcePositions.add( position );
}
private OrdinalParameterDescriptor complete() {
return new OrdinalParameterDescriptor(
private OrdinalParameterDescriptor<?> complete() {
return new OrdinalParameterDescriptor<>(
identifier,
identifier - 1,
null,

View File

@ -48,7 +48,7 @@ public interface CascadingAction {
* @param collection The collection instance.
* @return The children iterator.
*/
Iterator getCascadableChildrenIterator(
Iterator<?> getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection);

View File

@ -54,11 +54,11 @@ public class CascadingActions {
Object anything,
boolean isCascadeDeleteEnabled) {
LOG.tracev( "Cascading to delete: {0}", entityName );
session.delete( entityName, child, isCascadeDeleteEnabled, (Set) anything );
session.delete( entityName, child, isCascadeDeleteEnabled, (Set<?>) anything );
}
@Override
public Iterator getCascadableChildrenIterator(
public Iterator<?> getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
@ -106,7 +106,7 @@ public class CascadingActions {
}
@Override
public Iterator getCascadableChildrenIterator(
public Iterator<?> getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
@ -139,11 +139,11 @@ public class CascadingActions {
boolean isCascadeDeleteEnabled)
throws HibernateException {
LOG.tracev( "Cascading to refresh: {0}", entityName );
session.refresh( entityName, child, (Map) anything );
session.refresh( entityName, child, (Map<?,?>) anything );
}
@Override
public Iterator getCascadableChildrenIterator(
public Iterator<?> getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
@ -179,7 +179,7 @@ public class CascadingActions {
}
@Override
public Iterator getCascadableChildrenIterator(
public Iterator<?> getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
@ -220,7 +220,7 @@ public class CascadingActions {
}
@Override
public Iterator getCascadableChildrenIterator(
public Iterator<?> getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
@ -258,11 +258,11 @@ public class CascadingActions {
boolean isCascadeDeleteEnabled)
throws HibernateException {
LOG.tracev( "Cascading to merge: {0}", entityName );
session.merge( entityName, child, (Map) anything );
session.merge( entityName, child, (Map<?,?>) anything );
}
@Override
public Iterator getCascadableChildrenIterator(
public Iterator<?> getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
@ -295,11 +295,11 @@ public class CascadingActions {
boolean isCascadeDeleteEnabled)
throws HibernateException {
LOG.tracev( "Cascading to persist: {0}", entityName );
session.persist( entityName, child, (Map) anything );
session.persist( entityName, child, (Map<?,?>) anything );
}
@Override
public Iterator getCascadableChildrenIterator(
public Iterator<?> getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
@ -338,11 +338,11 @@ public class CascadingActions {
boolean isCascadeDeleteEnabled)
throws HibernateException {
LOG.tracev( "Cascading to persist on flush: {0}", entityName );
session.persistOnFlush( entityName, child, (Map) anything );
session.persistOnFlush( entityName, child, (Map<?,?>) anything );
}
@Override
public Iterator getCascadableChildrenIterator(
public Iterator<?> getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
@ -425,7 +425,7 @@ public class CascadingActions {
}
@Override
public Iterator getCascadableChildrenIterator(
public Iterator<?> getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
@ -470,7 +470,7 @@ public class CascadingActions {
*
* @return The children iterator.
*/
public static Iterator getAllElementsIterator(
public static Iterator<?> getAllElementsIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
@ -481,7 +481,7 @@ public class CascadingActions {
* Iterate just the elements of the collection that are already there. Don't load
* any new elements from the database.
*/
public static Iterator getLoadedElementsIterator(
public static Iterator<?> getLoadedElementsIterator(
SharedSessionContractImplementor session,
CollectionType collectionType,
Object collection) {
@ -492,11 +492,12 @@ public class CascadingActions {
else {
// does not handle arrays (thats ok, cos they can't be lazy)
// or newly instantiated collections, so we can do the cast
return ((PersistentCollection) collection).queuedAdditionIterator();
return ((PersistentCollection<?>) collection).queuedAdditionIterator();
}
}
private static boolean collectionIsInitialized(Object collection) {
return !(collection instanceof PersistentCollection) || ((PersistentCollection) collection).wasInitialized();
return !(collection instanceof PersistentCollection)
|| ((PersistentCollection<?>) collection).wasInitialized();
}
}

View File

@ -14,7 +14,6 @@ import java.util.Collection;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.collection.spi.AbstractPersistentCollection;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.internal.CoreLogging;
@ -63,7 +62,7 @@ public final class CollectionEntry implements Serializable {
/**
* For newly wrapped collections, or dereferenced collection wrappers
*/
public CollectionEntry(CollectionPersister persister, PersistentCollection collection) {
public CollectionEntry(CollectionPersister persister, PersistentCollection<?> collection) {
// new collections that get found + wrapped
// during flush shouldn't be ignored
ignore = false;
@ -80,7 +79,7 @@ public final class CollectionEntry implements Serializable {
* For collections just loaded from the database
*/
public CollectionEntry(
final PersistentCollection collection,
final PersistentCollection<?> collection,
final CollectionPersister loadedPersister,
final Object loadedKey,
final boolean ignore ) {
@ -113,7 +112,7 @@ public final class CollectionEntry implements Serializable {
/**
* For initialized detached collections
*/
public CollectionEntry(PersistentCollection collection, SessionFactoryImplementor factory) throws MappingException {
public CollectionEntry(PersistentCollection<?> collection, SessionFactoryImplementor factory) {
// detached collections that get found + reattached
// during flush shouldn't be ignored
ignore = false;
@ -147,7 +146,7 @@ public final class CollectionEntry implements Serializable {
* Determine if the collection is "really" dirty, by checking dirtiness
* of the collection elements, if necessary
*/
private void dirty(PersistentCollection collection) throws HibernateException {
private void dirty(PersistentCollection<?> collection) throws HibernateException {
final CollectionPersister loadedPersister = getLoadedPersister();
boolean forceDirty = collection.wasInitialized() &&
@ -163,7 +162,7 @@ public final class CollectionEntry implements Serializable {
}
public void preFlush(PersistentCollection collection) throws HibernateException {
public void preFlush(PersistentCollection<?> collection) throws HibernateException {
if ( loadedKey == null && collection.getKey() != null ) {
loadedKey = collection.getKey();
}
@ -196,14 +195,14 @@ public final class CollectionEntry implements Serializable {
setDorecreate( false );
}
public void postInitialize(PersistentCollection collection) throws HibernateException {
public void postInitialize(PersistentCollection<?> collection) throws HibernateException {
final CollectionPersister loadedPersister = getLoadedPersister();
snapshot = loadedPersister.isMutable()
? collection.getSnapshot( loadedPersister )
: null;
collection.setSnapshot(loadedKey, role, snapshot);
if ( loadedPersister.getBatchSize() > 1 ) {
( (AbstractPersistentCollection) collection ).getSession()
( (AbstractPersistentCollection<?>) collection ).getSession()
.getPersistenceContextInternal()
.getBatchFetchQueue()
.removeBatchLoadableCollection( this );
@ -213,7 +212,7 @@ public final class CollectionEntry implements Serializable {
/**
* Called after a successful flush
*/
public void postFlush(PersistentCollection collection) throws HibernateException {
public void postFlush(PersistentCollection<?> collection) throws HibernateException {
if ( isIgnore() ) {
ignore = false;
}
@ -226,7 +225,7 @@ public final class CollectionEntry implements Serializable {
/**
* Called after execution of an action
*/
public void afterAction(PersistentCollection collection) {
public void afterAction(PersistentCollection<?> collection) {
loadedKey = getCurrentKey();
setLoadedPersister( getCurrentPersister() );
@ -262,7 +261,7 @@ public final class CollectionEntry implements Serializable {
* @param collection the persistentcollection to be updated
* @param storedSnapshot the new stored snapshot
*/
public void resetStoredSnapshot(PersistentCollection collection, Serializable storedSnapshot) {
public void resetStoredSnapshot(PersistentCollection<?> collection, Serializable storedSnapshot) {
LOG.debugf("Reset storedSnapshot to %s for %s", storedSnapshot, this);
if ( fromMerge ) {
@ -380,14 +379,14 @@ public final class CollectionEntry implements Serializable {
/**
* Get the collection orphans (entities which were removed from the collection)
*/
public Collection getOrphans(String entityName, PersistentCollection collection) throws HibernateException {
public Collection<?> getOrphans(String entityName, PersistentCollection<?> collection) throws HibernateException {
if ( snapshot == null ) {
throw new AssertionFailure( "no collection snapshot for orphan delete" );
}
return collection.getOrphans( snapshot, entityName );
}
public boolean isSnapshotEmpty(PersistentCollection collection) {
public boolean isSnapshotEmpty(PersistentCollection<?> collection) {
//TODO: does this really need to be here?
// does the collection already have
// it's own up-to-date snapshot?

View File

@ -7,7 +7,6 @@
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;
@ -37,14 +36,12 @@ import org.hibernate.sql.results.spi.LoadContexts;
* @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();
/**
@ -61,13 +58,13 @@ public interface PersistenceContext {
*/
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);
// /**
// * 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
@ -79,7 +76,7 @@ public interface PersistenceContext {
*
* @return The unowned collection, or {@code null}
*/
PersistentCollection useUnownedCollection(CollectionKey key);
PersistentCollection<?> useUnownedCollection(CollectionKey key);
/**
* Get the {@link BatchFetchQueue}, instantiating one if necessary.
@ -93,11 +90,10 @@ public interface PersistenceContext {
*/
void clear();
/**
* @return false if we know for certain that all the entities are read-only
*/
@SuppressWarnings( {"UnusedDeclaration"})
boolean hasNonReadOnlyEntities();
// /**
// * @return false if we know for certain that all the entities are read-only
// */
// boolean hasNonReadOnlyEntities();
/**
* Set the status of an entry
@ -233,7 +229,7 @@ public interface PersistenceContext {
*
* @return The matching collection entry
*/
CollectionEntry getCollectionEntry(PersistentCollection coll);
CollectionEntry getCollectionEntry(PersistentCollection<?> coll);
/**
* Adds an entity to the internal caches.
@ -268,7 +264,7 @@ public interface PersistenceContext {
/**
* Is the given collection associated with this persistence context?
*/
boolean containsCollection(PersistentCollection collection);
boolean containsCollection(PersistentCollection<?> collection);
/**
* Is the given proxy associated with this persistence context?
@ -280,7 +276,6 @@ public interface PersistenceContext {
*
* @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) ;
@ -302,7 +297,6 @@ public interface PersistenceContext {
*
* @param maybeProxy The reference to be unproxied if it currently represents a proxy.
* @return The unproxied instance.
* @throws HibernateException
*/
Object unproxyAndReassociate(Object maybeProxy);
@ -311,8 +305,6 @@ public interface PersistenceContext {
* current session.
*
* @param object The entity reference against which to perform the uniqueness check.
*
* @throws HibernateException
*/
void checkUniqueness(EntityKey key, Object object);
@ -327,7 +319,6 @@ public interface PersistenceContext {
* @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);
@ -363,7 +354,7 @@ public interface PersistenceContext {
* @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);
Object getLoadedCollectionOwnerOrNull(PersistentCollection<?> collection);
/**
* Get the ID for the entity that owned this persistent collection when it was loaded
@ -371,24 +362,24 @@ public interface PersistenceContext {
* @param collection The persistent collection
* @return the owner ID if available from the collection's loaded key; otherwise, returns null
*/
Object getLoadedCollectionOwnerIdOrNull(PersistentCollection collection);
Object getLoadedCollectionOwnerIdOrNull(PersistentCollection<?> collection);
/**
* add a collection we just loaded up (still needs initializing)
*/
void addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Object id);
void addUninitializedCollection(CollectionPersister persister, PersistentCollection<?> collection, Object id);
/**
* add a detached uninitialized collection
*/
void addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection 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);
void addNewCollection(CollectionPersister persister, PersistentCollection<?> collection);
/**
* add an (initialized) collection that was created by another session and passed
@ -396,26 +387,26 @@ public interface PersistenceContext {
*/
void addInitializedDetachedCollection(
CollectionPersister collectionPersister,
PersistentCollection collection);
PersistentCollection<?> collection);
/**
* add a collection we just pulled out of the cache (does not need initializing)
*/
CollectionEntry addInitializedCollection(
CollectionPersister persister,
PersistentCollection collection,
PersistentCollection<?> collection,
Object id);
/**
* Get the collection instance associated with the {@code CollectionKey}
*/
PersistentCollection getCollection(CollectionKey collectionKey);
PersistentCollection<?> getCollection(CollectionKey collectionKey);
/**
* Register a collection for non-lazy loading at the end of the
* two-phase load
*/
void addNonLazyCollection(PersistentCollection collection);
void addNonLazyCollection(PersistentCollection<?> collection);
/**
* Force initialization of all non-lazy collections encountered during
@ -427,36 +418,36 @@ public interface PersistenceContext {
/**
* Get the {@code PersistentCollection} object for an array
*/
PersistentCollection getCollectionHolder(Object array);
PersistentCollection<?> getCollectionHolder(Object array);
/**
* Register a {@code PersistentCollection} 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);
void addCollectionHolder(PersistentCollection<?> holder);
/**
* Remove the mapping of collection to holder during eviction
* of the owning entity
*/
PersistentCollection removeCollectionHolder(Object array);
PersistentCollection<?> removeCollectionHolder(Object array);
/**
* Get the snapshot of the pre-flush collection state
*/
Serializable getSnapshot(PersistentCollection coll);
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 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
@ -479,12 +470,12 @@ public interface PersistenceContext {
*/
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();
// /**
// * 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
@ -492,7 +483,7 @@ public interface PersistenceContext {
* for specific access needs. Consider using #iterateEntities instead.
*/
@Deprecated
Map getEntitiesByKey();
Map<EntityKey,Object> getEntitiesByKey();
/**
* Provides access to the entity/EntityEntry combos associated with the persistence context in a manner that
@ -500,15 +491,15 @@ public interface PersistenceContext {
*/
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();
// /**
// * 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();
@ -517,14 +508,14 @@ public interface PersistenceContext {
* @deprecated use {@link #removeCollectionEntry(PersistentCollection)} or {@link #getCollectionEntriesSize()}, {@link #forEachCollectionEntry(BiConsumer,boolean)}.
*/
@Deprecated
Map getCollectionEntries();
Map<PersistentCollection<?>,CollectionEntry> 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);
void forEachCollectionEntry(BiConsumer<PersistentCollection<?>,CollectionEntry> action, boolean concurrent);
/**
* Get the mapping from collection key to collection instance
@ -534,7 +525,7 @@ public interface PersistenceContext {
* N.B. This might return an immutable map: do not use for mutations!
*/
@Deprecated
Map getCollectionsByKey();
Map<CollectionKey,PersistentCollection<?>> getCollectionsByKey();
/**
* How deep are we cascaded?
@ -554,7 +545,6 @@ public interface PersistenceContext {
/**
* Is a flush cycle currently in process?
*/
@SuppressWarnings( {"UnusedDeclaration"})
boolean isFlushing();
/**
@ -774,7 +764,7 @@ public interface PersistenceContext {
* @param collection the collection to remove
* @return the matching {@link CollectionEntry}, if any was removed.
*/
CollectionEntry removeCollectionEntry(PersistentCollection collection);
CollectionEntry removeCollectionEntry(PersistentCollection<?> collection);
/**
* Remove all state of the collections-by-key map.
@ -787,7 +777,7 @@ public interface PersistenceContext {
* @param persistentCollection
* @return the previous collection, it the key was already mapped.
*/
PersistentCollection addCollectionByKey(CollectionKey collectionKey, PersistentCollection persistentCollection);
PersistentCollection<?> addCollectionByKey(CollectionKey collectionKey, PersistentCollection<?> persistentCollection);
/**
* Remove a collection-by-key mapping.
@ -798,7 +788,7 @@ public interface PersistenceContext {
/**
* A read-only iterator on all entities managed by this persistence context
*/
Iterator managedEntitiesIterator();
Iterator<Object> managedEntitiesIterator();
/**
* Access to the natural-id helper for this persistence context

View File

@ -10,7 +10,6 @@ import org.hibernate.HibernateException;
import org.hibernate.Incubating;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.WrongClassException;
import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.entry.CacheEntry;
import org.hibernate.cache.spi.entry.ReferenceCacheEntryImpl;
@ -308,7 +307,9 @@ public class CacheEntityLoaderHelper {
if ( entity == null ) {
throw new IllegalStateException(
"Reference cache entry contained null : " + referenceCacheEntry.toString() );
"Reference cache entry contained null : "
+ referenceCacheEntry.toString()
);
}
else {
makeEntityCircularReferenceSafe( referenceCacheEntry, session, entity, entityKey );
@ -366,10 +367,9 @@ public class CacheEntityLoaderHelper {
final Object entity;
subclassPersister = factory.getEntityPersister( entry.getSubclass() );
final Object optionalObject = instanceToLoad;
entity = optionalObject == null
entity = instanceToLoad == null
? source.instantiate( subclassPersister, entityId )
: optionalObject;
: instanceToLoad;
// make it circular-reference safe
TwoPhaseLoad.addUninitializedCachedEntity(
@ -437,7 +437,7 @@ public class CacheEntityLoaderHelper {
public static class PersistenceContextEntry {
private final Object entity;
private EntityStatus status;
private final EntityStatus status;
public PersistenceContextEntry(Object entity, EntityStatus status) {
this.entity = entity;

View File

@ -97,8 +97,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa
bootEntityDescriptor.getIdentifier(),
getJavaType(),
propertyAccess.getGetter(),
instanceCreator,
sessionFactory
instanceCreator
);
}

View File

@ -63,7 +63,7 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti
String attributeName,
String columnTableExpression,
String columnExpression,
BasicType versionBasicType,
BasicType<?> versionBasicType,
EntityMappingType declaringType,
MappingModelCreationProcess creationProcess) {
this.attributeName = attributeName;
@ -76,13 +76,12 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti
unsavedValueStrategy = UnsavedValueFactory.getUnsavedVersionValue(
(KeyValue) bootEntityDescriptor.getVersion().getValue(),
(VersionJavaType) versionBasicType.getJavaTypeDescriptor(),
(VersionJavaType<?>) versionBasicType.getJavaTypeDescriptor(),
declaringType
.getRepresentationStrategy()
.resolvePropertyAccess( bootEntityDescriptor.getVersion() )
.getGetter(),
templateInstanceAccess,
creationProcess.getCreationContext().getSessionFactory()
templateInstanceAccess
);
}

View File

@ -146,7 +146,7 @@ public class StatelessSessionPersistentContextTest {
"StatelessSession: PersistenceContext has not been cleared"
);
assertTrue(
persistenceContextInternal.getCollectionsByKey() == Collections.emptyMap(),
persistenceContextInternal.getCollectionsByKey() == Collections.EMPTY_MAP,
"StatelessSession: PersistenceContext has not been cleared"
);
}