Package it.eng.spagobi.tools.dataset.common.datastore

Examples of it.eng.spagobi.tools.dataset.common.datastore.IDataStore


  private static transient Logger logger = Logger.getLogger(SpagoBIWidgetInternalEngine.class);

  public void doExecute() {
    JSONObject jsonResponse;
    IDataSet  dataSet = getDataSet();
    IDataStore dataStore;
   
    try {
     
      jsonResponse = new JSONObject();
     
      // get data
      dataSet.setParamsMap(new HashMap());
      dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes( getUserProfile() ));
      dataSet.loadData();
      dataStore = dataSet.getDataStore();
      Object resultNumber = dataStore.getMetaData().getProperty("resultNumber");
      if(resultNumber == null) dataStore.getMetaData().setProperty("resultNumber", new Integer(0));
     
      JSONDataWriter dataStoreWriter = new JSONDataWriter();
      JSONObject data = (JSONObject)dataStoreWriter.write(dataStore);
     
      jsonResponse.put("data", data);
View Full Code Here


              JRParameter parameter = (JRParameter)jasperDesign.getParametersList().get(y);
              String paramName = parameter.getName();
              if(parameter.getValueClassName().equals("net.sf.jasperreports.engine.JRDataSource")&& paramName.equals(datasetName)){//&& parameter.getName().equals(dataset.getLabel()
                //set dataset query value
                dataset.loadData();
                IDataStore dstore = dataset.getDataStore();
              JRSpagoBIDataStoreDataSource dataSource = new JRSpagoBIDataStoreDataSource( dstore );
               
                getEnv().put(paramName, dataSource);
                logger.debug("set parameter"+ paramName+" value");
              }
View Full Code Here

    String geoIdPValue;
   
    GeoReportEngineInstance engineInstance;
   
    IDataSet dataSet;
    IDataStore dataStore;
    IDataStoreMetaData dataStoreMeta;
   
    logger.debug("IN");
   
    try {
     
      featureSourceType = servletIOManager.getParameterAsString(FEATURE_SOURCE_TYPE);
      logger.debug("Parameter [" + FEATURE_SOURCE_TYPE + "] is equal to [" + featureSourceType + "]");
     
      featureSource = servletIOManager.getParameterAsString(FEATURE_SOURCE);
      logger.debug("Parameter [" + FEATURE_SOURCE + "] is equal to [" + featureSourceType + "]");
     
      layerName = servletIOManager.getParameterAsString(LAYER_NAME);
      logger.debug("Parameter [" + LAYER_NAME + "] is equal to [" + layerName + "]");
     
      businessIdPName = servletIOManager.getParameterAsString(BUSINESSID_PNAME);
      logger.debug("Parameter [" + BUSINESSID_PNAME + "] is equal to [" + businessIdPName + "]");
     
      geoIdPName = servletIOManager.getParameterAsString(GEOID_PNAME);
      logger.debug("Parameter [" + GEOID_PNAME + "] is equal to [" + geoIdPName + "]");
     
     
     
     
      engineInstance =  (GeoReportEngineInstance)servletIOManager.getHttpSession().getAttribute(EngineConstants.ENGINE_INSTANCE);
     
      //DataSet
      dataSet = engineInstance.getDataSet();
      dataSet.setParamsMap(engineInstance.getEnv());
      dataSet.loadData();
     
      //Datastore
      dataStore = dataSet.getDataStore();
      dataStoreMeta = dataStore.getMetaData();
           
      // # COL NUMBER
      int nc = dataStoreMeta.getFieldCount();

     
     
      //Create Output Collection of Features
      Collection outputFeatureCollection = new ArrayList();
     
      // used to avoid multiple creation of the same geographical feature
      Set geoIdPValues = new HashSet();
     

      // for each row
      Iterator it = dataStore.iterator();

      IFeaturesProviderDAO featuresProvider = FeaturesProviderDAOFactory.getFeaturesProviderDAO(featureSourceType);
     
      while(it.hasNext()) {
            
View Full Code Here

   
    Integer limit = null;
    Integer start = null;
    Integer maxSize = null;
    boolean isMaxResultsLimitBlocking = false;
    IDataStore dataStore = null;
    IDataSet dataSet = null;
   
    Integer resultNumber = null;
   
   
    try {
      statement.setParameters( engineInstance.getEnv() );
     
      String jpaQueryStr = statement.getQueryString();
      //String sqlQuery = statement.getSqlQueryString();
      logger.debug("Executable query (HQL/JPQL): [" +  jpaQueryStr+ "]");
      //logger.debug("Executable query (SQL): [" + sqlQuery + "]");
      UserProfile userProfile = (UserProfile)engineInstance.getEnv().get(EngineConstants.ENV_USER_PROFILE);
      auditlogger.info("[" + userProfile.getUserId() + "]:: HQL/JPQL: " + jpaQueryStr);
      //auditlogger.info("[" + userProfile.getUserId() + "]:: SQL: " + sqlQuery);
     
     
      logger.debug("Executing query ...");
      dataSet = QbeDatasetFactory.createDataSet(statement);
      dataSet.setAbortOnOverflow(isMaxResultsLimitBlocking);
       
      Map userAttributes = new HashMap();
      UserProfile profile = (UserProfile)engineInstance.getEnv().get(EngineConstants.ENV_USER_PROFILE);
      Iterator it = profile.getUserAttributeNames().iterator();
      while(it.hasNext()) {
        String attributeName = (String)it.next();
        Object attributeValue = profile.getUserAttribute(attributeName);
        userAttributes.put(attributeName, attributeValue);
      }
      dataSet.addBinding("attributes", userAttributes);
      dataSet.addBinding("parameters", engineInstance.getEnv());
      dataSet.loadData(start, limit, (maxSize == null? -1: maxSize.intValue()));
       
      dataStore = dataSet.getDataStore();
      Assert.assertNotNull(dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
     
      logger.debug("Query executed succesfully");
     
      resultNumber = (Integer)dataStore.getMetaData().getProperty("resultNumber");
      Assert.assertNotNull(resultNumber, "property [resultNumber] of the dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
      logger.debug("Total records: " + resultNumber);     
     
     
      boolean overflow = maxSize != null && resultNumber >= maxSize;
View Full Code Here

   
    dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes( profile ));
    dataSet.setParamsMap(parametersFilled);   
    try {
      dataSet.loadData(start, limit, GeneralUtilities.getDatasetMaxResults());
      IDataStore dataStore = dataSet.getDataStore();
      DatasetMetadataParser dsp = new DatasetMetadataParser();
      dsMetadata = dsp.metadataToXML(dataStore);
    }
    catch (Exception e) {
      logger.error("Error while executing dataset for test purpose",e);
View Full Code Here

      if(dataSet.getTransformerId()!=null){
        dataSet.loadData();
      }else{
        dataSet.loadData(start, limit, GeneralUtilities.getDatasetMaxResults());
      }   
      IDataStore dataStore = dataSet.getDataStore();
      JSONDataWriter dataSetWriter = new JSONDataWriter();
      dataSetJSON = (JSONObject) dataSetWriter.write(dataStore);
    }
    catch (Exception e) {
      logger.error("Error while executing dataset for test purpose",e);
View Full Code Here

    public static transient Logger auditlogger = Logger.getLogger("audit.query");
   
 
  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;
        }
      }

      Assert.assertNotNull(dataStore, "The dataStore cannot be null");
      logger.debug("Query executed succesfully");
     
      resultNumber = (Integer)dataStore.getMetaData().getProperty("resultNumber");
      Assert.assertNotNull(resultNumber, "property [resultNumber] of the dataStore returned by queryTemporaryTable method of the class [" + TemporaryTableManager.class.getName()+ "] cannot be null");
      logger.debug("Total records: " + resultNumber);     
     
     
      boolean overflow = maxSize != null && resultNumber >= maxSize;
View Full Code Here

          parameters.put(aDataSetParameterItem.getName(), parameterValues);
        }
      }
      dataSet.setParamsMap(parameters);
      dataSet.loadData();
      IDataStore dataStore = dataSet.getDataStore();
      DataStoreMetaData dataStoreMetadata = (DataStoreMetaData) dataStore.getMetaData();
      toReturn = new SDKObjectsConverter().fromDataStoreMetadataToSDKDataStoreMetadata(dataStoreMetadata);
    } catch(NotAllowedOperationException e) {
      throw e;
    } catch(MissingParameterValue e) {
      throw e;
View Full Code Here

    Integer limit;
    Integer start;
    JSONArray groupFields;
    Integer maxSize;
    boolean isMaxResultsLimitBlocking;
    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;
      }
      logger.debug("Query executed succesfully");
     
     
      //dataStore.getMetaData().setProperty("resultNumber", new Integer( (int)dataStore.getRecordsCount() ));
     
      resultNumber = (Integer)dataStore.getMetaData().getProperty("resultNumber");
      Assert.assertNotNull(resultNumber, "property [resultNumber] of the dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
      logger.debug("Total records: " + resultNumber);     
     
     
      boolean overflow = maxSize != null && resultNumber >= maxSize;
View Full Code Here

      templateContent = templateBuilder.buildTemplate();
     
      if( !"text/jrxml".equalsIgnoreCase( mimeType ) ) {
        if( "application/vnd.ms-excel".equalsIgnoreCase( mimeType ) ) {
         
          IDataStore dataStore = null;
         
          if (!isFormEngineInstance) {
            // case of standard QBE
           
            IDataSet dataSet = null;
View Full Code Here

TOP

Related Classes of it.eng.spagobi.tools.dataset.common.datastore.IDataStore

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.