AW: [OJB-developers] OJB ManageableCollection ?
Brought to you by:
thma
From: Mahler T. <tho...@it...> - 2001-12-18 08:11:40
|
Hi Jakob, =20 the ManageableCollection interface maybe helpful if you don't want to = (or can't) implement 1:n association with java.util.Collection derived = classes or with arrays. A typical example are user defined typed collections. See sample code = from package test.ojb.broker below. There is a ProductGroup class with a collection implementor=20 allArticlesInGroup of type ArticleCollection. =20 Class ArticleCollection only allows typed access (as opposed to the = untyped access with java.util.Collection). You can add only InterfaceArticle objects and with get(...) you = retrieve InterfaceArticle objects from the collection. =20 OJB must interact with such user defined collections in a standardized = way. That's the reason for the callback interface ManageableCollection. It provides elementary access to the user defined collection for the materialisation process and for update and delete routines (through ojbIterator()). =20 HTH, =20 Thomas =20 public class ProductGroupWithTypedCollection { // ... =20 /** collection containing all articles of a given product group*/ private ArticleCollection allArticlesInGroup; // ... } =20 public class ArticleCollection implements ManageableCollection { private Vector elements; =20 /** * ArticleCollection constructor comment. */ public ArticleCollection() { super(); elements =3D new Vector(); } =20 public void add(InterfaceArticle article) { if (elements =3D=3D null) elements =3D new Vector(); elements.add(article); } =20 public InterfaceArticle get(int index) { return (InterfaceArticle) elements.get(index); } =20 /** * add method comment. */ public void ojbAdd(java.lang.Object anObject) { elements.add((InterfaceArticle) anObject); } =20 /** * addAll method comment. */ public void ojbAddAll(ojb.broker.ManageableCollection = otherCollection) { elements.addAll(((ArticleCollection) = otherCollection).elements); } =20 /** * ojbIterator method comment. */ public java.util.Iterator ojbIterator() { return elements.iterator(); } =20 public int size() { return elements.size(); } =20 public String toString() { return elements.toString(); } } =20 =20 -----Urspr=FCngliche Nachricht----- Von: Jakob Braeuchi [mailto:jbr...@ho...] Gesendet: Dienstag, 18. Dezember 2001 08:33 An: Objectbridge Developers List (E-mail) Betreff: [OJB-developers] OJB ManageableCollection ? hi, =20 while working on the proxy-collection, i came across the ManageableCollection. i do not know what they are needed for, the three methods defined in = this interface are also defined (without ojb prefix) in Collection. =20 jakob |