001: package com.quadcap.sql.file;
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.File;
042: import java.io.IOException;
043:
044: import java.util.Properties;
045:
046: import com.quadcap.sql.lock.Transaction;
047:
048: import com.quadcap.util.Debug;
049:
050: /**
051: * Interface to logging subsystem.
052: *
053: * @author Stan Bailes
054: */
055: public class Log2 extends Log1 {
056:
057: /**
058: * Initialize the logging subsystem
059: */
060: public void init(Datafile db, boolean create, Properties props)
061: throws IOException {
062: super .init(db, create, props);
063: }
064:
065: /**
066: * Start the logging subsystem
067: */
068: public void start() {
069: }
070:
071: /**
072: * Add a transaction's log record to the end of the open log file
073: */
074: public void addEntry(LogEntry entry) throws IOException {
075: synchronized (fileLock) {
076: super .reallyAddEntry(entry);
077: }
078: }
079:
080: /**
081: * XXX why public?
082: */
083: public void reallyAddEntry(LogEntry entry) throws IOException {
084: synchronized (fileLock) {
085: super .reallyAddEntry(entry);
086: }
087: }
088:
089: /**
090: * Flush and close the log file.
091: */
092: public void close() throws IOException {
093: synchronized (fileLock) {
094: logger.close();
095: reallyClose();
096: }
097: }
098:
099: /**
100: * Flush all log records to disk.
101: */
102: public void flushLog() throws IOException {
103: synchronized (fileLock) {
104: reallyFlush();
105: maybeCheckpoint();
106: }
107: }
108:
109: /**
110: * Perform a checkpoint operation.
111: */
112: public void checkpoint() throws IOException {
113: synchronized (fileLock) {
114: reallyCheckpoint();
115: }
116: }
117:
118: /**
119: * Wait for all queued ops to be processed by the log sync thread
120: */
121: public void sync() throws IOException {
122: synchronized (fileLock) {
123: // we're synchronous, remember?
124: }
125: }
126:
127: /**
128: * Transaction rollback.
129: */
130: public void rollbackTransaction(Transaction trans)
131: throws IOException {
132: try {
133: synchronized (fileLock) {
134: reallyRollbackTransaction(trans);
135: }
136: } catch (Exception e) {
137: throw new DatafileException(e);
138: }
139: }
140:
141: /**
142: * Statement rollback.
143: */
144: public void rollbackStatement(Transaction trans, int stmtId)
145: throws IOException {
146: try {
147: synchronized (fileLock) {
148: reallyRollbackStatement(trans, stmtId);
149: }
150: } catch (Exception e) {
151: throw new DatafileException(e);
152: }
153: }
154:
155: /**
156: * Restart from a previous state
157: */
158: public void restart() throws Exception {
159: synchronized (fileLock) {
160: reallyRestart();
161: }
162: }
163: }
|