I'm working on a project that started out fine, but has now kind of hit a wall. It's object oriented, but using a relational database (mysql). The original model was to map each table to a class (basic object relational mapping), and for a while everything was fine.
Then I got to the point where I needed to do sql join, which combines the result from multiple tables. And suddenly my object model didn't match the database model any longer, and I was in trouble. It's apperantly called impedence mismatch, and is well known.
I'm looking at different solutions, all requireing a considerable amount of work. The one I'm most happy with (in theory), goes something like this.
I have class for each table, that extends a field class. Rather than have a single instance of that class cover a row in that table, it only covers a single field/column of a single row. Then I create an entity class that collects all the field instances in a list/array. Does that make sense?
In theory now when I do a join sql statement, I can take the result and create one instance of each field, and one entity for the row that collects all the fields. Each field storing the id of the row it came from, so I can find it again in the database.
So if I wanted to draw an entity, it would simply loop through all it's fields and run the draw method on each.
In theory I can't see any big problems with it, but I'm sure there are some? I was wondering if anyone here has been down the same path and could point out to me some of the holes I'm likely to find in the road so that I can avoid them, before I begin the work of changing the code around considerably.
Cheers,
Ragnar
Then I got to the point where I needed to do sql join, which combines the result from multiple tables. And suddenly my object model didn't match the database model any longer, and I was in trouble. It's apperantly called impedence mismatch, and is well known.
I'm looking at different solutions, all requireing a considerable amount of work. The one I'm most happy with (in theory), goes something like this.
I have class for each table, that extends a field class. Rather than have a single instance of that class cover a row in that table, it only covers a single field/column of a single row. Then I create an entity class that collects all the field instances in a list/array. Does that make sense?
In theory now when I do a join sql statement, I can take the result and create one instance of each field, and one entity for the row that collects all the fields. Each field storing the id of the row it came from, so I can find it again in the database.
So if I wanted to draw an entity, it would simply loop through all it's fields and run the draw method on each.
In theory I can't see any big problems with it, but I'm sure there are some? I was wondering if anyone here has been down the same path and could point out to me some of the holes I'm likely to find in the road so that I can avoid them, before I begin the work of changing the code around considerably.
Cheers,
Ragnar