|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.hibernate.collection.PersistentCollection
Persistent collections are treated as value objects by Hibernate.
ie. they have no independent existence beyond the object holding
a reference to them. Unlike instances of entity classes, they are
automatically deleted when unreferenced and automatically become
persistent when held by a persistent object. Collections can be
passed between different objects (change "roles") and this might
cause their elements to move from one database table to another.
Hibernate "wraps" a java collection in an instance of
PersistentCollection. This mechanism is designed to support
tracking of changes to the collection's persistent state and
lazy instantiation of collection elements. The downside is that
only certain abstract collection types are supported and any
extra semantics are lost
Applications should never use classes in this package
directly, unless extending the "framework" here.
Changes to structure of the collection are recorded by the
collection calling back to the session. Changes to mutable
elements (ie. composite elements) are discovered by cloning their
state when the collection is initialized and comparing at flush
time.
Constructor Summary | |
|
PersistentCollection()
Not called by Hibernate, but used by non-JDK serialization, eg. |
protected |
PersistentCollection(SessionImplementor session)
|
Method Summary | |
void |
afterRowInsert(CollectionPersister persister,
Object entry,
int i)
Called after inserting a row, to fetch the natively generated id |
abstract void |
beforeInitialize(CollectionPersister persister)
Called before any elements are read into the collection, allowing appropriate initializations to occur. |
void |
beginRead()
Called just before reading any rows from the JDBC result set |
void |
delayedAddAll(Collection coll)
After reading all existing elements from the database, add the queued elements to the underlying collection. |
abstract Serializable |
disassemble(CollectionPersister persister)
Disassemble the collection, ready for the cache |
abstract boolean |
empty()
Is the initialized collection empty? |
boolean |
endRead()
Called after reading all rows from the JDBC result set |
abstract Iterator |
entries()
Iterate all collection entries, during update of the database |
abstract boolean |
entryExists(Object entry,
int i)
Does an element exist at this entry in the collection? |
abstract boolean |
equalsSnapshot(Type elementType)
Does the current state exactly match the snapshot? |
void |
forceInitialization()
To be called internally by the session, forcing immediate initialization. |
CollectionSnapshot |
getCollectionSnapshot()
Returns the collectionSnapshot. |
abstract Iterator |
getDeletes(Type elemType)
Get all the elements that need deleting |
abstract Object |
getIndex(Object entry,
int i)
Get the index of the given collection entry |
protected static Collection |
getOrphans(Collection oldElements,
Collection currentElements,
SessionImplementor session)
|
abstract Collection |
getOrphans(Serializable snapshot)
get all "orphaned" elements |
protected SessionImplementor |
getSession()
Get the current session |
protected Serializable |
getSnapshot()
Get the current snapshot from the session |
Serializable |
getSnapshot(CollectionPersister persister)
Return a new snapshot of the current state of the collection, or null if no persister is passed |
Object |
getValue()
return the user-visible collection (or array) instance |
boolean |
hasQueuedAdditions()
Does this instance have any "queued" additions? |
protected void |
initialize(boolean writing)
Initialize the collection, if possible, wrapping any exceptions in a runtime exception |
abstract void |
initializeFromCache(CollectionPersister persister,
Serializable disassembled,
Object owner)
Read the state of the collection from a disassembled cached value |
boolean |
isDirectlyAccessible()
Could the application possibly have a direct reference to the underlying collection implementation? |
abstract boolean |
isWrapper(Object collection)
Is this the wrapper for the given underlying collection instance? |
abstract boolean |
needsInserting(Object entry,
int i,
Type elemType)
Do we need to insert this element? |
boolean |
needsRecreate(CollectionPersister persister)
Do we need to completely recreate this collection when it changes? |
abstract boolean |
needsUpdating(Object entry,
int i,
Type elemType)
Do we need to update this element? |
void |
postFlush()
After flushing, clear any "queued" additions, since the database state is now synchronized with the memory state. |
void |
preInsert(CollectionPersister persister)
Called before inserting rows, to ensure that any surrogate keys are fully generated |
protected boolean |
queueAdd(Object element)
Queue an addition |
protected boolean |
queueAddAll(Collection coll)
Queue additions |
Iterator |
queuedAdditionIterator()
Iterate the "queued" additions |
void |
read()
Called by any read-only method of the collection interface |
abstract Object |
readFrom(ResultSet rs,
CollectionPersister role,
Object owner)
Read a row from the JDBC result set |
void |
setCollectionSnapshot(CollectionSnapshot collectionSnapshot)
Sets the collectionSnapshot. |
boolean |
setCurrentSession(SessionImplementor session)
Associate the collection with the given session. |
protected void |
setDirectlyAccessible(boolean directlyAccessible)
|
protected void |
setInitialized()
|
protected abstract Serializable |
snapshot(CollectionPersister persister)
Return a new snapshot of the current state |
boolean |
unsetSession(SessionImplementor currentSession)
Disassociate this collection from the given session. |
boolean |
wasInitialized()
Is this instance initialized? |
protected void |
write()
Called by any writer method of the collection interface |
abstract void |
writeTo(PreparedStatement st,
CollectionPersister role,
Object entry,
int i,
boolean writeOrder)
Write a row to the JDBC prepared statement |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PersistentCollection()
protected PersistentCollection(SessionImplementor session)
Method Detail |
public abstract boolean empty()
public final void read()
protected final void write()
protected final boolean queueAdd(Object element)
protected final boolean queueAddAll(Collection coll)
public void delayedAddAll(Collection coll)
public void postFlush()
public Object getValue()
public void beginRead()
public boolean endRead()
protected final void initialize(boolean writing)
writing
- currently obsolete
LazyInitializationException
- if we cannot initializeprotected final void setInitialized()
protected final void setDirectlyAccessible(boolean directlyAccessible)
public boolean isDirectlyAccessible()
public final boolean unsetSession(SessionImplementor currentSession)
public final boolean setCurrentSession(SessionImplementor session) throws HibernateException
HibernateException
- if the collection was already associated
with another open sessionpublic abstract void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException
HibernateException
public abstract Iterator entries()
public abstract Object readFrom(ResultSet rs, CollectionPersister role, Object owner) throws HibernateException, SQLException
HibernateException
SQLException
public abstract void writeTo(PreparedStatement st, CollectionPersister role, Object entry, int i, boolean writeOrder) throws HibernateException, SQLException
HibernateException
SQLException
public abstract Object getIndex(Object entry, int i)
public abstract void beforeInitialize(CollectionPersister persister)
public abstract boolean equalsSnapshot(Type elementType) throws HibernateException
HibernateException
protected abstract Serializable snapshot(CollectionPersister persister) throws HibernateException
HibernateException
public abstract Serializable disassemble(CollectionPersister persister) throws HibernateException
HibernateException
public boolean needsRecreate(CollectionPersister persister)
public final Serializable getSnapshot(CollectionPersister persister) throws HibernateException
HibernateException
public final void forceInitialization() throws HibernateException
HibernateException
public abstract boolean entryExists(Object entry, int i)
public abstract boolean needsInserting(Object entry, int i, Type elemType) throws HibernateException
HibernateException
public abstract boolean needsUpdating(Object entry, int i, Type elemType) throws HibernateException
HibernateException
public abstract Iterator getDeletes(Type elemType) throws HibernateException
HibernateException
public abstract boolean isWrapper(Object collection)
protected final Serializable getSnapshot()
public final boolean wasInitialized()
public final boolean hasQueuedAdditions()
public final Iterator queuedAdditionIterator()
public CollectionSnapshot getCollectionSnapshot()
public void setCollectionSnapshot(CollectionSnapshot collectionSnapshot)
collectionSnapshot
- The collectionSnapshot to setpublic void preInsert(CollectionPersister persister) throws HibernateException
HibernateException
public void afterRowInsert(CollectionPersister persister, Object entry, int i) throws HibernateException
HibernateException
public abstract Collection getOrphans(Serializable snapshot) throws HibernateException
HibernateException
protected final SessionImplementor getSession()
protected static Collection getOrphans(Collection oldElements, Collection currentElements, SessionImplementor session) throws HibernateException
HibernateException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |