![]() |
Quadcap Embeddable Database |
00001 package com.quadcap.sql; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 00039 */ 00040 00041 import java.io.Externalizable; 00042 import java.io.File; 00043 import java.io.IOException; 00044 import java.io.ObjectInput; 00045 import java.io.ObjectOutput; 00046 00047 import java.util.Properties; 00048 00049 import com.quadcap.sql.file.DatafileRoot; 00050 00051 /** 00052 * The persistent root block of the database. 00053 * 00054 * @author Stan Bailes 00055 */ 00056 public class DatabaseRoot implements Externalizable, DatafileRoot { 00057 int buildNumber = -1; 00058 long tableIndexNode = -1; 00059 long indexIndexNode = -1; 00060 long forwardDepsNode = -1; 00061 long reverseDepsNode = -1; 00062 long blobRefCountRoot = -1; 00063 long nextTransId = 1; 00064 String dbFileName = null; 00065 String unused1 = null; 00066 String unused2 = null; 00067 String backupDir = null; 00068 00069 /** Backups roll; Number of backups to keep. */ 00070 int backupCount = 1; 00071 00072 /** bitmap SUN=1 - SAT=7 */ 00073 int backupDays = 0; 00074 00075 /** minutes after midnight */ 00076 int backupTime = 0; 00077 00078 /** Julian day of previous backup. */ 00079 int backupLastDay = -1; 00080 00081 String backupFormat = "xml.gz"; 00082 00083 Database db; 00084 00085 /** 00086 * Default constructor 00087 */ 00088 public DatabaseRoot() {} 00089 00090 /** 00091 * Explicit constuctor for database creation 00092 */ 00093 public DatabaseRoot(Database db, String dbFileName, Properties props) 00094 throws IOException 00095 { 00096 this.dbFileName = dbFileName; 00097 this.unused2 = ""; 00098 this.unused1 = ""; 00099 this.buildNumber = Version.buildNumber; 00100 tableIndexNode = db.getFile().newPage(); 00101 indexIndexNode = db.getFile().newPage(); 00102 forwardDepsNode = db.getFile().newPage(); 00103 reverseDepsNode = db.getFile().newPage(); 00104 blobRefCountRoot = db.getFile().newPage(); 00105 backupDir = props.getProperty("backup-directory"); 00106 } 00107 00108 /** 00109 * Set the database which owns this root 00110 */ 00111 public void setDatabase(Database db) { 00112 this.db = db; 00113 } 00114 00115 /** 00116 * Return the build number 00117 */ 00118 public int getBuildNumber() { return buildNumber; } 00119 00120 /** 00121 * Return the root block of the relation index 00122 */ 00123 public long getRelationIndexNode() { return tableIndexNode; } 00124 00125 /** 00126 * Return the root block of the index index 00127 */ 00128 public long getIndexIndexNode() { return indexIndexNode; } 00129 00130 /** 00131 * Return the root block of the forward dependencies graph 00132 */ 00133 public long getForwardDepsNode() { return forwardDepsNode; } 00134 00135 /** 00136 * Return the root block of the reverse dependencies graph 00137 */ 00138 public long getReverseDepsNode() { return reverseDepsNode; } 00139 00140 /** 00141 * Return the root block of the blob ref count index 00142 */ 00143 public long getBlobRefCountRoot() { return blobRefCountRoot; } 00144 00145 /** 00146 * Return the next transaction id 00147 */ 00148 public long getNextTransId() { return nextTransId++; } 00149 00150 /** 00151 * Return the backup directory name 00152 */ 00153 public String getBackupDir() { return backupDir; } 00154 00155 /** 00156 * Return the backup count 00157 */ 00158 public int getBackupCount() { return backupCount; } 00159 00160 /** 00161 * Return the backup days 00162 */ 00163 public int getBackupDays() { return backupDays; } 00164 00165 /** 00166 * Return the backup last day 00167 */ 00168 public int getBackupLastDay() { return backupLastDay; } 00169 00170 /** 00171 * Return the backup time 00172 */ 00173 public int getBackupTime() { return backupTime; } 00174 00175 /** 00176 * Return the backup format 00177 */ 00178 public String getBackupFormat() { return backupFormat; } 00179 00180 /** 00181 * Set the backup directory 00182 */ 00183 public void setBackupDir(String dir) { backupDir = dir; } 00184 00185 /** 00186 * Set the backup count 00187 */ 00188 public void setBackupCount(int count) { backupCount = count; } 00189 00190 /** 00191 * Set the backup days 00192 */ 00193 public void setBackupDays(int days) { backupDays = days; } 00194 00195 /** 00196 * Set the backup last day 00197 */ 00198 public void setBackupLastDay(int day) { backupLastDay = day; } 00199 00200 /** 00201 * Set the backup time 00202 */ 00203 public void setBackupTime(int time) { backupTime = time; } 00204 00205 /** 00206 * Set the backup format 00207 */ 00208 public void setBackupFormat(String fmt) { backupFormat = fmt; } 00209 00210 /** 00211 * Set the backup directory 00212 */ 00213 public void setNextTransId(long id) { nextTransId = id; } 00214 00215 /** 00216 * Read me from a stream 00217 */ 00218 public void readExternal(ObjectInput in) 00219 throws IOException, ClassNotFoundException 00220 { 00221 buildNumber = in.readInt(); 00222 tableIndexNode = in.readLong(); 00223 indexIndexNode = in.readLong(); 00224 forwardDepsNode = in.readLong(); 00225 reverseDepsNode = in.readLong(); 00226 blobRefCountRoot = in.readLong(); 00227 nextTransId = in.readLong(); 00228 dbFileName = (String)in.readObject(); 00229 unused2 = (String)in.readObject(); 00230 unused1 = (String)in.readObject(); 00231 backupDir = (String)in.readObject(); 00232 backupCount = in.readInt(); 00233 backupDays = in.readInt(); 00234 backupLastDay = in.readInt(); 00235 backupTime = in.readInt(); 00236 backupFormat = (String)in.readObject(); 00237 } 00238 00239 /** 00240 * Write me to a stream 00241 */ 00242 public void writeExternal(ObjectOutput out) throws IOException { 00243 out.writeInt(buildNumber); 00244 out.writeLong(tableIndexNode); 00245 out.writeLong(indexIndexNode); 00246 out.writeLong(forwardDepsNode); 00247 out.writeLong(reverseDepsNode); 00248 out.writeLong(blobRefCountRoot); 00249 out.writeLong(nextTransId); 00250 out.writeObject(dbFileName); 00251 out.writeObject(unused2); 00252 out.writeObject(unused1); 00253 out.writeObject(backupDir); 00254 out.writeInt(backupCount); 00255 out.writeInt(backupDays); 00256 out.writeInt(backupLastDay); 00257 out.writeInt(backupTime); 00258 out.writeObject(backupFormat); 00259 } 00260 }