You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by "Joe Crichton (JIRA)" <de...@tuscany.apache.org> on 2008/12/05 14:57:44 UTC

[jira] Created: (TUSCANY-2722) getInsertOrder needs to support multiple children per parent

getInsertOrder needs to support multiple children per parent
------------------------------------------------------------

                 Key: TUSCANY-2722
                 URL: https://issues.apache.org/jira/browse/TUSCANY-2722
             Project: Tuscany
          Issue Type: Bug
          Components: Java DAS RDB
    Affects Versions: Java-DAS-beta1
            Reporter: Joe Crichton


I am not patch savvy, but here is the 'new' getInsertOrder I am using to support multiple parent-child relationships WRT insert/delete ordering:

    // TODO optimize
    public List getInsertOrder() {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Getting insert order");
        }

        List inserts = new ArrayList();

        // JMC - this must allow multiple children per parent
        Map<String,List<String>> parentToChildren = new HashMap<String,List<String>>();
       //Map parentToChild = new HashMap();

        List parents = new ArrayList();
        List children = new ArrayList();
        if (config != null) {
            Iterator i = getConfig().getRelationship().iterator();
            while (i.hasNext()) {
                Relationship r = (Relationship) i.next();
                parents.add(r.getPrimaryKeyTable());
                children.add(r.getForeignKeyTable());
                
                // JMC - mapping must be multiple children per parent
                List<String>rchildren = parentToChildren.get(r.getPrimaryKeyTable());
                if (rchildren == null) parentToChildren.put(r.getPrimaryKeyTable(), rchildren=new ArrayList<String>());
                rchildren.add(r.getForeignKeyTable());
                //parentToChild.put(r.getPrimaryKeyTable(), r.getForeignKeyTable());
            }
            while (parents.size() > 0) {
                String parent = (String) parents.get(0);
                if (!children.contains(parent)) {
                    if (!inserts.contains(parent)) {
                        inserts.add(parent);
                    }
                    
                    // JMC - Deal with ALL relationships
                    //String child = (String) parentToChild.get(parent);
                    List<String> rchildren = parentToChildren.get(parent);
                    Iterator<String> it = rchildren.iterator();
                    while(it.hasNext()) {
                       String child = it.next();                    
                       if (!inserts.contains(child)) {
                          inserts.add(child);
                          children.remove(child);
                       }
                    }
                    parents.remove(parent);

                } else {
                    parents.add(parents.remove(0));
                }
            }
            inserts.addAll(children);
        }

        if (this.logger.isDebugEnabled()) {
            this.logger.debug(inserts);
        }

        return inserts;
    }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.