I have multiple tables in the database with unknown schema and would like to use one class to manage their records. Where I should start to implement mapping at runtime?
Would it be possible to do something like the following using Hibernate (or I'm selecting wrong tool)? I'd like to use database meta data classes provided by hibernate and also to analyse relations in the database.
1. get names of tables from configuration file.
2. detect primary/foreign keys in the tables.
3. generete mapping to generic classes to store only primary/foreign keys in classes.
4. generate mappings to the *foreign/parent* records containing refferences to the child records.
5. use these generic classes to process generic queries (provided in some configuration files)
Questions:
Which classes to use to detect/analyse database schema, export it to the file, compare schemas/MetaDatas for two databases?
Which classes to use to generate mapping on the fly to bind tables with generic template classes.
Where I can find static class diagram for Hibernate mapping classes?
table1(id, col1, col2, col3)
=>
class Row<"table1"> {
Object id; // mapped to in the table
theRest; // mapped to all other data in the
}
=Database=
table1 (id, ...)
table2 (id, table1_id, ...)
table3 (id, ...)
=Class=
Row<String> : SomeInterface {
id
...
List getChildRows();
}
ChildRow<String> : SomeInterface {
id
prent_id
}
=Usage=
List results;
// assume that we will get list of object of the Row<"table1"> type
results = dao.getRows("table1", <some generic query>);
((SomeInterface)results.get(0)).doSomething();
... process results
Thanks a lot in advance!
|