KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quadcap > sql > LogStep


1 package com.quadcap.sql;
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.Externalizable JavaDoc;
42 import java.io.IOException JavaDoc;
43 import java.io.ObjectInput JavaDoc;
44 import java.io.ObjectOutput JavaDoc;
45
46 import java.util.Vector JavaDoc;
47
48 import java.sql.SQLException JavaDoc;
49
50 import com.quadcap.sql.file.Datafile;
51 import com.quadcap.sql.file.DatafileException;
52 import com.quadcap.sql.file.LogEntry;
53
54 import com.quadcap.sql.lock.Transaction;
55
56 import com.quadcap.util.Debug;
57
58 /**
59  * Basic unit of write-ahead logging strategy.
60  *
61  * @author Stan Bailes
62  */

63 public abstract class LogStep extends LogEntry {
64     Session mySession;
65     
66     public LogStep() {
67         super(-1, -1, STEP);
68     }
69     
70     public LogStep(Session session) {
71         super(session.getTransactionId(), session.getStmtId(), STEP);
72         mySession = session;
73     }
74
75     /**
76      * Undo the effects of this step from the database.
77      */

78     public void undo(Transaction t, Datafile df)
79         throws IOException JavaDoc, DatafileException
80     {
81         try {
82             Session s = mySession;
83             if (s == null) {
84                 Database db = (Database)df;
85                 s = db.getSession(t);
86             }
87             undo(s);
88             //#ifdef DEBUG
89
if (Trace.bit(15)) {
90                 Debug.println("LogStep.UNDO(" + this + ")");
91             }
92             //#endif
93
} catch (SQLException JavaDoc ex) {
94             throw new DatafileException(ex);
95         }
96     }
97     
98     /**
99      * Undo the effects of this step from the database.
100      */

101     public void redo(Transaction t, Datafile df)
102         throws IOException JavaDoc, DatafileException
103     {
104         try {
105             Session s = mySession;
106             if (s == null) {
107                 Database db = (Database)df;
108                 s = db.getSession(t);
109             }
110             redo(s);
111             //#ifdef DEBUG
112
if (Trace.bit(16)) {
113                 Debug.println("LogStep.redo(" + this + ")");
114             }
115             //#endif
116
} catch (SQLException JavaDoc ex) {
117             throw new DatafileException(ex);
118         }
119     }
120     
121     /**
122      * Do/redo this step.
123      */

124     abstract public void undo(Session session)
125     throws IOException JavaDoc, SQLException JavaDoc
126     ;
127
128     /**
129      * Do/redo this step.
130      */

131     abstract public void redo(Session session)
132     throws IOException JavaDoc, SQLException JavaDoc
133     ;
134
135     /**
136      * Perform any actions that are necessary to prepare this log record
137      * for being written to the log. This is called before the log
138      * record is written, and before the first invocation of 'redo'. It
139      * is not called subsequently, or during recovery.
140      */

141     public void prepare(Session session) throws IOException JavaDoc, SQLException JavaDoc {
142         mySession = session;
143     }
144 }
145
Popular Tags