示例#1
0
 /**
  * Get the key from the row.
  *
  * @param row the row
  * @param ifEmpty the value to use if the row is empty
  * @param ifNull the value to use if the column is NULL
  * @return the key
  */
 long getKey(SearchRow row, long ifEmpty, long ifNull) {
   if (row == null) {
     return ifEmpty;
   }
   Value v = row.getValue(mainIndexColumn);
   if (v == null) {
     throw DbException.throwInternalError(row.toString());
   } else if (v == ValueNull.INSTANCE) {
     return ifNull;
   }
   return v.getLong();
 }
示例#2
0
 /**
  * This method is called if a file should no longer be deleted if the object is garbage collected.
  *
  * @param ref the reference as returned by addFile
  * @param fileName the file name
  */
 public void stopAutoDelete(Reference<?> ref, String fileName) {
   IOUtils.trace("TempFileDeleter.stopAutoDelete", fileName, ref);
   if (ref != null) {
     String f2 = refMap.remove(ref);
     if (SysProperties.CHECK) {
       if (f2 == null || !f2.equals(fileName)) {
         DbException.throwInternalError(
             "f2:" + f2 + " " + (f2 == null ? "" : f2) + " f:" + fileName);
       }
     }
   }
   deleteUnused();
 }
示例#3
0
  public PageDataIndex(
      RegularTable table,
      int id,
      IndexColumn[] columns,
      IndexType indexType,
      boolean create,
      Session session) {
    initBaseIndex(table, id, table.getName() + "_DATA", columns, indexType);
    RegularDatabase database = (RegularDatabase) this.database;
    this.multiVersion = database.isMultiVersion();

    // trace = database.getTrace(Trace.PAGE_STORE + "_di");
    // trace.setLevel(TraceSystem.DEBUG);
    if (multiVersion) {
      sessionRowCount = New.hashMap();
      isMultiVersion = true;
    } else {
      sessionRowCount = null;
    }
    tableData = table;
    this.store = database.getPageStore();
    store.addIndex(this);
    if (!database.isPersistent()) {
      throw DbException.throwInternalError(table.getName());
    }
    if (create) {
      rootPageId = store.allocatePage();
      store.addMeta(this, session);
      PageDataLeaf root = PageDataLeaf.create(this, rootPageId, PageData.ROOT);
      store.update(root);
    } else {
      rootPageId = store.getRootPageId(id);
      PageData root = getPage(rootPageId, 0);
      lastKey = root.getLastKey();
      rowCount = root.getRowCount();
    }
    if (trace.isDebugEnabled()) {
      trace.debug("{0} opened rows: {1}", this, rowCount);
    }
    table.setRowCount(rowCount);
    memoryPerPage = (Constants.MEMORY_PAGE_DATA + store.getPageSize()) >> 2;
  }
示例#4
0
 /**
  * Read the given page.
  *
  * @param id the page id
  * @param parent the parent, or -1 if unknown
  * @return the page
  */
 PageData getPage(int id, int parent) {
   Page pd = store.getPage(id);
   if (pd == null) {
     PageDataLeaf empty = PageDataLeaf.create(this, id, parent);
     // could have been created before, but never committed
     store.logUndo(empty, null);
     store.update(empty);
     return empty;
   } else if (!(pd instanceof PageData)) {
     throw DbException.get(ErrorCode.FILE_CORRUPTED_1, "" + pd);
   }
   PageData p = (PageData) pd;
   if (parent != -1) {
     if (p.getParentPageId() != parent) {
       throw DbException.throwInternalError(
           p + " parent " + p.getParentPageId() + " expected " + parent);
     }
   }
   return p;
 }
示例#5
0
 /**
  * Delete the given file now. This will remove the reference from the list.
  *
  * @param ref the reference as returned by addFile
  * @param fileName the file name
  */
 public synchronized void deleteFile(Reference<?> ref, String fileName) {
   if (ref != null) {
     String f2 = refMap.remove(ref);
     if (f2 != null) {
       if (SysProperties.CHECK) {
         if (fileName != null && !f2.equals(fileName)) {
           DbException.throwInternalError("f2:" + f2 + " f:" + fileName);
         }
       }
       fileName = f2;
     }
   }
   if (fileName != null && FileUtils.exists(fileName)) {
     try {
       IOUtils.trace("TempFileDeleter.deleteFile", fileName, null);
       FileUtils.tryDelete(fileName);
     } catch (Exception e) {
       // TODO log such errors?
     }
   }
 }
示例#6
0
 public Cursor findFirstOrLast(Session session, boolean first) {
   throw DbException.throwInternalError();
 }
示例#7
0
 public String getCreateSQLForCopy(Table table, String quotedName) {
   throw DbException.throwInternalError();
 }