001: package com.quadcap.sql;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.io.Externalizable;
042: import java.io.File;
043: import java.io.IOException;
044: import java.io.ObjectInput;
045: import java.io.ObjectOutput;
046:
047: import java.util.Properties;
048:
049: import com.quadcap.sql.file.DatafileRoot;
050:
051: /**
052: * The persistent root block of the database.
053: *
054: * @author Stan Bailes
055: */
056: public class DatabaseRoot implements Externalizable, DatafileRoot {
057: int buildNumber = -1;
058: long tableIndexNode = -1;
059: long indexIndexNode = -1;
060: long forwardDepsNode = -1;
061: long reverseDepsNode = -1;
062: long blobRefCountRoot = -1;
063: long nextTransId = 1;
064: String dbFileName = null;
065: String unused1 = null;
066: String unused2 = null;
067: String backupDir = null;
068:
069: /** Backups roll; Number of backups to keep. */
070: int backupCount = 1;
071:
072: /** bitmap SUN=1 - SAT=7 */
073: int backupDays = 0;
074:
075: /** minutes after midnight */
076: int backupTime = 0;
077:
078: /** Julian day of previous backup. */
079: int backupLastDay = -1;
080:
081: String backupFormat = "xml.gz";
082:
083: Database db;
084:
085: /**
086: * Default constructor
087: */
088: public DatabaseRoot() {
089: }
090:
091: /**
092: * Explicit constuctor for database creation
093: */
094: public DatabaseRoot(Database db, String dbFileName, Properties props)
095: throws IOException {
096: this .dbFileName = dbFileName;
097: this .unused2 = "";
098: this .unused1 = "";
099: 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() {
119: return buildNumber;
120: }
121:
122: /**
123: * Return the root block of the relation index
124: */
125: public long getRelationIndexNode() {
126: return tableIndexNode;
127: }
128:
129: /**
130: * Return the root block of the index index
131: */
132: public long getIndexIndexNode() {
133: return indexIndexNode;
134: }
135:
136: /**
137: * Return the root block of the forward dependencies graph
138: */
139: public long getForwardDepsNode() {
140: return forwardDepsNode;
141: }
142:
143: /**
144: * Return the root block of the reverse dependencies graph
145: */
146: public long getReverseDepsNode() {
147: return reverseDepsNode;
148: }
149:
150: /**
151: * Return the root block of the blob ref count index
152: */
153: public long getBlobRefCountRoot() {
154: return blobRefCountRoot;
155: }
156:
157: /**
158: * Return the next transaction id
159: */
160: public long getNextTransId() {
161: return nextTransId++;
162: }
163:
164: /**
165: * Return the backup directory name
166: */
167: public String getBackupDir() {
168: return backupDir;
169: }
170:
171: /**
172: * Return the backup count
173: */
174: public int getBackupCount() {
175: return backupCount;
176: }
177:
178: /**
179: * Return the backup days
180: */
181: public int getBackupDays() {
182: return backupDays;
183: }
184:
185: /**
186: * Return the backup last day
187: */
188: public int getBackupLastDay() {
189: return backupLastDay;
190: }
191:
192: /**
193: * Return the backup time
194: */
195: public int getBackupTime() {
196: return backupTime;
197: }
198:
199: /**
200: * Return the backup format
201: */
202: public String getBackupFormat() {
203: return backupFormat;
204: }
205:
206: /**
207: * Set the backup directory
208: */
209: public void setBackupDir(String dir) {
210: backupDir = dir;
211: }
212:
213: /**
214: * Set the backup count
215: */
216: public void setBackupCount(int count) {
217: backupCount = count;
218: }
219:
220: /**
221: * Set the backup days
222: */
223: public void setBackupDays(int days) {
224: backupDays = days;
225: }
226:
227: /**
228: * Set the backup last day
229: */
230: public void setBackupLastDay(int day) {
231: backupLastDay = day;
232: }
233:
234: /**
235: * Set the backup time
236: */
237: public void setBackupTime(int time) {
238: backupTime = time;
239: }
240:
241: /**
242: * Set the backup format
243: */
244: public void setBackupFormat(String fmt) {
245: backupFormat = fmt;
246: }
247:
248: /**
249: * Set the backup directory
250: */
251: public void setNextTransId(long id) {
252: nextTransId = id;
253: }
254:
255: /**
256: * Read me from a stream
257: */
258: public void readExternal(ObjectInput in) throws IOException,
259: ClassNotFoundException {
260: buildNumber = in.readInt();
261: tableIndexNode = in.readLong();
262: indexIndexNode = in.readLong();
263: forwardDepsNode = in.readLong();
264: reverseDepsNode = in.readLong();
265: blobRefCountRoot = in.readLong();
266: nextTransId = in.readLong();
267: dbFileName = (String) in.readObject();
268: unused2 = (String) in.readObject();
269: unused1 = (String) in.readObject();
270: backupDir = (String) in.readObject();
271: backupCount = in.readInt();
272: backupDays = in.readInt();
273: backupLastDay = in.readInt();
274: backupTime = in.readInt();
275: backupFormat = (String) in.readObject();
276: }
277:
278: /**
279: * Write me to a stream
280: */
281: public void writeExternal(ObjectOutput out) throws IOException {
282: out.writeInt(buildNumber);
283: out.writeLong(tableIndexNode);
284: out.writeLong(indexIndexNode);
285: out.writeLong(forwardDepsNode);
286: out.writeLong(reverseDepsNode);
287: out.writeLong(blobRefCountRoot);
288: out.writeLong(nextTransId);
289: out.writeObject(dbFileName);
290: out.writeObject(unused2);
291: out.writeObject(unused1);
292: out.writeObject(backupDir);
293: out.writeInt(backupCount);
294: out.writeInt(backupDays);
295: out.writeInt(backupLastDay);
296: out.writeInt(backupTime);
297: out.writeObject(backupFormat);
298: }
299: }
|