FileDocCategorySizeDatePackage
CommitOrderDependencyNode.javaAPI DocGlassfish v2 API9763Tue May 22 16:54:42 BST 2007oracle.toplink.essentials.internal.sessions

CommitOrderDependencyNode

public class CommitOrderDependencyNode extends Object
This wraps a descriptor with information required to compute an order for dependencies. The algorithm is a simple topological sort.

Fields Summary
protected CommitOrderCalculator
owner
protected ClassDescriptor
descriptor
protected AbstractSession
session
protected Vector
relatedNodes
protected CommitOrderDependencyNode
predecessor
protected int
traversalState
public static int
NotVisited
public static int
InProgress
public static int
Visited
protected int
discoveryTime
protected int
finishingTime
Constructors Summary
public CommitOrderDependencyNode(CommitOrderCalculator calculator, ClassDescriptor descriptor, AbstractSession session)


           
        this.owner = calculator;
        this.descriptor = descriptor;
        this.relatedNodes = new Vector();
        this.session = session;
    
Methods Summary
public oracle.toplink.essentials.descriptors.ClassDescriptorgetDescriptor()

        return descriptor;
    
public intgetFinishingTime()

        return finishingTime;
    
public oracle.toplink.essentials.internal.sessions.CommitOrderCalculatorgetOwner()

        return owner;
    
public oracle.toplink.essentials.internal.sessions.CommitOrderDependencyNodegetPredecessor()

        return predecessor;
    
public java.util.VectorgetRelatedNodes()

        return relatedNodes;
    
public booleanhasBeenVisited()

        return (traversalState == Visited);
    
public booleanhasNotBeenVisited()

        return (traversalState == NotVisited);
    
public voidmarkInProgress()

        traversalState = InProgress;
    
public voidmarkNotVisited()

        traversalState = NotVisited;
    
public voidmarkVisited()

        traversalState = Visited;
    
public voidrecordMappingDependencies()
Add all owned classes for each descriptor through checking the mappings. If I have a foreign mapping with a constraint dependency, then add it If I'm related to a class, I'm related to all its subclasses and superclasses. If my superclass is related to a class, I'm related to it.

        for (Enumeration mappings = getDescriptor().getMappings().elements();
                 mappings.hasMoreElements();) {
            DatabaseMapping mapping = (DatabaseMapping)mappings.nextElement();
            if (mapping.isForeignReferenceMapping()) {
                if (((ForeignReferenceMapping)mapping).hasConstraintDependency()) {
                    Class ownedClass;
                    ClassDescriptor refDescriptor = ((ForeignReferenceMapping)mapping).getReferenceDescriptor();
                    if (refDescriptor == null) {
                        refDescriptor = session.getDescriptor(((ForeignReferenceMapping)mapping).getReferenceClass());
                    }
                    ownedClass = refDescriptor.getJavaClass();

                    if (ownedClass == null) {
                        throw oracle.toplink.essentials.exceptions.DescriptorException.referenceClassNotSpecified(mapping);
                    }
                    CommitOrderDependencyNode node = getOwner().nodeFor(ownedClass);
                    Vector ownedNodes = withAllSubclasses(node);

                    // I could remove duplicates here, but it's not that big a deal.
                    Helper.addAllToVector(relatedNodes, ownedNodes);
                } else if (((ForeignReferenceMapping)mapping).hasInverseConstraintDependency()) {
                    Class ownerClass;
                    ClassDescriptor refDescriptor = ((ForeignReferenceMapping)mapping).getReferenceDescriptor();
                    if (refDescriptor == null) {
                        refDescriptor = session.getDescriptor(((ForeignReferenceMapping)mapping).getReferenceClass());
                    }
                    ownerClass = refDescriptor.getJavaClass();
                    if (ownerClass == null) {
                        throw oracle.toplink.essentials.exceptions.DescriptorException.referenceClassNotSpecified(mapping);
                    }
                    CommitOrderDependencyNode ownerNode = getOwner().nodeFor(ownerClass);
                    Vector ownedNodes = withAllSubclasses(this);

                    // I could remove duplicates here, but it's not that big a deal.
                    Helper.addAllToVector(ownerNode.getRelatedNodes(), ownedNodes);
                }
            }
        }
    
public voidrecordSpecifiedDependencies()
Add all owned classes for each descriptor through checking the mappings. If I have a foreign mapping with a constraint dependency, then add it If I'm related to a class, I'm related to all its subclasses and superclasses. If my superclass is related to a class, I'm related to it.

        for (Enumeration constraintsEnum = getDescriptor().getConstraintDependencies().elements();
                 constraintsEnum.hasMoreElements();) {
            Class ownedClass = (Class)constraintsEnum.nextElement();
            CommitOrderDependencyNode node = getOwner().nodeFor(ownedClass);
            Vector ownedNodes = withAllSubclasses(node);

            // I could remove duplicates here, but it's not that big a deal.
            Helper.addAllToVector(relatedNodes, ownedNodes);
        }
    
public voidsetDiscoveryTime(int time)

        discoveryTime = time;
    
public voidsetFinishingTime(int time)

        finishingTime = time;
    
public voidsetPredecessor(oracle.toplink.essentials.internal.sessions.CommitOrderDependencyNode n)

        predecessor = n;
    
public java.lang.StringtoString()

        if (descriptor == null) {
            return ToStringLocalization.buildMessage("empty_commit_order_dependency_node", (Object[])null);
        } else {
            Object[] args = { descriptor };
            return ToStringLocalization.buildMessage("node", args);
        }
    
public voidvisit()

        //Visit this node as part of a topological sort
        int startTime;
        markInProgress();
        startTime = getOwner().getNextTime();
        setDiscoveryTime(startTime);

        for (Enumeration e = getRelatedNodes().elements(); e.hasMoreElements();) {
            CommitOrderDependencyNode node = (CommitOrderDependencyNode)e.nextElement();
            if (node.hasNotBeenVisited()) {
                node.setPredecessor(this);
                node.visit();
            }
            if (node.getPredecessor() == null) {
                node.setPredecessor(this);
            }
        }

        markVisited();
        setFinishingTime(getOwner().getNextTime());
    
public java.util.VectorwithAllSubclasses(oracle.toplink.essentials.internal.sessions.CommitOrderDependencyNode node)

        Vector results = new Vector();
        results.addElement(node);

        if (node.getDescriptor().hasInheritance()) {
            InheritancePolicy p = node.getDescriptor().getInheritancePolicy();

            // For bug 3019934 replace getChildDescriptors with getAllChildDescriptors.
            for (Enumeration e = p.getAllChildDescriptors().elements(); e.hasMoreElements();) {
                results.addElement(getOwner().nodeFor((ClassDescriptor)e.nextElement()));
            }
        }
        return results;