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

COVERAGE SUMMARY FOR SOURCE FILE [Comment.java]

nameclass, %method, %block, %line, %
Comment.java100% (1/1)70%  (7/10)90%  (108/120)85%  (29/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Comment100% (1/1)70%  (7/10)90%  (108/120)85%  (29/34)
checkRename (): void 0%   (0/1)0%   (0/3)0%   (0/2)
getCreateSQLForCopy (Table, String): String 0%   (0/1)0%   (0/2)0%   (0/1)
getDropSQL (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getCreateSQL (): String 100% (1/1)86%  (30/35)83%  (5/6)
Comment (Database, int, DbObject): void 100% (1/1)100% (18/18)100% (5/5)
getKey (DbObject): String 100% (1/1)100% (14/14)100% (1/1)
getType (): int 100% (1/1)100% (2/2)100% (1/1)
getTypeName (int): String 100% (1/1)100% (33/33)100% (13/13)
removeChildrenAndResources (Session): void 100% (1/1)100% (7/7)100% (2/2)
setCommentText (String): void 100% (1/1)100% (4/4)100% (2/2)

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.engine;
7 
8import org.h2.message.DbException;
9import org.h2.message.Trace;
10import org.h2.table.Table;
11import org.h2.util.StringUtils;
12 
13/**
14 * Represents a database object comment.
15 */
16public class Comment extends DbObjectBase {
17 
18    private final int objectType;
19    private final String objectName;
20    private String commentText;
21 
22    public Comment(Database database, int id, DbObject obj) {
23        initDbObjectBase(database, id,  getKey(obj), Trace.DATABASE);
24        this.objectType = obj.getType();
25        this.objectName = obj.getSQL();
26    }
27 
28    @Override
29    public String getCreateSQLForCopy(Table table, String quotedName) {
30        throw DbException.throwInternalError();
31    }
32 
33    private static String getTypeName(int type) {
34        switch(type) {
35        case DbObject.CONSTANT:
36            return "CONSTANT";
37        case DbObject.CONSTRAINT:
38            return "CONSTRAINT";
39        case DbObject.FUNCTION_ALIAS:
40            return "ALIAS";
41        case DbObject.INDEX:
42            return "INDEX";
43        case DbObject.ROLE:
44            return "ROLE";
45        case DbObject.SCHEMA:
46            return "SCHEMA";
47        case DbObject.SEQUENCE:
48            return "SEQUENCE";
49        case DbObject.TABLE_OR_VIEW:
50            return "TABLE";
51        case DbObject.TRIGGER:
52            return "TRIGGER";
53        case DbObject.USER:
54            return "USER";
55        case DbObject.USER_DATATYPE:
56            return "DOMAIN";
57        default:
58            // not supported by parser, but required when trying to find a
59            // comment
60            return "type" + type;
61        }
62    }
63 
64    @Override
65    public String getDropSQL() {
66        return null;
67    }
68 
69    @Override
70    public String getCreateSQL() {
71        StringBuilder buff = new StringBuilder("COMMENT ON ");
72        buff.append(getTypeName(objectType)).append(' ').
73                append(objectName).append(" IS ");
74        if (commentText == null) {
75            buff.append("NULL");
76        } else {
77            buff.append(StringUtils.quoteStringSQL(commentText));
78        }
79        return buff.toString();
80    }
81 
82    @Override
83    public int getType() {
84        return DbObject.COMMENT;
85    }
86 
87    @Override
88    public void removeChildrenAndResources(Session session) {
89        database.removeMeta(session, getId());
90    }
91 
92    @Override
93    public void checkRename() {
94        DbException.throwInternalError();
95    }
96 
97    /**
98     * Get the comment key name for the given database object. This key name is
99     * used internally to associate the comment to the object.
100     *
101     * @param obj the object
102     * @return the key name
103     */
104    static String getKey(DbObject obj) {
105        return getTypeName(obj.getType()) + " " + obj.getSQL();
106    }
107 
108    /**
109     * Set the comment text.
110     *
111     * @param comment the text
112     */
113    public void setCommentText(String comment) {
114        this.commentText = comment;
115    }
116 
117}

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