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