Package it.eng.qbe.statement

Examples of it.eng.qbe.statement.IStatement


 
  public static transient Logger logger = Logger.getLogger(ValidateCatalogueAction.class);
 
  public void service(SourceBean request, SourceBean response) {
    Query query;
    IStatement statement;
    boolean validationResult = false;
    String jpaQueryStr;
    String sqlQueryStr;
   
    logger.debug("IN");
   
    try {
      super.service(request, response);
           
      Set queries = getEngineInstance().getQueryCatalogue().getAllQueries(false);
      logger.debug("Query catalogue contains [" + queries.size() + "] first-class query");
     
      Iterator it = queries.iterator();
      while(it.hasNext()) {
        query = (Query)it.next();
        logger.debug("Validating query [" + query.getName() +"] ...");
       
        statement = getEngineInstance().getDataSource().createStatement( query );
        statement.setParameters( getEnv() );
       
        jpaQueryStr = statement.getQueryString();
        //sqlQueryStr = statement.getSqlQueryString();
        logger.debug("Validating query (HQL/JPQL): [" +  jpaQueryStr+ "]");
        //logger.debug("Validating query (SQL): [" + sqlQueryStr + "]");
       
        try {
View Full Code Here


    query.setWhereClauseStructure(leftExpression);
  }
 
  @Override
  protected IStatement getStatement(Query query){
    IStatement statement =  getDataSource().createStatement( query );
    return statement;
  }
View Full Code Here

  public void service(SourceBean request, SourceBean response)  {       
       
    IDataStore dataStore = null;
   
    Query query = null;
    IStatement statement = null;
       
    JSONObject jsonFormState=null;
   
    Integer maxSize = null;
    Integer resultNumber = null;
    CrosstabDefinition crosstabDefinition = null;
   
    Monitor totalTimeMonitor = null;
    Monitor errorHitsMonitor = null;
         
    logger.debug("IN");
   
    try {
   
      super.service(request, response)
     
      totalTimeMonitor = MonitorFactory.start("QbeEngine.executeCrosstabQueryAction.totalTime");
     
      JSONObject crosstabDefinitionJSON = getAttributeAsJSONObject( QbeEngineStaticVariables.CROSSTAB_DEFINITION );
      jsonFormState = loadSmartFilterFormValues();
      logger.debug("Form state retrieved as a string: " + jsonFormState);
     
      Assert.assertNotNull(crosstabDefinitionJSON, "Parameter [" + QbeEngineStaticVariables.CROSSTAB_DEFINITION + "] cannot be null in oder to execute " + this.getActionName() + " service");
      logger.debug("Parameter [" + crosstabDefinitionJSON + "] is equals to [" + crosstabDefinitionJSON.toString() + "]");
      //crosstabDefinition = SerializerFactory.getDeserializer("application/json").deserializeCrosstabDefinition(crosstabDefinitionJSON);;
      crosstabDefinition = (CrosstabDefinition)SerializationManager.deserialize(crosstabDefinitionJSON, "application/json", CrosstabDefinition.class);
      crosstabDefinition.setCellLimit( new Integer((String)ConfigSingleton.getInstance().getAttribute("QBE.QBE-CROSSTAB-CELLS-LIMIT.value")) );
      maxSize = QbeEngineConfig.getInstance().getResultLimit();     
      logger.debug("Configuration setting  [" + "QBE.QBE-SQL-RESULT-LIMIT.value" + "] is equals to [" + (maxSize != null? maxSize: "none") + "]");
     
      Assert.assertNotNull(getEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
     
      // retrieving first QbE query and setting it as active query
      query = getEngineInstance().getQueryCatalogue().getFirstQuery();
     
      //build the query filtered for the smart filter
      if (jsonFormState != null) {
        query = getFilteredQuery(query, jsonFormState);
      }
     
      getEngineInstance().setActiveQuery(query);
     
      statement = getEngineInstance().getStatment()
      statement.setParameters( getEnv() );
     

      String sqlQuery = statement.getSqlQueryString();
      UserProfile userProfile = (UserProfile)getEnv().get(EngineConstants.ENV_USER_PROFILE);
     
      ConnectionDescriptor connection = (ConnectionDescriptor)getDataSource().getConfiguration().loadDataSourceProperties().get("connection");
      DataSource dataSource = getDataSource(connection);
     
      String sqlStatement = buildSqlStatement(crosstabDefinition, query, sqlQuery, statement);
      logger.debug("Querying temporary table: user [" + userProfile.getUserId() + "] (SQL): [" + sqlStatement + "]");
     
      if (!TemporaryTableManager.isEnabled()) {
        logger.warn("TEMPORARY TABLE STRATEGY IS DISABLED!!! " +
            "Using inline view construct, therefore performance will be very low");
        int beginIndex = sqlStatement.toUpperCase().indexOf(" FROM ") + " FROM ".length();
        int endIndex = sqlStatement.indexOf(" ", beginIndex);
        String inlineSQLQuery = sqlStatement.substring(0, beginIndex) + " ( " + sqlQuery + " ) TEMP " + sqlStatement.substring(endIndex);
        logger.debug("Executable query for user [" + userProfile.getUserId() + "] (SQL): [" + inlineSQLQuery + "]");
        auditlogger.info("[" + userProfile.getUserId() + "]:: SQL: " + inlineSQLQuery);
        JDBCDataSet dataSet = new JDBCDataSet();
        dataSet.setDataSource(dataSource);
        dataSet.setQuery(inlineSQLQuery);
        dataSet.loadData();
        dataStore = (DataStore) dataSet.getDataStore();
      } else {
        logger.debug("Using temporary table strategy....");
   
        logger.debug("Temporary table definition for user [" + userProfile.getUserId() + "] (SQL): [" + sqlQuery + "]");
   
        auditlogger.info("Temporary table definition for user [" + userProfile.getUserId() + "]:: SQL: " + sqlQuery);
        auditlogger.info("Querying temporary table: user [" + userProfile.getUserId() + "] (SQL): [" + sqlStatement + "]");

        try {
          dataStore = TemporaryTableManager.queryTemporaryTable(userProfile, sqlStatement, sqlQuery, dataSource);
        } catch (Exception e) {
          logger.debug("Query execution aborted because of an internal exception");
          String message = "An error occurred in " + getActionName() + " service while querying temporary table";       
          SpagoBIEngineServiceException exception = new SpagoBIEngineServiceException(getActionName(), message, e);
          exception.addHint("Check if the base query is properly formed: [" + statement.getQueryString() + "]");
          exception.addHint("Check if the crosstab's query is properly formed: [" + sqlStatement + "]");
          exception.addHint("Check connection configuration: connection's user must have DROP and CREATE privileges");
         
          throw exception;
        }
View Full Code Here

      Query query = engineInstance.getQueryCatalogue().getQuery(queryId);
      execute(engineInstance, query);
    }
   
    public static void execute(QbeEngineInstance engineInstance, Query query) {
      IStatement statement = engineInstance.getDataSource().createStatement( query );
      execute(engineInstance, statement);
    }
View Full Code Here

    public static final String ENGINE_NAME = "SpagoBIQbeEngine";
   
    public void service(SourceBean request, SourceBean response) {
   
    Query query = null;
    IStatement statement = null;
     
      logger.debug("IN");
      
      try {
      super.service(request, response)
     
      // retrieving query specified by id on request
      query = getEngineInstance().getActiveQuery();
      if (query == null) {
        query = getEngineInstance().getQueryCatalogue().getFirstQuery();
        getEngineInstance().setActiveQuery(query);
      }
      Assert.assertNotNull(query, "Query not found!!");

      // promptable filters values may come with request (read-only user modality)
      ExecuteQueryAction.updatePromptableFiltersValue(query, this);
     
      statement = getEngineInstance().getStatment()
      statement.setParameters( getEnv() );
     
      String jpaQueryStr = statement.getQueryString();
      String sqlQuery = statement.getSqlQueryString();
      logger.debug("Executable query (HQL/JPQL): [" +  jpaQueryStr+ "]");
      logger.debug("Executable query (SQL): [" + sqlQuery + "]");
     
      JSONObject toReturn = new JSONObject();
      toReturn.put("sql", sqlQuery);
View Full Code Here

   
    String responseType = null;
    boolean writeBackResponseInline = false;
    String mimeType = null;
    String fileExtension = null;
    IStatement statement = null;
    ITransaction transaction = null
    Connection connection = null;
    //HQL2SQLStatementRewriter queryRewriter = null;
    String jpaQueryStr = null;
    String sqlQuery = null;
    SQLFieldsReader fieldsReader = null;
    Vector extractedFields = null;
    Map params = null;
    TemplateBuilder templateBuilder = null;
    String templateContent = null;
    File reportFile = null;
    ReportRunner runner = null;
    boolean isFormEngineInstance = false;
   
    logger.debug("IN");
   
    try {
      super.service(request, response)
     
      mimeType = getAttributeAsString( MIME_TYPE );
      logger.debug(MIME_TYPE + ": " + mimeType);   
      responseType = getAttributeAsString( RESPONSE_TYPE );
      logger.debug(RESPONSE_TYPE + ": " + responseType);
         
      Assert.assertNotNull(getEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
     
      transaction = (getEngineInstance().getDataSource()).getTransaction()
      transaction.open();
     
      fileExtension = MimeUtils.getFileExtension( mimeType );
      writeBackResponseInline = RESPONSE_TYPE_INLINE.equalsIgnoreCase(responseType);
     
      isFormEngineInstance = getEngineInstance().getTemplate().getProperty("formJSONTemplate") != null;
      if (!isFormEngineInstance) {
        // case of standard QBE
       
        Assert.assertNotNull(getEngineInstance().getActiveQuery(), "Query object cannot be null in oder to execute " + this.getActionName() + " service");
        Assert.assertTrue(getEngineInstance().getActiveQuery().isEmpty() == false, "Query object cannot be empty in oder to execute " + this.getActionName() + " service");
           
        Assert.assertNotNull(mimeType, "Input parameter [" + MIME_TYPE + "] cannot be null in oder to execute " + this.getActionName() + " service");   
        Assert.assertTrue( MimeUtils.isValidMimeType( mimeType ) == true, "[" + mimeType + "] is not a valid value for " + MIME_TYPE + " parameter");
       
        Assert.assertNotNull(responseType, "Input parameter [" + RESPONSE_TYPE + "] cannot be null in oder to execute " + this.getActionName() + " service");   
        Assert.assertTrue( RESPONSE_TYPE_INLINE.equalsIgnoreCase(responseType) || RESPONSE_TYPE_ATTACHMENT.equalsIgnoreCase(responseType), "[" + responseType + "] is not a valid value for " + RESPONSE_TYPE + " parameter");
       
        statement = getEngineInstance().getDataSource().createStatement( getEngineInstance().getActiveQuery() );   
        //logger.debug("Parametric query: [" + statement.getQueryString() + "]");
       
        statement.setParameters( getEnv() );
        jpaQueryStr = statement.getQueryString();
        logger.debug("Executable HQL/JPQL query: [" + jpaQueryStr + "]");
       
        sqlQuery = statement.getSqlQueryString();
        Assert.assertNotNull(sqlQuery, "The SQL query is needed while exporting results.");
       
      } else {
        // case of FormEngine
       
View Full Code Here

    IDataStore dataStore;
    JDBCDataSet dataSet;
    JSONDataWriter dataSetWriter;
   
    Query query;
    IStatement statement;
   
    Integer resultNumber;
    JSONObject gridDataFeed = new JSONObject();
   
    Monitor totalTimeMonitor = null;
    Monitor errorHitsMonitor;
         
    logger.debug("IN");
   
    try {
   
      super.service(request, response)
     
      totalTimeMonitor = MonitorFactory.start("QbeEngine.executeQueryAction.totalTime");
     
      start = getAttributeAsInteger( START )
      logger.debug("Parameter [" + START + "] is equals to [" + start + "]");
     
      limit = getAttributeAsInteger( LIMIT );
      logger.debug("Parameter [" + LIMIT + "] is equals to [" + limit + "]");
     
      groupFields = getAttributeAsJSONArray( GROUPBY_FIELDS );
      logger.debug("Parameter [" + GROUPBY_FIELDS + "] is equals to [" + groupFields + "]");
      Assert.assertNotNull(groupFields, "Parameter [" + GROUPBY_FIELDS + "] cannot be null");
      Assert.assertTrue(groupFields.length() > 0, "GroupBy fileds list cannot be empty");
           
      maxSize = QbeEngineConfig.getInstance().getResultLimit();     
      logger.debug("Configuration setting  [" + "QBE.QBE-SQL-RESULT-LIMIT.value" + "] is equals to [" + (maxSize != null? maxSize: "none") + "]");
      isMaxResultsLimitBlocking = QbeEngineConfig.getInstance().isMaxResultLimitBlocking();
      logger.debug("Configuration setting  [" + "QBE.QBE-SQL-RESULT-LIMIT.isBlocking" + "] is equals to [" + isMaxResultsLimitBlocking + "]");
     
      Assert.assertNotNull(getEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
     
     
      // STEP 1: modify the query according to the input that come from the form
      query = getEngineInstance().getQueryCatalogue().getFirstQuery();
     
      // ... query transformation goes here 
      logger.debug("Making a deep copy of the original query...");
      String store = ((JSONObject)SerializerFactory.getSerializer("application/json").serialize(query, getEngineInstance().getDataSource(), getLocale())).toString();
      Query copy = SerializerFactory.getDeserializer("application/json").deserializeQuery(store, getEngineInstance().getDataSource());
      logger.debug("Deep copy of the original query produced");
     
      String jsonEncodedFormState = getAttributeAsString( FORM_STATE );
      logger.debug("Form state retrieved as a string: " + jsonEncodedFormState);
      JSONObject formState = new JSONObject(jsonEncodedFormState);
      logger.debug("Form state converted into a valid JSONObject: " + formState.toString(3));
      JSONObject template = (JSONObject) getEngineInstance().getFormState().getConf();
      logger.debug("Form viewer template retrieved.");
     
      FormViewerQueryTransformer formViewerQueryTransformer = new FormViewerQueryTransformer();
      formViewerQueryTransformer.setFormState(formState);
      formViewerQueryTransformer.setTemplate(template);
      logger.debug("Applying Form Viewer query transformation...");
      query = formViewerQueryTransformer.execTransformation(copy);
      logger.debug("Applying Form Viewer query transformation...");
     
      updatePromptableFiltersValue(query);
      getEngineInstance().setActiveQuery(query);
     
     
      // STEP 2: prepare statment and obtain the corresponding sql query
      statement = getEngineInstance().getStatment()
      statement.setParameters( getEnv() );
     
      //String jpaQueryStr = statement.getQueryString();
      String sqlQuery = statement.getSqlQueryString();
     
      UserProfile userProfile = (UserProfile)getEnv().get(EngineConstants.ENV_USER_PROFILE);
     
     
      // STEP 3: transform the sql query
      GroupByQueryTransformer transformer = new GroupByQueryTransformer();
      List selectFields = SqlUtils.getSelectFields(sqlQuery);
     
      for(int i = 0; i < groupFields.length(); i++) {
        String groupByField = groupFields.getString(i);
        int fieldIndex = query.getSelectFieldIndex(groupByField);   
        Assert.assertTrue(fieldIndex >= 0 && fieldIndex <selectFields.size(), "Impossible to group on field [" + groupByField + "]");
        String[] f = (String[])selectFields.get(fieldIndex);       
        transformer.addGrouByColumn(f[1]!=null? f[1]:f[0], query.getSelectFieldByIndex(fieldIndex).getAlias());
      }
     
      // count column
      transformer.addAggregateColumn("*"/*f[1]!=null? f[1]:f[0]*/, "COUNT", "Records");
     
      // aggregate measures
      List dataMartSelectFields = query.getDataMartSelectFields(true);
      Iterator it = dataMartSelectFields.iterator();
      while (it.hasNext()) {
        DataMartSelectField field = (DataMartSelectField) it.next();
        int fieldIndex = query.getSelectFieldIndex(field.getUniqueName());       
        String[] f = (String[])selectFields.get(fieldIndex);
        IAggregationFunction aggregationFunction = field.getFunction();
        if (aggregationFunction != null && aggregationFunction != AggregationFunctions.NONE_FUNCTION) {
          transformer.addAggregateColumn(f[1]!=null? f[1]:f[0], aggregationFunction.getName(), field.getAlias());
        }
      }
     
      sqlQuery = (String)transformer.transformQuery(sqlQuery);
     
      // STEP 4: execute the query
     
      try {
        logger.debug("Executing query: [" + sqlQuery + "]");
        auditlogger.info("[" + userProfile.getUserId() + "]:: SQL: " + sqlQuery);
       
        dataSet = new JDBCDataSet();
        ConnectionDescriptor connection = (ConnectionDescriptor)getDataSource().getConfiguration().loadDataSourceProperties().get("connection");
        DataSource dataSource = new DataSource();
        dataSource.setJndi(connection.getJndiName());
        dataSource.setHibDialectName(connection.getDialect());
        dataSource.setUrlConnection(connection.getUrl());
        dataSource.setDriver(connection.getDriverClass());
        dataSource.setUser(connection.getUsername());
        dataSource.setPwd(connection.getPassword());
        dataSet.setDataSource(dataSource);
        dataSet.setQuery(sqlQuery);
        dataSet.loadData(start, limit, -1);
        dataStore = dataSet.getDataStore();
      } 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;
      }
View Full Code Here

   
    try {
      super.service(request, response);
     
      boolean validationResult = false;
      IStatement statement = getEngineInstance().getStatment()
      statement.setParameters( getEnv() );
      String jpaQueryStr = statement.getQueryString();
    //  String sqlQuery = statement.getSqlQueryString();
      logger.debug("Validating query (HQL/JPQL): [" +  jpaQueryStr+ "]");
    //  logger.debug("Validating query (SQL): [" + sqlQuery + "]");
      try {
        IDataSet dataSet = QbeDatasetFactory.createDataSet(statement);
View Full Code Here

    boolean isMaxResultsLimitBlocking = false;
    IDataStore dataStore = null;
    JSONDataWriter dataSetWriter;
   
    Query query = null;
    IStatement statement = null;
   
    Integer resultNumber = null;
    JSONObject gridDataFeed = new JSONObject();
   
    Monitor totalTimeMonitor = null;
View Full Code Here

   * Build the statement
   * @param query
   * @return
   */
  protected IStatement getStatement(Query query){
    IStatement statement = getEngineInstance().getStatment()
    statement.setParameters( getEnv() );
    return statement;
  }
View Full Code Here

TOP

Related Classes of it.eng.qbe.statement.IStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.