Debian Codegraph @

src/main/org/h2/mode/PgCatalogSchema.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.mode;
7
8 import java.util.HashMap;
9 import java.util.Map;
10
11 import org.h2.engine.Constants;
12 import org.h2.engine.Database;
13 import org.h2.engine.SessionLocal;
14 import org.h2.engine.User;
15 import org.h2.schema.MetaSchema;
16 import org.h2.table.Table;
17
18 /**
19 * {@code pg_catalog} schema.
20 */
21 public final class PgCatalogSchema extends MetaSchema {
22
23 private volatile HashMap<String, Table> tables;
24
25 /**
26 * Creates new instance of {@code pg_catalog} schema.
27 *
28 * @param database
29 * the database
30 * @param owner
31 * the owner of the schema (system user)
32 */
33 public PgCatalogSchema(Database database, User owner) {
34 super(database, Constants.PG_CATALOG_SCHEMA_ID, database.sysIdentifier(Constants.SCHEMA_PG_CATALOG), owner);
35 }
36
37 @Override
38 protected Map<String, Table> getMap(SessionLocal session) {
39 HashMap<String, Table> map = tables;
40 if (map == null) {
41 map = fillMap();
42 }
43 return map;
44 }
45
46 private synchronized HashMap<String, Table> fillMap() {
47 HashMap<String, Table> map = tables;
48 if (map == null) {
49 map = database.newStringMap();
50 for (int type = 0; type < PgCatalogTable.META_TABLE_TYPE_COUNT; type++) {
51 PgCatalogTable table = new PgCatalogTable(this, Constants.PG_CATALOG_SCHEMA_ID - type, type);
52 map.put(table.getName(), table);
53 }
54 tables = map;
55 }
56 return map;
57 }
58
59 }