1
2
3
4
5
6
7
8
9
10
11 package com.jsql.model.bean.database;
12
13 import com.jsql.util.LogLevelUtil;
14 import com.jsql.util.StringUtil;
15 import org.apache.commons.lang3.StringUtils;
16 import org.apache.logging.log4j.LogManager;
17 import org.apache.logging.log4j.Logger;
18
19
20
21
22
23 public class Table extends AbstractElementDatabase {
24
25 private static final Logger LOGGER = LogManager.getRootLogger();
26
27
28 private final Database parentDatabase;
29
30
31
32 private String rowCount;
33
34
35
36
37 public Table(String tableName, String rowCount, Database parentDatabase) {
38 this.elementValue = tableName;
39 this.rowCount = rowCount;
40 this.parentDatabase = parentDatabase;
41 }
42
43
44 @Override
45 public AbstractElementDatabase getParent() {
46 return this.parentDatabase;
47 }
48
49
50 @Override
51 public int getChildCount() {
52 return Integer.parseInt(this.rowCount);
53 }
54
55
56
57
58
59
60 @Override
61 public String getLabelWithCount() {
62 String nbRow = StringUtil.INFORMATION_SCHEMA.equals(this.parentDatabase.toString())
63 ? "?"
64 : this.rowCount;
65
66
67 String sPlural = StringUtils.EMPTY;
68 try {
69 if (Integer.parseInt(this.rowCount) > 1) {
70 sPlural = "s";
71 }
72 } catch (NumberFormatException e) {
73 this.rowCount = "0";
74 nbRow = "0";
75 LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Incorrect number of rows.");
76 }
77
78 return String.format(
79 "%s (%s row%s)",
80 this.elementValue,
81 nbRow,
82 sPlural
83 );
84 }
85 }