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.Result;
039: import org.hsqldb.Session;
040: import org.hsqldb.Table;
041: import org.hsqldb.rowio.RowOutputBinary;
042:
043: /**
044: * @author fredt@users
045: * @since 1.8.0
046: * @version 1.7.2
047: */
048: class ScriptWriterBinary extends ScriptWriterBase {
049:
050: RowOutputBinary rowOut;
051:
052: ScriptWriterBinary(Database db, String file, boolean includeCached,
053: boolean newFile) throws HsqlException {
054: super (db, file, includeCached, newFile, false);
055: }
056:
057: protected void initBuffers() {
058: rowOut = new RowOutputBinary();
059: }
060:
061: protected void writeSingleColumnResult(Result r)
062: throws IOException, HsqlException {
063: Result.write(r, rowOut, fileStreamOut);
064: }
065:
066: // int : row size (0 if no more rows) ,
067: // RowInput/OutputBinary : row (column values)
068: protected void writeRow(Session session, Table t, Object[] data)
069: throws IOException, HsqlException {
070:
071: rowOut.reset();
072: rowOut.writeRow(data, t);
073: fileStreamOut.write(rowOut.getBuffer(), 0, rowOut.size());
074:
075: tableRowCount++;
076: }
077:
078: // int : headersize (0 if no more tables), String : tablename, int : operation,
079: protected void writeTableInit(Table t) throws HsqlException,
080: IOException {
081:
082: tableRowCount = 0;
083:
084: rowOut.reset();
085: rowOut.writeSize(0);
086: rowOut.writeString(t.getName().name);
087: rowOut.writeIntData(INSERT_WITH_SCHEMA);
088: rowOut.writeString(t.getSchemaName());
089: rowOut.writeIntData(rowOut.size(), 0);
090: fileStreamOut.write(rowOut.getBuffer(), 0, rowOut.size());
091: }
092:
093: protected void writeTableTerm(Table t) throws IOException {
094:
095: rowOut.reset();
096: rowOut.writeSize(0);
097: rowOut.writeIntData(this .tableRowCount);
098: fileStreamOut.write(rowOut.getBuffer(), 0, rowOut.size());
099: }
100:
101: protected void writeDataTerm() throws IOException {
102:
103: rowOut.reset();
104: rowOut.writeSize(0);
105: fileStreamOut.write(rowOut.getBuffer(), 0, rowOut.size());
106: }
107:
108: public void writeLogStatement(Session session, String s)
109: throws IOException, HsqlException {
110: }
111:
112: protected void addSessionId(Session session) throws IOException {
113: }
114:
115: public void writeDeleteStatement(Session session, Table table,
116: Object[] ddata) throws HsqlException, IOException {
117: }
118:
119: public void writeSequenceStatement(Session session,
120: NumberSequence seq) throws HsqlException, IOException {
121: }
122:
123: public void writeInsertStatement(Session session, Table table,
124: Object[] data) throws HsqlException, IOException {
125: }
126:
127: public void writeCommitStatement(Session session)
128: throws HsqlException, IOException {
129: }
130: }
|