Quadcap Embeddable Database

com/quadcap/sql/file/Log2.java

Go to the documentation of this file.
00001 package com.quadcap.sql.file; 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.File; 00042 import java.io.IOException; 00043 00044 import java.util.Properties; 00045 00046 import com.quadcap.sql.lock.Transaction; 00047 00048 import com.quadcap.util.Debug; 00049 00050 00051 /** 00052 * Interface to logging subsystem. 00053 * 00054 * @author Stan Bailes 00055 */ 00056 public class Log2 extends Log1 { 00057 00058 /** 00059 * Initialize the logging subsystem 00060 */ 00061 public void init(Datafile db, boolean create, Properties props) 00062 throws IOException 00063 { 00064 super.init(db, create, props); 00065 } 00066 00067 /** 00068 * Start the logging subsystem 00069 */ 00070 public void start() {} 00071 00072 /** 00073 * Add a transaction's log record to the end of the open log file 00074 */ 00075 public void addEntry(LogEntry entry) throws IOException { 00076 synchronized (fileLock) { 00077 super.reallyAddEntry(entry); 00078 } 00079 } 00080 00081 /** 00082 * XXX why public? 00083 */ 00084 public void reallyAddEntry(LogEntry entry) throws IOException { 00085 synchronized (fileLock) { 00086 super.reallyAddEntry(entry); 00087 } 00088 } 00089 00090 /** 00091 * Flush and close the log file. 00092 */ 00093 public void close() throws IOException { 00094 synchronized (fileLock) { 00095 logger.close(); 00096 reallyClose(); 00097 } 00098 } 00099 00100 00101 /** 00102 * Flush all log records to disk. 00103 */ 00104 public void flushLog() throws IOException { 00105 synchronized (fileLock) { 00106 reallyFlush(); 00107 maybeCheckpoint(); 00108 } 00109 } 00110 00111 /** 00112 * Perform a checkpoint operation. 00113 */ 00114 public void checkpoint() throws IOException { 00115 synchronized (fileLock) { 00116 reallyCheckpoint(); 00117 } 00118 } 00119 00120 /** 00121 * Wait for all queued ops to be processed by the log sync thread 00122 */ 00123 public void sync() throws IOException { 00124 synchronized (fileLock) { 00125 // we're synchronous, remember? 00126 } 00127 } 00128 00129 /** 00130 * Transaction rollback. 00131 */ 00132 public void rollbackTransaction(Transaction trans) throws IOException { 00133 try { 00134 synchronized (fileLock) { 00135 reallyRollbackTransaction(trans); 00136 } 00137 } catch (Exception e) { 00138 throw new DatafileException(e); 00139 } 00140 } 00141 00142 /** 00143 * Statement rollback. 00144 */ 00145 public void rollbackStatement(Transaction trans, int stmtId) 00146 throws IOException 00147 { 00148 try { 00149 synchronized (fileLock) { 00150 reallyRollbackStatement(trans, stmtId); 00151 } 00152 } catch (Exception e) { 00153 throw new DatafileException(e); 00154 } 00155 } 00156 00157 /** 00158 * Restart from a previous state 00159 */ 00160 public void restart() throws Exception { 00161 synchronized (fileLock) { 00162 reallyRestart(); 00163 } 00164 } 00165 } 00166