KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > engine > Comment


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.engine;
6
7 import java.sql.SQLException JavaDoc;
8
9 import org.h2.message.Message;
10 import org.h2.message.Trace;
11 import org.h2.table.Table;
12 import org.h2.util.StringUtils;
13
14 public class Comment extends DbObject {
15
16     private int objectType;
17     private String JavaDoc objectName;
18     private String JavaDoc commentText;
19
20     public Comment(Database database, int id, DbObject obj) {
21         super(database, id, getKey(obj), Trace.DATABASE);
22         this.objectType = obj.getType();
23         this.objectName = obj.getSQL();
24     }
25
26     public String JavaDoc getCreateSQLForCopy(Table table, String JavaDoc quotedName) {
27         throw Message.getInternalError();
28     }
29
30     private static String JavaDoc getTypeName(int type) {
31         switch(type) {
32         case DbObject.CONSTANT:
33             return "CONSTANT";
34         case DbObject.CONSTRAINT:
35             return "CONSTRAINT";
36         case DbObject.FUNCTION_ALIAS:
37             return "ALIAS";
38         case DbObject.INDEX:
39             return "INDEX";
40         case DbObject.ROLE:
41             return "ROLE";
42         case DbObject.SCHEMA:
43             return "SCHEMA";
44         case DbObject.SEQUENCE:
45             return "SEQUENCE";
46         case DbObject.TABLE_OR_VIEW:
47             return "TABLE";
48         case DbObject.TRIGGER:
49             return "TRIGGER";
50         case DbObject.USER:
51             return "USER";
52         case DbObject.USER_DATATYPE:
53             return "DOMAIN";
54         default:
55             // not supported by parser, but required when trying to find a comment
56
return "type" + type;
57         }
58     }
59
60     public String JavaDoc getCreateSQL() {
61         StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
62         buff.append("COMMENT ON ");
63         buff.append(getTypeName(objectType));
64         buff.append(' ');
65         buff.append(objectName);
66         buff.append(" IS ");
67         if(commentText == null) {
68             buff.append("NULL");
69         } else {
70             buff.append(StringUtils.quoteStringSQL(commentText));
71         }
72         return buff.toString();
73     }
74
75     public int getType() {
76         return DbObject.COMMENT;
77     }
78
79     public void removeChildrenAndResources(Session session) throws SQLException JavaDoc {
80     }
81
82     public void checkRename() throws SQLException JavaDoc {
83         throw Message.getInternalError();
84     }
85
86     public static String JavaDoc getKey(DbObject obj) {
87         return getTypeName(obj.getType()) + " " + obj.getSQL();
88     }
89
90     public void setCommentText(String JavaDoc comment) {
91         this.commentText = comment;
92     }
93
94 }
95
Popular Tags