Example #1
0
  @Override
  public ResultSet apply(ResultSet pResultSet) {
    TableMetadata tableMetadata = pResultSet.getTableMetadata();

    LinkedList<String> tmp = new LinkedList<String>();

    for (int x = 0; x < tableMetadata.getTableColumns().size(); x++) {
      tmp.add("null");
    }

    LinkedList<Integer> colIndex = new LinkedList<>();
    LinkedList<Integer> colNull = new LinkedList<>();

    Iterator<String> i = this._Columns.iterator();

    String col;

    while (i.hasNext()) {
      col = i.next();
      int indexOfColumn = tableMetadata.indexByName(col);
      System.out.println(indexOfColumn);
      colIndex.add(indexOfColumn);
    }

    for (int c = 0; c < tableMetadata.getTableColumns().size(); c++) {
      System.out.println("concha");
      if (!colIndex.contains(c)) {
        System.out.println("culo");
        colNull.add(c);
      }
    }

    for (int j = 0; j < this._Values.size(); j++) {
      System.out.println("pene");
      tmp.set(colIndex.get(j), this._Values.get(j));
    }

    for (int k = 0; k < colNull.size(); k++) {
      System.out.println("astro");
      tmp.set(colNull.get(k), "null");
    }
    TableRegister tr = new TableRegister(tmp);
    LinkedList<TableRegister> list = new LinkedList<TableRegister>();
    list.add(tr);
    TableData t = new TableData(list);

    return (new ResultSet(t, tableMetadata));
  }
Example #2
0
  public ResultSet crossTable(ResultSet pTable, ResultSet pAnotherTable) {
    String PKName1 = pTable.getTableMetadata().getPrimaryKey().getName();
    String PKName2 = pAnotherTable.getTableMetadata().getPrimaryKey().getName();

    // Position of PK in the data structure.
    int indexOfPrimaryKey1 = pTable.getTableMetadata().indexByName(PKName1);
    int indexOfPrimaryKey2 = pAnotherTable.getTableMetadata().indexByName(PKName2);

    Iterator<TableRegister> iteratorFromTable = pTable.getTableData().getData().iterator();
    Iterator<TableRegister> iteratorToTable = pAnotherTable.getTableData().getData().iterator();

    Iterator<String> stringIterator;

    TableRegister tmpRegisterFrom = null;
    TableRegister tmpRegisterTo = null;

    TableData newData = new TableData();
    TableMetadata newMetadata =
        this.crossMetadata(pTable.getTableMetadata(), pAnotherTable.getTableMetadata());
    while (iteratorFromTable.hasNext()) {
      tmpRegisterFrom = iteratorFromTable.next();
      while (iteratorToTable.hasNext()) {
        tmpRegisterTo = iteratorToTable.next();

        // If Primary Key Is Equal
        if (tmpRegisterFrom
            .getRegister()
            .get(indexOfPrimaryKey1)
            .equalsIgnoreCase(tmpRegisterTo.getRegister().get(indexOfPrimaryKey2))) {
          stringIterator = tmpRegisterTo.getRegister().iterator();
          while (stringIterator.hasNext()) {
            tmpRegisterFrom.getRegister().add(stringIterator.next());
          }
          newData.getData().add(tmpRegisterFrom);
        }
      }
    }
    return (new ResultSet(newData, newMetadata));
  }