Top Description Fields Constructors Methods
org.eclipse.persistence.internal.sessions

public Class CommitOrderCalculator

extends Object
Class Inheritance
Imports
org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.internal.helper.DescriptorCompare, java.util.*

This class calculates a commit order for a series of classes based on the dependencies between them. It builds up a graph of dependencies (CommitOrderDependencyNodes) then applies topological sort to them to get an ordering. This is a throwaway class, which exists only for the lifetime of the calculation. The algorithm is described in the method comment for orderCommits(). This class also includes static methods for quicksort, copied from the standard libraries and adapted for these objects, since that seemed like the easiest way to sort.

Field Summary

Modifier and TypeField and Description
protected int
protected Vector<CommitOrderDependencyNode>
protected Vector<E>
protected AbstractSession

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
public void
addNodes(Vector<E> descriptors)

public void
calculateMappingDependencies()

Add to each node the dependent nodes

public void
calculateSpecifiedDependencies()

Add to each node the dependent nodes

public void
private static int
public int
public Vector<CommitOrderDependencyNode>
public Vector<E>
getOrderedClasses()

Return the constraint ordered classes.

public Vector<E>
getOrderedDescriptors()

Return the constraint ordered descriptors.

public CommitOrderDependencyNode
nodeFor(Class<?> c)

public CommitOrderDependencyNode
public void
orderCommits()

Calculate the commit order.

private static void
quicksort(Object[] arr)

Perform a sort using the specified comparator object.

private static void
quicksort(Object[]
- an array of objects
arr
,
int
- the start index - from where to begin sorting
left
,
int
- the last index.
right
)

quicksort the array of objects.

private static void
swap(Object[] arr, int i, int j)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentTimeback to summary
protected int currentTime
nodesback to summary
protected Vector<CommitOrderDependencyNode> nodes
orderedDescriptorsback to summary
protected Vector<E> orderedDescriptors
sessionback to summary
protected AbstractSession session

Constructor Detail

CommitOrderCalculatorback to summary
public CommitOrderCalculator(AbstractSession session)

Method Detail

addNodeback to summary
protected void addNode(ClassDescriptor d)
addNodesback to summary
public void addNodes(Vector<E> descriptors)
calculateMappingDependenciesback to summary
public void calculateMappingDependencies()

Add to each node the dependent nodes

calculateSpecifiedDependenciesback to summary
public void calculateSpecifiedDependencies()

Add to each node the dependent nodes

depthFirstSearchback to summary
public void depthFirstSearch()
doCompareback to summary
private static int doCompare(Object o1, Object o2)
getNextTimeback to summary
public int getNextTime()
getNodesback to summary
public Vector<CommitOrderDependencyNode> getNodes()
getOrderedClassesback to summary
public Vector<E> getOrderedClasses()

Return the constraint ordered classes.

getOrderedDescriptorsback to summary
public Vector<E> getOrderedDescriptors()

Return the constraint ordered descriptors.

nodeForback to summary
public CommitOrderDependencyNode nodeFor(Class<?> c)
nodeForback to summary
public CommitOrderDependencyNode nodeFor(ClassDescriptor d)
orderCommitsback to summary
public void orderCommits()

Calculate the commit order. Do a depth first search on the graph, skipping nodes that we have already visited or are in the process of visiting. Keep a counter and note when we first encounter a node and when we finish visiting it. Once we've visited everything, sort nodes by finishing time

quicksortback to summary
private static void quicksort(Object[] arr)

Perform a sort using the specified comparator object.

quicksortback to summary
private static void quicksort(Object[] arr, int left, int right)

quicksort the array of objects.

Parameters
arr:Object[]

- an array of objects

left:int

- the start index - from where to begin sorting

right:int

- the last index.

swapback to summary
private static void swap(Object[] arr, int i, int j)