org.hibernate.collection

Class PersistentMap

Implemented Interfaces:
Map, Serializable, PersistentCollection
Known Direct Subclasses:
PersistentSortedMap

public class PersistentMap
extends AbstractPersistentCollection
implements Map

A persistent wrapper for a java.util.Map. Underlying collection is a HashMap.
Author:
Gavin King
See Also:
java.util.HashMap

Nested Class Summary

Nested classes/interfaces inherited from class org.hibernate.collection.AbstractPersistentCollection

AbstractPersistentCollection.DelayedOperation

Field Summary

protected Map
map

Fields inherited from class org.hibernate.collection.AbstractPersistentCollection

UNKNOWN

Constructor Summary

PersistentMap()
Empty constructor.
PersistentMap(SessionImplementor session)
Instantiates a lazy map (the underlying map is un-initialized).
PersistentMap(SessionImplementor session, Map map)
Instantiates a non-lazy map (the underlying map is constructed from the incoming map reference).

Method Summary

void
beforeInitialize(CollectionPersister persister, int anticipatedSize)
Called before any elements are read into the collection, allowing appropriate initializations to occur.
void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
Serializable
disassemble(CollectionPersister persister)
Disassemble the collection, ready for the cache
boolean
empty()
Is the initialized collection empty?
Iterator
entries(CollectionPersister persister)
Iterate all collection entries, during update of the database
boolean
entryExists(Object entry, int i)
Does an element exist at this entry in the collection?
Set
entrySet()
boolean
equals(Object other)
boolean
equalsSnapshot(CollectionPersister persister)
Does the current state exactly match the snapshot?
Object
get(Object key)
Iterator
getDeletes(CollectionPersister persister, boolean indexIsFormula)
Get all the elements that need deleting
Object
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 entry
Collection
getOrphans(Serializable snapshot, String entityName)
get all "orphaned" elements
Serializable
getSnapshot(CollectionPersister persister)
Return a new snapshot of the current state of the collection
Object
getSnapshotElement(Object entry, int i)
Get the snapshot value of the given collection entry
int
hashCode()
void
initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner)
Read the state of the collection from a disassembled cached value
boolean
isEmpty()
boolean
isSnapshotEmpty(Serializable snapshot)
Is the snapshot empty?
boolean
isWrapper(Object collection)
Is this the wrapper for the given underlying collection instance?
Set
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?
Object
put(Object key, Object value)
void
putAll(Map puts)
Object
readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner)
Read a row from the JDBC result set
Object
remove(Object key)
int
size()
String
toString()
Collection
values()

Methods inherited from class org.hibernate.collection.AbstractPersistentCollection

afterInitialize, afterRowInsert, beginRead, clearDirty, dirty, empty, endRead, forceInitialization, getCachedSize, getIdentifier, getKey, getOrphans, getOrphans, getOwner, getQueuedOrphans, getRole, getSession, getSnapshot, getStoredSnapshot, getValue, hasQueuedOperations, initialize, isClearQueueEnabled, isDirectlyAccessible, isDirty, isOperationQueueEnabled, isPutQueueEnabled, isRowUpdatePossible, isUnreferenced, needsRecreate, performQueuedOperations, postAction, preInsert, queueOperation, queuedAdditionIterator, read, readElementByIndex, readElementExistence, readIndexExistence, readSize, setCurrentSession, setDirectlyAccessible, setInitialized, setOwner, setSnapshot, unsetSession, wasInitialized, write

Field Details

map

protected Map map

Constructor Details

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(SessionImplementor session)
Instantiates a lazy map (the underlying map is un-initialized).
Parameters:
session - The session to which this map will belong.

PersistentMap

public PersistentMap(SessionImplementor session,
                     Map 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 Details

beforeInitialize

public void beforeInitialize(CollectionPersister persister,
                             int anticipatedSize)
Called before any elements are read into the collection, allowing appropriate initializations to occur.
Specified by:
beforeInitialize in interface PersistentCollection
Parameters:
persister - The underlying collection persister.
anticipatedSize - The anticipated size of the collection after initilization is complete.

clear

public void clear()
See Also:
java.util.Map.clear()

containsKey

public boolean containsKey(Object key)
See Also:
java.util.Map.containsKey(Object)

containsValue

public boolean containsValue(Object value)
See Also:
java.util.Map.containsValue(Object)

disassemble

public Serializable disassemble(CollectionPersister persister)
            throws HibernateException
Disassemble the collection, ready for the cache
Specified by:
disassemble in interface PersistentCollection

empty

public boolean empty()
Is the initialized collection empty?
Specified by:
empty in interface PersistentCollection
Overrides:
empty in interface AbstractPersistentCollection

entries

public Iterator entries(CollectionPersister persister)
Iterate all collection entries, during update of the database
Specified by:
entries in interface PersistentCollection

entryExists

public boolean entryExists(Object entry,
                           int i)
Does an element exist at this entry in the collection?
Specified by:
entryExists in interface PersistentCollection

entrySet

public Set entrySet()
See Also:
java.util.Map.entrySet()

equals

public boolean equals(Object other)

equalsSnapshot

public boolean equalsSnapshot(CollectionPersister persister)
            throws HibernateException
Does the current state exactly match the snapshot?
Specified by:
equalsSnapshot in interface PersistentCollection

get

public Object get(Object key)
See Also:
java.util.Map.get(Object)

getDeletes

public Iterator getDeletes(CollectionPersister persister,
                           boolean indexIsFormula)
            throws HibernateException
Get all the elements that need deleting
Specified by:
getDeletes in interface PersistentCollection

getElement

public Object getElement(Object entry)
Get the value of the given collection entry
Specified by:
getElement in interface PersistentCollection

getIndex

public Object getIndex(Object entry,
                       int i,
                       CollectionPersister persister)
Get the index of the given collection entry
Specified by:
getIndex in interface PersistentCollection
Parameters:
persister - it was more elegant before we added this...

getOrphans

public Collection getOrphans(Serializable snapshot,
                             String entityName)
            throws HibernateException
get all "orphaned" elements
Specified by:
getOrphans in interface PersistentCollection
Overrides:
getOrphans in interface AbstractPersistentCollection

getSnapshot

public Serializable getSnapshot(CollectionPersister persister)
            throws HibernateException
Return a new snapshot of the current state of the collection
Specified by:
getSnapshot in interface PersistentCollection

getSnapshotElement

public Object getSnapshotElement(Object entry,
                                 int i)
Get the snapshot value of the given collection entry
Specified by:
getSnapshotElement in interface PersistentCollection

hashCode

public int hashCode()

initializeFromCache

public void initializeFromCache(CollectionPersister persister,
                                Serializable disassembled,
                                Object owner)
            throws HibernateException
Read the state of the collection from a disassembled cached value
Specified by:
initializeFromCache in interface PersistentCollection

isEmpty

public boolean isEmpty()
See Also:
java.util.Map.isEmpty()

isSnapshotEmpty

public boolean isSnapshotEmpty(Serializable snapshot)
Is the snapshot empty?
Specified by:
isSnapshotEmpty in interface PersistentCollection

isWrapper

public boolean isWrapper(Object collection)
Is this the wrapper for the given underlying collection instance?
Specified by:
isWrapper in interface PersistentCollection

keySet

public Set keySet()
See Also:
java.util.Map.keySet()

needsInserting

public boolean needsInserting(Object entry,
                              int i,
                              Type elemType)
            throws HibernateException
Do we need to insert this element?
Specified by:
needsInserting in interface PersistentCollection

needsUpdating

public boolean needsUpdating(Object entry,
                             int i,
                             Type elemType)
            throws HibernateException
Do we need to update this element?
Specified by:
needsUpdating in interface PersistentCollection

put

public Object put(Object key,
                  Object value)
See Also:
java.util.Map.put(Object, Object)

putAll

public void putAll(Map puts)
See Also:
java.util.Map.putAll(java.util.Map puts)

readFrom

public Object readFrom(ResultSet rs,
                       CollectionPersister persister,
                       CollectionAliases descriptor,
                       Object owner)
            throws HibernateException,
                   SQLException
Read a row from the JDBC result set
Specified by:
readFrom in interface PersistentCollection

remove

public Object remove(Object key)
See Also:
java.util.Map.remove(Object)

size

public int size()
See Also:
java.util.Map.size()

toString

public String toString()

values

public Collection values()
See Also:
java.util.Map.values()