1 | /******************************************************************************* | |
2 | * Copyhacked (H) 2012-2020. | |
3 | * This program and the accompanying materials | |
4 | * are made available under no term at all, use it like | |
5 | * you want, but share and discuss about it | |
6 | * every time possible with every body. | |
7 | * | |
8 | * Contributors: | |
9 | * ron190 at ymail dot com - initial implementation | |
10 | ******************************************************************************/ | |
11 | package com.jsql.model.bean.database; | |
12 | ||
13 | import com.jsql.util.LogLevelUtil; | |
14 | import org.apache.commons.lang3.StringUtils; | |
15 | import org.apache.logging.log4j.LogManager; | |
16 | import org.apache.logging.log4j.Logger; | |
17 | ||
18 | /** | |
19 | * Define a Table, e.g. is sent to the view by the model after injection. | |
20 | * Allow to traverse upward to its corresponding database. | |
21 | */ | |
22 | public class Table extends AbstractElementDatabase { | |
23 | | |
24 | /** | |
25 | * Log4j logger sent to view. | |
26 | */ | |
27 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
28 | | |
29 | // The database that contains the current column. | |
30 | private final Database parentDatabase; | |
31 | | |
32 | // The number of rows in the table. | |
33 | // TODO to int and move to abstract class | |
34 | private String rowCount; | |
35 | ||
36 | /** | |
37 | * Define the table label, number of rows and parent database. | |
38 | * @param tableName | |
39 | * @param rowCount | |
40 | * @param parentDatabase | |
41 | */ | |
42 | public Table(String tableName, String rowCount, Database parentDatabase) { | |
43 | | |
44 | this.elementValue = tableName; | |
45 | this.rowCount = rowCount; | |
46 | this.parentDatabase = parentDatabase; | |
47 | } | |
48 | | |
49 | // Return the parent database. | |
50 | @Override | |
51 | public AbstractElementDatabase getParent() { | |
52 |
1
1. getParent : replaced return value with null for com/jsql/model/bean/database/Table::getParent → KILLED |
return this.parentDatabase; |
53 | } | |
54 | | |
55 | // Return the number of rows in the table. | |
56 | @Override | |
57 | public int getChildCount() { | |
58 |
1
1. getChildCount : replaced int return with 0 for com/jsql/model/bean/database/Table::getChildCount → NO_COVERAGE |
return Integer.parseInt(this.rowCount); |
59 | } | |
60 | ||
61 | /** | |
62 | * A readable label for the table, with number of rows, displayed | |
63 | * by the view. If parent database is the system information_schema, number | |
64 | * of rows is unknown, e.g. my_table (7 rows). | |
65 | */ | |
66 | @Override | |
67 | public String getLabelCount() { | |
68 | | |
69 |
1
1. getLabelCount : negated conditional → KILLED |
String nbRow = "information_schema".equals(this.parentDatabase.toString()) |
70 | ? "?" | |
71 | : this.rowCount; | |
72 | | |
73 | // Report #138: detect incorrect number of rows | |
74 | String sPlural = StringUtils.EMPTY; | |
75 | | |
76 | try { | |
77 |
2
1. getLabelCount : changed conditional boundary → SURVIVED 2. getLabelCount : negated conditional → KILLED |
if (Integer.parseInt(this.rowCount) > 1) { |
78 | sPlural = "s"; | |
79 | } | |
80 | } catch (NumberFormatException e) { | |
81 | | |
82 | this.rowCount = "0"; | |
83 | nbRow = "0"; | |
84 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Incorrect number of rows."); | |
85 | } | |
86 | | |
87 |
1
1. getLabelCount : replaced return value with "" for com/jsql/model/bean/database/Table::getLabelCount → KILLED |
return String.format( |
88 | "%s (%s row%s)", | |
89 | this.elementValue, | |
90 | nbRow, | |
91 | sPlural | |
92 | ); | |
93 | } | |
94 | } | |
Mutations | ||
52 |
1.1 |
|
58 |
1.1 |
|
69 |
1.1 |
|
77 |
1.1 2.2 |
|
87 |
1.1 |