Exemplo n.º 1
0
  private List getMatchingRowDataList(Map connectorMap, TableData childRt) {
    List filteredList = new ArrayList();
    boolean allPassed = true;
    int size = childRt.getTableSize();
    for (int i = 0; i < size; i++) {
      RowData child = childRt.getRow(i);

      for (Iterator it = connectorMap.keySet().iterator(); it.hasNext(); ) {
        String key = (String) it.next();
        Object keyData = connectorMap.get(key);
        Object rowData = child.getField(key);
        if (rowData == null || !rowData.toString().equalsIgnoreCase(keyData.toString())) {
          allPassed = false;
          break;
        }
      }

      if (allPassed) {
        filteredList.add(child);
      }

      allPassed = true;
    }

    return filteredList;
  }
Exemplo n.º 2
0
  /**
   * Retrieve a list of rows from database with a certain limit range. If the number of returned
   * records is more than the preset limit range, an UnexpectedDataException will be thrown.
   *
   * <p>If DataProcessor.input_key_records_fixed key has value "true" in inputs, absolute fixed
   * number of records is required. An UnexpectedDataException will be thrown if the number of
   * retrieved records is not equal to limitOrFixed.
   *
   * <p>If the limitOrFixed = -1, all records are retrieved.
   *
   * <p>offset defaults to 0.
   *
   * @param inputs Map of input data
   * @param processorType A named sql or direct sql or stored procedure
   * @param processorName Sql name or sql itself or stored procedure name
   * @param limitOrFixed Number of desired (limit) or fixed records to retrieve
   * @param offset int for offset
   * @return TableData The row data
   * @throws com.scooterframework.orm.sqldataexpress.exception.BaseSQLException
   */
  public TableData retrieveRows(
      Map inputs, String processorType, String processorName, int limitOrFixed, int offset)
      throws BaseSQLException {
    if (processorType == null || processorName == null)
      throw new IllegalArgumentException("processorType or processorName is null.");

    if (inputs == null) inputs = new HashMap();

    inputs.put(DataProcessor.input_key_records_offset, new Integer(offset));
    inputs.put(DataProcessor.input_key_records_limit, new Integer(limitOrFixed));

    OmniDTO dto = execute(inputs, processorType, processorName);
    TableData td = dto.getTableData(processorName);

    if (limitOrFixed != DataProcessor.NO_ROW_LIMIT) {
      if (td.getTableSize() > limitOrFixed) {
        throw new UnexpectedDataException(
            "Failed to retrieveRows: required "
                + limitOrFixed
                + " but retrieved "
                + td.getTableSize()
                + ".");
      } else {
        boolean requireFixed =
            Util.getBooleanValue(inputs, DataProcessor.input_key_records_fixed, false);
        if (requireFixed) {
          if (td.getTableSize() != limitOrFixed) {
            throw new UnexpectedDataException(
                "Failed to retrieveRows: required only "
                    + limitOrFixed
                    + " but retrieved "
                    + td.getTableSize()
                    + ".");
          }
        }
      }
    }
    return td;
  }
Exemplo n.º 3
0
  private void linkParentWithChild(
      TableData parentRt, TableData childRt, String processorName, List connectorList) {
    if (parentRt == null || childRt == null || childRt.getTableSize() == 0) return;

    int size = parentRt.getAllRows().size();
    Map connectorMap = new HashMap();
    for (int i = 0; i < size; i++) {
      RowData parentRow = parentRt.getRow(i);
      populateConnectorMap(connectorMap, parentRow, connectorList);
      parentRow.addChildRowToMap(processorName, getMatchingRowDataList(connectorMap, childRt));

      // clear the map for next row
      connectorMap.clear();
    }
  }