コード例 #1
0
  public ReportParameterValue[] getParamValues(
      ReportParameter reportParameter, Map<String, Object> parameters) throws ProviderException {
    if (reportParameter.getType().equals(ReportParameter.QUERY_PARAM)) {
      return getParamValuesFromDataSource(reportParameter, parameters);
    } else if (reportParameter.getType().equals(ReportParameter.LIST_PARAM)) {
      return parseListValues(reportParameter);
    } else if (reportParameter.getType().equals(ReportParameter.BOOLEAN_PARAM)) {
      // default to Yes/No
      if (reportParameter.getData() == null || reportParameter.getData().indexOf("|") == -1) {
        reportParameter.setData("true:Yes|false:No");
      }

      return parseListValues(reportParameter);
    }

    throw new ProviderException(
        reportParameter.getName()
            + ": param-type "
            + reportParameter.getType()
            + " not supported!");
  }
コード例 #2
0
  protected ReportParameterValue[] parseListValues(ReportParameter reportParameter)
      throws ProviderException {
    StringTokenizer st = new StringTokenizer(reportParameter.getData(), "|");

    ReportParameterValue[] values = new ReportParameterValue[st.countTokens()];

    int index = 0;
    while (st.hasMoreTokens()) {
      String token = st.nextToken();
      String id = token;
      String description = token;

      StringTokenizer paramValue = new StringTokenizer(token, ":");
      if (paramValue.countTokens() == 2) {
        id = paramValue.nextToken();
        description = paramValue.nextToken();
      }

      try {
        if (reportParameter.getClassName().equals("java.lang.Integer")) {
          values[index] = new ReportParameterValue(Integer.valueOf(id), description);
        } else if (reportParameter.getClassName().equals("java.lang.Double")) {
          values[index] = new ReportParameterValue(Double.valueOf(id), description);
        } else if (reportParameter.getClassName().equals("java.lang.Long")) {
          values[index] = new ReportParameterValue(Long.valueOf(id), description);
        } else if (reportParameter.getClassName().equals("java.math.BigDecimal")) {
          values[index] = new ReportParameterValue(new BigDecimal(id), description);
        } else {
          values[index] = new ReportParameterValue(id, description);
        }
      } catch (Exception e) {
        throw new ProviderException(
            reportParameter.getData() + " contains invalid " + reportParameter.getClassName());
      }

      index++;
    }

    return values;
  }
コード例 #3
0
  protected ReportParameterValue[] getParamValuesFromDataSource(
      ReportParameter param, Map<String, Object> parameters) throws ProviderException {
    Connection conn = null;
    PreparedStatement pStmt = null;
    ResultSet rs = null;

    try {
      ReportDataSource dataSource = param.getDataSource();
      conn = dataSourceProvider.getConnection(dataSource.getId());

      if (parameters == null || parameters.isEmpty()) {
        pStmt = conn.prepareStatement(param.getData());
      } else {
      }

      rs = pStmt.executeQuery();

      ResultSetMetaData rsMetaData = rs.getMetaData();

      boolean multipleColumns = false;
      if (rsMetaData.getColumnCount() > 1) multipleColumns = true;

      ArrayList<ReportParameterValue> v = new ArrayList<ReportParameterValue>();

      while (rs.next()) {
        ReportParameterValue value = new ReportParameterValue();

        if (param.getClassName().equals("java.lang.String")) {
          value.setId(rs.getString(1));
        } else if (param.getClassName().equals("java.lang.Double")) {
          value.setId(new Double(rs.getDouble(1)));
        } else if (param.getClassName().equals("java.lang.Integer")) {
          value.setId(new Integer(rs.getInt(1)));
        } else if (param.getClassName().equals("java.lang.Long")) {
          value.setId(new Long(rs.getLong(1)));
        } else if (param.getClassName().equals("java.math.BigDecimal")) {
          value.setId(rs.getBigDecimal(1));
        } else if (param.getClassName().equals("java.util.Date")) {
          value.setId(rs.getDate(1));
        } else if (param.getClassName().equals("java.sql.Date")) {
          value.setId(rs.getDate(1));
        } else if (param.getClassName().equals("java.sql.Timestamp")) {
          value.setId(rs.getTimestamp(1));
        }

        if (multipleColumns) {
          value.setDescription(rs.getString(2));
        }

        v.add(value);
      }

      rs.close();

      ReportParameterValue[] values = new ReportParameterValue[v.size()];
      v.toArray(values);

      return values;
    } catch (Exception e) {
      throw new ProviderException("Error retreiving param values from database: " + e.getMessage());
    } finally {
      try {
        if (pStmt != null) pStmt.close();
        if (conn != null) conn.close();
      } catch (Exception c) {
        log.error("Error closing");
      }
    }
  }