EMMA Coverage Report (generated Sun Mar 01 22:06:14 CET 2015)
[all classes][org.h2.bnf.context]

COVERAGE SUMMARY FOR SOURCE FILE [DbColumn.java]

nameclass, %method, %block, %line, %
DbColumn.java100% (1/1)100% (7/7)91%  (116/127)97%  (28/29)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DbColumn100% (1/1)100% (7/7)91%  (116/127)97%  (28/29)
DbColumn (DbContents, ResultSet, boolean): void 100% (1/1)89%  (90/101)96%  (22/23)
getColumn (DbContents, ResultSet): DbColumn 100% (1/1)100% (7/7)100% (1/1)
getDataType (): String 100% (1/1)100% (3/3)100% (1/1)
getName (): String 100% (1/1)100% (3/3)100% (1/1)
getPosition (): int 100% (1/1)100% (3/3)100% (1/1)
getProcedureColumn (DbContents, ResultSet): DbColumn 100% (1/1)100% (7/7)100% (1/1)
getQuotedName (): String 100% (1/1)100% (3/3)100% (1/1)

1/*
2 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (http://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6package org.h2.bnf.context;
7 
8import java.sql.DatabaseMetaData;
9import java.sql.ResultSet;
10import java.sql.SQLException;
11 
12/**
13 * Keeps the meta data information of a column.
14 * This class is used by the H2 Console.
15 */
16public class DbColumn {
17 
18    private final String name;
19 
20    private final String quotedName;
21 
22    private final String dataType;
23 
24    private int position;
25 
26    private DbColumn(DbContents contents, ResultSet rs, boolean procedureColumn)
27            throws SQLException {
28        name = rs.getString("COLUMN_NAME");
29        quotedName = contents.quoteIdentifier(name);
30        String type = rs.getString("TYPE_NAME");
31        // a procedures column size is identified by PRECISION, for table this
32        // is COLUMN_SIZE
33        String precisionColumnName;
34        if (procedureColumn) {
35            precisionColumnName = "PRECISION";
36        } else {
37            precisionColumnName = "COLUMN_SIZE";
38        }
39        int precision = rs.getInt(precisionColumnName);
40        position = rs.getInt("ORDINAL_POSITION");
41        boolean isSQLite = contents.isSQLite();
42        if (precision > 0 && !isSQLite) {
43            type += "(" + precision;
44            String scaleColumnName;
45            if (procedureColumn) {
46                scaleColumnName = "SCALE";
47            } else {
48                scaleColumnName = "DECIMAL_DIGITS";
49            }
50            int prec = rs.getInt(scaleColumnName);
51            if (prec > 0) {
52                type += ", " + prec;
53            }
54            type += ")";
55        }
56        if (rs.getInt("NULLABLE") == DatabaseMetaData.columnNoNulls) {
57            type += " NOT NULL";
58        }
59        dataType = type;
60    }
61 
62    /**
63     * Create a column from a DatabaseMetaData.getProcedureColumns row.
64     *
65     * @param contents the database contents
66     * @param rs the result set
67     * @return the column
68     */
69    public static DbColumn getProcedureColumn(DbContents contents, ResultSet rs)
70            throws SQLException {
71        return new DbColumn(contents, rs, true);
72    }
73 
74    /**
75     * Create a column from a DatabaseMetaData.getColumns row.
76     *
77     * @param contents the database contents
78     * @param rs the result set
79     * @return the column
80     */
81    public static DbColumn getColumn(DbContents contents, ResultSet rs)
82            throws SQLException {
83        return new DbColumn(contents, rs, false);
84    }
85 
86    /**
87     * @return The data type name (including precision and the NOT NULL flag if
88     * applicable).
89     */
90    public String getDataType() {
91        return dataType;
92    }
93 
94    /**
95     * @return The column name.
96     */
97    public String getName() {
98        return name;
99    }
100 
101    /**
102     * @return The quoted table name.
103     */
104    public String getQuotedName() {
105        return quotedName;
106    }
107 
108    /**
109     * @return Column index
110     */
111    public int getPosition() {
112        return position;
113    }
114 
115}

[all classes][org.h2.bnf.context]
EMMA 2.0.5312 (C) Vladimir Roubtsov