Uploaded image for project: 'Tuscany'
  1. Tuscany
  2. TUSCANY-2722

getInsertOrder needs to support multiple children per parent

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • Java-DAS-beta1
    • Java-DAS-Next
    • Java DAS RDB
    • None

    Description

      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;
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            joecrichton Joe Crichton
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: