Beispiel #1
0
  /**
   * To add the Id columns of MainEntities in the SQL if its not present. It will also populate
   * entityIdIndexMap passes it.
   *
   * @param columnIndex columnIndex
   * @param selectSql selectSql
   * @param entityIdIndexMap entityIdIndexMap
   * @param selectSqlColumnList selectSqlColumnList
   * @param outputTreeDataNode outputTreeDataNode
   * @return The modified SQL string.
   */
  private static Map putIdColumnsInSql(
      int colIndex,
      String selectSql,
      Map<EntityInterface, Integer> entityIdIndexMap,
      List<String> selectSqlColumnList,
      OutputTreeDataNode outputTreeDataNode,
      Map<String, String> specimenMap,
      Map<String, String> columnNameVsAliasMap) {
    int columnIndex = colIndex;
    StringBuffer sql = new StringBuffer(selectSql);
    Map sqlIndexMap = new HashMap();
    if (outputTreeDataNode != null) {
      List<QueryOutputTreeAttributeMetadata> attributes = outputTreeDataNode.getAttributes();
      for (QueryOutputTreeAttributeMetadata attributeMetaData : attributes) {
        AttributeInterface attribute = attributeMetaData.getAttribute();
        String sqlColumnName = attributeMetaData.getColumnName().trim();
        if (attribute.getName().equals(AQConstants.IDENTIFIER)) {
          int index =
              selectSqlColumnList.indexOf(
                  columnNameVsAliasMap.get(sqlColumnName) + " " + sqlColumnName);

          if (index >= 0) {
            entityIdIndexMap.put(attribute.getEntity(), index);
            break;
          } else {
            // appendColNameToSql(selectSql, sql, sqlColumnName);
            entityIdIndexMap.put(attribute.getEntity(), null);
            columnIndex++;
            if (outputTreeDataNode
                .getOutputEntity()
                .getDynamicExtensionsEntity()
                .getName()
                .equals("edu.wustl.catissuecore.domain.Specimen")) {
              if (specimenMap == null) {
                specimenMap = new HashMap<String, String>();
              }
              specimenMap.put("specimenKey", "edu.wustl.catissuecore.domain.Specimen");
              specimenMap.put("columnIndex", String.valueOf(columnIndex - 1));
            }
            break;
          }
        }
      }
    }
    sqlIndexMap.put(AQConstants.SQL, sql.toString());
    sqlIndexMap.put(AQConstants.ID_COLUMN_ID, columnIndex);
    return sqlIndexMap;
  }