File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\engine\Comment.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.engine;
8
9 import org.h2.message.DbException;
10 import org.h2.message.Trace;
11 import org.h2.table.Table;
12 import org.h2.util.StringUtils;
13
14 /**
15 * Represents a database object comment.
16 */
17 public class Comment extends DbObjectBase {
18
19 private final int objectType;
20 private final String objectName;
21 private String commentText;
22
23 public Comment(Database database, int id, DbObject obj) {
24 initDbObjectBase(database, id, getKey(obj), Trace.DATABASE);
25 this.objectType = obj.getType();
26 this.objectName = obj.getSQL();
27 }
28
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 comment
59 return "type" + type;
60 }
61 }
62
63 public String getDropSQL() {
64 return null;
65 }
66
67 public String getCreateSQL() {
68 StringBuilder buff = new StringBuilder("COMMENT ON ");
69 buff.append(getTypeName(objectType)).append(' ').append(objectName).append(" IS ");
70 if (commentText == null) {
71 buff.append("NULL");
72 } else {
73 buff.append(StringUtils.quoteStringSQL(commentText));
74 }
75 return buff.toString();
76 }
77
78 public int getType() {
79 return DbObject.COMMENT;
80 }
81
82 public void removeChildrenAndResources(Session session) {
83 database.removeMeta(session, getId());
84 }
85
86 public void checkRename() {
87 DbException.throwInternalError();
88 }
89
90 /**
91 * Get the comment key name for the given database object. This key name is
92 * used internally to associate the comment to the object.
93 *
94 * @param obj the object
95 * @return the key name
96 */
97 static String getKey(DbObject obj) {
98 return getTypeName(obj.getType()) + " " + obj.getSQL();
99 }
100
101 /**
102 * Set the comment text.
103 *
104 * @param comment the text
105 */
106 public void setCommentText(String comment) {
107 this.commentText = comment;
108 }
109
110 }
111