1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.infra.metadata.database.schema.model;
19
20 import lombok.Getter;
21
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Map.Entry;
27 import java.util.concurrent.ConcurrentHashMap;
28
29
30
31
32 @Getter
33 public final class ShardingSphereSchema {
34
35 private final Map<String, ShardingSphereTable> tables;
36
37 private final Map<String, ShardingSphereView> views;
38
39 @SuppressWarnings("CollectionWithoutInitialCapacity")
40 public ShardingSphereSchema() {
41 tables = new ConcurrentHashMap<>();
42 views = new ConcurrentHashMap<>();
43 }
44
45 public ShardingSphereSchema(final Map<String, ShardingSphereTable> tables, final Map<String, ShardingSphereView> views) {
46 this.tables = new ConcurrentHashMap<>(tables.size(), 1F);
47 this.views = new ConcurrentHashMap<>(views.size(), 1F);
48 tables.forEach((key, value) -> this.tables.put(key.toLowerCase(), value));
49 views.forEach((key, value) -> this.views.put(key.toLowerCase(), value));
50 }
51
52
53
54
55
56
57 public Collection<String> getAllTableNames() {
58 return tables.keySet();
59 }
60
61
62
63
64
65
66 public Collection<String> getAllViewNames() {
67 return views.keySet();
68 }
69
70
71
72
73
74
75
76 public ShardingSphereTable getTable(final String tableName) {
77 return tables.get(tableName.toLowerCase());
78 }
79
80
81
82
83
84
85
86 public ShardingSphereView getView(final String viewName) {
87 return views.get(viewName.toLowerCase());
88 }
89
90
91
92
93
94
95
96 public void putTable(final String tableName, final ShardingSphereTable table) {
97 tables.put(tableName.toLowerCase(), table);
98 }
99
100
101
102
103
104
105
106 public void putView(final String viewName, final ShardingSphereView view) {
107 views.put(viewName.toLowerCase(), view);
108 }
109
110
111
112
113
114
115 public void putAll(final Map<String, ShardingSphereTable> tables) {
116 for (Entry<String, ShardingSphereTable> entry : tables.entrySet()) {
117 putTable(entry.getKey(), entry.getValue());
118 }
119 }
120
121
122
123
124
125
126 public void removeTable(final String tableName) {
127 tables.remove(tableName.toLowerCase());
128 }
129
130
131
132
133
134
135 public void removeView(final String viewName) {
136 views.remove(viewName.toLowerCase());
137 }
138
139
140
141
142
143
144
145 public boolean containsTable(final String tableName) {
146 return tables.containsKey(tableName.toLowerCase());
147 }
148
149
150
151
152
153
154
155
156 public boolean containsColumn(final String tableName, final String columnName) {
157 return containsTable(tableName) && getTable(tableName).containsColumn(columnName);
158 }
159
160
161
162
163
164
165
166
167 public boolean containsIndex(final String tableName, final String indexName) {
168 return containsTable(tableName) && getTable(tableName).containsIndex(indexName);
169 }
170
171
172
173
174
175
176
177 public boolean containsView(final String viewName) {
178 return views.containsKey(viewName.toLowerCase());
179 }
180
181
182
183
184
185
186
187 public List<String> getAllColumnNames(final String tableName) {
188 return containsTable(tableName) ? getTable(tableName).getColumnNames() : Collections.emptyList();
189 }
190
191
192
193
194
195
196
197 public List<String> getVisibleColumnNames(final String tableName) {
198 return containsTable(tableName) ? getTable(tableName).getVisibleColumns() : Collections.emptyList();
199 }
200 }