Package org.hibernate.collection.spi
Class PersistentMap<K,E>
- java.lang.Object
-
- org.hibernate.collection.spi.AbstractPersistentCollection<E>
-
- org.hibernate.collection.spi.PersistentMap<K,E>
-
- All Implemented Interfaces:
Serializable
,Map<K,E>
,LazyInitializable
,PersistentCollection<E>
- Direct Known Subclasses:
PersistentSortedMap
@Incubating public class PersistentMap<K,E> extends AbstractPersistentCollection<E> implements Map<K,E>
A persistent wrapper for aMap
. Underlying collection is aHashMap
.- See Also:
- Serialized Form
- API Note:
- Incubating in terms of making this non-internal. These contracts will be getting cleaned up in following releases.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.hibernate.collection.spi.AbstractPersistentCollection
AbstractPersistentCollection.AbstractValueDelayedOperation, AbstractPersistentCollection.DelayedOperation<E>, AbstractPersistentCollection.IteratorProxy<E>, AbstractPersistentCollection.LazyInitializationWork<T>, AbstractPersistentCollection.ListIteratorProxy, AbstractPersistentCollection.ListProxy, AbstractPersistentCollection.SetProxy<E>, AbstractPersistentCollection.ValueDelayedOperation<E>
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<K,E>
map
-
Fields inherited from class org.hibernate.collection.spi.AbstractPersistentCollection
elementRemoved, UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description PersistentMap()
Empty constructor.PersistentMap(SharedSessionContractImplementor session)
Instantiates a lazy map (the underlying map is un-initialized).PersistentMap(SharedSessionContractImplementor session, Map<K,E> map)
Instantiates a non-lazy map (the underlying map is constructed from the incoming map reference).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
Object
disassemble(CollectionPersister persister)
Disassemble the collection to get it ready for the cacheboolean
empty()
Is the collection empty? (don't try to initialize the collection)Iterator<Map.Entry<K,E>>
entries(CollectionPersister persister)
Iterate all collection entries, during update of the databaseboolean
entryExists(Object entry, int i)
Does the given element/entry exist in the collection?Set<Map.Entry<K,E>>
entrySet()
boolean
equals(Object other)
boolean
equalsSnapshot(CollectionPersister persister)
Does the current state exactly match the snapshot?E
get(Object key)
Iterator<?>
getDeletes(CollectionPersister persister, boolean indexIsFormula)
Get all the elements that need deletingObject
getElement(Object entry)
Get the value of the given collection entry.Object
getIndex(Object entry, int i, CollectionPersister persister)
Get the index of the given collection entryCollection<E>
getOrphans(Serializable snapshot, String entityName)
get all "orphaned" elementsSerializable
getSnapshot(CollectionPersister persister)
Return a new snapshot of the current state of the collectionObject
getSnapshotElement(Object entry, int i)
Get the snapshot value of the given collection entryint
hashCode()
void
initializeEmptyCollection(CollectionPersister persister)
void
initializeFromCache(CollectionPersister persister, Object disassembled, Object owner)
Read the state of the collection from a disassembled cached valuevoid
injectLoadedState(PluralAttributeMapping attributeMapping, List<?> loadingState)
Inject the state loaded for a collection instance.boolean
isEmpty()
boolean
isSnapshotEmpty(Serializable snapshot)
Is the snapshot empty?boolean
isWrapper(Object collection)
Is this the wrapper for the given collection instance?Set<K>
keySet()
boolean
needsInserting(Object entry, int i, Type elemType)
Do we need to insert this element?boolean
needsUpdating(Object entry, int i, Type elemType)
Do we need to update this element?E
put(K key, E value)
void
putAll(Map<? extends K,? extends E> puts)
E
remove(Object key)
int
size()
String
toString()
Collection<E>
values()
-
Methods inherited from class org.hibernate.collection.spi.AbstractPersistentCollection
afterInitialize, afterRowInsert, beforeInitialize, beginRead, clearDirty, clearOperationQueue, dirty, elementByIndex, elementExists, endRead, forceInitialization, getCachedSize, getIdentifier, getKey, getOrphans, getOwner, getQueuedOrphans, getRole, getSession, getSize, getSnapshot, getStoredSnapshot, getValue, hasQueuedOperations, identityRemove, initialize, isClearQueueEnabled, isConnectedToSession, isDirectlyAccessible, isDirty, isElementRemoved, isInitialized, isInitializing, isInverseCollection, isInverseCollectionNoOrphanDelete, isInverseOneToManyOrNoOrphanDelete, isOperationQueueEnabled, isPutQueueEnabled, isRowUpdatePossible, isUnreferenced, needsRecreate, performQueuedOperations, postAction, preInsert, prepareForPossibleLoadingOutsideTransaction, queuedAdditionIterator, queueOperation, read, readElementByIndex, readElementExistence, readIndexExistence, readSize, replaceQueuedOperationValues, setCurrentSession, setDirectlyAccessible, setInitialized, setOwner, setSnapshot, unsetSession, wasInitialized, write
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Methods inherited from interface org.hibernate.collection.spi.PersistentCollection
includeInInsert, includeInRecreate, isDirectlyProvidedCollection, isNewlyInstantiated, needsUpdating, render
-
-
-
-
Constructor Detail
-
PersistentMap
public PersistentMap()
Empty constructor.Note: this form is not ever ever ever used by Hibernate; it is, however, needed for SOAP libraries and other such marshalling code.
-
PersistentMap
public PersistentMap(SharedSessionContractImplementor session)
Instantiates a lazy map (the underlying map is un-initialized).- Parameters:
session
- The session to which this map will belong.
-
PersistentMap
public PersistentMap(SharedSessionContractImplementor session, Map<K,E> map)
Instantiates a non-lazy map (the underlying map is constructed from the incoming map reference).- Parameters:
session
- The session to which this map will belong.map
- The underlying map data.
-
-
Method Detail
-
getSnapshot
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException
Description copied from interface:PersistentCollection
Return a new snapshot of the current state of the collection- Specified by:
getSnapshot
in interfacePersistentCollection<K>
- Parameters:
persister
- The collection persister- Returns:
- The snapshot
- Throws:
HibernateException
-
getOrphans
public Collection<E> getOrphans(Serializable snapshot, String entityName) throws HibernateException
Description copied from interface:PersistentCollection
get all "orphaned" elements- Specified by:
getOrphans
in interfacePersistentCollection<K>
- Specified by:
getOrphans
in classAbstractPersistentCollection<E>
- Parameters:
snapshot
- The snapshot stateentityName
- The name of the entity that are the elements of the collection- Returns:
- The orphans
- Throws:
HibernateException
-
initializeEmptyCollection
public void initializeEmptyCollection(CollectionPersister persister)
- Specified by:
initializeEmptyCollection
in interfacePersistentCollection<K>
-
equalsSnapshot
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException
Description copied from interface:PersistentCollection
Does the current state exactly match the snapshot?- Specified by:
equalsSnapshot
in interfacePersistentCollection<K>
- Parameters:
persister
- The collection persister- Returns:
true
if the current state and the snapshot state match.- Throws:
HibernateException
-
isSnapshotEmpty
public boolean isSnapshotEmpty(Serializable snapshot)
Description copied from interface:PersistentCollection
Is the snapshot empty?- Specified by:
isSnapshotEmpty
in interfacePersistentCollection<K>
- Parameters:
snapshot
- The snapshot to check- Returns:
true
if the given snapshot is empty
-
isWrapper
public boolean isWrapper(Object collection)
Description copied from interface:PersistentCollection
Is this the wrapper for the given collection instance?- Specified by:
isWrapper
in interfacePersistentCollection<K>
- Parameters:
collection
- The collection to check whether this is wrapping it- Returns:
true
if this is a wrapper around that given collection instance.
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,E>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<K,E>
-
empty
public boolean empty()
Description copied from interface:PersistentCollection
Is the collection empty? (don't try to initialize the collection)- Specified by:
empty
in interfacePersistentCollection<K>
- Specified by:
empty
in classAbstractPersistentCollection<E>
- Returns:
false
if the collection is non-empty;true
otherwise.
-
entries
public Iterator<Map.Entry<K,E>> entries(CollectionPersister persister)
Description copied from interface:PersistentCollection
Iterate all collection entries, during update of the database- Specified by:
entries
in interfacePersistentCollection<K>
- Parameters:
persister
- The collection persister.- Returns:
- The iterator
-
injectLoadedState
public void injectLoadedState(PluralAttributeMapping attributeMapping, List<?> loadingState)
Description copied from interface:PersistentCollection
Inject the state loaded for a collection instance.- Specified by:
injectLoadedState
in interfacePersistentCollection<K>
-
initializeFromCache
public void initializeFromCache(CollectionPersister persister, Object disassembled, Object owner) throws HibernateException
Description copied from interface:PersistentCollection
Read the state of the collection from a disassembled cached value- Specified by:
initializeFromCache
in interfacePersistentCollection<K>
- Parameters:
persister
- The collection persisterdisassembled
- The disassembled cached stateowner
- The collection owner- Throws:
HibernateException
-
disassemble
public Object disassemble(CollectionPersister persister) throws HibernateException
Description copied from interface:PersistentCollection
Disassemble the collection to get it ready for the cache- Specified by:
disassemble
in interfacePersistentCollection<K>
- Parameters:
persister
- The collection persister- Returns:
- The disassembled state
- Throws:
HibernateException
-
getDeletes
public Iterator<?> getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException
Description copied from interface:PersistentCollection
Get all the elements that need deleting- Specified by:
getDeletes
in interfacePersistentCollection<K>
- Parameters:
persister
- The collection persisterindexIsFormula
- For indexed collections, tells whether the index is a formula (calculated value) mapping- Returns:
- An iterator over the elements to delete
- Throws:
HibernateException
-
needsInserting
public boolean needsInserting(Object entry, int i, Type elemType) throws HibernateException
Description copied from interface:PersistentCollection
Do we need to insert this element?- Specified by:
needsInserting
in interfacePersistentCollection<K>
- Parameters:
entry
- The collection element to checki
- The index (for indexed collections)elemType
- The type for the element- Returns:
true
if the element needs inserting- Throws:
HibernateException
-
needsUpdating
public boolean needsUpdating(Object entry, int i, Type elemType) throws HibernateException
Description copied from interface:PersistentCollection
Do we need to update this element?- Specified by:
needsUpdating
in interfacePersistentCollection<K>
- Parameters:
entry
- The collection element to checki
- The index (for indexed collections)elemType
- The type for the element- Returns:
true
if the element needs updating- Throws:
HibernateException
-
getIndex
public Object getIndex(Object entry, int i, CollectionPersister persister)
Description copied from interface:PersistentCollection
Get the index of the given collection entry- Specified by:
getIndex
in interfacePersistentCollection<K>
- Parameters:
entry
- The collection entry/elementi
- The assumed indexpersister
- it was more elegant before we added this...- Returns:
- The index value
-
getElement
public Object getElement(Object entry)
Description copied from interface:PersistentCollection
Get the value of the given collection entry. Generally the given entry parameter value will just be returned. Might get a different value for a duplicate entries in a Set.- Specified by:
getElement
in interfacePersistentCollection<K>
- Parameters:
entry
- The object instance for which to get the collection element instance.- Returns:
- The corresponding object that is part of the collection elements.
-
getSnapshotElement
public Object getSnapshotElement(Object entry, int i)
Description copied from interface:PersistentCollection
Get the snapshot value of the given collection entry- Specified by:
getSnapshotElement
in interfacePersistentCollection<K>
- Parameters:
entry
- The entryi
- The index- Returns:
- The snapshot state for that element
-
equals
public boolean equals(Object other)
-
hashCode
public int hashCode()
-
entryExists
public boolean entryExists(Object entry, int i)
Description copied from interface:PersistentCollection
Does the given element/entry exist in the collection?- Specified by:
entryExists
in interfacePersistentCollection<K>
- Parameters:
entry
- The object to check if it exists as a collection elementi
- Unused- Returns:
true
if the given entry is a collection element
-
-