Package it.eng.qbe.query

Examples of it.eng.qbe.query.ISelectField


    JSONArray selectedFieldsJSON;
   
    selectedFieldsJSON = new JSONArray();
   
    for(int i = 0; i < selectedFields.size(); i++) {
      ISelectField f = (ISelectField)selectedFields.get(i);
      if(f.isDataMartField()) {
        DataMartSelectField dataMartSelectField = (DataMartSelectField)f;
        JSONObject selectFieldJSON = new JSONObject();
        try {
          selectFieldJSON.put("name", dataMartSelectField.getUniqueName());
          selectFieldJSON.put("alias", dataMartSelectField.getAlias());
View Full Code Here


    List selectedFields = getEngineInstance().getActiveQuery().getSelectFields(true);
    Iterator selectedFieldsIterator = selectedFields.iterator();
    Iterator extractedFieldsIterator =  extractedFields.iterator();
    while( extractedFieldsIterator.hasNext() ) {
      Field exctractedField = (Field)extractedFieldsIterator.next();
      ISelectField selectedField = (ISelectField)selectedFieldsIterator.next();
      exctractedField.setAlias( selectedField.getAlias() );
      exctractedField.setVisible( selectedField.isVisible() );
      if(selectedField.isDataMartField())
        exctractedField.setPattern( ((DataMartSelectField)selectedField).getPattern() );
    }
  }
View Full Code Here

    String toReturn = null;
   
    List qbeQueryFields = baseQuery.getSelectFields(true);
    int index = -1;
    for (int i = 0; i < qbeQueryFields.size(); i++) {
      ISelectField field = (ISelectField) qbeQueryFields.get(i);
      if (field.getAlias().equals(elementElias)) {
        index = i;
        break;
      }
    }
   
View Full Code Here

      FilterQueryTransformer transformer = new FilterQueryTransformer();
      List selectFields = SqlUtils.getSelectFields(sqlQuery);
     
      List queryFields = query.getDataMartSelectFields(true);
      for(int i = 0; i < queryFields.size(); i++) {
        ISelectField queryField = (ISelectField)queryFields.get(i);
        String[] f = (String[])selectFields.get(i)
        transformer.addColumn(f[1]!=null? f[1]:f[0], f[1]!=null? f[1]:f[0]);       
      }
     
      for(int i = 0; i < filters.length(); i++) {
        JSONObject filter = filters.getJSONObject(i);
        String columnName = filter.getString("columnName");
        String value = filter.getString("value");
       
        int fieldIndex = query.getSelectFieldIndex(columnName);       
        String[] f = (String[])selectFields.get(fieldIndex);   
        transformer.addFilter(f[1]!=null? f[1]:f[0], value);
      }
     
      sqlQuery = (String)transformer.transformQuery(sqlQuery);
     
      // put the query into session
      this.setAttributeInSession(LAST_DETAIL_QUERY, sqlQuery);
     
      // STEP 4: execute the query
     
      try {
        logger.debug("Executing query: [" + sqlQuery + "]");
        auditlogger.info("[" + userProfile.getUserId() + "]:: SQL: " + sqlQuery);
       
        dataSet = new JDBCDataSet();
        //Session session = getDatamartModel().getDataSource().getSessionFactory().openSession();
        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();
        IDataStoreMetaData dataStoreMetadata = dataStore.getMetaData();
        for(int i = 0; i < dataStoreMetadata.getFieldCount(); i++) {
          ISelectField queryField = (ISelectField)queryFields.get(i);
          dataStoreMetadata.changeFieldAlias(i, queryField.getAlias());
        }
      } catch (Exception e) {
        logger.debug("Query execution aborted because of an internal exceptian");
        SpagoBIEngineServiceException exception;
        String message;
View Full Code Here

   */
  private JSONArray serializeFields(Query query, IDataSource dataSource, Locale locale) throws SerializationException {
    JSONArray result;
   
    List fields;
    ISelectField field;
    String fieldUniqueName;
    IModelField datamartField;
    JSONObject fieldJSON;
    Iterator it;
    IModelProperties datamartLabels;
    String label, longDescription;
   
    logger.debug("IN");
   
    try {
      datamartLabels = null;
      if(locale != null) {
        //datamartLabels =  QbeCacheManager.getInstance().getLabels( dataSource , locale );
        datamartLabels = dataSource.getModelI18NProperties(locale);
      }
     
      fields = query.getSelectFields(false);
      Assert.assertNotNull(fields, "Fields cannot be null");
      logger.debug("Query [" + query.getId() + "] have [" + fields.size() + "] field/s to serialize");
     
      result = new JSONArray();
      it = fields.iterator();
      while( it.hasNext() ) {
        field = (ISelectField)it.next();
        logger.debug("Serializing filed [" + field.getAlias() + "]");
        try {
          fieldJSON = new JSONObject();
         
          fieldJSON.put(QuerySerializationConstants.FIELD_ALIAS, field.getAlias());
         
          fieldJSON.put(QuerySerializationConstants.FIELD_VISIBLE, field.isVisible());
          fieldJSON.put(QuerySerializationConstants.FIELD_INCLUDE, field.isIncluded());         
         
          // field nature can me "measure" or "attribute"
          String nature = null;
         
          if (field.isDataMartField()) {
            DataMartSelectField dataMartSelectField = (DataMartSelectField)field;
           
            fieldJSON.put(QuerySerializationConstants.FIELD_TYPE, field.DATAMART_FIELD);
           
            fieldUniqueName = dataMartSelectField.getUniqueName();
            datamartField = dataSource.getModelStructure().getField( fieldUniqueName );
            Assert.assertNotNull(datamartField, "A filed named [" + fieldUniqueName + "] does not exist in the datamart model");
           
            fieldJSON.put(QuerySerializationConstants.FIELD_ID, datamartField.getUniqueName());
                       
            // localize entity name
            label = null;
            if(datamartLabels != null) {
              label = datamartLabels.getProperty(datamartField.getParent(), "label");
            }
            label = StringUtilities.isEmpty(label)? datamartField.getParent().getName(): label;
            fieldJSON.put(QuerySerializationConstants.FIELD_ENTITY, label);
           
            // localize field name
            label = null;
            if(datamartLabels != null) {
              label = datamartLabels.getProperty(datamartField, "label");
            }
            label = StringUtilities.isEmpty(label)? datamartField.getName(): label;
            fieldJSON.put(QuerySerializationConstants.FIELD_NAME, label);
            longDescription = getFieldLongDescription(datamartField, datamartLabels);
            fieldJSON.put(QuerySerializationConstants.FIELD_LONG_DESCRIPTION, longDescription);
           
            if( dataMartSelectField.isGroupByField() ) {
              fieldJSON.put(QuerySerializationConstants.FIELD_GROUP, "true");
            } else {
              fieldJSON.put(QuerySerializationConstants.FIELD_GROUP, "");
            }
            fieldJSON.put(QuerySerializationConstants.FIELD_ORDER, dataMartSelectField.getOrderType());
            fieldJSON.put(QuerySerializationConstants.FIELD_AGGREGATION_FUNCTION, dataMartSelectField.getFunction().getName());
           
            //DatamartProperties datamartProperties = dataSource.getDataMartProperties();
            String iconCls = datamartField.getPropertyAsString("type")
            fieldJSON.put(QuerySerializationConstants.FIELD_ICON_CLS, iconCls);
           
            // if an aggregation function is defined or if the field is declared as "measure" into property file,
            // then it is a measure, elsewhere it is an attribute
            if (
                (dataMartSelectField.getFunction() != null
                && !dataMartSelectField.getFunction().equals(AggregationFunctions.NONE_FUNCTION))
                || iconCls.equals("measure")) {
              nature = QuerySerializationConstants.FIELD_NATURE_MEASURE;
            } else {
              nature = QuerySerializationConstants.FIELD_NATURE_ATTRIBUTE;
            }
           
          } else if (field.isCalculatedField()){
            CalculatedSelectField calculatedSelectField = (CalculatedSelectField)field;
           
            fieldJSON.put(QuerySerializationConstants.FIELD_TYPE, field.CALCULATED_FIELD);
           
            JSONObject fieldClaculationDescriptor = new JSONObject();
            fieldClaculationDescriptor.put(QuerySerializationConstants.FIELD_TYPE, calculatedSelectField.getType());
            fieldClaculationDescriptor.put(QuerySerializationConstants.FIELD_EXPRESSION, calculatedSelectField.getExpression());
            fieldJSON.put(QuerySerializationConstants.FIELD_ID, fieldClaculationDescriptor);
           
            fieldJSON.put(QuerySerializationConstants.FIELD_ICON_CLS, "calculation");
           
            nature = QuerySerializationConstants.FIELD_NATURE_POST_LINE_CALCULATED;
           
          } else if (field.isInLineCalculatedField()) {
            InLineCalculatedSelectField calculatedSelectField = (InLineCalculatedSelectField)field;
           
            fieldJSON.put(QuerySerializationConstants.FIELD_TYPE, field.IN_LINE_CALCULATED_FIELD);
           
            JSONObject fieldClaculationDescriptor = new JSONObject();
            fieldClaculationDescriptor.put(QuerySerializationConstants.FIELD_ALIAS, calculatedSelectField.getAlias());
            fieldClaculationDescriptor.put(QuerySerializationConstants.FIELD_TYPE, calculatedSelectField.getType());
            fieldClaculationDescriptor.put(QuerySerializationConstants.FIELD_EXPRESSION, calculatedSelectField.getExpression());
            fieldJSON.put(QuerySerializationConstants.FIELD_ID, fieldClaculationDescriptor);
            fieldJSON.put(QuerySerializationConstants.FIELD_LONG_DESCRIPTION, calculatedSelectField.getExpression());

            if ( calculatedSelectField.isGroupByField() ) {
              fieldJSON.put(QuerySerializationConstants.FIELD_GROUP, "true");
            } else {
              fieldJSON.put(QuerySerializationConstants.FIELD_GROUP, "");
            }
           
            fieldJSON.put(QuerySerializationConstants.FIELD_AGGREGATION_FUNCTION, calculatedSelectField.getFunction().getName());
            fieldJSON.put(QuerySerializationConstants.FIELD_ORDER, calculatedSelectField.getOrderType());
           
            //fieldJSON.put(SerializationConstants.FIELD_GROUP, "");
            fieldJSON.put(QuerySerializationConstants.FIELD_ORDER, "");
            //fieldJSON.put(SerializationConstants.FIELD_AGGREGATION_FUNCTION, "");
           
            fieldJSON.put(QuerySerializationConstants.FIELD_ICON_CLS, "calculation");
           
            /*
             * We should understand if the calculated field is an attribute (i.e. a composition of attributes)
             * or a measure (i.e. a composition of measures).
             * The easiest way to understand this it to see if it is a grouping field.
             * TODO manage queries without any aggregation and grouping.
             * At the time being this information is used only in crosstab definition, and crosstab base query SHOULD
             * make aggregation.
             */
            if ( calculatedSelectField.isGroupByField() ) {
              nature = QuerySerializationConstants.FIELD_NATURE_ATTRIBUTE;
            } else {
              nature = QuerySerializationConstants.FIELD_NATURE_MEASURE;
            }
           
          }
         
          fieldJSON.put(QuerySerializationConstants.FIELD_NATURE, nature)
         
        } catch(Throwable t) {
          throw new SerializationException("An error occurred while serializing field: " + field.getAlias(), t);
        }
        logger.debug("Filed [" + field.getAlias() + "] serialized succesfully: [" + fieldJSON.toString() + "]");
        result.put(fieldJSON);
      }
     
    }catch (Throwable t) {
      throw new SerializationException("An error occurred while serializing select clause of query: " + query.getId(), t);
View Full Code Here

    return dataStore;
  }

  private DataStoreMetaData getDataStoreMeta(Query query) {
    DataStoreMetaData dataStoreMeta;
    ISelectField queryFiled;
    FieldMetadata dataStoreFieldMeta;
   
    dataStoreMeta = new DataStoreMetaData();
   
    Iterator fieldsIterator = query.getSelectFields(true).iterator();
    while(fieldsIterator.hasNext()) {
      queryFiled = (ISelectField)fieldsIterator.next();
     
      dataStoreFieldMeta = new FieldMetadata();
      dataStoreFieldMeta.setAlias( queryFiled.getAlias() );
      if(queryFiled.isDataMartField()) {
        DataMartSelectField dataMartSelectField = (DataMartSelectField) queryFiled;
        dataStoreFieldMeta.setName( ((DataMartSelectField)queryFiled).getUniqueName() );
        dataStoreFieldMeta.setProperty("calculated", new Boolean(false));
        dataStoreFieldMeta.setProperty("uniqueName", dataMartSelectField.getUniqueName());
        dataStoreFieldMeta.setType(Object.class);
        String format = dataMartSelectField.getPattern();
        if (format != null && !format.trim().equals("")) {
          dataStoreFieldMeta.setProperty("format", format);
        }
      } else if(queryFiled.isCalculatedField()){
        CalculatedSelectField claculatedQueryField = (CalculatedSelectField)queryFiled;
        dataStoreFieldMeta.setName(claculatedQueryField.getAlias());
        dataStoreFieldMeta.setProperty("calculated", new Boolean(true))
        // FIXME also calculated field must have uniquename for uniformity
        dataStoreFieldMeta.setProperty("uniqueName", claculatedQueryField.getAlias());
        DataSetVariable variable = new DataSetVariable(claculatedQueryField.getAlias(), claculatedQueryField.getType(), claculatedQueryField.getExpression());
        dataStoreFieldMeta.setProperty("variable", variable)
        dataStoreFieldMeta.setType( variable.getTypeClass() )
       
      } else if(queryFiled.isInLineCalculatedField()){
        InLineCalculatedSelectField claculatedQueryField = (InLineCalculatedSelectField)queryFiled;
        dataStoreFieldMeta.setName(claculatedQueryField.getAlias());
        dataStoreFieldMeta.setProperty("calculated", new Boolean(false))
        // FIXME also calculated field must have uniquename for uniformity
        dataStoreFieldMeta.setProperty("uniqueName", claculatedQueryField.getAlias());
        DataSetVariable variable = new DataSetVariable(claculatedQueryField.getAlias(), claculatedQueryField.getType(), claculatedQueryField.getExpression());
        dataStoreFieldMeta.setProperty("variable", variable)
        dataStoreFieldMeta.setType( variable.getTypeClass() )
       
      }
      dataStoreFieldMeta.setProperty("visible", new Boolean(queryFiled.isVisible()))
     
      dataStoreMeta.addFiedMeta(dataStoreFieldMeta);
    }
   
    return dataStoreMeta;
View Full Code Here

TOP

Related Classes of it.eng.qbe.query.ISelectField

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.