1 30 31 32 package org.hsqldb.rowio; 33 34 import java.math.BigDecimal ; 35 import java.sql.Date ; 36 import java.sql.Time ; 37 import java.sql.Timestamp ; 38 39 import org.hsqldb.CachedRow; 40 import org.hsqldb.Column; 41 import org.hsqldb.HsqlDateTime; 42 import org.hsqldb.lib.StringConverter; 43 import org.hsqldb.types.Binary; 44 import org.hsqldb.types.JavaObject; 45 46 51 public class RowOutputTextLog extends RowOutputBase { 52 53 static final byte[] BYTES_NULL = "NULL".getBytes(); 54 static final byte[] BYTES_TRUE = "TRUE".getBytes(); 55 static final byte[] BYTES_FALSE = "FALSE".getBytes(); 56 static final byte[] BYTES_AND = " AND ".getBytes(); 57 static final byte[] BYTES_IS = " IS ".getBytes(); 58 public static final int MODE_DELETE = 1; 59 public static final int MODE_INSERT = 0; 60 private boolean isWritten; 61 private int logMode; 62 63 public void setMode(int mode) { 64 logMode = mode; 65 } 66 67 protected void writeFieldPrefix() { 68 69 if (logMode == MODE_DELETE && isWritten) { 70 write(BYTES_AND); 71 } 72 } 73 74 protected void writeChar(String s, int t) { 75 76 write('\''); 77 StringConverter.unicodeToAscii(this, s, true); 78 write('\''); 79 } 80 81 protected void writeReal(Double o, int type) { 82 writeBytes(Column.createSQLString(((Number ) o).doubleValue())); 83 } 84 85 protected void writeSmallint(Number o) { 86 this.writeBytes(o.toString()); 87 } 88 89 public void writeEnd() {} 90 91 protected void writeTime(Time o) { 92 93 write('\''); 94 writeBytes(o.toString()); 95 write('\''); 96 } 97 98 protected void writeBinary(Binary o, int t) { 99 100 ensureRoom(o.getBytesLength() * 2 + 2); 101 write('\''); 102 StringConverter.writeHex(getBuffer(), count, o.getBytes()); 103 104 count += o.getBytesLength() * 2; 105 106 write('\''); 107 } 108 109 public void writeType(int type) {} 110 111 public void writeSize(int size) {} 112 113 protected void writeDate(Date o) { 114 115 write('\''); 116 this.writeBytes(o.toString()); 117 write('\''); 118 } 119 120 public int getSize(CachedRow row) { 121 return 0; 122 } 123 124 protected void writeInteger(Number o) { 125 this.writeBytes(o.toString()); 126 } 127 128 protected void writeBigint(Number o) { 129 this.writeBytes(o.toString()); 130 } 131 132 protected void writeNull(int type) { 134 135 if (logMode == MODE_DELETE) { 136 write(BYTES_IS); 137 } else if (isWritten) { 138 write(','); 139 } 140 141 isWritten = true; 142 143 write(BYTES_NULL); 144 } 145 146 protected void writeOther(JavaObject o) { 147 148 ensureRoom(o.getBytesLength() * 2 + 2); 149 write('\''); 150 StringConverter.writeHex(getBuffer(), count, o.getBytes()); 151 152 count += o.getBytesLength() * 2; 153 154 write('\''); 155 } 156 157 public void writeString(String value) { 158 StringConverter.unicodeToAscii(this, value, false); 159 } 160 161 protected void writeBit(Boolean o) { 162 write(o.booleanValue() ? BYTES_TRUE 163 : BYTES_FALSE); 164 } 165 166 protected void writeDecimal(BigDecimal o) { 167 this.writeBytes(o.toString()); 168 } 169 170 protected void writeFieldType(int type) { 171 172 if (logMode == MODE_DELETE) { 173 write('='); 174 } else if (isWritten) { 175 write(','); 176 } 177 178 isWritten = true; 179 } 180 181 public void writeLongData(long value) { 182 this.writeBytes(Long.toString(value)); 183 } 184 185 public void writeIntData(int i, int position) {} 186 187 protected void writeTimestamp(Timestamp o) { 188 189 write('\''); 190 this.writeBytes(HsqlDateTime.getTimestampString(o)); 191 write('\''); 192 } 193 194 public void writeShortData(short i) { 195 writeBytes(Integer.toString(i)); 196 } 197 198 public void writeIntData(int i) { 199 writeBytes(Integer.toString(i)); 200 } 201 202 public void reset() { 203 204 super.reset(); 205 206 isWritten = false; 207 } 208 } 209 | Popular Tags |