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
26
27
28 private static final Logger LOGGER = LogManager.getRootLogger();
29
30
31 private final Database parentDatabase;
32
33
34
35 private String rowCount;
36
37
38
39
40 public Table(String tableName, String rowCount, Database parentDatabase) {
41 this.elementValue = tableName;
42 this.rowCount = rowCount;
43 this.parentDatabase = parentDatabase;
44 }
45
46
47 @Override
48 public AbstractElementDatabase getParent() {
49 return this.parentDatabase;
50 }
51
52
53 @Override
54 public int getChildCount() {
55 return Integer.parseInt(this.rowCount);
56 }
57
58
59
60
61
62
63 @Override
64 public String getLabelWithCount() {
65 String nbRow = StringUtil.INFORMATION_SCHEMA.equals(this.parentDatabase.toString())
66 ? "?"
67 : this.rowCount;
68
69
70 String sPlural = StringUtils.EMPTY;
71 try {
72 if (Integer.parseInt(this.rowCount) > 1) {
73 sPlural = "s";
74 }
75 } catch (NumberFormatException e) {
76 this.rowCount = "0";
77 nbRow = "0";
78 LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Incorrect number of rows.");
79 }
80
81 return String.format(
82 "%s (%s row%s)",
83 this.elementValue,
84 nbRow,
85 sPlural
86 );
87 }
88 }