1 5 package org.h2.engine; 6 7 import java.sql.SQLException ; 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 objectName; 18 private String 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 getCreateSQLForCopy(Table table, String quotedName) { 27 throw Message.getInternalError(); 28 } 29 30 private static String 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 return "type" + type; 57 } 58 } 59 60 public String getCreateSQL() { 61 StringBuffer buff = new StringBuffer (); 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 { 80 } 81 82 public void checkRename() throws SQLException { 83 throw Message.getInternalError(); 84 } 85 86 public static String getKey(DbObject obj) { 87 return getTypeName(obj.getType()) + " " + obj.getSQL(); 88 } 89 90 public void setCommentText(String comment) { 91 this.commentText = comment; 92 } 93 94 } 95 | Popular Tags |