Debian Codegraph @

src/main/org/h2/schema/MetaSchema.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.schema;
7
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Map;
11
12 import org.h2.engine.Database;
13 import org.h2.engine.SessionLocal;
14 import org.h2.engine.User;
15 import org.h2.table.Table;
16
17 /**
18 * Meta data schema.
19 */
20 public abstract class MetaSchema extends Schema {
21
22 /**
23 * Creates a new instance of meta data schema.
24 *
25 * @param database
26 * the database
27 * @param id
28 * the object id
29 * @param schemaName
30 * the schema name
31 * @param owner
32 * the owner of the schema
33 */
34 public MetaSchema(Database database, int id, String schemaName, User owner) {
35 super(database, id, schemaName, owner, true);
36 }
37
38 @Override
39 public Table findTableOrView(SessionLocal session, String name) {
40 Map<String, Table> map = getMap(session);
41 Table table = map.get(name);
42 if (table != null) {
43 return table;
44 }
45 return super.findTableOrView(session, name);
46 }
47
48 @Override
49 public Collection<Table> getAllTablesAndViews(SessionLocal session) {
50 Collection<Table> userTables = super.getAllTablesAndViews(session);
51 if (session == null) {
52 return userTables;
53 }
54 Collection<Table> systemTables = getMap(session).values();
55 if (userTables.isEmpty()) {
56 return systemTables;
57 }
58 ArrayList<Table> list = new ArrayList<>(systemTables.size() + userTables.size());
59 list.addAll(systemTables);
60 list.addAll(userTables);
61 return list;
62 }
63
64 @Override
65 public Table getTableOrView(SessionLocal session, String name) {
66 Map<String, Table> map = getMap(session);
67 Table table = map.get(name);
68 if (table != null) {
69 return table;
70 }
71 return super.getTableOrView(session, name);
72 }
73
74 @Override
75 public Table getTableOrViewByName(SessionLocal session, String name) {
76 Map<String, Table> map = getMap(session);
77 Table table = map.get(name);
78 if (table != null) {
79 return table;
80 }
81 return super.getTableOrViewByName(session, name);
82 }
83
84 /**
85 * Returns map of tables in this schema.
86 *
87 * @param session the session
88 * @return map of tables in this schema
89 */
90 protected abstract Map<String, Table> getMap(SessionLocal session);
91
92 @Override
93 public boolean isEmpty() {
94 return false;
95 }
96
97 }