KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quadcap > sql > file > Log2


1 package com.quadcap.sql.file;
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.File JavaDoc;
42 import java.io.IOException JavaDoc;
43
44 import java.util.Properties JavaDoc;
45
46 import com.quadcap.sql.lock.Transaction;
47
48 import com.quadcap.util.Debug;
49
50
51 /**
52  * Interface to logging subsystem.
53  *
54  * @author Stan Bailes
55  */

56 public class Log2 extends Log1 {
57
58     /**
59      * Initialize the logging subsystem
60      */

61     public void init(Datafile db, boolean create, Properties JavaDoc props)
62     throws IOException JavaDoc
63     {
64         super.init(db, create, props);
65     }
66
67     /**
68      * Start the logging subsystem
69      */

70     public void start() {}
71
72     /**
73      * Add a transaction's log record to the end of the open log file
74      */

75     public void addEntry(LogEntry entry) throws IOException JavaDoc {
76         synchronized (fileLock) {
77             super.reallyAddEntry(entry);
78         }
79     }
80
81     /**
82      * XXX why public?
83      */

84     public void reallyAddEntry(LogEntry entry) throws IOException JavaDoc {
85         synchronized (fileLock) {
86             super.reallyAddEntry(entry);
87         }
88     }
89     
90     /**
91      * Flush and close the log file.
92      */

93     public void close() throws IOException JavaDoc {
94         synchronized (fileLock) {
95             logger.close();
96             reallyClose();
97         }
98     }
99         
100     
101     /**
102      * Flush all log records to disk.
103      */

104     public void flushLog() throws IOException JavaDoc {
105         synchronized (fileLock) {
106             reallyFlush();
107             maybeCheckpoint();
108         }
109     }
110
111     /**
112      * Perform a checkpoint operation.
113      */

114     public void checkpoint() throws IOException JavaDoc {
115         synchronized (fileLock) {
116             reallyCheckpoint();
117         }
118     }
119
120     /**
121      * Wait for all queued ops to be processed by the log sync thread
122      */

123     public void sync() throws IOException JavaDoc {
124         synchronized (fileLock) {
125             // we're synchronous, remember?
126
}
127     }
128
129     /**
130      * Transaction rollback.
131      */

132     public void rollbackTransaction(Transaction trans) throws IOException JavaDoc {
133         try {
134             synchronized (fileLock) {
135                 reallyRollbackTransaction(trans);
136             }
137         } catch (Exception JavaDoc e) {
138             throw new DatafileException(e);
139         }
140     }
141         
142     /**
143      * Statement rollback.
144      */

145     public void rollbackStatement(Transaction trans, int stmtId)
146     throws IOException JavaDoc
147     {
148         try {
149             synchronized (fileLock) {
150                 reallyRollbackStatement(trans, stmtId);
151             }
152         } catch (Exception JavaDoc e) {
153             throw new DatafileException(e);
154         }
155     }
156
157     /**
158      * Restart from a previous state
159      */

160     public void restart() throws Exception JavaDoc {
161         synchronized (fileLock) {
162             reallyRestart();
163         }
164     }
165 }
166
167
Popular Tags