Revize d3fafcf1
Přidáno uživatelem Jiri Trefil před asi 2 roky(ů)
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/DatabaseConnection.java | ||
---|---|---|
18 | 18 |
public class DatabaseConnection { |
19 | 19 |
private final Logger LOGGER = LoggerFactory.getLogger(DatabaseConnection.class); |
20 | 20 |
|
21 |
private Connection databaseConnection; |
|
21 |
private final Connection databaseConnection;
|
|
22 | 22 |
|
23 | 23 |
/** |
24 | 24 |
* Constructor that takes application properties from configuration file name application.properties |
... | ... | |
85 | 85 |
* @return result set of results |
86 | 86 |
*/ |
87 | 87 |
public ResultSet executeQueries(Project project, List<String> queries) { |
88 |
Statement stmt; |
|
89 | 88 |
ResultSet resultSet = null; |
90 |
try { |
|
91 |
stmt = this.getDatabaseConnection().createStatement(); |
|
89 |
try (Statement stmt = this.getDatabaseConnection().createStatement()) { |
|
92 | 90 |
|
93 | 91 |
for (String query : queries) { |
94 | 92 |
if (queries.indexOf(query) != queries.size() - 1) { |
... | ... | |
114 | 112 |
* @return object of results |
115 | 113 |
*/ |
116 | 114 |
public List<List<Map<String, Object>>> executeQueriesWithMultipleResults(Project project, List<String> queries) { |
117 |
Statement stmt; |
|
118 | 115 |
List<List<Map<String, Object>>> allResults = new ArrayList<>(); |
119 | 116 |
ResultSet resultSet; |
120 | 117 |
try(Statement stmt = this.getDatabaseConnection().createStatement()) { |
121 | 118 |
|
122 | 119 |
for (String query : queries) { |
123 | 120 |
if (queries.indexOf(query) != queries.size() - 1) { |
124 |
if (query.contains("?")) |
|
121 |
if (query.contains("?")) {
|
|
125 | 122 |
query = query.replace("?", project.getId().toString()); |
126 |
resultSet = stmt.executeQuery(query); |
|
127 |
} else { |
|
128 |
resultSet = stmt.executeQuery(query); |
|
123 |
} |
|
129 | 124 |
} |
125 |
resultSet = stmt.executeQuery(query); |
|
130 | 126 |
|
131 | 127 |
if (query.toLowerCase().startsWith("select")) { |
132 | 128 |
allResults.add(Utils.resultSetToArrayList(resultSet)); |
133 | 129 |
} |
134 |
|
|
135 | 130 |
} |
136 | 131 |
} catch (SQLException e) { |
137 | 132 |
LOGGER.error("DB query with multiple results could not be performed!"); |
Také k dispozici: Unified diff
#10244 Očista kódu