001: package com.quadcap.sql;
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.BufferedOutputStream;
042: import java.io.Externalizable;
043: import java.io.IOException;
044: import java.io.ObjectInput;
045: import java.io.ObjectOutput;
046: import java.io.OutputStream;
047:
048: import java.util.Enumeration;
049: import java.util.Vector;
050:
051: import java.sql.SQLException;
052:
053: import com.quadcap.sql.io.ObjectInputStream;
054: import com.quadcap.sql.io.ObjectOutputStream;
055: import com.quadcap.sql.io.Extern;
056:
057: import com.quadcap.sql.file.BlockAccess;
058: import com.quadcap.sql.file.BlockFile;
059: import com.quadcap.sql.file.PageManager;
060: import com.quadcap.sql.file.SubPageManager;
061:
062: import com.quadcap.sql.types.Value;
063:
064: import com.quadcap.util.Debug;
065:
066: /**
067: * Log step to remove a table from a database.
068: *
069: * @author Stan Bailes
070: */
071: public class DropTable extends LogStep implements Externalizable {
072: Relation table;
073: Vector bases;
074:
075: public DropTable() {
076: }
077:
078: public DropTable(Session session, Relation table) {
079: super (session);
080: this .table = table;
081: }
082:
083: public void undo(Session session) throws IOException, SQLException {
084: Database db = session.getDatabase();
085: db.addRelation(table);
086: if (bases != null) {
087: for (int i = 0; i < bases.size(); i++) {
088: db.addViewDependency(bases.elementAt(i).toString(),
089: table.getName());
090: }
091: }
092: }
093:
094: public void redo(Session session) throws IOException, SQLException {
095: Database db = session.getDatabase();
096: db.removeRelation(table.getName());
097: }
098:
099: public void prepare(Session session) throws IOException,
100: SQLException {
101: Database db = session.getDatabase();
102: Enumeration b = db.getBases(table.getName());
103: this .bases = new Vector();
104: while (b.hasMoreElements()) {
105: bases.addElement(b.nextElement());
106: }
107: }
108:
109: public void readExternal(ObjectInput in) throws IOException,
110: ClassNotFoundException {
111: super .readExternal(in);
112: table = (Relation) in.readObject();
113: this .bases = (Vector) in.readObject();
114: }
115:
116: public void writeExternal(ObjectOutput out) throws IOException {
117: super .writeExternal(out);
118: out.writeObject(table);
119: out.writeObject(bases);
120: }
121:
122: //#ifdef DEBUG
123: public String toString() {
124: StringBuffer sb = new StringBuffer(super .toString());
125: sb.append(" DropTable(");
126: sb.append(table.toString());
127: sb.append(')');
128: return sb.toString();
129: }
130:
131: //#endif
132:
133: static Extern extern;
134:
135: public void setExtern(Extern extern) {
136: DropTable.extern = extern;
137: }
138:
139: public Extern getExtern() {
140: return extern;
141: }
142: }
|