@Override
  public IDataStore executeQuery(Integer start, Integer limit) {
    IDataStore dataStore = null;
    IDataSet dataSet = this.getEngineInstance().getActiveQueryAsDataSet();
    AbstractQbeDataSet qbeDataSet = (AbstractQbeDataSet) dataSet;
    IStatement statement = qbeDataSet.getStatement();
    // QueryGraph graph = statement.getQuery().getQueryGraph();
    boolean valid =
        true; // GraphManager.getGraphValidatorInstance(QbeEngineConfig.getInstance().getGraphValidatorImpl()).isValid(graph, statement.getQuery().getQueryEntities(getDataSource()));
    // logger.debug("QueryGraph valid = " + valid);
    if (!valid) {
      throw new SpagoBIEngineServiceException(
          getActionName(), "error.mesage.description.relationship.not.enough");
    }
    try {
      logger.debug("Executing query ...");
      Integer maxSize = QbeEngineConfig.getInstance().getResultLimit();
      logger.debug(
          "Configuration setting  ["
              + "QBE.QBE-SQL-RESULT-LIMIT.value"
              + "] is equals to ["
              + (maxSize != null ? maxSize : "none")
              + "]");
      String jpaQueryStr = statement.getQueryString();
      logger.debug("Executable query (HQL/JPQL): [" + jpaQueryStr + "]");
      UserProfile userProfile = (UserProfile) getEnv().get(EngineConstants.ENV_USER_PROFILE);
      auditlogger.info("[" + userProfile.getUserId() + "]:: HQL/JPQL: " + jpaQueryStr);
      auditlogger.info("[" + userProfile.getUserId() + "]:: SQL: " + statement.getSqlQueryString());

      int startI = start;
      int limitI = (limit == null ? (maxSize == null ? -1 : maxSize) : limit);
      int maxI = (maxSize == null ? -1 : maxSize.intValue());
      dataSet.loadData(startI, limitI, maxI);
      dataStore = dataSet.getDataStore();
      changeAlias(dataStore);
      Assert.assertNotNull(
          dataStore,
          "The dataStore returned by loadData method of the class ["
              + dataSet.getClass().getName()
              + "] cannot be null");
    } catch (Exception e) {
      logger.debug("Query execution aborted because of an internal exceptian");
      SpagoBIEngineServiceException exception;
      String message;

      message =
          "An error occurred in "
              + getActionName()
              + " service while executing query: ["
              + statement.getQueryString()
              + "]";
      exception = new SpagoBIEngineServiceException(getActionName(), message, e);
      exception.addHint(
          "Check if the query is properly formed: [" + statement.getQueryString() + "]");
      exception.addHint("Check connection configuration");
      exception.addHint("Check the qbe jar file");

      throw exception;
    }
    logger.debug("Query executed succesfully");
    return dataStore;
  }
Example #2
0
 private static JSONObject createResponseContent(SpagoBIEngineServiceException exception)
     throws JSONException {
   JSONObject content = new JSONObject();
   content.put("message", exception.getMessage());
   return content;
 }