File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\server\web\DbTableOrView.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
15 /**
16 * Contains meta data information about a table or a view.
17 * This class is used by the H2 Console.
18 */
19 public class DbTableOrView {
20
21 /**
22 * The schema this table belongs to.
23 */
24 final DbSchema schema;
25
26 /**
27 * The table name.
28 */
29 final String name;
30
31 /**
32 * The quoted table name.
33 */
34 final String quotedName;
35
36 /**
37 * True if this represents a view.
38 */
39 final boolean isView;
40
41 /**
42 * The column list.
43 */
44 DbColumn[] columns;
45
46 DbTableOrView(DbSchema schema, ResultSet rs) throws SQLException {
47 this.schema = schema;
48 name = rs.getString("TABLE_NAME");
49 String type = rs.getString("TABLE_TYPE");
50 isView = "VIEW".equals(type);
51 quotedName = schema.contents.quoteIdentifier(name);
52 }
53
54 /**
55 * Read the column for this table from the database meta data.
56 *
57 * @param meta the database meta data
58 */
59 void readColumns(DatabaseMetaData meta) throws SQLException {
60 ResultSet rs = meta.getColumns(null, schema.name, name, null);
61 ArrayList<DbColumn> list = New.arrayList();
62 while (rs.next()) {
63 DbColumn column = new DbColumn(schema.contents, rs);
64 list.add(column);
65 }
66 rs.close();
67 columns = new DbColumn[list.size()];
68 list.toArray(columns);
69 }
70
71 }
72