db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Mahler <thm...@web.de>
Subject Re: mapping table rows into a map?
Date Fri, 28 Feb 2003 21:57:06 GMT
Hi Neeme,

The best solution will be to let OJB produce the Map for
getAttributes() for you.

I posted the following answer to a similar question to the user list the 
other day:

Hi,


 > -----Original Message-----
 > From: Rice Yeh [mailto:riceyeh@yahoo.com]
 > Sent: Thursday, February 27, 2003 2:29 PM
 > To: ojb-user@db.apache.org
 > Subject: How to handle java.util.Map
 >
 >
 > Hi,
 >   In OJB document, I can find information on how to
 > handle collection mapping. However, I can not find
 > information on how to handle java.util.Map. Is it
 > supported?


Yes,

http://db.apache.org/ojb/tutorial3.html#types%20allowed%20for%20implementing
%201:n%20associations

explains that it is possible to use user defined collections. SO it would be
a no brainer to use write a class extending HashMap and implementing
ManageableCollection.
(there is a an example implementation for a java.util.set:
http://cvs.apache.org/viewcvs/db-ojb/src/java/org/apache/ojb/broker/util/col
lections/ManageableHashSet.java?rev=HEAD&content-type=text/vnd.viewcvs-marku
p)

cheers,
Thomas


Under ODMG you have a working Map implementation already:
http://db.apache.org/ojb/api/org/odmg/DMap.html

cheers,
Thomas




Neeme Praks wrote:
> Hi!
> 
> I an issue and I would like to see if and how can OJB handle this...
> I have the following (simplified) table structure:
> 
> table: object
> ------
> field: id int
> field: type_id int --references id field in table type
> ...other fields...
> 
> table: type
> ------
> field: id int
> field: name varchar(15)
> 
> table: attribute
> ------
> field: id int
> field: name varchar(15)
> 
> table: type_attribute
> ------
> field: id int
> field: type_id int --references id field in table type
> field: attribute_id int --references id field in table attribute
> 
> table: attribute_value
> ------
> field: id int
> field: object_id int --references id field in table object
> field: type_attribute_id int --references id field in type_attribute
> field: value varchar(15)
> 
> A little explanation:
> I have a table structure with objects, their types and attributes. All 
> objects have a type and type can be associated with different 
> attributes. Object can define it's own value for each typeattribute.
> 
> Now, I would like to present this with the following object model in Java:
> 
> interface MyObject {
>     Integer getId();
>     void setId(Integer id);
> 
>     Integer getTypeId();
>     void setTypeId(Integer id);
> 
>     Type getType();
>     void setType(Type type);
> 
>     String getAttribute(String key);
>     void setAttribute(String key, String value);
> 
>     /**
>      * @return a map of (String key, String value) pairs
>      */
>     Map getAttributes();
> }
> 
> interface Type {
>     Integer getId();
>     void setId(Integer id);
> 
>     String getName();
>     void setName(String name);
> 
>     /**
>      * @return a collection of Attribute objects
>      */
>     Collection getAttributes();
> 
>     /**
>      * @return a collection of attribute names (strings)
>      */
>     Collection getAttributesAsString();
> }
> 
> interface Attribute {
>     Integer getId();
>     void setId(Integer id);
> 
>     String getName();
>     void setName(String name);
> }
> 
> The difficult parts for me are these methods in MyObject interface:
>     String getAttribute(String key);
>     void setAttribute(String key, String value);
> 
>     /**
>      * @return a map of (String key, String value) pairs
>      */
>     Map getAttributes();
> 
> Any easy way of handling this kind of stuff? Or should I also create a 
> separate object/interface also for remaining tables (TypeAttribute and 
> AttributeValue) and then simulate these methods with custom java code?
> 
> Thanks,
> Neeme
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 



Mime
View raw message