コード例 #1
0
  private ResultSet getQueryResult(
      Connection connection, PivotWidget widget, Map<String, Object> urlQueryParameters)
      throws ReportRunnerException {

    Entity entity = widget.getEntity();
    ro.nextreports.engine.Report report =
        NextUtil.getNextReport(storageService.getSettings(), entity);
    DataSource dataSource = getDataSource(entity);

    String sql = ro.nextreports.engine.util.ReportUtil.getSql(report);
    // retrieves the report parameters
    Map<String, QueryParameter> parameters = new LinkedHashMap<String, QueryParameter>();
    List<QueryParameter> parameterList = report.getParameters();
    if (parameterList != null) {
      for (QueryParameter param : parameterList) {
        parameters.put(param.getName(), param);
      }
    }

    Map<String, Object> parameterValues = new HashMap<String, Object>();

    // pivot is running with settings parameter values
    ChartUtil.initParameterSettings(
        parameterValues,
        widget.getQueryRuntime(),
        dashboardService.getUserWidgetParameters(widget.getId()));

    // parameters from embedded code
    try {
      ReportUtil.addUrlQueryParameters(
          storageService.getSettings(), entity, parameterValues, urlQueryParameters);
    } catch (Exception e1) {
      e1.printStackTrace();
      LOG.error(e1.getMessage(), e1);
    }

    QueryExecutor executor = null;
    try {
      boolean csv = CSVDialect.DRIVER_CLASS.equals(dataSource.getDriver());

      Query query = new Query(sql);
      executor = new QueryExecutor(query, parameters, parameterValues, connection, true, true, csv);
      executor.setMaxRows(0);
      executor.setTimeout(storageService.getSettings().getQueryTimeout());

      QueryResult queryResult = executor.execute();

      return queryResult.getResultSet();
    } catch (Exception e) {
      throw new ReportRunnerException(e);
    } finally {
      if (executor != null) {
        executor.closeCursors();
      }
    }
  }
コード例 #2
0
  public RunHistoryQueryPanel(String id, final RunReportHistory runHistory) {
    super(id);

    int index = runHistory.getPath().lastIndexOf("/runHistory");
    String reportPath = runHistory.getPath().substring(0, index);
    Report report;
    String query = "NA";
    try {
      report = (Report) storageService.getEntity(reportPath);

      if (ReportConstants.NEXT.equals(report.getType())) {
        query =
            ro.nextreports.engine.util.ReportUtil.getSql(
                NextUtil.getNextReport(settings.getSettings(), report),
                runHistory.getParametersValues());
      }
    } catch (NotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    add(new MultiLineLabel("query", new Model<String>(query)));
  }