You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Neeme Praks <ne...@inpoc.ee> on 2003/02/28 12:03:39 UTC
mapping table rows into a map?
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