Methods Summary |
---|
public boolean | afterInitialize()
setInitialized();
//do this bit after setting initialized to true or it will recurse
if (operationQueue!=null) {
performQueuedOperations();
operationQueue=null;
cachedSize = -1;
return false;
}
else {
return true;
}
|
public void | afterRowInsert(org.hibernate.persister.collection.CollectionPersister persister, java.lang.Object entry, int i)Called after inserting a row, to fetch the natively generated id
|
public void | beginRead()Called just before reading any rows from the JDBC result set
// override on some subclasses
initializing = true;
|
public final void | clearDirty()
dirty = false;
|
public final void | dirty()
dirty = true;
|
public abstract boolean | empty()Is the initialized collection empty?
|
public boolean | endRead()Called after reading all rows from the JDBC result set
//override on some subclasses
return afterInitialize();
|
public final void | forceInitialization()To be called internally by the session, forcing
immediate initialization.
if (!initialized) {
if (initializing) {
throw new AssertionFailure("force initialize loading collection");
}
if (session==null) {
throw new HibernateException("collection is not associated with any session");
}
if ( !session.isConnected() ) {
throw new HibernateException("disconnected session");
}
session.initializeCollection(this, false);
}
|
protected int | getCachedSize()
return cachedSize;
|
public java.lang.Object | getIdentifier(java.lang.Object entry, int i)
throw new UnsupportedOperationException();
|
public final java.io.Serializable | getKey()
return key;
|
public abstract java.util.Collection | getOrphans(java.io.Serializable snapshot, java.lang.String entityName)get all "orphaned" elements
|
protected static java.util.Collection | getOrphans(java.util.Collection oldElements, java.util.Collection currentElements, java.lang.String entityName, org.hibernate.engine.SessionImplementor session)Given a collection of entity instances that used to
belong to the collection, and a collection of instances
that currently belong, return a collection of orphans
// short-circuit(s)
if ( currentElements.size()==0 ) return oldElements; // no new elements, the old list contains only Orphans
if ( oldElements.size()==0) return oldElements; // no old elements, so no Orphans neither
Type idType = session.getFactory().getEntityPersister(entityName).getIdentifierType();
// create the collection holding the Orphans
Collection res = new ArrayList();
// collect EntityIdentifier(s) of the *current* elements - add them into a HashSet for fast access
java.util.Set currentIds = new HashSet();
for ( Iterator it=currentElements.iterator(); it.hasNext(); ) {
Object current = it.next();
if ( current!=null && ForeignKeys.isNotTransient(entityName, current, null, session) ) {
Serializable currentId = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, current, session);
currentIds.add( new TypedValue( idType, currentId, session.getEntityMode() ) );
}
}
// iterate over the *old* list
for ( Iterator it=oldElements.iterator(); it.hasNext(); ) {
Object old = it.next();
Serializable oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, old, session);
if ( !currentIds.contains( new TypedValue( idType, oldId, session.getEntityMode() ) ) ) {
res.add(old);
}
}
return res;
|
public java.lang.Object | getOwner()
return owner;
|
public final java.util.Collection | getQueuedOrphans(java.lang.String entityName)Iterate the "queued" additions
if ( hasQueuedOperations() ) {
Collection additions = new ArrayList( operationQueue.size() );
Collection removals = new ArrayList( operationQueue.size() );
for ( int i = 0; i < operationQueue.size(); i++ ) {
DelayedOperation op = (DelayedOperation) operationQueue.get(i);
additions.add( op.getAddedInstance() );
removals.add( op.getOrphan() );
}
return getOrphans(removals, additions, entityName, session);
}
else {
return CollectionHelper.EMPTY_COLLECTION;
}
|
public final java.lang.String | getRole()
return role;
|
public final org.hibernate.engine.SessionImplementor | getSession()Get the current session
return session;
|
protected final java.io.Serializable | getSnapshot()Get the current snapshot from the session
return session.getPersistenceContext().getSnapshot(this);
|
public final java.io.Serializable | getStoredSnapshot()
return storedSnapshot;
|
public java.lang.Object | getValue()return the user-visible collection (or array) instance
return this;
|
public final boolean | hasQueuedOperations()Does this instance have any "queued" additions?
return operationQueue!=null;
|
static void | identityRemove(java.util.Collection list, java.lang.Object object, java.lang.String entityName, org.hibernate.engine.SessionImplementor session)
if ( object!=null && ForeignKeys.isNotTransient(entityName, object, null, session) ) {
Type idType = session.getFactory().getEntityPersister(entityName).getIdentifierType();
Serializable idOfCurrent = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, object, session);
Iterator iter = list.iterator();
while ( iter.hasNext() ) {
Serializable idOfOld = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, iter.next(), session);
if ( idType.isEqual( idOfCurrent, idOfOld, session.getEntityMode(), session.getFactory() ) ) {
iter.remove();
break;
}
}
}
|
protected final void | initialize(boolean writing)Initialize the collection, if possible, wrapping any exceptions
in a runtime exception
if (!initialized) {
if (initializing) {
throw new LazyInitializationException("illegal access to loading collection");
}
throwLazyInitializationExceptionIfNotConnected();
session.initializeCollection(this, writing);
}
|
protected boolean | isClearQueueEnabled()Is this collection in a state that would allow us to
"queue" clear? This is a special case, because of orphan
delete.
return !initialized &&
isConnectedToSession() &&
isInverseCollectionNoOrphanDelete();
|
private final boolean | isConnectedToSession()Is the collection currently connected to an open session?
return session!=null &&
session.isOpen() &&
session.getPersistenceContext().containsCollection(this);
|
public boolean | isDirectlyAccessible()Could the application possibly have a direct reference to
the underlying collection implementation?
return directlyAccessible;
|
public final boolean | isDirty()
return dirty;
|
private boolean | isInverseCollection()Is this the "inverse" end of a bidirectional association?
CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(this);
return ce != null && ce.getLoadedPersister().isInverse();
|
private boolean | isInverseCollectionNoOrphanDelete()Is this the "inverse" end of a bidirectional association with
no orphan delete enabled?
CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(this);
return ce != null &&
ce.getLoadedPersister().isInverse() &&
!ce.getLoadedPersister().hasOrphanDelete();
|
private boolean | isInverseOneToManyOrNoOrphanDelete()Is this the "inverse" end of a bidirectional one-to-many, or
of a collection with no orphan delete?
CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(this);
return ce != null && ce.getLoadedPersister().isInverse() && (
ce.getLoadedPersister().isOneToMany() ||
!ce.getLoadedPersister().hasOrphanDelete()
);
|
protected boolean | isOperationQueueEnabled()Is this collection in a state that would allow us to
"queue" operations?
return !initialized &&
isConnectedToSession() &&
isInverseCollection();
|
protected boolean | isPutQueueEnabled()Is this collection in a state that would allow us to
"queue" puts? This is a special case, because of orphan
delete.
return !initialized &&
isConnectedToSession() &&
isInverseOneToManyOrNoOrphanDelete();
|
public boolean | isRowUpdatePossible()
return true;
|
public final boolean | isUnreferenced()
return role==null;
|
public boolean | needsRecreate(org.hibernate.persister.collection.CollectionPersister persister)Do we need to completely recreate this collection when it changes?
return false;
|
protected final void | performQueuedOperations()After reading all existing elements from the database,
add the queued elements to the underlying collection.
for ( int i=0; i<operationQueue.size(); i++ ) {
( (DelayedOperation) operationQueue.get(i) ).operate();
}
|
public void | postAction()After flushing, clear any "queued" additions, since the
database state is now synchronized with the memory state.
operationQueue=null;
cachedSize = -1;
clearDirty();
|
public void | preInsert(org.hibernate.persister.collection.CollectionPersister persister)Called before inserting rows, to ensure that any surrogate keys
are fully generated
|
protected final void | queueOperation(java.lang.Object element)Queue an addition
if (operationQueue==null) operationQueue = new ArrayList(10);
operationQueue.add(element);
dirty = true; //needed so that we remove this collection from the second-level cache
|
public final java.util.Iterator | queuedAdditionIterator()Iterate the "queued" additions
if ( hasQueuedOperations() ) {
return new Iterator() {
int i = 0;
public Object next() {
return ( (DelayedOperation) operationQueue.get(i++) ).getAddedInstance();
}
public boolean hasNext() {
return i<operationQueue.size();
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
else {
return EmptyIterator.INSTANCE;
}
|
protected final void | read()Called by any read-only method of the collection interface
initialize(false);
|
protected java.lang.Object | readElementByIndex(java.lang.Object index)
if (!initialized) {
throwLazyInitializationExceptionIfNotConnected();
CollectionEntry entry = session.getPersistenceContext().getCollectionEntry(this);
CollectionPersister persister = entry.getLoadedPersister();
if ( persister.isExtraLazy() ) {
if ( hasQueuedOperations() ) {
session.flush();
}
return persister.getElementByIndex( entry.getLoadedKey(), index, session, owner );
}
}
read();
return UNKNOWN;
|
protected java.lang.Boolean | readElementExistence(java.lang.Object element)
if (!initialized) {
throwLazyInitializationExceptionIfNotConnected();
CollectionEntry entry = session.getPersistenceContext().getCollectionEntry(this);
CollectionPersister persister = entry.getLoadedPersister();
if ( persister.isExtraLazy() ) {
if ( hasQueuedOperations() ) {
session.flush();
}
return new Boolean( persister.elementExists( entry.getLoadedKey(), element, session ) );
}
}
read();
return null;
|
protected java.lang.Boolean | readIndexExistence(java.lang.Object index)
if (!initialized) {
throwLazyInitializationExceptionIfNotConnected();
CollectionEntry entry = session.getPersistenceContext().getCollectionEntry(this);
CollectionPersister persister = entry.getLoadedPersister();
if ( persister.isExtraLazy() ) {
if ( hasQueuedOperations() ) {
session.flush();
}
return new Boolean( persister.indexExists( entry.getLoadedKey(), index, session ) );
}
}
read();
return null;
|
protected boolean | readSize()Called by the size() method
if (!initialized) {
if ( cachedSize!=-1 && !hasQueuedOperations() ) {
return true;
}
else {
throwLazyInitializationExceptionIfNotConnected();
CollectionEntry entry = session.getPersistenceContext().getCollectionEntry(this);
CollectionPersister persister = entry.getLoadedPersister();
if ( persister.isExtraLazy() ) {
if ( hasQueuedOperations() ) {
session.flush();
}
cachedSize = persister.getSize( entry.getLoadedKey(), session );
return true;
}
}
}
read();
return false;
|
public final boolean | setCurrentSession(org.hibernate.engine.SessionImplementor session)Associate the collection with the given session.
if (session==this.session) {
return false;
}
else {
if ( isConnectedToSession() ) {
CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(this);
if (ce==null) {
throw new HibernateException(
"Illegal attempt to associate a collection with two open sessions"
);
}
else {
throw new HibernateException(
"Illegal attempt to associate a collection with two open sessions: " +
MessageHelper.collectionInfoString(
ce.getLoadedPersister(),
ce.getLoadedKey(),
session.getFactory()
)
);
}
}
else {
this.session = session;
return true;
}
}
|
protected final void | setDirectlyAccessible(boolean directlyAccessible)
this.directlyAccessible = directlyAccessible;
|
protected final void | setInitialized()
this.initializing = false;
this.initialized = true;
|
public void | setOwner(java.lang.Object owner)
this.owner = owner;
|
public void | setSnapshot(java.io.Serializable key, java.lang.String role, java.io.Serializable snapshot)After flushing, re-init snapshot state.
this.key = key;
this.role = role;
this.storedSnapshot = snapshot;
|
private void | throwLazyInitializationException(java.lang.String message)
throw new LazyInitializationException(
"failed to lazily initialize a collection" +
( role==null ? "" : " of role: " + role ) +
", " + message
);
|
private void | throwLazyInitializationExceptionIfNotConnected()
if ( !isConnectedToSession() ) {
throwLazyInitializationException("no session or session was closed");
}
if ( !session.isConnected() ) {
throwLazyInitializationException("session is disconnected");
}
|
public final boolean | unsetSession(org.hibernate.engine.SessionImplementor currentSession)Disassociate this collection from the given session.
if (currentSession==this.session) {
this.session=null;
return true;
}
else {
return false;
}
|
public final boolean | wasInitialized()Is this instance initialized?
return initialized;
|
protected final void | write()Called by any writer method of the collection interface
initialize(true);
dirty();
|