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 org.apache.commons.lang3.StringUtils;
15 import org.apache.logging.log4j.LogManager;
16 import org.apache.logging.log4j.Logger;
17
18
19
20
21 public class Database extends AbstractElementDatabase {
22
23 private static final Logger LOGGER = LogManager.getRootLogger();
24
25
26
27 private String tableCount;
28
29
30
31
32 public Database(String databaseName, String tableCount) {
33 this.elementValue = databaseName;
34 this.tableCount = tableCount;
35 }
36
37
38 @Override
39 public AbstractElementDatabase getParent() {
40 return null;
41 }
42
43
44 @Override
45 public int getChildCount() {
46 return Integer.parseInt(this.tableCount);
47 }
48
49
50
51
52
53 @Override
54 public String getLabelWithCount() {
55
56 String sPlural = StringUtils.EMPTY;
57
58 try {
59 if (Integer.parseInt(this.tableCount) > 1) {
60 sPlural = "s";
61 }
62 } catch (NumberFormatException e) {
63 this.tableCount = "0";
64 LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Incorrect number of tables for [{}].", this);
65 }
66
67 return String.format(
68 "%s (%s table%s)",
69 this.elementValue,
70 this.tableCount,
71 sPlural
72 );
73 }
74 }