Insert order of DBEntities

From: Craig Miskell (cmiskel..lbatross.co.nz)
Date: Mon Nov 18 2002 - 21:32:14 EST

  • Next message: Andrus: "Re: Insert order of DBEntities"

    Hi,
            Just thought I'd mention that I've discovered some issues with
    OperationSorter and the EntityComparator. Basically, it doesn't work!
    That it works in any particular case is largely a co-incidence. I
    haven't yet been able to create a suitable test case in the unit tests,
    but I can assure you that it is broken in our map. So, I'll resort to
    logical argument:

    The EntityComparator tries to order Entities so that they will insert
    statements can be generated in the correct order based on
    primary/foreign key relationships/constraints. However, it uses the
    Collections sort system (the class in question is a Comparator). The
    basic contract for such a comparator is that a set of Entities has an
    absolute (total?) order. Fundamental to this is the concept that *ANY*
    two entities can be compared, and an absolute order derived from them.
    This is not the case in an DB map. There can be multiple non-connected
    "graphs" of relationships partitioning the entity space ('scuse my
    terminology). It is impossible to compare one entity from one "graph"
    to an entity from another and be sure you can order them appropriately.

    Whether this issue causes problems depends on the names of the entities,
    the relationships and the precise sorting algorithm used (unspecified I
    believe... you just have to trust it :-)). This also means that I'm
    reasonably confident that if I cut down the DataMap we have that's
    causing problems, the problem will go away because of changes in the
    order entities are compared. It also means that the 3-4 ways I've tried
    to create a test case in the current (and modified) unit test db have
    all failed. <BANGS HEAD>

    I'm off to figure out the true algorithm (it's going to include
    partitioning the entities into separate disconnected graphs for a
    start), but just wanted to give a heads up in case any of you:
    a) notice this issue in the meantime
    b) have any good ideas as to the algorithm to use (especially any graph
    theory things I should be aware of)

    I'll post the algorithm once I've figured it out, just to get some other
    eyes to pass over it in pseudo-code form.

    Craig



    This archive was generated by hypermail 2.0.0 : Mon Nov 18 2002 - 21:31:47 EST