Exemple #1
0
 /** Write the header data. */
 void initWrite() {
   data = store.createData();
   data.writeByte((byte) Page.TYPE_STREAM_DATA);
   data.writeShortInt(0);
   data.writeInt(trunk);
   data.writeInt(logKey);
   remaining = store.getPageSize() - data.length();
 }
Exemple #2
0
 private void writeRow(Data buff, Row r) {
   buff.checkCapacity(1 + Data.LENGTH_INT * 8);
   buff.writeByte((byte) 1);
   buff.writeInt(r.getMemory());
   int columnCount = r.getColumnCount();
   buff.writeInt(columnCount);
   buff.writeLong(r.getKey());
   buff.writeInt(r.getVersion());
   buff.writeInt(r.isDeleted() ? 1 : 0);
   buff.writeInt(r.getSessionId());
   for (int i = 0; i < columnCount; i++) {
     Value v = r.getValue(i);
     buff.checkCapacity(1);
     if (v == null) {
       buff.writeByte((byte) 0);
     } else {
       buff.writeByte((byte) 1);
       if (v.getType() == Value.CLOB || v.getType() == Value.BLOB) {
         // need to keep a reference to temporary lobs,
         // otherwise the temp file is deleted
         if (v.getSmall() == null && v.getTableId() == 0) {
           if (lobs == null) {
             lobs = New.arrayList();
           }
           // need to create a copy, otherwise,
           // if stored multiple times, it may be renamed
           // and then not found
           v = v.copyToTemp();
           lobs.add(v);
         }
       }
       buff.checkCapacity(buff.getValueLen(v));
       buff.writeValue(v);
     }
   }
 }
 @Override
 public int addRows(ArrayList<Value[]> rows) {
   if (sort != null) {
     sort.sort(rows);
   }
   Data buff = rowBuff;
   long start = file.getFilePointer();
   ByteArrayOutputStream buffer = new ByteArrayOutputStream();
   int bufferLen = 0;
   for (Value[] row : rows) {
     buff.reset();
     buff.writeInt(0);
     for (int j = 0; j < columnCount; j++) {
       Value v = row[j];
       buff.checkCapacity(buff.getValueLen(v));
       buff.writeValue(v);
     }
     buff.fillAligned();
     int len = buff.length();
     buff.setInt(0, len);
     if (maxBufferSize > 0) {
       buffer.write(buff.getBytes(), 0, len);
       bufferLen += len;
       if (bufferLen > maxBufferSize) {
         byte[] data = buffer.toByteArray();
         buffer.reset();
         file.write(data, 0, data.length);
         bufferLen = 0;
       }
     } else {
       file.write(buff.getBytes(), 0, len);
     }
   }
   if (bufferLen > 0) {
     byte[] data = buffer.toByteArray();
     file.write(data, 0, data.length);
   }
   if (sort != null) {
     ResultDiskTape tape = new ResultDiskTape();
     tape.start = start;
     tape.end = file.getFilePointer();
     tapes.add(tape);
   } else {
     mainTape.end = file.getFilePointer();
   }
   rowCount += rows.size();
   return rowCount;
 }
Exemple #4
0
 private static void initBuffer(Data buff) {
   buff.reset();
   buff.writeInt(0);
 }
Exemple #5
0
 /**
  * Append a long value. This method writes two int values.
  *
  * @param x the value
  */
 public void writeLong(long x) {
   writeInt((int) (x >>> 32));
   writeInt((int) x);
 }