KickJava   Java API By Example, From Geeks To Geeks.

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


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.command.Parser;
10 import org.h2.message.Message;
11 import org.h2.message.Trace;
12 import org.h2.table.Table;
13 import org.h2.util.ObjectArray;
14
15 /**
16  * @author Thomas
17  */

18
19 public abstract class DbObject {
20     public static final int TABLE_OR_VIEW=0, INDEX=1, USER=2, SEQUENCE=3, TRIGGER=4;
21     public static final int CONSTRAINT = 5, SETTING = 6, ROLE = 7, RIGHT = 8, FUNCTION_ALIAS = 9;
22     public static final int SCHEMA = 10, CONSTANT = 11;
23     public static final int USER_DATATYPE = 12, COMMENT = 13;
24
25     protected String JavaDoc comment;
26
27     static int getCreateOrder(int type) {
28         switch(type) {
29         case SETTING:
30             return 0;
31         case USER:
32             return 1;
33         case SCHEMA:
34             return 2;
35         case USER_DATATYPE:
36             return 3;
37         case SEQUENCE:
38             return 4;
39         case CONSTANT:
40             return 5;
41         case FUNCTION_ALIAS:
42             return 6;
43         case TABLE_OR_VIEW:
44             return 7;
45         case INDEX:
46             return 8;
47         case CONSTRAINT:
48             return 9;
49         case TRIGGER:
50             return 10;
51         case ROLE:
52             return 11;
53         case RIGHT:
54             return 12;
55         case COMMENT:
56             return 13;
57         default:
58             throw Message.getInternalError("type="+type);
59         }
60     }
61
62     private int id;
63     protected Database database;
64     protected Trace trace;
65     private String JavaDoc objectName;
66     private long modificationId;
67     private boolean temporary;
68
69     protected DbObject(Database database, int id, String JavaDoc name, String JavaDoc traceModule) {
70         this.database = database;
71         this.trace = database.getTrace(traceModule);
72         this.id = id;
73         this.objectName = name;
74         this.modificationId = database.getModificationMetaId();
75     }
76
77     public void setModified() {
78         this.modificationId = database == null ? -1 : database.getNextModificationMetaId();
79     }
80
81     public long getModificationId() {
82         return modificationId;
83     }
84
85     protected void setObjectName(String JavaDoc name) {
86         objectName = name;
87     }
88
89     public String JavaDoc getSQL() {
90         return Parser.quoteIdentifier(objectName);
91     }
92
93     public ObjectArray getChildren() {
94         return null;
95     }
96
97     public Database getDatabase() {
98         return database;
99     }
100
101     public int getId() {
102         return id;
103     }
104
105     public String JavaDoc getName() {
106         return objectName;
107     }
108
109     public abstract String JavaDoc getCreateSQLForCopy(Table table, String JavaDoc quotedName);
110     public abstract String JavaDoc getCreateSQL();
111     public abstract int getType();
112     public abstract void removeChildrenAndResources(Session session) throws SQLException JavaDoc;
113     public abstract void checkRename() throws SQLException JavaDoc;
114
115     protected void invalidate() {
116         setModified();
117         id = -1;
118         database = null;
119         trace = null;
120         objectName = null;
121     }
122
123     protected int getHeadPos() {
124         return 0;
125     }
126
127     public void rename(String JavaDoc newName) throws SQLException JavaDoc {
128         checkRename();
129         objectName = newName;
130         setModified();
131     }
132
133     public boolean getTemporary() {
134         return temporary;
135     }
136
137     public void setTemporary(boolean temporary) {
138         this.temporary = temporary;
139     }
140
141     public void setComment(String JavaDoc comment) {
142         this.comment = comment;
143     }
144
145     public String JavaDoc getComment() {
146         return comment;
147     }
148
149 }
150
Popular Tags