| java.lang.Object org.apache.ojb.odmg.ObjectEnvelopeOrdering
ObjectEnvelopeOrdering | class ObjectEnvelopeOrdering (Code) | | Implements an algorithm for reordering the object envelopes of a pending
transaction to minimized the probability of foreign key constraint
violations.
The algorithm is based on a graph theoretical approach: Each object
envelope is represented by a vertex in a graph. Each possible constraint
on the order of database operations is represented by a directed edge
in this graph, in which the initial vertex represents the object envelope
to be sent to the database first and the terminal index represents the
object envelope that might cause a FK violation if the initial vertex
has not been sent to the database before.
Additionally the edges in this graph are weighted. This is necessary
because the object envelopes provide only information on the relation
between objects after the transaction. FK violations,
however, can also occur due to relations that existed before
the transaction. Therefore the algorithm also considers potential relations
between objects due to the fact that an object is of a class that is
the item class of a object or collection reference of another object.
Graph edges representing such potential relationships receive a lower
weight than edges representing concrete relationships that exist in the
current state of the object model.
Once all graph edges have been established, the algorithm proceeds as
follows:
- Iterate through all vertices and sum up the weight of all incoming
edges (i.e. those edges whose terminal vertex is the current vertex).
- Find the minimum value of this weight sums (ideally this minimum is zero,
meaning that there are object envelopes that can be sent to the
database without risking FK violations)
- Add all vertices with a weight sum that is equal to this minimum to the
reordered sequence of object envelopes and remove the vertices
and all connected edges from the graph.
- If there are vertices left, repeat steps (1) through (3), otherwise
we are done.
author: Gerhard Grosse version: $Id: ObjectEnvelopeOrdering.java,v 1.1.2.9 2005/12/21 22:29:21 tomdz Exp $ since: Nov 15, 2004 |
Method Summary | |
protected Edge | buildConcrete11Edge(Vertex vertex1, Vertex vertex2, boolean fkToRef) Checks if the database operations associated with two object envelopes
that are related via an 1:1 (or n:1) reference needs to be performed
in a particular order and if so builds and returns a corresponding
directed edge weighted with CONCRETE_EDGE_WEIGHT . | protected Edge | buildConcrete1NEdge(Vertex vertex1, Vertex vertex2) Checks if the database operations associated with two object envelopes
that are related via an 1:n collection reference needs to be performed
in a particular order and if so builds and returns a corresponding
directed edge weighted with CONCRETE_EDGE_WEIGHT . | protected Edge | buildConcreteMNEdge(Vertex vertex1, Vertex vertex2) Checks if the database operations associated with two object envelopes
that are related via an m:n collection reference needs to be performed
in a particular order and if so builds and returns a corresponding
directed edge weighted with CONCRETE_EDGE_WEIGHT . | protected Edge | buildPotential11Edge(Vertex vertex1, Vertex vertex2, boolean fkToRef) Checks if the database operations associated with two object envelopes
that might have been related via an 1:1 (or n:1) reference before
the current transaction needs to be performed
in a particular order and if so builds and returns a corresponding
directed edge weighted with POTENTIAL_EDGE_WEIGHT . | protected Edge | buildPotential1NEdge(Vertex vertex1, Vertex vertex2) Checks if the database operations associated with two object envelopes
that are might have been related via an 1:n collection reference before
the current transaction needs to be performed
in a particular order and if so builds and returns a corresponding
directed edge weighted with POTENTIAL_EDGE_WEIGHT . | protected Edge | buildPotentialMNEdge(Vertex vertex1, Vertex vertex2) Checks if the database operations associated with two object envelopes
that might have been related via an m:n collection reference before
the current transaction needs to be performed
in a particular order and if so builds and returns a corresponding
directed edge weighted with POTENTIAL_EDGE_WEIGHT . | public Identity[] | getOrdering() | public void | reorder() Reorders the object envelopes. |
ObjectEnvelopeOrdering | public ObjectEnvelopeOrdering(List originalOrder, Map envelopes)(Code) | | Creates an object envelope ordering based on an original ordering
of Identity objects and an Identity->ObjectEnvelope map
Parameters: originalOrder - a list of Identity objects Parameters: envelopes - a map with ObjectEnvelope-s with their respectiveIdentity-s as key |
buildConcrete11Edge | protected Edge buildConcrete11Edge(Vertex vertex1, Vertex vertex2, boolean fkToRef)(Code) | | Checks if the database operations associated with two object envelopes
that are related via an 1:1 (or n:1) reference needs to be performed
in a particular order and if so builds and returns a corresponding
directed edge weighted with CONCRETE_EDGE_WEIGHT .
The following cases are considered (* means object needs update, + means
object needs insert, - means object needs to be deleted):
(1)* -(1:1)-> (2)* | no edge |
(1)* -(1:1)-> (2)+ | (2)->(1) edge |
(1)* -(1:1)-> (2)- | no edge (cannot occur) |
(1)+ -(1:1)-> (2)* | no edge |
(1)+ -(1:1)-> (2)+ | (2)->(1) edge |
(1)+ -(1:1)-> (2)- | no edge (cannot occur) |
(1)- -(1:1)-> (2)* | no edge |
(1)- -(1:1)-> (2)+ | no edge |
(1)- -(1:1)-> (2)- | (1)->(2) edge |
Parameters: vertex1 - object envelope vertex of the object holding the reference Parameters: vertex2 - object envelope vertex of the referenced object an Edge object or null if the two database operations canbe performed in any order
buildConcrete1NEdge | protected Edge buildConcrete1NEdge(Vertex vertex1, Vertex vertex2)(Code) | | Checks if the database operations associated with two object envelopes
that are related via an 1:n collection reference needs to be performed
in a particular order and if so builds and returns a corresponding
directed edge weighted with CONCRETE_EDGE_WEIGHT .
The following cases are considered (* means object needs update, + means
object needs insert, - means object needs to be deleted):
(1)* -(1:n)-> (2)* | no edge |
(1)* -(1:n)-> (2)+ | no edge |
(1)* -(1:n)-> (2)- | no edge |
(1)+ -(1:n)-> (2)* | (1)->(2) edge |
(1)+ -(1:n)-> (2)+ | (1)->(2) edge |
(1)+ -(1:n)-> (2)- | no edge (cannot occur) |
(1)- -(1:n)-> (2)* | (2)->(1) edge |
(1)- -(1:n)-> (2)+ | no edge |
(1)- -(1:n)-> (2)- | (2)->(1) edge |
Parameters: vertex1 - object envelope vertex of the object holding the collection Parameters: vertex2 - object envelope vertex of the object contained in the collection an Edge object or null if the two database operations canbe performed in any order
buildConcreteMNEdge | protected Edge buildConcreteMNEdge(Vertex vertex1, Vertex vertex2)(Code) | | Checks if the database operations associated with two object envelopes
that are related via an m:n collection reference needs to be performed
in a particular order and if so builds and returns a corresponding
directed edge weighted with CONCRETE_EDGE_WEIGHT .
The following cases are considered (* means object needs update, + means
object needs insert, - means object needs to be deleted):
(1)* -(m:n)-> (2)* | no edge |
(1)* -(m:n)-> (2)+ | (2)->(1) edge |
(1)* -(m:n)-> (2)- | no edge (cannot occur) |
(1)+ -(m:n)-> (2)* | no edge |
(1)+ -(m:n)-> (2)+ | (2)->(1) edge |
(1)+ -(m:n)-> (2)- | no edge (cannot occur) |
(1)- -(m:n)-> (2)* | no edge |
(1)- -(m:n)-> (2)+ | no edge |
(1)- -(m:n)-> (2)- | (1)->(2) edge |
Parameters: vertex1 - object envelope vertex of the object holding the collection Parameters: vertex2 - object envelope vertex of the object contained in the collection an Edge object or null if the two database operations canbe performed in any order
buildPotential11Edge | protected Edge buildPotential11Edge(Vertex vertex1, Vertex vertex2, boolean fkToRef)(Code) | | Checks if the database operations associated with two object envelopes
that might have been related via an 1:1 (or n:1) reference before
the current transaction needs to be performed
in a particular order and if so builds and returns a corresponding
directed edge weighted with POTENTIAL_EDGE_WEIGHT .
The following cases are considered (* means object needs update, + means
object needs insert, - means object needs to be deleted):
(1)* -(1:1)-> (2)* | no edge |
(1)* -(1:1)-> (2)+ | no edge |
(1)* -(1:1)-> (2)- | (1)->(2) edge |
(1)+ -(1:1)-> (2)* | no edge |
(1)+ -(1:1)-> (2)+ | no edge |
(1)+ -(1:1)-> (2)- | no edge |
(1)- -(1:1)-> (2)* | no edge |
(1)- -(1:1)-> (2)+ | no edge |
(1)- -(1:1)-> (2)- | (1)->(2) edge |
Parameters: vertex1 - object envelope vertex of the object that might have hold the reference Parameters: vertex2 - object envelope vertex of the potentially referenced object an Edge object or null if the two database operations canbe performed in any order
buildPotential1NEdge | protected Edge buildPotential1NEdge(Vertex vertex1, Vertex vertex2)(Code) | | Checks if the database operations associated with two object envelopes
that are might have been related via an 1:n collection reference before
the current transaction needs to be performed
in a particular order and if so builds and returns a corresponding
directed edge weighted with POTENTIAL_EDGE_WEIGHT .
The following cases are considered (* means object needs update, + means
object needs insert, - means object needs to be deleted):
(1)* -(1:n)-> (2)* | no edge |
(1)* -(1:n)-> (2)+ | no edge |
(1)* -(1:n)-> (2)- | no edge |
(1)+ -(1:n)-> (2)* | no edge |
(1)+ -(1:n)-> (2)+ | no edge |
(1)+ -(1:n)-> (2)- | no edge |
(1)- -(1:n)-> (2)* | (2)->(1) edge |
(1)- -(1:n)-> (2)+ | no edge |
(1)- -(1:n)-> (2)- | (2)->(1) edge |
Parameters: vertex1 - object envelope vertex of the object holding the collection Parameters: vertex2 - object envelope vertex of the object that might havebeen contained in the collection an Edge object or null if the two database operations canbe performed in any order
buildPotentialMNEdge | protected Edge buildPotentialMNEdge(Vertex vertex1, Vertex vertex2)(Code) | | Checks if the database operations associated with two object envelopes
that might have been related via an m:n collection reference before
the current transaction needs to be performed
in a particular order and if so builds and returns a corresponding
directed edge weighted with POTENTIAL_EDGE_WEIGHT .
The following cases are considered (* means object needs update, + means
object needs insert, - means object needs to be deleted):
(1)* -(m:n)-> (2)* | no edge |
(1)* -(m:n)-> (2)+ | no edge |
(1)* -(m:n)-> (2)- | (1)->(2) edge |
(1)+ -(m:n)-> (2)* | no edge |
(1)+ -(m:n)-> (2)+ | no edge |
(1)+ -(m:n)-> (2)- | no edge |
(1)- -(m:n)-> (2)* | no edge |
(1)- -(m:n)-> (2)+ | no edge |
(1)- -(m:n)-> (2)- | (1)->(2) edge |
Parameters: vertex1 - object envelope vertex of the object holding the collection Parameters: vertex2 - object envelope vertex of the object that might havebeen contained in the collection an Edge object or null if the two database operations canbe performed in any order
getOrdering | public Identity[] getOrdering()(Code) | | Gets the reordered sequence of object envelopes
an array of Identity objects representing the opimized sequenceof database operations |
|
|
www.java2java.com | Contact Us | Copyright 2009 - 12 Demo Source and Support. All rights reserved. | All other trademarks are property of their respective owners. |
|
|
|
|
|
|