Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 830a7e2e

Přidáno uživatelem Michal Linha před téměř 4 roky(ů)

re #8176 nothing; re #8178 added checks for data types; added table name to the generated table

Zobrazit rozdíly:

src/main/java/vldc/aswi/service/SqlQueryManagerImpl.java
5 5
import org.springframework.stereotype.Service;
6 6
import vldc.aswi.database.DatabaseInterface;
7 7
import vldc.aswi.domain.Assembly;
8
import vldc.aswi.domain.Configuration;
9 8
import vldc.aswi.domain.Function;
10 9
import vldc.aswi.domain.parameter.ParameterInConfiguration;
11 10
import vldc.aswi.model.table.NameUserName;
......
35 34
     * @param assembly Assembly from which configuration was created.
36 35
     * @param parametersInConfiguration Parameters in configuration with their locations and operators.
37 36
     * @param isNotRemoveEmpty Sets if empty rows and columns should not be removed.
38
     * @return List of contingencyTableRow.
37
     * @param tableName Name of the table.
38
     * @return List of contingencyTableRow or null, if error in SQL query occurred.
39 39
     */
40 40
    @Override
41 41
    public List<ContingencyTableRow> getContingencyTableRow(Assembly assembly,
42 42
                                                            List<ParameterInConfiguration> parametersInConfiguration,
43
                                                            boolean isNotRemoveEmpty) {
43
                                                            boolean isNotRemoveEmpty, String tableName) {
44 44
        long startTime = System.nanoTime();
45 45

  
46 46
        Map<String, TableColumn> tableColumns = this.databaseInterface.executeQueryAndReturnTableColumns(
47 47
                generateFullSQLQuery(assembly.getSQLQuery(), parametersInConfiguration)
48 48
        );
49 49

  
50
        if (tableColumns == null) {
51
            return null;
52
        }
53

  
54
        if (tableColumns.values().iterator().next().getValues().size() == 0) {
55
            return new ArrayList<>();
56
        }
57

  
50 58
        long stopTime = System.nanoTime();
51 59
        System.out.println("Select:" + TimeUnit.MILLISECONDS.convert((stopTime - startTime), TimeUnit.NANOSECONDS));
52 60
        List<NameUserName> rowNames = new ArrayList<>();
......
61 69

  
62 70
        initializeContingencyTableDataLists(rowNames, columnNames, valueFunctions, copiedParametersInConfiguration);
63 71

  
64
        Converter converter = new Converter(tableColumns, rowNames, columnNames, valueFunctions, isNotRemoveEmpty);
72
        Converter converter = new Converter(tableColumns, rowNames, columnNames, valueFunctions, isNotRemoveEmpty, tableName);
65 73
        return converter.convertTableColumnsToContingencyTableRows();
66 74
    }
67 75

  
......
84 92
        return this.databaseInterface.getNameOfColumnsFromQuery(sqlQuery);
85 93
    }
86 94

  
95
    /**
96
     * Initializes list with values.
97
     * @param rowNames List of selected rows.
98
     * @param columnNames List of selected columns.
99
     * @param valueFunctions List of selected values and functions.
100
     * @param parametersInConfiguration List of parameters in configuration.
101
     */
87 102
    private void initializeContingencyTableDataLists(List<NameUserName> rowNames, List<NameUserName> columnNames,
88 103
                                                     List<ValueFunction> valueFunctions, List<ParameterInConfiguration> parametersInConfiguration) {
89 104
        for (ParameterInConfiguration parameterInConfiguration : parametersInConfiguration) {
......
151 166
    }
152 167

  
153 168
    /**
154
     * Precesses listing (enum) type.
169
     * Processes listing (enum) type.
155 170
     * @param parameterInConfiguration Listing type parameter iin configuration.
156 171
     * @param finalSQLQuery Resulting SQL query.
157 172
     * @param isWhereDefined Variable storing information if WHERE clause was defined in the resulting SQL query.
......
240 255
        StringBuilder SQLQueryPart = new StringBuilder();
241 256
        SQLQueryPart.append("(");
242 257
        for (int i = 0; i < values.length; i++) {
258
            if (type.equals("Datum")) {
259
                SQLQueryPart.append("date ");
260
            }
261

  
243 262
            addQuotes(type, SQLQueryPart);
244 263
            SQLQueryPart.append(values[i]);
245 264
            addQuotes(type, SQLQueryPart);
......
261 280
    private String betweenNotBetween(String[] values, String type) {
262 281
        StringBuilder SQLQueryPart = new StringBuilder();
263 282

  
283
        if (type.equals("Datum")) {
284
            SQLQueryPart.append("date ");
285
        }
286

  
264 287
        addQuotes(type, SQLQueryPart);
265 288
        SQLQueryPart.append(values[0]);
266 289
        addQuotes(type, SQLQueryPart);
267 290

  
268 291
        SQLQueryPart.append(" AND ");
269 292

  
293
        if (type.equals("Datum")) {
294
            SQLQueryPart.append("date ");
295
        }
296

  
270 297
        addQuotes(type, SQLQueryPart);
271 298
        SQLQueryPart.append(values[1]);
272 299
        addQuotes(type, SQLQueryPart);
......
283 310
    private String otherOperators(String[] values, String type) {
284 311
        StringBuilder SQLQueryPart = new StringBuilder();
285 312

  
313
        if (type.equals("Datum")) {
314
            SQLQueryPart.append("date ");
315
        }
316

  
286 317
        addQuotes(type, SQLQueryPart);
287 318
        SQLQueryPart.append(values[0]);
288 319
        addQuotes(type, SQLQueryPart);

Také k dispozici: Unified diff