Esempio n. 1
0
  /**
   * 保存Table数据,并指定列范围
   *
   * @param conn
   * @param table
   * @param tableName 数据库表名
   * @param columns 列范围
   * @throws SQLException
   */
  public static void saveData(
      Connection conn, Table table, String tableName, Collection<String> columns)
      throws SQLException {
    if (columns == null) {
      columns = new ArrayList<String>();
      columns.addAll(table.getColumnNames());
    }
    String idColumn = table.getIDColumn();

    PreparedStatement newStat = conn.prepareStatement(createNewSQL(table, tableName, columns));
    try {
      for (Row row : table.getRows(RowState.NEW)) {
        int i = 1;
        for (String column : columns) {
          newStat.setObject(i, row.getValue(column));
          i++;
        }
        newStat.execute();
      }
    } finally {
      newStat.close();
    }
    PreparedStatement editStat = conn.prepareStatement(createUpdateSQL(table, tableName, columns));
    try {
      for (Row row : table.getRows(RowState.EDIT)) {
        int i = 1;
        for (String column : columns) {
          editStat.setObject(i, row.getValue(column));
          i++;
        }
        editStat.setObject(
            columns.size() + 1,
            row.isChanged(idColumn)
                ? row.getOldValue(table.getIDColumn())
                : row.getValue(idColumn));
        editStat.execute();
      }
    } finally {
      editStat.close();
    }
    PreparedStatement deleteStat = conn.prepareStatement(createDeleteSQL(table, tableName));
    try {
      for (Row row : table.getRows(RowState.DELETE)) {
        deleteStat.setObject(
            1,
            row.isChanged(idColumn)
                ? row.getOldValue(table.getIDColumn())
                : row.getValue(idColumn));
        deleteStat.execute();
      }
    } finally {
      deleteStat.close();
    }
  }
  public List<Integer> result(Table table) {
    LinearRegressionCreater linearRegressionCreater = new LinearRegressionCreater(table);
    Map<Integer, LinearRegression> linearRegressions = linearRegressionCreater.create();

    Majority majority = new Majority();
    for (int i = 1; i < table.getRows().size(); i++) {
      List<String> row = table.getRow(i);
      List<Double> absoluteValues = calcuLowAbsoluteValues(row, linearRegressions);
      majority.addPoints(absoluteValues);
    }
    return majority.calculate();
  }
Esempio n. 3
0
  /**
   * Appends all rows and tables of the actual schema to the result. Only tables that are in the
   * expected schema will be appended.
   *
   * @param schema The expected schema, not null
   * @param actualSchema The actual schema, not null
   * @param result The result to append to, not null
   */
  protected void appendSchemaContent(Schema schema, Schema actualSchema, StringBuilder result) {
    for (Table table : schema.getTables()) {
      Table actualTable = actualSchema.getTable(table.getName());
      if (actualTable == null) {
        continue;
      }
      appendTableName(schema, actualTable, result);
      result.append("\n");

      if (actualTable.getRows().isEmpty()) {
        result.append("  <empty table>\n");
      } else {
        result.append("  ");
        appendColumnNames(actualTable.getRows().get(0), result);
        result.append("\n");
        for (Row row : actualTable.getRows()) {
          result.append("  ");
          appendRow(row, result);
          result.append("\n");
        }
      }
      result.append("\n");
    }
  }
Esempio n. 4
0
 /**
  * @param objects
  * @param pageSize
  */
 public TableScroller(Table table, int pageSize) {
   super(table.getRows(), pageSize);
   this.table = table;
 }
Esempio n. 5
0
 public Row[] getRows() {
   return mainTable.getRows();
 }