001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb.scriptio;
032:
033: import java.io.IOException;
034:
035: import org.hsqldb.Database;
036: import org.hsqldb.HsqlException;
037: import org.hsqldb.NumberSequence;
038: import org.hsqldb.Session;
039: import org.hsqldb.Table;
040:
041: /**
042: * Base class for all script readers.
043: *
044: * @author fredt@users
045: * @version 1.7.2
046: * @since 1.7.2
047: */
048: public abstract class ScriptReaderBase {
049:
050: public static ScriptReaderBase newScriptReader(Database db,
051: String file, int scriptType) throws HsqlException,
052: IOException {
053:
054: if (scriptType == ScriptWriterBase.SCRIPT_TEXT_170) {
055: return new ScriptReaderText(db, file);
056: } else if (scriptType == ScriptWriterBase.SCRIPT_BINARY_172) {
057: return new ScriptReaderBinary(db, file);
058: } else {
059: return new ScriptReaderZipped(db, file);
060: }
061: }
062:
063: public static final int ANY_STATEMENT = 1;
064: public static final int DELETE_STATEMENT = 2;
065: public static final int INSERT_STATEMENT = 3;
066: public static final int SEQUENCE_STATEMENT = 4;
067: public static final int COMMIT_STATEMENT = 5;
068: public static final int SESSION_ID = 6;
069: public static final int SCHEMA_STATEMENT = 7;
070: Database db;
071: int lineCount;
072:
073: // int byteCount;
074: String fileName;
075:
076: ScriptReaderBase(Database db, String file) throws HsqlException,
077: IOException {
078:
079: this .db = db;
080: fileName = file;
081:
082: openFile();
083: }
084:
085: protected abstract void openFile() throws IOException;
086:
087: public void readAll(Session session) throws IOException,
088: HsqlException {
089: readDDL(session);
090: readExistingData(session);
091: }
092:
093: protected abstract void readDDL(Session session)
094: throws IOException, HsqlException;
095:
096: protected abstract void readExistingData(Session session)
097: throws IOException, HsqlException;
098:
099: public abstract boolean readLoggedStatement(Session session)
100: throws IOException;
101:
102: int statementType;
103: int sessionNumber;
104: Object[] rowData;
105: long sequenceValue;
106: String statement;
107: Table currentTable;
108: NumberSequence currentSequence;
109: String currentSchema;
110:
111: public int getStatementType() {
112: return statementType;
113: }
114:
115: public int getSessionNumber() {
116: return sessionNumber;
117: }
118:
119: public Object[] getData() {
120: return rowData;
121: }
122:
123: public String getLoggedStatement() {
124: return statement;
125: }
126:
127: public NumberSequence getCurrentSequence() {
128: return currentSequence;
129: }
130:
131: public long getSequenceValue() {
132: return sequenceValue;
133: }
134:
135: public Table getCurrentTable() {
136: return currentTable;
137: }
138:
139: public String getCurrentSchema() {
140: return currentSchema;
141: }
142:
143: public int getLineNumber() {
144: return lineCount;
145: }
146:
147: public abstract void close();
148: }
|