Exemplo n.º 1
0
  public List<SqlDataItem> getDataItemList() {
    List<SqlDataItem> result = new ArrayList<SqlDataItem>();
    if (mCurRow == 0 && !mClose) {
      try {
        next();
      } catch (SQLException e) {
        Factory.getLogger()
            .log(Level.WARNING, "Unable to initialize group's data items children", e);
      }
    }

    if (mNbRows >= 0 && mCurRow == 1) {
      try {
        ResultSet set = getResultSet();
        ResultSetMetaData meta = set.getMetaData();
        int count = meta.getColumnCount();

        // prepare columns names
        String[] names = new String[count];
        SqlDataItem[] items = new SqlDataItem[count];

        // Create a SQL array loader
        SqlArrayLoader loader = new SqlArrayLoader(this);
        SqlArray[] arrays = loader.getArrays();

        // Get name for each items
        for (int col = 1; col <= count; col++) {
          // Get the name of the column
          names[col - 1] = meta.getColumnName(col);
        }

        // Fill the array asynchronously
        Thread thread = PostTreatmentManager.launchParallelTreatment(loader);

        // Create items for each arrays
        for (int col = 1; col <= count; col++) {
          // Create the data item
          try {
            items[col - 1] =
                new SqlDataItem(
                    mDataset.getFactoryName(), (SqlGroup) mDataset.getRootGroup(), names[col - 1]);
            result.add(items[col - 1]);
            items[col - 1].setCachedData(arrays[col - 1], false);
          } catch (InvalidArrayTypeException e) {
            Factory.getLogger()
                .log(
                    Level.SEVERE,
                    "Unable to initialize data for the data item: " + names[col - 1],
                    e);
          }
        }
      } catch (SQLException e) {
        Factory.getLogger().log(Level.WARNING, "Unable to initialize group's children", e);
      }
    }
    return result;
  }