Program: 129066
Project: 129066
Buggy source:
/** 
 * DOC cantoine. Method to return a Collection of Column description(metadata) for a DB connection.
 * @param DatabaseMetaData dbMetaData
 * @param MetadataTable medataTable
 * @return Collection of MetadataColumn Object
 * @deprecated
 */
public static List<TdColumn> extractMetadataColumnsFormTable(DatabaseMetaData dbMetaData,String medataLabel,IMetadataConnection metadataConnection,String databaseType){
  columnIndex=0;
  List<TdColumn> metadataColumns=new ArrayList<TdColumn>();
  HashMap<String,String> primaryKeys=new HashMap<String,String>();
  try {
    String originSchema=null;
    if (!"String_Node_Str".equals(medataLabel) && medataLabel != null) {
      originSchema=tableSchemaMap.get(medataLabel);
    }
    if (!"String_Node_Str".equals(metadataConnection.getSchema()) && (metadataConnection.getSchema() != null)) {
      originSchema=metadataConnection.getSchema();
    }
    boolean isAccess=EDatabaseTypeName.ACCESS.getDisplayName().equals(metadataConnection.getDbType());
    try {
      ResultSet keys;
      if (dbMetaData.supportsSchemasInDataManipulation() && (originSchema != null)) {
        if (!isAccess) {
          keys=dbMetaData.getPrimaryKeys(null,originSchema,medataLabel);
        }
 else {
          keys=dbMetaData.getIndexInfo(null,originSchema,medataLabel,true,true);
        }
      }
 else {
        if (!isAccess) {
          keys=dbMetaData.getPrimaryKeys(null,null,medataLabel);
        }
 else {
          keys=dbMetaData.getIndexInfo(null,null,medataLabel,true,true);
        }
      }
      primaryKeys.clear();
      while (keys.next()) {
        primaryKeys.put(keys.getString("String_Node_Str"),"String_Node_Str");
      }
      keys.close();
    }
 catch (    Exception e) {
      log.error(e.toString());
    }
    Connection connection=dbMetaData.getConnection();
    checkUniqueKeyConstraint(medataLabel,primaryKeys,connection);
    String tableName=medataLabel;
    ResultSet columns;
    ResultSetMetaData resultMetadata=null;
    if (ExtractMetaDataUtils.isUseAllSynonyms()) {
      String sql="String_Node_Str" + tableName + "String_Node_Str";
      Statement stmt=ExtractMetaDataUtils.conn.createStatement();
      ExtractMetaDataUtils.setQueryStatementTimeout(stmt);
      columns=stmt.executeQuery(sql);
    }
 else {
      if (dbMetaData.supportsSchemasInDataManipulation() && (originSchema != null)) {
        columns=dbMetaData.getColumns(null,originSchema,tableName,null);
      }
 else {
        columns=dbMetaData.getColumns(null,null,tableName,null);
      }
    }
    boolean isMYSQL=EDatabaseTypeName.MYSQL.getDisplayName().equals(metadataConnection.getDbType());
    if (isMYSQL) {
      Statement statement=connection.createStatement();
      String query="String_Node_Str" + tableName + "String_Node_Str";
      ResultSet resultSet=statement.executeQuery(query);
      resultMetadata=resultSet.getMetaData();
    }
    IRepositoryService repositoryService=CoreRuntimePlugin.getInstance().getRepositoryService();
    boolean isMSSQL=EDatabaseTypeName.MSSQL.getDisplayName().equals(metadataConnection.getDbType());
    while (columns.next()) {
      Boolean b=false;
      String fetchTableName=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",null);
      fetchTableName=ManagementTextUtils.filterSpecialChar(fetchTableName);
      if (fetchTableName.equals(tableName) || databaseType.equals(EDatabaseTypeName.SQLITE.getDisplayName())) {
        TdColumn metadataColumn=RelationalFactory.eINSTANCE.createTdColumn();
        String label=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",null);
        label=ManagementTextUtils.filterSpecialChar(label);
        String sub="String_Node_Str";
        String sub2="String_Node_Str";
        String label2=label;
        if (label != null && label.length() > 0 && label.startsWith("String_Node_Str")) {
          sub=label.substring(1);
          if (sub != null && sub.length() > 0) {
            sub2=sub.substring(1);
          }
        }
        if (coreService.isKeyword(label) || coreService.isKeyword(sub) || coreService.isKeyword(sub2)) {
          label="String_Node_Str" + label;
          b=true;
        }
        metadataColumn.setLabel(label);
        metadataColumn.setOriginalField(label2);
        if (repositoryService != null) {
          label=repositoryService.validateColumnName(label,columnIndex);
          metadataColumn.setLabel(label);
        }
        columnIndex++;
        if (primaryKeys != null && !primaryKeys.isEmpty() && primaryKeys.get(metadataColumn.getOriginalField()) != null) {
          metadataColumn.setKey(true);
        }
 else {
          metadataColumn.setKey(false);
        }
        String typeName="String_Node_Str";
        if (ExtractMetaDataUtils.isUseAllSynonyms()) {
          typeName="String_Node_Str";
        }
        String dbType=ExtractMetaDataUtils.getStringMetaDataInfo(columns,typeName,null).toUpperCase();
        dbType=dbType.trim();
        dbType=ManagementTextUtils.filterSpecialChar(dbType);
        dbType=handleDBtype(dbType);
        metadataColumn.setSourceType(dbType);
        Integer columnSize;
        if (ExtractMetaDataUtils.isUseAllSynonyms()) {
          columnSize=ExtractMetaDataUtils.getOracleIntMatadataInfo(columns,"String_Node_Str");
        }
 else {
          if (isMYSQL) {
            columnSize=ExtractMetaDataUtils.getMysqlIntMetaDataInfo(resultMetadata,columnIndex);
          }
 else {
            columnSize=ExtractMetaDataUtils.getIntMetaDataInfo(columns,"String_Node_Str");
          }
        }
        metadataColumn.setLength(columnSize);
        String talendType=null;
        if (metadataConnection.getMapping() != null) {
          mappingTypeRetriever=MetadataTalendType.getMappingTypeRetriever(metadataConnection.getMapping());
        }
        Integer intMetaDataInfo=ExtractMetaDataUtils.getIntMetaDataInfo(columns,"String_Node_Str");
        talendType=mappingTypeRetriever.getDefaultSelectedTalendType(dbType,columnSize,intMetaDataInfo);
        talendType=ManagementTextUtils.filterSpecialChar(talendType);
        if (talendType == null) {
          if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
            talendType=JavaTypesManager.getDefaultJavaType().getId();
            log.warn(Messages.getString("String_Node_Str",dbType));
          }
 else {
            talendType="String_Node_Str";
            log.warn(Messages.getString("String_Node_Str",dbType));
          }
        }
 else {
        }
        metadataColumn.setTalendType(talendType);
        boolean isNullable=ExtractMetaDataUtils.getBooleanMetaDataInfo(columns,"String_Node_Str");
        metadataColumn.setNullable(isNullable);
        String commentInfo=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",null);
        if (commentInfo != null && commentInfo.length() > 0) {
          commentInfo=ManagementTextUtils.filterSpecialChar(commentInfo);
        }
        metadataColumn.setComment(commentInfo);
        if (!isAccess) {
          TDColumnAttributeHelper.addColumnAttribute(label,label2,dbType,columnSize,intMetaDataInfo,commentInfo,columns,metadataColumn,(DatabaseConnection)metadataConnection.getCurrentConnection());
        }
        if (isMSSQL && "String_Node_Str".equals(dbType)) {
          Integer ident1=0;
          Integer ident2=0;
          try {
            PreparedStatement statement=ExtractMetaDataUtils.conn.prepareStatement("String_Node_Str" + medataLabel + "String_Node_Str"+ "String_Node_Str"+ medataLabel+ "String_Node_Str");
            ResultSet resultSet=null;
            ExtractMetaDataUtils.setQueryStatementTimeout(statement);
            if (statement.execute()) {
              resultSet=statement.getResultSet();
              while (resultSet.next()) {
                String st1=resultSet.getString(1);
                String st2=resultSet.getString(2);
                Integer valueOf1=Integer.valueOf(st1);
                if (valueOf1 != null) {
                  ident1=valueOf1;
                }
                Integer valueOf2=Integer.valueOf(st2);
                if (valueOf2 != null) {
                  ident2=valueOf2;
                }
              }
            }
            resultSet.close();
            statement.close();
          }
 catch (          Exception e) {
            log.error(e.toString());
          }
          metadataColumn.setLength(ident1);
          metadataColumn.setPrecision(ident2);
        }
 else {
          metadataColumn.setPrecision(intMetaDataInfo);
        }
        metadataColumns.add(metadataColumn);
        String stringMetaDataInfo=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",dbMetaData);
        if (stringMetaDataInfo != null && stringMetaDataInfo.length() > 0 && stringMetaDataInfo.charAt(0) == 0x0) {
          stringMetaDataInfo="String_Node_Str";
        }
        stringMetaDataInfo=ManagementTextUtils.filterSpecialChar(stringMetaDataInfo);
        metadataColumn.setDefaultValue(stringMetaDataInfo);
        if (EDatabaseTypeName.ORACLEFORSID.getDisplayName().equals(metadataConnection.getDbType()) || EDatabaseTypeName.ORACLESN.getDisplayName().equals(metadataConnection.getDbType())) {
          if (dbType.equals("String_Node_Str")) {
            metadataColumn.setLength(metadataColumn.getPrecision());
            metadataColumn.setPrecision(-1);
          }
        }
      }
    }
    if (EDatabaseTypeName.ORACLEFORSID.getDisplayName().equals(metadataConnection.getDbType()) || EDatabaseTypeName.ORACLESN.getDisplayName().equals(metadataConnection.getDbType())) {
      try {
        PreparedStatement statement=ExtractMetaDataUtils.conn.prepareStatement("String_Node_Str" + medataLabel + "String_Node_Str");
        ResultSet keys=null;
        ExtractMetaDataUtils.setQueryStatementTimeout(statement);
        if (statement.execute()) {
          keys=statement.getResultSet();
          int i=0;
          while (keys.next()) {
            MetadataColumn metadataColumn=(MetadataColumn)metadataColumns.get(i++);
            metadataColumn.setComment(ManagementTextUtils.filterSpecialChar(keys.getString("String_Node_Str")));
          }
        }
        keys.close();
        statement.close();
      }
 catch (      Exception e) {
        log.error(e.toString());
      }
    }
    columns.close();
  }
 catch (  SQLException e) {
    log.error(e.toString());
    throw new RuntimeException(e);
  }
catch (  Exception e) {
    ExceptionHandler.process(e);
    log.error(e.toString());
    throw new RuntimeException(e);
  }
  return metadataColumns;
}

Fixed version (ground truth):
/** 
 * DOC cantoine. Method to return a Collection of Column description(metadata) for a DB connection.
 * @param DatabaseMetaData dbMetaData
 * @param MetadataTable medataTable
 * @return Collection of MetadataColumn Object
 * @deprecated
 */
@Deprecated public static List<TdColumn> extractMetadataColumnsFormTable(DatabaseMetaData dbMetaData,String medataLabel,IMetadataConnection metadataConnection,String databaseType){
  columnIndex=0;
  List<TdColumn> metadataColumns=new ArrayList<TdColumn>();
  HashMap<String,String> primaryKeys=new HashMap<String,String>();
  try {
    String originSchema=null;
    if (!"String_Node_Str".equals(medataLabel) && medataLabel != null) {
      originSchema=tableSchemaMap.get(medataLabel);
    }
    if (!"String_Node_Str".equals(metadataConnection.getSchema()) && (metadataConnection.getSchema() != null)) {
      originSchema=metadataConnection.getSchema();
    }
    boolean isAccess=EDatabaseTypeName.ACCESS.getDisplayName().equals(metadataConnection.getDbType());
    try {
      ResultSet keys;
      if (dbMetaData.supportsSchemasInDataManipulation() && (originSchema != null)) {
        if (!isAccess) {
          keys=dbMetaData.getPrimaryKeys(null,originSchema,medataLabel);
        }
 else {
          keys=dbMetaData.getIndexInfo(null,originSchema,medataLabel,true,true);
        }
      }
 else {
        if (!isAccess) {
          keys=dbMetaData.getPrimaryKeys(null,null,medataLabel);
        }
 else {
          keys=dbMetaData.getIndexInfo(null,null,medataLabel,true,true);
        }
      }
      primaryKeys.clear();
      while (keys.next()) {
        primaryKeys.put(keys.getString("String_Node_Str"),"String_Node_Str");
      }
      keys.close();
    }
 catch (    Exception e) {
      log.error(e.toString());
    }
    Connection connection=dbMetaData.getConnection();
    checkUniqueKeyConstraint(medataLabel,primaryKeys,connection);
    String tableName=medataLabel;
    ResultSet columns;
    ResultSetMetaData resultMetadata=null;
    if (ExtractMetaDataUtils.isUseAllSynonyms()) {
      String sql="String_Node_Str" + tableName + "String_Node_Str";
      Statement stmt=ExtractMetaDataUtils.conn.createStatement();
      ExtractMetaDataUtils.setQueryStatementTimeout(stmt);
      columns=stmt.executeQuery(sql);
    }
 else {
      if (dbMetaData.supportsSchemasInDataManipulation() && (originSchema != null)) {
        columns=dbMetaData.getColumns(null,originSchema,tableName,null);
      }
 else {
        columns=dbMetaData.getColumns(null,null,tableName,null);
      }
    }
    boolean isMYSQL=EDatabaseTypeName.MYSQL.getDisplayName().equals(metadataConnection.getDbType());
    if (isMYSQL) {
      Statement statement=connection.createStatement();
      String query="String_Node_Str" + tableName + "String_Node_Str";
      ResultSet resultSet=statement.executeQuery(query);
      resultMetadata=resultSet.getMetaData();
    }
    IRepositoryService repositoryService=CoreRuntimePlugin.getInstance().getRepositoryService();
    boolean isMSSQL=EDatabaseTypeName.MSSQL.getDisplayName().equals(metadataConnection.getDbType());
    while (columns.next()) {
      Boolean b=false;
      String fetchTableName=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",null);
      fetchTableName=ManagementTextUtils.filterSpecialChar(fetchTableName);
      if (fetchTableName.equals(tableName) || databaseType.equals(EDatabaseTypeName.SQLITE.getDisplayName())) {
        TdColumn metadataColumn=RelationalFactory.eINSTANCE.createTdColumn();
        String label=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",null);
        label=ManagementTextUtils.filterSpecialChar(label);
        String sub="String_Node_Str";
        String sub2="String_Node_Str";
        String label2=label;
        if (label != null && label.length() > 0 && label.startsWith("String_Node_Str")) {
          sub=label.substring(1);
          if (sub != null && sub.length() > 0) {
            sub2=sub.substring(1);
          }
        }
        if (coreService.isKeyword(label) || coreService.isKeyword(sub) || coreService.isKeyword(sub2)) {
          label="String_Node_Str" + label;
          b=true;
        }
        metadataColumn.setLabel(label);
        metadataColumn.setOriginalField(label2);
        if (repositoryService != null) {
          label=repositoryService.validateColumnName(label,columnIndex);
          metadataColumn.setLabel(label);
        }
        columnIndex++;
        if (primaryKeys != null && !primaryKeys.isEmpty() && primaryKeys.get(metadataColumn.getOriginalField()) != null) {
          metadataColumn.setKey(true);
        }
 else {
          metadataColumn.setKey(false);
        }
        String typeName="String_Node_Str";
        if (ExtractMetaDataUtils.isUseAllSynonyms()) {
          typeName="String_Node_Str";
        }
        String dbType=ExtractMetaDataUtils.getStringMetaDataInfo(columns,typeName,null).toUpperCase();
        dbType=dbType.trim();
        dbType=ManagementTextUtils.filterSpecialChar(dbType);
        dbType=handleDBtype(dbType);
        metadataColumn.setSourceType(dbType);
        Integer columnSize;
        if (ExtractMetaDataUtils.isUseAllSynonyms()) {
          columnSize=ExtractMetaDataUtils.getOracleIntMatadataInfo(columns,"String_Node_Str");
        }
 else {
          if (isMYSQL) {
            columnSize=ExtractMetaDataUtils.getMysqlIntMetaDataInfo(resultMetadata,columnIndex);
          }
 else {
            columnSize=ExtractMetaDataUtils.getIntMetaDataInfo(columns,"String_Node_Str");
          }
        }
        metadataColumn.setLength(columnSize);
        String talendType=null;
        if (metadataConnection.getMapping() != null) {
          mappingTypeRetriever=MetadataTalendType.getMappingTypeRetriever(metadataConnection.getMapping());
        }
        Integer intMetaDataInfo=ExtractMetaDataUtils.getIntMetaDataInfo(columns,"String_Node_Str");
        talendType=mappingTypeRetriever.getDefaultSelectedTalendType(dbType,columnSize,intMetaDataInfo);
        talendType=ManagementTextUtils.filterSpecialChar(talendType);
        if (talendType == null) {
          if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
            talendType=JavaTypesManager.getDefaultJavaType().getId();
            log.warn(Messages.getString("String_Node_Str",dbType));
          }
 else {
            talendType="String_Node_Str";
            log.warn(Messages.getString("String_Node_Str",dbType));
          }
        }
 else {
        }
        metadataColumn.setTalendType(talendType);
        boolean isNullable=ExtractMetaDataUtils.getBooleanMetaDataInfo(columns,"String_Node_Str");
        metadataColumn.setNullable(isNullable);
        String commentInfo=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",null);
        if (commentInfo != null && commentInfo.length() > 0) {
          commentInfo=ManagementTextUtils.filterSpecialChar(commentInfo);
        }
        metadataColumn.setComment(commentInfo);
        if (!isAccess) {
          TDColumnAttributeHelper.addColumnAttribute(label,label2,dbType,columnSize,intMetaDataInfo,commentInfo,columns,metadataColumn,(DatabaseConnection)metadataConnection.getCurrentConnection());
        }
        if (isMSSQL && "String_Node_Str".equals(dbType)) {
          Integer ident1=0;
          Integer ident2=0;
          try {
            PreparedStatement statement=ExtractMetaDataUtils.conn.prepareStatement("String_Node_Str" + medataLabel + "String_Node_Str"+ "String_Node_Str"+ medataLabel+ "String_Node_Str");
            ResultSet resultSet=null;
            ExtractMetaDataUtils.setQueryStatementTimeout(statement);
            if (statement.execute()) {
              resultSet=statement.getResultSet();
              while (resultSet.next()) {
                String st1=resultSet.getString(1);
                String st2=resultSet.getString(2);
                Integer valueOf1=Integer.valueOf(st1);
                if (valueOf1 != null) {
                  ident1=valueOf1;
                }
                Integer valueOf2=Integer.valueOf(st2);
                if (valueOf2 != null) {
                  ident2=valueOf2;
                }
              }
            }
            resultSet.close();
            statement.close();
          }
 catch (          Exception e) {
            log.error(e.toString());
          }
          metadataColumn.setLength(ident1);
          metadataColumn.setPrecision(ident2);
        }
 else {
          metadataColumn.setPrecision(intMetaDataInfo);
        }
        metadataColumns.add(metadataColumn);
        String stringMetaDataInfo=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",dbMetaData);
        if (stringMetaDataInfo != null && stringMetaDataInfo.length() > 0 && stringMetaDataInfo.charAt(0) == 0x0) {
          stringMetaDataInfo="String_Node_Str";
        }
        stringMetaDataInfo=ManagementTextUtils.filterSpecialChar(stringMetaDataInfo);
        metadataColumn.setDefaultValue(stringMetaDataInfo);
        if (EDatabaseTypeName.ORACLEFORSID.getDisplayName().equals(metadataConnection.getDbType()) || EDatabaseTypeName.ORACLESN.getDisplayName().equals(metadataConnection.getDbType())) {
          if (dbType.equals("String_Node_Str")) {
            metadataColumn.setLength(metadataColumn.getPrecision());
            metadataColumn.setPrecision(-1);
          }
        }
      }
    }
    if (EDatabaseTypeName.ORACLEFORSID.getDisplayName().equals(metadataConnection.getDbType()) || EDatabaseTypeName.ORACLESN.getDisplayName().equals(metadataConnection.getDbType())) {
      try {
        PreparedStatement statement=ExtractMetaDataUtils.conn.prepareStatement("String_Node_Str" + medataLabel + "String_Node_Str");
        ResultSet keys=null;
        ExtractMetaDataUtils.setQueryStatementTimeout(statement);
        if (statement.execute()) {
          keys=statement.getResultSet();
          int i=0;
          while (keys.next()) {
            MetadataColumn metadataColumn=metadataColumns.get(i++);
            metadataColumn.setComment(ManagementTextUtils.filterSpecialChar(keys.getString("String_Node_Str")));
          }
        }
        keys.close();
        statement.close();
      }
 catch (      Exception e) {
        log.error(e.toString());
      }
    }
    columns.close();
  }
 catch (  SQLException e) {
    log.error(e.toString());
    throw new RuntimeException(e);
  }
catch (  Exception e) {
    ExceptionHandler.process(e);
    log.error(e.toString());
    throw new RuntimeException(e);
  }
  return metadataColumns;
}