*/
public EntityEntry removeEntityEntry(Object entity) {
dirty = true;
// again, resolve the entity to a ManagedEntity (which may not be possible for non-enhanced)...
final ManagedEntity managedEntity;
if ( ManagedEntity.class.isInstance( entity ) ) {
managedEntity = (ManagedEntity) entity;
}
else if ( nonEnhancedEntityXref == null ) {
managedEntity = null;
}
else {
managedEntity = nonEnhancedEntityXref.remove( entity );
}
// if we could not resolve it, just return (it was not associated with this context)
if ( managedEntity == null ) {
return null;
}
// prepare for re-linking...
final ManagedEntity previous = managedEntity.$$_hibernate_getPreviousManagedEntity();
final ManagedEntity next = managedEntity.$$_hibernate_getNextManagedEntity();
managedEntity.$$_hibernate_setPreviousManagedEntity( null );
managedEntity.$$_hibernate_setNextManagedEntity( null );
// re-link
count--;
if ( count == 0 ) {
// handle as a special case...
head = null;
tail = null;
assert previous == null;
assert next == null;
}
else {
// otherwise, previous or next (or both) should be non-null
if ( previous == null ) {
// we are removing head
assert managedEntity == head;
head = next;
}
else {
previous.$$_hibernate_setNextManagedEntity( next );
}
if ( next == null ) {
// we are removing tail
assert managedEntity == tail;
tail = previous;
}
else {
next.$$_hibernate_setPreviousManagedEntity( previous );
}
}
// finally clean out the ManagedEntity and return the associated EntityEntry
final EntityEntry theEntityEntry = managedEntity.$$_hibernate_getEntityEntry();