File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\server\web\DbSchema.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.server.web;
8
9 import java.sql.DatabaseMetaData;
10 import java.sql.ResultSet;
11 import java.sql.SQLException;
12 import java.util.ArrayList;
13 import org.h2.util.New;
14 import org.h2.util.StringUtils;
15
16 /**
17 * Contains meta data information about a database schema.
18 * This class is used by the H2 Console.
19 */
20 public class DbSchema {
21
22 /**
23 * Up to this many tables, the column type and indexes are listed.
24 */
25 static final int MAX_TABLES_LIST_INDEXES = 100;
26
27 /**
28 * Up to this many tables, the column names are listed.
29 */
30 static final int MAX_TABLES_LIST_COLUMNS = 500;
31
32 /**
33 * The database content container.
34 */
35 final DbContents contents;
36
37 /**
38 * The schema name.
39 */
40 final String name;
41
42 /**
43 * True if this is the default schema for this database.
44 */
45 final boolean isDefault;
46
47 /**
48 * True if this is a system schema (for example the INFORMATION_SCHEMA).
49 */
50 final boolean isSystem;
51
52 /**
53 * The quoted schema name.
54 */
55 final String quotedName;
56
57 /**
58 * The table list.
59 */
60 DbTableOrView[] tables;
61
62 DbSchema(DbContents contents, String name, boolean isDefault) {
63 this.contents = contents;
64 this.name = name;
65 this.quotedName = contents.quoteIdentifier(name);
66 this.isDefault = isDefault;
67 if (StringUtils.toUpperEnglish(name).startsWith("INFO")) {
68 isSystem = true;
69 } else if (contents.isPostgreSQL && StringUtils.toUpperEnglish(name).startsWith("PG_")) {
70 isSystem = true;
71 } else if (contents.isDerby && name.startsWith("SYS")) {
72 isSystem = true;
73 } else {
74 isSystem = false;
75 }
76 }
77
78 /**
79 * Read all tables for this schema from the database meta data.
80 *
81 * @param meta the database meta data
82 * @param tableTypes the table types to read
83 */
84 void readTables(DatabaseMetaData meta, String[] tableTypes) throws SQLException {
85 ResultSet rs = meta.getTables(null, name, null, tableTypes);
86 ArrayList<DbTableOrView> list = New.arrayList();
87 while (rs.next()) {
88 DbTableOrView table = new DbTableOrView(this, rs);
89 if (contents.isOracle && table.name.indexOf('$') > 0) {
90 continue;
91 }
92 list.add(table);
93 }
94 rs.close();
95 tables = new DbTableOrView[list.size()];
96 list.toArray(tables);
97 if (tables.length < MAX_TABLES_LIST_COLUMNS) {
98 for (DbTableOrView tab : tables) {
99 tab.readColumns(meta);
100 }
101 }
102 }
103
104 }
105