Example #1
0
 /**
  * Get the row at the given index.
  *
  * @param at the index
  * @return the row
  */
 Row getRowAt(int at) {
   Row r = rows[at];
   if (r == null) {
     if (firstOverflowPageId == 0) {
       r = readRow(data, offsets[at], columnCount);
     } else {
       if (rowRef != null) {
         r = rowRef.get();
         if (r != null) {
           return r;
         }
       }
       PageStore store = index.getPageStore();
       Data buff = store.createData();
       int pageSize = store.getPageSize();
       int offset = offsets[at];
       buff.write(data.getBytes(), offset, pageSize - offset);
       int next = firstOverflowPageId;
       do {
         PageDataOverflow page = index.getPageOverflow(next);
         next = page.readInto(buff);
       } while (next != 0);
       overflowRowSize = pageSize + buff.length();
       r = readRow(buff, 0, columnCount);
     }
     r.setKey(keys[at]);
     if (firstOverflowPageId != 0) {
       rowRef = new SoftReference<Row>(r);
     } else {
       rows[at] = r;
       memoryChange(true, r);
     }
   }
   return r;
 }
Example #2
0
 public void moveTo(Session session, int newPos) {
   PageStore store = index.getPageStore();
   // load the pages into the cache, to ensure old pages
   // are written
   if (parentPageId != ROOT) {
     store.getPage(parentPageId);
   }
   store.logUndo(this, data);
   PageDataLeaf p2 = PageDataLeaf.create(index, newPos, parentPageId);
   readAllRows();
   p2.keys = keys;
   p2.overflowRowSize = overflowRowSize;
   p2.firstOverflowPageId = firstOverflowPageId;
   p2.rowRef = rowRef;
   p2.rows = rows;
   if (firstOverflowPageId != 0) {
     p2.rows[0] = getRowAt(0);
   }
   p2.entryCount = entryCount;
   p2.offsets = offsets;
   p2.start = start;
   p2.remapChildren(getPos());
   p2.writeData();
   p2.data.truncate(index.getPageStore().getPageSize());
   store.update(p2);
   if (parentPageId == ROOT) {
     index.setRootPageId(session, newPos);
   } else {
     PageDataNode p = (PageDataNode) store.getPage(parentPageId);
     p.moveChild(getPos(), newPos);
   }
   store.free(getPos());
 }
Example #3
0
 public PageDelegateIndex(
     TableData table,
     int id,
     String name,
     IndexType indexType,
     PageDataIndex mainIndex,
     int headPos,
     Session session)
     throws SQLException {
   IndexColumn[] columns =
       IndexColumn.wrap(new Column[] {table.getColumn(mainIndex.getMainIndexColumn())});
   this.initBaseIndex(table, id, name, columns, indexType);
   this.mainIndex = mainIndex;
   if (!database.isPersistent() || id < 0) {
     throw Message.throwInternalError("" + name);
   }
   PageStore store = database.getPageStore();
   store.addIndex(this);
   if (headPos == Index.EMPTY_HEAD) {
     store.addMeta(this, session);
   }
 }