bug corrected in "showCreateTable" method of MySQLTableStructure class (result managed in a correct way using aliasToEntityOrderedMapResultTransformer class).
Bug fixed in "DatabaseManagement" class in "writeTableIntoFile" method to manage for SubmitQuery e sampling operations tables with one column. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-access/DatabasesResourcesManager@98835 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ba20c2730e
commit
7762f7a162
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.dataaccess.databases.structure;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.dataaccess.databases.utils.ConnectionManager;
|
||||
|
@ -16,7 +18,8 @@ public class MySQLTableStructure extends AbstractTableStructure {
|
|||
|
||||
// Method that executes the query "show create table" in order to retrieve
|
||||
// the "create table" statement
|
||||
public String showCreateTable(ConnectionManager connection, SessionFactory dbSession) throws Exception {
|
||||
public String showCreateTable(ConnectionManager connection,
|
||||
SessionFactory dbSession) throws Exception {
|
||||
|
||||
// Retrieve the query
|
||||
String queryForIndexes = getQueryForIndexes(dbSession);
|
||||
|
@ -26,9 +29,22 @@ public class MySQLTableStructure extends AbstractTableStructure {
|
|||
// List<Object> indexSet = DatabaseFactory.executeSQLQuery(
|
||||
// String.format(queryForIndexes, tableName), dbSession);
|
||||
|
||||
List<Object> indexSet = connection.executeQuery(String.format(queryForIndexes, tableName), dbSession);
|
||||
// List<Object> indexSet =
|
||||
// connection.executeQuery(String.format(queryForIndexes,
|
||||
// tableName), dbSession);
|
||||
|
||||
String createTableStatement = (String) (((Object[]) indexSet.get(0))[1]);
|
||||
// String createTableStatement = (String) (((Object[])
|
||||
// indexSet.get(0))[1]);
|
||||
|
||||
List<Object> result = connection.executeQuery(
|
||||
String.format(queryForIndexes, tableName), dbSession);
|
||||
|
||||
Object element = result.get(0);
|
||||
|
||||
ArrayList<Object> listvalues = new ArrayList<Object>(
|
||||
((LinkedHashMap<String, Object>) element).values());
|
||||
|
||||
String createTableStatement = listvalues.get(1).toString();
|
||||
|
||||
AnalysisLogger.getLogger().debug(
|
||||
"MySQLTableStructure->'Create Table' statement: "
|
||||
|
|
|
@ -112,8 +112,17 @@ public class DatabaseManagement {
|
|||
private String convertToJavaType(String type, String val) throws Exception {
|
||||
|
||||
type = type.toLowerCase();
|
||||
|
||||
// AnalysisLogger.getLogger()
|
||||
// .debug("In DatabaseManagement->type: "
|
||||
// + type);
|
||||
|
||||
String valConverted = val;
|
||||
|
||||
// AnalysisLogger.getLogger()
|
||||
// .debug("In DatabaseManagement->val: "
|
||||
// + valConverted);
|
||||
|
||||
try {
|
||||
|
||||
// parse to Long
|
||||
|
@ -168,6 +177,21 @@ public class DatabaseManagement {
|
|||
|
||||
}
|
||||
|
||||
if (((type.contains("string")))||(type.contains("varchar")) || (type.contains("char"))
|
||||
|| (type.contains("text")) || (type
|
||||
.contains("character varying"))) {
|
||||
|
||||
valConverted= "\"" + valConverted + "\"";
|
||||
|
||||
// // check the parsed value
|
||||
// AnalysisLogger.getLogger().debug(
|
||||
// "In DatabaseManagement->parsed value string: "
|
||||
// + valConverted);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception excp) {
|
||||
|
@ -424,7 +448,6 @@ public class DatabaseManagement {
|
|||
|
||||
for (int j = 0; j < listvalues.size(); j++) {
|
||||
|
||||
|
||||
tablesname.add(listvalues.get(j).toString());
|
||||
|
||||
// AnalysisLogger.getLogger().debug(
|
||||
|
@ -432,11 +455,8 @@ public class DatabaseManagement {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// for (Object result : resultSet) {
|
||||
// tablesname.add((String) result);
|
||||
//
|
||||
|
@ -481,16 +501,14 @@ public class DatabaseManagement {
|
|||
|
||||
for (int j = 0; j < listvalues.size(); j++) {
|
||||
|
||||
|
||||
list.add(listvalues.get(j).toString());
|
||||
|
||||
// AnalysisLogger.getLogger().debug(
|
||||
// "DatabaseManagement->" + listvalues.get(j).toString());
|
||||
// "DatabaseManagement->" +
|
||||
// listvalues.get(j).toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1001,8 +1019,6 @@ public class DatabaseManagement {
|
|||
|
||||
if (result != null && result.size() != 0) {
|
||||
|
||||
|
||||
|
||||
// // write operation in the file
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
|
||||
|
@ -1010,6 +1026,7 @@ public class DatabaseManagement {
|
|||
|
||||
Object element = result.get(i);
|
||||
|
||||
//arraylist in which each element is a row result
|
||||
ArrayList<Object> listvalues = new ArrayList<Object>(
|
||||
((LinkedHashMap<String, Object>) element).values());
|
||||
|
||||
|
@ -1017,9 +1034,10 @@ public class DatabaseManagement {
|
|||
// AnalysisLogger.getLogger().debug(
|
||||
// "DatabaseManagement->values: " + listvalues);
|
||||
|
||||
//each row could have several column values
|
||||
Object[] row = listvalues.toArray();
|
||||
|
||||
if (row.length > 1) {
|
||||
if (row.length >= 1) {
|
||||
|
||||
for (int j = 0; j < row.length; j++) {
|
||||
|
||||
|
@ -1043,8 +1061,8 @@ public class DatabaseManagement {
|
|||
// convert database datatypes to Java datatypes
|
||||
if (DataTypeColumns == null
|
||||
|| DataTypeColumns.size() == 0)
|
||||
parsed = convertToJavaType(row[j]
|
||||
.getClass().getName(), parsed);
|
||||
parsed = convertToJavaType(row[j].getClass()
|
||||
.getName(), parsed);
|
||||
else
|
||||
parsed = convertToJavaType(
|
||||
DataTypeColumns.get(j), parsed);
|
||||
|
@ -1060,9 +1078,12 @@ public class DatabaseManagement {
|
|||
|
||||
if (j != row.length - 1) {
|
||||
|
||||
out.write("\"" + parsed + "\"");
|
||||
// out.write("\"" + parsed + "\"");
|
||||
|
||||
// out.write(",");
|
||||
out.write(parsed);
|
||||
out.write(",");
|
||||
|
||||
// System.out.println("write column : " + j);
|
||||
// RowString = RowString + parsed + " ";
|
||||
if (j == 0) {
|
||||
|
@ -1075,7 +1096,10 @@ public class DatabaseManagement {
|
|||
}
|
||||
if (j == row.length - 1) {
|
||||
|
||||
out.write("\"" + parsed + "\"");
|
||||
// out.write("\"" + parsed + "\"");
|
||||
// out.newLine();
|
||||
|
||||
out.write(parsed);
|
||||
out.newLine();
|
||||
|
||||
// to add a row to the map
|
||||
|
@ -1119,11 +1143,11 @@ public class DatabaseManagement {
|
|||
// convert database datatypes to Java datatypes
|
||||
if (DataTypeColumns == null
|
||||
|| DataTypeColumns.size() == 0)
|
||||
parsed = convertToJavaType(row[0]
|
||||
.getClass().getName(), parsed);
|
||||
parsed = convertToJavaType(row[0].getClass()
|
||||
.getName(), parsed);
|
||||
else
|
||||
parsed = convertToJavaType(
|
||||
DataTypeColumns.get(0), parsed);
|
||||
parsed = convertToJavaType(DataTypeColumns.get(0),
|
||||
parsed);
|
||||
}
|
||||
|
||||
out.write(row[0].toString());
|
||||
|
@ -1136,8 +1160,6 @@ public class DatabaseManagement {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// close the file
|
||||
|
@ -1289,7 +1311,6 @@ public class DatabaseManagement {
|
|||
|
||||
for (int j = 0; j < listvalues.size(); j++) {
|
||||
|
||||
|
||||
listColumnNamesTable.add(listvalues.get(j).toString());
|
||||
|
||||
// AnalysisLogger.getLogger().debug(
|
||||
|
|
Loading…
Reference in New Issue