Revize 7638be72
Přidáno uživatelem Vojtěch Danišík před asi 4 roky(ů)
src/main/java/vldc/aswi/database/DatabaseInterface.java | ||
---|---|---|
31 | 31 |
this.jdbcTemplate = jdbcTemplate; |
32 | 32 |
} |
33 | 33 |
|
34 |
/** |
|
35 |
* Get list of table column names from SQL query. |
|
36 |
* @param sqlQuery - SQL query. |
|
37 |
* @return List of table column names. If null is returned, then it means that SQL query is not valid. |
|
38 |
*/ |
|
39 |
public List<String> getNameOfColumnsFromQuery(String sqlQuery) { |
|
40 |
try |
|
41 |
{ |
|
42 |
// Try extract columns from database using SQL query. |
|
43 |
return jdbcTemplate.query( |
|
44 |
sqlQuery, |
|
45 |
new ResultSetExtractor<List<String>>() { |
|
46 |
@Override |
|
47 |
public List<String> extractData(ResultSet resultSet) throws SQLException { |
|
48 |
List<String> tableColumnNames = new ArrayList<>(); |
|
49 |
|
|
50 |
ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); |
|
51 |
int columnCount = resultSetMetaData.getColumnCount(); |
|
52 |
|
|
53 |
// The column count starts from 1. |
|
54 |
for (int i = 1; i <= columnCount; i++ ) { |
|
55 |
String columnName = resultSetMetaData.getColumnName(i); |
|
56 |
tableColumnNames.add(columnName); |
|
57 |
} |
|
58 |
|
|
59 |
return tableColumnNames; |
|
60 |
} |
|
61 |
} |
|
62 |
); |
|
63 |
|
|
64 |
} |
|
65 |
catch (DataAccessException e) |
|
66 |
{ |
|
67 |
// If SQL query is not valid, then JdbcTemplate returned DataAccess exception. |
|
68 |
return null; |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
34 | 72 |
/** |
35 | 73 |
* Validate given SQLQuery. |
36 | 74 |
* @param sqlQuery - Tested SQL Query. |
37 | 75 |
* @return true if SQL query is valid, false if not. |
38 | 76 |
*/ |
39 | 77 |
public boolean validateSQLQuery(String sqlQuery) { |
78 |
|
|
40 | 79 |
try |
41 | 80 |
{ |
81 |
// Try validate SQL query. |
|
42 | 82 |
jdbcTemplate.execute("EXPLAIN PLAN FOR " + sqlQuery); |
43 | 83 |
return true; |
44 | 84 |
} |
45 | 85 |
catch (DataAccessException e) |
46 | 86 |
{ |
87 |
// If SQL query is not valid, then JdbcTemplate returned DataAccess exception. |
|
47 | 88 |
return false; |
48 | 89 |
} |
49 | 90 |
} |
... | ... | |
70 | 111 |
tableColumnsList.add(new TableColumn(columnName)); |
71 | 112 |
} |
72 | 113 |
|
114 |
// Add values from row to every column. |
|
73 | 115 |
while(resultSet.next()) { |
74 | 116 |
for (int i = 1; i <= columnCount; i++) { |
75 | 117 |
tableColumnsList.get(i - 1).addValue(resultSet.getString(i)); |
... | ... | |
78 | 120 |
|
79 | 121 |
Map<String, TableColumn> tableColumnMap = new HashMap<>(); |
80 | 122 |
|
123 |
// Create map, where key is tablecolumn name. |
|
81 | 124 |
for (TableColumn column : tableColumnsList) { |
82 | 125 |
tableColumnMap.put(column.getName(), column); |
83 | 126 |
} |
Také k dispozici: Unified diff
re #7886 Assembly validator completed (validating sql query, parameter name in select and parameter location) + displaying temp error message.
Added title for edit / add assembly forms.
Added toString method for all domains.