1
|
package vldc.aswi.service;
|
2
|
|
3
|
import lombok.extern.slf4j.Slf4j;
|
4
|
import org.springframework.beans.factory.annotation.Autowired;
|
5
|
import org.springframework.stereotype.Service;
|
6
|
import vldc.aswi.database.DatabaseInterface;
|
7
|
import vldc.aswi.model.table.TableColumn;
|
8
|
import vldc.aswi.model.table.contingencyTable.ContingencyTableRow;
|
9
|
import vldc.aswi.utils.Converter;
|
10
|
|
11
|
import javax.sql.DataSource;
|
12
|
import java.util.List;
|
13
|
import java.util.Map;
|
14
|
|
15
|
/**
|
16
|
* Manager for SqlQuery.
|
17
|
*/
|
18
|
@Service
|
19
|
@Slf4j
|
20
|
public class SqlQueryManagerImpl implements SqlQueryManager{
|
21
|
|
22
|
/** Autowired databaseInterface component. */
|
23
|
@Autowired
|
24
|
private DatabaseInterface databaseInterface;
|
25
|
|
26
|
/**
|
27
|
* Get list of contingencyTableRow.
|
28
|
* @param sqlQuery - SQL query.
|
29
|
* @return List of contingencyTableRow.
|
30
|
*/
|
31
|
@Override
|
32
|
public List<ContingencyTableRow> getContingencyTableRow(String sqlQuery) {
|
33
|
Map<String, TableColumn> tableColumns = this.databaseInterface.executeQueryAndReturnTableColumns(sqlQuery);
|
34
|
return Converter.convertTableColumnsToContingencyTableRows(tableColumns);
|
35
|
}
|
36
|
|
37
|
/**
|
38
|
* Validate given SQL query.
|
39
|
* @param sqlQuery - Validated SQL query.
|
40
|
* @return true if SQL query is ok, false if not.
|
41
|
*/
|
42
|
@Override
|
43
|
public boolean validateSQLQuery(String sqlQuery) {
|
44
|
return this.databaseInterface.validateSQLQuery(sqlQuery);
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* Get list of table column names from SQL query.
|
49
|
* @param sqlQuery - SQL query.
|
50
|
* @return List of table column names.
|
51
|
*/
|
52
|
public List<String> getNameOfColumnsFromQuery(String sqlQuery) {
|
53
|
return this.databaseInterface.getNameOfColumnsFromQuery(sqlQuery);
|
54
|
}
|
55
|
}
|