KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quadcap > sql > DatabaseRoot


1 package com.quadcap.sql;
2
3 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
4  *
5  * This software is distributed under the Quadcap Free Software License.
6  * This software may be used or modified for any purpose, personal or
7  * commercial. Open Source redistributions are permitted. Commercial
8  * redistribution of larger works derived from, or works which bundle
9  * this software requires a "Commercial Redistribution License"; see
10  * http://www.quadcap.com/purchase.
11  *
12  * Redistributions qualify as "Open Source" under one of the following terms:
13  *
14  * Redistributions are made at no charge beyond the reasonable cost of
15  * materials and delivery.
16  *
17  * Redistributions are accompanied by a copy of the Source Code or by an
18  * irrevocable offer to provide a copy of the Source Code for up to three
19  * years at the cost of materials and delivery. Such redistributions
20  * must allow further use, modification, and redistribution of the Source
21  * Code under substantially the same terms as this license.
22  *
23  * Redistributions of source code must retain the copyright notices as they
24  * appear in each source code file, these license terms, and the
25  * disclaimer/limitation of liability set forth as paragraph 6 below.
26  *
27  * Redistributions in binary form must reproduce this Copyright Notice,
28  * these license terms, and the disclaimer/limitation of liability set
29  * forth as paragraph 6 below, in the documentation and/or other materials
30  * provided with the distribution.
31  *
32  * The Software is provided on an "AS IS" basis. No warranty is
33  * provided that the Software is free of defects, or fit for a
34  * particular purpose.
35  *
36  * Limitation of Liability. Quadcap Software shall not be liable
37  * for any damages suffered by the Licensee or any third party resulting
38  * from use of the Software.
39  */

40
41 import java.io.Externalizable JavaDoc;
42 import java.io.File JavaDoc;
43 import java.io.IOException JavaDoc;
44 import java.io.ObjectInput JavaDoc;
45 import java.io.ObjectOutput JavaDoc;
46
47 import java.util.Properties JavaDoc;
48
49 import com.quadcap.sql.file.DatafileRoot;
50
51 /**
52  * The persistent root block of the database.
53  *
54  * @author Stan Bailes
55  */

56 public class DatabaseRoot implements Externalizable JavaDoc, DatafileRoot {
57     int buildNumber = -1;
58     long tableIndexNode = -1;
59     long indexIndexNode = -1;
60     long forwardDepsNode = -1;
61     long reverseDepsNode = -1;
62     long blobRefCountRoot = -1;
63     long nextTransId = 1;
64     String JavaDoc dbFileName = null;
65     String JavaDoc unused1 = null;
66     String JavaDoc unused2 = null;
67     String JavaDoc backupDir = null;
68
69     /** Backups roll; Number of backups to keep. */
70     int backupCount = 1;
71
72     /** bitmap SUN=1 - SAT=7 */
73     int backupDays = 0;
74
75     /** minutes after midnight */
76     int backupTime = 0;
77
78     /** Julian day of previous backup. */
79     int backupLastDay = -1;
80
81     String JavaDoc backupFormat = "xml.gz";
82
83     Database db;
84
85     /**
86      * Default constructor
87      */

88     public DatabaseRoot() {}
89
90     /**
91      * Explicit constuctor for database creation
92      */

93     public DatabaseRoot(Database db, String JavaDoc dbFileName, Properties JavaDoc props)
94     throws IOException JavaDoc
95     {
96     this.dbFileName = dbFileName;
97     this.unused2 = "";
98     this.unused1 = "";
99     this.buildNumber = Version.buildNumber;
100     tableIndexNode = db.getFile().newPage();
101     indexIndexNode = db.getFile().newPage();
102     forwardDepsNode = db.getFile().newPage();
103     reverseDepsNode = db.getFile().newPage();
104     blobRefCountRoot = db.getFile().newPage();
105     backupDir = props.getProperty("backup-directory");
106     }
107
108     /**
109      * Set the database which owns this root
110      */

111     public void setDatabase(Database db) {
112     this.db = db;
113     }
114
115     /**
116      * Return the build number
117      */

118     public int getBuildNumber() { return buildNumber; }
119
120     /**
121      * Return the root block of the relation index
122      */

123     public long getRelationIndexNode() { return tableIndexNode; }
124
125     /**
126      * Return the root block of the index index
127      */

128     public long getIndexIndexNode() { return indexIndexNode; }
129
130     /**
131      * Return the root block of the forward dependencies graph
132      */

133     public long getForwardDepsNode() { return forwardDepsNode; }
134
135     /**
136      * Return the root block of the reverse dependencies graph
137      */

138     public long getReverseDepsNode() { return reverseDepsNode; }
139
140     /**
141      * Return the root block of the blob ref count index
142      */

143     public long getBlobRefCountRoot() { return blobRefCountRoot; }
144
145     /**
146      * Return the next transaction id
147      */

148     public long getNextTransId() { return nextTransId++; }
149
150     /**
151      * Return the backup directory name
152      */

153     public String JavaDoc getBackupDir() { return backupDir; }
154
155     /**
156      * Return the backup count
157      */

158     public int getBackupCount() { return backupCount; }
159
160     /**
161      * Return the backup days
162      */

163     public int getBackupDays() { return backupDays; }
164
165     /**
166      * Return the backup last day
167      */

168     public int getBackupLastDay() { return backupLastDay; }
169
170     /**
171      * Return the backup time
172      */

173     public int getBackupTime() { return backupTime; }
174
175     /**
176      * Return the backup format
177      */

178     public String JavaDoc getBackupFormat() { return backupFormat; }
179
180     /**
181      * Set the backup directory
182      */

183     public void setBackupDir(String JavaDoc dir) { backupDir = dir; }
184
185     /**
186      * Set the backup count
187      */

188     public void setBackupCount(int count) { backupCount = count; }
189
190     /**
191      * Set the backup days
192      */

193     public void setBackupDays(int days) { backupDays = days; }
194
195     /**
196      * Set the backup last day
197      */

198     public void setBackupLastDay(int day) { backupLastDay = day; }
199
200     /**
201      * Set the backup time
202      */

203     public void setBackupTime(int time) { backupTime = time; }
204
205     /**
206      * Set the backup format
207      */

208     public void setBackupFormat(String JavaDoc fmt) { backupFormat = fmt; }
209
210     /**
211      * Set the backup directory
212      */

213     public void setNextTransId(long id) { nextTransId = id; }
214
215     /**
216      * Read me from a stream
217      */

218     public void readExternal(ObjectInput JavaDoc in)
219     throws IOException JavaDoc, ClassNotFoundException JavaDoc
220     {
221     buildNumber = in.readInt();
222     tableIndexNode = in.readLong();
223     indexIndexNode = in.readLong();
224     forwardDepsNode = in.readLong();
225     reverseDepsNode = in.readLong();
226     blobRefCountRoot = in.readLong();
227     nextTransId = in.readLong();
228     dbFileName = (String JavaDoc)in.readObject();
229     unused2 = (String JavaDoc)in.readObject();
230     unused1 = (String JavaDoc)in.readObject();
231     backupDir = (String JavaDoc)in.readObject();
232     backupCount = in.readInt();
233     backupDays = in.readInt();
234     backupLastDay = in.readInt();
235     backupTime = in.readInt();
236     backupFormat = (String JavaDoc)in.readObject();
237     }
238
239     /**
240      * Write me to a stream
241      */

242     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
243     out.writeInt(buildNumber);
244     out.writeLong(tableIndexNode);
245     out.writeLong(indexIndexNode);
246     out.writeLong(forwardDepsNode);
247     out.writeLong(reverseDepsNode);
248     out.writeLong(blobRefCountRoot);
249     out.writeLong(nextTransId);
250     out.writeObject(dbFileName);
251     out.writeObject(unused2);
252     out.writeObject(unused1);
253     out.writeObject(backupDir);
254     out.writeInt(backupCount);
255     out.writeInt(backupDays);
256     out.writeInt(backupLastDay);
257     out.writeInt(backupTime);
258     out.writeObject(backupFormat);
259     }
260 }
261
Popular Tags