Exemplo n.º 1
0
 private void addToData(
     Record rec, XSQLBluePrintNode bpn, XSQLBluePrint bluePrint, Map<String, Object> fullRecord) {
   XSQLBluePrintNode eNodes[] =
       bluePrint.getBluePrintNodeByODLTableName(XSQLODLUtils.getNodeIdentiofier(rec.element));
   if (bpn != null) {
     for (XSQLColumn c : fieldsInQuery) {
       for (XSQLBluePrintNode eNode : eNodes) {
         if (((XSQLBluePrintNode) c.getBluePrintNode())
             .getBluePrintNodeName()
             .equals(eNode.getBluePrintNodeName())) {
           // Object value = Criteria.getValue(rec.element,
           // c.getName());
           String columnName = c.toString();
           Object value = fullRecord.get(columnName);
           if (value != null) {
             try {
               Object rsValue = c.getResultSetValue(value);
               c.setCharWidth(rsValue.toString().length());
               rec.data.put(columnName, rsValue);
             } catch (Exception err) {
             }
           }
         }
       }
     }
   }
 }
Exemplo n.º 2
0
 private void collectColumnValues(RecordsContainer rContainer, XSQLBluePrintNode bpn) {
   Collection<?> subChildren = XSQLODLUtils.getChildrenCollection(rContainer.currentObject);
   Record r = new Record();
   r.element = rContainer.currentObject;
   for (Object stc : subChildren) {
     if (stc.getClass().getName().endsWith("ImmutableUnkeyedListEntryNode")) {
       r.fitCriteria = false;
       rContainer.currentObject = stc;
       collectColumnValues(rContainer, bpn);
     } else if (stc.getClass().getName().endsWith("ImmutableAugmentationNode")) {
       Map<?, ?> values = XSQLODLUtils.getChildren(stc);
       for (Object key : values.keySet()) {
         Object val = values.get(key);
         if (val.getClass().getName().endsWith("ImmutableLeafNode")) {
           Object value = XSQLODLUtils.getValue(val);
           String k = XSQLODLUtils.getNodeName(val);
           if (value != null) {
             r.data.put(bpn.getBluePrintNodeName() + "." + k, value.toString());
           }
         }
       }
     } else if (stc.getClass().getName().endsWith("ImmutableLeafNode")) {
       String k = XSQLODLUtils.getNodeName(stc);
       Object value = XSQLODLUtils.getValue(stc);
       if (value != null) {
         r.data.put(bpn.getBluePrintNodeName() + "." + k, value.toString());
       }
     }
   }
   if (r.fitCriteria) {
     rContainer.records.add(r);
   }
 }
Exemplo n.º 3
0
 public void addTableToQuery(XSQLBluePrintNode node) {
   if (this.tablesInQueryMap.containsKey(node.getBluePrintNodeName())) {
     return;
   }
   this.tablesInQuery.add(node);
   this.tablesInQueryMap.put(node.getBluePrintNodeName(), node);
 }
Exemplo n.º 4
0
  public List<Object> getChildren(Object node, String tableName, XSQLBluePrint bluePrint) {

    List<Object> children = XSQLODLUtils.getMChildren(node);
    List<Object> result = new LinkedList<Object>();

    for (Object child : children) {

      String odlNodeName = XSQLODLUtils.getNodeIdentiofier(child);
      if (odlNodeName == null) {
        if (child instanceof DataContainerNode) {
          List<Object> augChidlren = getChildren(child, tableName, bluePrint);
          result.addAll(augChidlren);
        }
        continue;
      }

      XSQLBluePrintNode eNodes[] = bluePrint.getBluePrintNodeByODLTableName(odlNodeName);
      if (eNodes == null) {
        continue;
      }

      boolean match = false;
      for (XSQLBluePrintNode enode : eNodes) {
        if (tableName.startsWith(enode.toString())) {
          match = true;
          break;
        }
      }

      if (!match) {
        continue;
      }

      if (child.getClass().getName().endsWith("ImmutableUnkeyedListNode")) {
        result.add(child);
      } else if (child.getClass().getName().endsWith("ImmutableContainerNode")) {
        result.add(child);
      } else if (child.getClass().getName().endsWith("ImmutableAugmentationNode")) {
        List<Object> _children = XSQLODLUtils.getMChildren(child);
        for (Object c : _children) {
          if (c.getClass().getName().endsWith("ImmutableContainerNode")) {
            result.add(c);
          }
        }
      } else if (child.getClass().getName().endsWith("ImmutableMapNode")) {
        result.addAll(XSQLODLUtils.getMChildren(child));
      } else {
        XSQLAdapter.log("Missed Node Data OF Type=" + child.getClass().getName());
      }
    }
    return result;
  }
Exemplo n.º 5
0
 public XSQLBluePrintNode getMainTable() {
   if (tablesInQuery.size() == 1) {
     return tablesInQuery.get(0);
   }
   XSQLBluePrintNode result = null;
   for (XSQLBluePrintNode node : tablesInQuery) {
     if (result == null) {
       result = node;
     } else if (result.getLevel() < node.getLevel()) {
       result = node;
     }
   }
   return result;
 }
Exemplo n.º 6
0
 private void createRecord(Object data, XSQLBluePrintNode node) {
   Map<String, Object> rec = new HashMap<>();
   for (XSQLColumn c : this.fieldsInQuery) {
     if (c.getTableName().equals(node.getBluePrintNodeName())) {
       try {
         Method m = node.getInterface().getMethod(c.getName(), null);
         Object value = m.invoke(data, null);
         if (value != null) {
           rec.put(c.getName(), value);
         } else {
           rec.put(c.getName(), "");
         }
       } catch (Exception err) {
         err.printStackTrace();
       }
     }
   }
 }
Exemplo n.º 7
0
  public List<Record> addRecords(
      Object element,
      XSQLBluePrintNode node,
      boolean root,
      String tableName,
      XSQLBluePrint bluePrint) {
    List<Record> result = new LinkedList<Record>();
    String nodeID = XSQLODLUtils.getNodeIdentiofier(element);
    if (node.getODLTableName().equals(nodeID)) {
      XSQLBluePrintNode bluePrintNode = bluePrint.getBluePrintNodeByODLTableName(nodeID)[0];
      RecordsContainer rContainer = new RecordsContainer();
      rContainer.currentObject = element;
      XSQLBluePrintNode bpn = this.tablesInQueryMap.get(bluePrintNode.getBluePrintNodeName());
      if (this.criteria.containsKey(bluePrintNode.getBluePrintNodeName()) || bpn != null) {
        collectColumnValues(rContainer, bpn);
        for (Record r : rContainer.records) {
          if (!(isObjectFitCriteria(r.data, bpn.getBluePrintNodeName()) == 1)) {
            r.fitCriteria = false;
          }
          if (r.fitCriteria) {
            Record rec = new Record();
            rec.element = r.element;
            addToData(rec, bpn, bluePrint, r.data);
            rContainer.fitRecords.add(rec);
          }
        }
        if (rContainer.fitRecords.isEmpty()) return EMPTY_RESULT;
      }
      if (rContainer.records.isEmpty()) {
        Record rec = new Record();
        rec.element = rContainer.currentObject;
        if (root) {
          addRecord(rec.data);
        } else {
          result.add(rec);
        }
      } else {
        for (Record rec : rContainer.fitRecords) {
          if (root) {
            addRecord(rec.data);
          } else {
            result.add(rec);
          }
        }
      }
      return result;
    }

    XSQLBluePrintNode parent = node.getParent();
    List<Record> subRecords = addRecords(element, parent, false, tableName, bluePrint);
    for (Record subRec : subRecords) {
      List<Object> subO = getChildren(subRec.element, tableName, bluePrint);
      if (subO != null) {
        for (Object subData : subO) {
          RecordsContainer rContainer = new RecordsContainer();
          rContainer.currentObject = subData;

          String recID = XSQLODLUtils.getNodeIdentiofier(rContainer.currentObject);
          XSQLBluePrintNode eNodes[] = bluePrint.getBluePrintNodeByODLTableName(recID);
          XSQLBluePrintNode bpn = null;
          for (XSQLBluePrintNode eNode : eNodes) {
            bpn = this.tablesInQueryMap.get(eNode.getBluePrintNodeName());
            if (bpn != null) {
              break;
            }
          }
          if (bpn != null) {
            collectColumnValues(rContainer, bpn);
            for (Record r : rContainer.records) {
              if ((isObjectFitCriteria(r.data, bpn.getBluePrintNodeName()) == 1)) {
                Record rec = new Record();
                rec.data.putAll(subRec.data);
                rec.element = r.element;
                addToData(rec, bpn, bluePrint, r.data);
              } else {
                r.fitCriteria = false;
              }
            }
          }
          if (rContainer.records.isEmpty()) {
            Record rec = new Record();
            rec.data.putAll(subRec.data);
            rec.element = rContainer.currentObject;
            if (root) {
              if (!rec.data.isEmpty()) {
                addRecord(rec.data);
              }
            } else {
              result.add(rec);
            }
          } else {
            for (Record r : rContainer.records) {
              r.data.putAll(subRec.data);
              if (r.fitCriteria) {
                if (root) {
                  if (!r.data.isEmpty()) {
                    addRecord(r.data);
                  }
                } else {
                  result.add(r);
                }
              }
            }
          }
        }
      }
    }
    return result;
  }