From: "Craig Miskell" <cmiskel..lbatross.co.nz>
Subject: Re: Contributions to Cayenne
> Reflexive relationships (table A->table A) are handled by my algorithm,
> but thats likely easily tacked onto the Andriy's work... the result of his
> algorithm will be an ordered set of entities. Just sort the actual
> objects within each entity based on any reflexive relationships it might
> have with itself.
>
Sure, you are absolutely right. The order of data objects induced by the
order of the topologically sorted strongly connected components in the
referential digraph (table A and table B belong to the same component if and
only if there exists a path of references, in general including several
other tables, from A to B and another one does from B to A) is such that all
the data objects related to one component or table with a reflexive
relationship are considered equal. But for each component or such a table we
can build a graph based on the actual relationships of the data objects
related to it. Then we sort these objects via the same algorithms we used in
the case of the entities. This approach allows us to establish totally
correct order of the data objects to insert (delete) and, moreover, it has
the following good side effect. While referential cycles and loops are
certainly acceptable in a database schema, it is always a logical error to
try to insert concrete records 'a', 'b', 'c' such that 'a' -> 'b' -> 'c' ->
'a', e.g. to have a cycle of the records to insert. As one of the properties
of the in-degree topological sorting is that it identifies such cycles
during the process of sorting a digraph, Cayenne will be able to find such
mischiefs and deny the commit without trying to actually commit the changes
to the database. Thus, the technique having been tested with entities, we
should probably try to apply it to data objects themselves.
Andriy.
This archive was generated by hypermail 2.0.0 : Sat Jan 04 2003 - 08:38:43 EST