public class ForceRecreationListType
extends java.lang.Object
implements org.hibernate.usertype.UserCollectionType
Domain Model -> Many Servers (s) - Many Config Channels(cc) rhnServer (s) 1 <-* rhnServerConfigChannel (scc)* -> 1 rhnConfigChannel(cc) s -> (id), scc ->(server_id, config_channel_id, position ), cc->(id) here we are representing Server as holding a list of config channels that is indexed according to the value of scc.position. Now lets say we subscribed and unsubscribed channels from the Server... When saving server, with hibernates default mechanism, the links between the Server & ConfigChannels are not deleted and remapped from scratch. Instead an "optimization" is done using updates. For eg, if SCC read -> (sid, ccid, position) ->{(2,1,0),(2,2,1),(2,3,2)} And we remove the link for CCID = 1 to end up with ->{(2,2,1),(2,3,2)} Hibernate achieves this in the following order a) remove(2,3,2) ,b) moves (2,1,0)-> (2,2,0), c) move (2,2,1) -> (2,3,1) Problem here is since (sid, ccid) combination must be unique step b fails (since 2,2,1 still exists).. So we have to force hibernate to do the following a) remove (2,*,*) b) insert(2,2,0) and c)insert(2,3,1) This list type will help us achieve that.
When you use a list in hbm.xml , to use this collection you must specify <list name="...." collection-type="com.redhat.rhn.common.hibernate.ForceRecreationListType">
Note in the above example if (sid, ccid, position) combination as a whole was unique we wouldn't have had to deal with this...... but positions can be null twice for the same server, so we cannot enforce that constraint.. ForceRecreationListType
Constructor and Description |
---|
ForceRecreationListType() |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(java.lang.Object collection,
java.lang.Object entity) |
java.util.Iterator |
getElementsIterator(java.lang.Object collection) |
java.lang.Object |
indexOf(java.lang.Object collection,
java.lang.Object entity) |
java.lang.Object |
instantiate()
Returns an ArrayList.
|
java.lang.Object |
instantiate(int anticipatedSize)
Instantiates an empty list.
|
org.hibernate.collection.PersistentCollection |
instantiate(org.hibernate.engine.SessionImplementor session,
org.hibernate.persister.collection.CollectionPersister persister) |
java.lang.Object |
replaceElements(java.lang.Object original,
java.lang.Object target,
org.hibernate.persister.collection.CollectionPersister persister,
java.lang.Object owner,
java.util.Map copyCache,
org.hibernate.engine.SessionImplementor session) |
org.hibernate.collection.PersistentCollection |
wrap(org.hibernate.engine.SessionImplementor session,
java.lang.Object collection) |
public org.hibernate.collection.PersistentCollection instantiate(org.hibernate.engine.SessionImplementor session, org.hibernate.persister.collection.CollectionPersister persister) throws org.hibernate.HibernateException
instantiate
in interface org.hibernate.usertype.UserCollectionType
org.hibernate.HibernateException
public org.hibernate.collection.PersistentCollection wrap(org.hibernate.engine.SessionImplementor session, java.lang.Object collection)
wrap
in interface org.hibernate.usertype.UserCollectionType
public java.util.Iterator getElementsIterator(java.lang.Object collection)
getElementsIterator
in interface org.hibernate.usertype.UserCollectionType
public boolean contains(java.lang.Object collection, java.lang.Object entity)
contains
in interface org.hibernate.usertype.UserCollectionType
public java.lang.Object indexOf(java.lang.Object collection, java.lang.Object entity)
indexOf
in interface org.hibernate.usertype.UserCollectionType
public java.lang.Object replaceElements(java.lang.Object original, java.lang.Object target, org.hibernate.persister.collection.CollectionPersister persister, java.lang.Object owner, java.util.Map copyCache, org.hibernate.engine.SessionImplementor session) throws org.hibernate.HibernateException
replaceElements
in interface org.hibernate.usertype.UserCollectionType
org.hibernate.HibernateException
public java.lang.Object instantiate(int anticipatedSize)
instantiate
in interface org.hibernate.usertype.UserCollectionType
anticipatedSize
- sample sizepublic java.lang.Object instantiate()