db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neeme Praks <neeme.pr...@inpoc.ee>
Subject mapping table rows into a map?
Date Fri, 28 Feb 2003 11:03:39 GMT
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


Mime
View raw message