So I was pondering about certain problem involving serialization of objects to relational databases.
Let’s say you have N different objects, all implementing a certain interface (a directed graph interface for that matter. they provide methods such as getIncomingNodes() , getOutgoingNodes()).
If each such object has a corresponding table in a relational database,
What’s the best practice of serializing such a directed graph to a relational database?
Assuming N is small, (in my case, N=3) I decomposed all possible links to be contained in a separate table.
For example, A table of links directed from object x to y will be similar to:
tbl_links_X_Y {
int X_id
int Y_id
}
Problem is , you get N^2 such tables – not very efficient, and could prove difficult to extend in the future to N+1 objects.
Is there any pattern that solves that issue? (even if it does not involve relational databases, I would be happy to hear…)
Thanks!o
So recently I ran into a NoSQL framework calls OrientDB
That DB engine handles this issue exactly.
It is a graph database that has the ability to perform SQL queries and lazy-load object (such as neighboring vertices) that are pointed by another object.
One thing that remains is to compare the performance of this framework to that of a traditional SQL database. (Of course, I’ll have to take into account the time it would take for constructing the objects from the raw responses to the query in a traditional SQL database.. )
Once I’ll have the results of this comparison i’ll post them here.