File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\engine\DbObjectBase.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 java.util.ArrayList;
10 import org.h2.command.Parser;
11 import org.h2.message.Trace;
12
13 /**
14 * The base class for all database objects.
15 */
16 public abstract class DbObjectBase implements DbObject {
17
18 /**
19 * The database.
20 */
21 protected Database database;
22
23 /**
24 * The trace module.
25 */
26 protected Trace trace;
27
28 /**
29 * The comment (if set).
30 */
31 protected String comment;
32
33 private int id;
34 private String objectName;
35 private long modificationId;
36 private boolean temporary;
37
38 /**
39 * Initialize some attributes of this object.
40 *
41 * @param db the database
42 * @param objectId the object id
43 * @param name the name
44 * @param traceModule the trace module name
45 */
46 protected void initDbObjectBase(Database db, int objectId, String name, String traceModule) {
47 this.database = db;
48 this.trace = db.getTrace(traceModule);
49 this.id = objectId;
50 this.objectName = name;
51 this.modificationId = db.getModificationMetaId();
52 }
53
54 /**
55 * Build a SQL statement to re-create this object.
56 *
57 * @return the SQL statement
58 */
59 public abstract String getCreateSQL();
60
61 /**
62 * Build a SQL statement to drop this object.
63 *
64 * @return the SQL statement
65 */
66 public abstract String getDropSQL();
67
68 /**
69 * Remove all dependent objects and free all resources (files, blocks in
70 * files) of this object.
71 *
72 * @param session the session
73 */
74 public abstract void removeChildrenAndResources(Session session);
75
76 /**
77 * Check if this object can be renamed. System objects may not be renamed.
78 */
79 public abstract void checkRename();
80
81 /**
82 * Tell the object that is was modified.
83 */
84 public void setModified() {
85 this.modificationId = database == null ? -1 : database.getNextModificationMetaId();
86 }
87
88 public long getModificationId() {
89 return modificationId;
90 }
91
92 protected void setObjectName(String name) {
93 objectName = name;
94 }
95
96 public String getSQL() {
97 return Parser.quoteIdentifier(objectName);
98 }
99
100 public ArrayList<DbObject> getChildren() {
101 return null;
102 }
103
104 public Database getDatabase() {
105 return database;
106 }
107
108 public int getId() {
109 return id;
110 }
111
112 public String getName() {
113 return objectName;
114 }
115
116 /**
117 * Set the main attributes to null to make sure the object is no longer
118 * used.
119 */
120 protected void invalidate() {
121 setModified();
122 id = -1;
123 database = null;
124 trace = null;
125 objectName = null;
126 }
127
128 public void rename(String newName) {
129 checkRename();
130 objectName = newName;
131 setModified();
132 }
133
134 public boolean isTemporary() {
135 return temporary;
136 }
137
138 public void setTemporary(boolean temporary) {
139 this.temporary = temporary;
140 }
141
142 public void setComment(String comment) {
143 this.comment = comment;
144 }
145
146 public String getComment() {
147 return comment;
148 }
149
150 public String toString() {
151 return objectName + ":" + id + ":" + super.toString();
152 }
153
154 }
155