From 78e9c6e2882b77a24c0611f0ce9097a7f762f132 Mon Sep 17 00:00:00 2001 From: Loredana Liccardo Date: Tue, 29 Jul 2014 09:30:18 +0000 Subject: [PATCH] Methods writeSampleTableIntoFile, writeQueryResultIntoFile, isHexadecimal removed because being commented were not used. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-access/DatabasesResourcesManager@99059 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../databases/utils/DatabaseManagement.java | 534 ------------------ 1 file changed, 534 deletions(-) diff --git a/src/main/java/org/gcube/dataaccess/databases/utils/DatabaseManagement.java b/src/main/java/org/gcube/dataaccess/databases/utils/DatabaseManagement.java index b3c7d75..270c64a 100644 --- a/src/main/java/org/gcube/dataaccess/databases/utils/DatabaseManagement.java +++ b/src/main/java/org/gcube/dataaccess/databases/utils/DatabaseManagement.java @@ -1266,538 +1266,4 @@ public class DatabaseManagement { return queryCorrected; } - - // write the table result in the file and build the map of results - // private void writeSampleTableIntoFile(List result, - // String tableName, String schemaName) throws Exception { - // - // // file that will contain sample result - // BufferedWriter out; - // String fileName; - // - // // fileName = "./cfg/" + "table.txt"; - // // fileName = "./files/" + "table.txt"; - // - // fileName = - // "/home/loredana/workspace/DatabasesResourcesManagerAlgorithms/cfg/" - // + "SampleOnTable.txt"; - // - // // fileName = "./files/" + "SmartSampleOnTable.txt"; - // // File file = new File(fileName); - // - // fileSample = new File(fileName); - // - // FileWriter fw = new FileWriter(fileSample.getAbsoluteFile()); - // out = new BufferedWriter(fw); - // - // // for the exact parsing of the obtained results with the values of - // // postgres, a check is needed against the data type columns - // - // String query; - // List resultDataTypeColumns = null; - // - // List DataTypeColumns = new ArrayList(); - // - // // query to get data type columns - // if (DBType.equals(POSTGRES)) { - // - // query = String.format(queryForDataTypeColumnsPostgres, tableName, - // schemaName); - // - // resultDataTypeColumns = connection.executeQuery(query, - // sourceDBSession); - // - // if (resultDataTypeColumns != null) { - // - // for (int i = 0; i < resultDataTypeColumns.size(); i++) { - // - // AnalysisLogger.getLogger().debug( - // "In DatabaseManagement->column: " + i - // + " data type: " - // + (String) resultDataTypeColumns.get(i)); - // - // // to add the data types columns - // DataTypeColumns.add(i, - // (String) resultDataTypeColumns.get(i)); - // - // } - // - // } - // - // } - // - // if (DBType.equals(MYSQL)) { - // - // - // - // query = String.format(queryForDataTypeColumnsMysql, tableName, - // schemaName); - // - // System.out.println("query: " + query); - // - // resultDataTypeColumns = connection.executeQuery(query, - // sourceDBSession); - // - // if (resultDataTypeColumns != null) { - // - // for (int i = 0; i < resultDataTypeColumns.size(); i++) { - // - // AnalysisLogger.getLogger().debug( - // "In DatabaseManagement->column: " + i - // + " data type: " - // + (String) resultDataTypeColumns.get(i)); - // - // // to add the data types columns - // DataTypeColumns.add(i, - // (String) resultDataTypeColumns.get(i)); - // - // } - // - // } - // - // } - // - // // write operation in the file - // for (int i = 0; i < result.size(); i++) { - // - // String RowString = ""; - // - // if (result.get(i).getClass().isArray()) { - // - // Object[] row = (Object[]) result.get(i); - // - // // String RowString = ""; - // - // for (int j = 0; j < row.length; j++) { - // - // if (row[j] == null) { - // row[j] = ""; - // } - // - // - // // to parse the obtained results in order to align number - // // values with - // // those of postgres - // String original = row[j].toString(); - // - // AnalysisLogger.getLogger().debug( - // "In DatabaseManagement->original value: " - // + original); - // - // String parsed = "" + row[j]; - // - // if(original!="") { - // - // try { - // - // - // // parse to Long - // parsed = "" + Long.parseLong(original); - // AnalysisLogger.getLogger().debug( - // "In DatabaseManagement->parsed value Long: " - // + parsed); - // - // } - // - // catch (Exception e) { - // try { - // - // // check to fix a problem for the database. - // // Indeed if the string is - // // an hexadecimal some strings as (6F or 6D that are - // // double and float values) are - // // casted to Double and the value returned is 6.0 - // // altering the original value. If the string is an - // // hexadecimal the cast is not performed. - // - // if ((DataTypeColumns.get(j) != null)) { - // - // AnalysisLogger.getLogger().debug( - // "In DatabaseManagement->check data type value: " - // + DataTypeColumns.get(j)); - // - // if ((DataTypeColumns.get(j).contains("decimal")) - // || (DataTypeColumns.get(j) - // .contains("double")) - // || (DataTypeColumns.get(j) - // .contains("real")) - // || (DataTypeColumns.get(j) - // .contains("numeric")) - // || (DataTypeColumns.get(j) - // .contains("float"))) { - // - // parsed = "" + Double.parseDouble(parsed); - // - // AnalysisLogger.getLogger().debug( - // "In DatabaseManagement->parsed value Double: " - // + parsed); - // - // } - // } - // - // // if (DBType.equals(POSTGRES)) { - // // - // // if ((DataTypeColumns.get(j) != null)) { - // // - // // AnalysisLogger.getLogger().debug( - // // "In DatabaseManagement->check data type value: " - // // + DataTypeColumns.get(j)); - // // - // // if ((DataTypeColumns.get(j) - // // .contains("decimal")) - // // || (DataTypeColumns.get(j) - // // .contains("double")) - // // || (DataTypeColumns.get(j) - // // .contains("real")) - // // || (DataTypeColumns.get(j) - // // .contains("numeric"))) { - // // - // // parsed = "" - // // + Double.parseDouble(parsed); - // // - // // AnalysisLogger.getLogger().debug( - // // "In DatabaseManagement->parsed value Double: " - // // + parsed); - // // - // // } - // // } - // // } - // - // // if (DBType.equals(MYSQL)) { - // // - // // if ((DataTypeColumns.get(j) != null)) { - // // - // // AnalysisLogger.getLogger().debug( - // // "In DatabaseManagement->check data type value: " - // // + DataTypeColumns.get(j)); - // // - // // if ((DataTypeColumns.get(j) - // // .contains("decimal")) - // // || (DataTypeColumns.get(j) - // // .contains("double")) - // // || (DataTypeColumns.get(j) - // // .contains("real")) - // // || (DataTypeColumns.get(j) - // // .contains("numeric")) - // // || (DataTypeColumns.get(j) - // // .contains("float"))) { - // // - // // parsed = "" - // // + Double.parseDouble(parsed); - // // - // // AnalysisLogger.getLogger().debug( - // // "In DatabaseManagement->parsed value Double: " - // // + parsed); - // // - // // } - // // } - // // } - // - // // else { - // // parsed = "" + Double.parseDouble(parsed); - // // - // // AnalysisLogger.getLogger().debug( - // // "In DatabaseManagement->parsed value Double: " - // // + parsed); - // // - // // } - // - // } catch (Exception e1) { - // throw e1; - // } - // } - // - // } - // - // AnalysisLogger.getLogger().debug( - // "In DatabaseManagement->row: " + (i + 1) - // + " column: " + (j + 1) + " value= " - // + parsed); - // - // // write in a file - // - // if (j != row.length - 1) { - // - // out.write(parsed); - // - // out.write(","); - // // System.out.println("write column : " + j); - // RowString = RowString + parsed + " "; - // - // } - // if (j == row.length - 1) { - // - // out.write(parsed); - // out.newLine(); - // - // // to add a row to the map - // mapSampleTableResult.put(String.valueOf(i), RowString); - // - // } - // - // } - // - // } - // - // else { - // - // Object RowElement = (Object) result.get(i); - // - // AnalysisLogger.getLogger().debug( - // "In DatabaseManagement->row: " + (i + 1) + " value= " - // + RowElement.toString()); - // - // // write in a file - // - // out.write(RowElement.toString()); - // out.newLine(); - // - // //to add a row to the map - // mapSampleTableResult.put(String.valueOf(i), RowElement.toString()); - // - // } - // } - // // close the file - // out.close(); - // - // } - - // write the query result in the file and build the map of results - // private void writeQueryResultIntoFile(List result) throws - // Exception { - // - // // file that will contain query result - // BufferedWriter out; - // String fileName; - // - // fileName = - // "/home/loredana/workspace/DatabasesResourcesManagerAlgorithms/cfg/" - // + "QueryResult.txt"; - // - // fileQueryResult = new File(fileName); - // - // FileWriter fw = new FileWriter(fileQueryResult.getAbsoluteFile()); - // out = new BufferedWriter(fw); - // - // for (int i = 0; i < result.size(); i++) { - // - // if (result.get(i).getClass().isArray()) { - // - // Object[] row = (Object[]) result.get(i); - // - // String RowString = ""; - // - // for (int j = 0; j < row.length; j++) { - // - // AnalysisLogger.getLogger().debug( - // "In DatabaseManagement->row: " + (i + 1) + " column: " - // + (j + 1) + " value= " + row[j].toString()); - // - // - // // write in a file - // - // if (j != row.length - 1) { - // - // out.write(row[j].toString()); - // out.write(","); - // RowString = RowString + row[j].toString() + " "; - // - // System.out.println("storing: " + RowString); - // - // // AnalysisLogger.getLogger().debug( - // // "In SubmitQuery->row " + (j+1) + ": " + - // // row[j].toString()); - // - // } - // if (j == row.length - 1) { - // - // out.write(row[j].toString()); - // out.newLine(); - // - // RowString = RowString + row[j].toString(); - // - // System.out.println("storing: " + RowString); - // - // //to add a row to the map - // mapQueryResult.put(String.valueOf(i), RowString); - // - // } - // - // } - // - // } - // - // else { - // // String RowElement=""; - // - // Object RowElement = (Object) result.get(i); - // - // // AnalysisLogger.getLogger().debug( - // // "In SubmitQuery->Query's Result: "); - // - // AnalysisLogger.getLogger().debug( - // "In DatabaseManagement->row: " + (i + 1) + " value= " - // + RowElement.toString()); - // - // // write in a file - // - // out.write(RowElement.toString()); - // out.newLine(); - // - // //to add a row to the map - // mapQueryResult.put(String.valueOf(i), RowElement.toString()); - // - // } - // - // } - // - // //close file - // out.close(); - // - // } - - // to check if the string is an hexadecimal - // private boolean isHexadecimal(String text) { - // - // boolean isHexadecimal = false; - // - // text = text.trim(); - // - // char[] hexDigits = { 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', - // 'E', 'F' }; - // - // check: for (char symbol : text.toCharArray()) { - // - // for (char hexDigit : hexDigits) { - // - // if (symbol == hexDigit) { - // - // isHexadecimal = true; - // - // break check; - // - // } - // - // } - // - // } - // - // return isHexadecimal; - // - // } - - // private void writeTableIntoFile(List result) throws IOException { - // - // // file that will contain query's result - // BufferedWriter out; - // String fileName; - // - // // fileName = "./cfg/" + "table.txt"; - // fileName = "./files/" + "table.txt"; - // - // // fileName = "./files/" + "SmartSampleOnTable.txt"; - // File file = new File(fileName); - // - // FileWriter fw = new FileWriter(file.getAbsoluteFile()); - // out = new BufferedWriter(fw); - // - // for (int i = 0; i < result.size(); i++) { - // - // // System.out.println(result.get(i).getClass().isArray()); - // - // if (result.get(i).getClass().isArray()) { - // - // Object[] row = (Object[]) result.get(i); - // - // String RowString = ""; - // - // for (int j = 0; j < row.length; j++) { - // - // if (row[j] == null) { - // row[j] = ""; - // } - // - // // to parse the obtained results to align number values with - // // those of postgres - // String original = row[j].toString(); - // String parsed = "" + row[j]; - // - // try { - // parsed = "" + Long.parseLong(parsed); - // } catch (Exception e) { - // try { - // parsed = "" + Double.parseDouble(parsed); - // } catch (Exception e1) { - // } - // } - // - // // AnalysisLogger.getLogger().debug( - // // "In SubmitQuery->row: " + (i + 1) + " column: " - // // + (j + 1) + " value= " - // // + row[j].toString()); - // - // AnalysisLogger.getLogger().debug( - // "In DatabaseManagement->row: " + (i + 1) + " column: " - // + (j + 1) + " value= " + parsed); - // - // // System.out.print("\"" + row[j] + "\"; "); - // - // // write in a file - // - // if (j != row.length - 1) { - // - // System.out - // .println("scrittura su file: elementi intermedi"); - // // out.write("1"); - // - // // out.write(row[j].toString()); - // out.write(parsed); - // - // out.write(","); - // RowString = RowString + row[j].toString() + " "; - // - // // AnalysisLogger.getLogger().debug( - // // "In SubmitQuery->row " + (j+1) + ": " + - // // row[j].toString()); - // - // } - // if (j == row.length - 1) { - // - // System.out - // .println("scrittura su file: elemento finale"); - // - // // out.write(row[j].toString()); - // out.write(parsed); - // out.newLine(); - // - // } - // - // } - // - // } - // - // else { - // // String RowElement=""; - // - // Object RowElement = (Object) result.get(i); - // - // // AnalysisLogger.getLogger().debug( - // // "In SubmitQuery->Query's Result: "); - // - // AnalysisLogger.getLogger().debug( - // "In DatabaseManagement->row: " + (i + 1) + " value= " - // + RowElement.toString()); - // - // // write in a file - // - // out.write(RowElement.toString()); - // out.newLine(); - // - // } - // } - // - // out.close(); - // - // } - }