예제 #1
0
 public DbException getNewDuplicateKeyException() {
   String sql = "PRIMARY KEY ON " + table.getSQL();
   if (mainIndexColumn >= 0 && mainIndexColumn < indexColumns.length) {
     sql += "(" + indexColumns[mainIndexColumn].getSQL() + ")";
   }
   DbException e = DbException.get(ErrorCode.DUPLICATE_KEY_1, sql);
   e.setSource(this);
   return e;
 }
예제 #2
0
 /**
  * Read an overflow page page.
  *
  * @param id the page id
  * @return the page
  */
 PageDataOverflow getPageOverflow(int id) {
   Page p = store.getPage(id);
   if (p instanceof PageDataOverflow) {
     return (PageDataOverflow) p;
   }
   throw DbException.get(ErrorCode.FILE_CORRUPTED_1, p == null ? "null" : p.toString());
 }
예제 #3
0
 private void open() {
   try {
     conn = JdbcUtils.getConnection(driver, url, user, password);
   } catch (SQLException e) {
     throw DbException.convert(e);
   }
 }
예제 #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
 /**
  * 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();
 }
예제 #6
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();
 }
예제 #7
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;
  }
예제 #8
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?
     }
   }
 }
예제 #9
0
 public void checkRename() {
   throw DbException.getUnsupportedException("PAGE");
 }
예제 #10
0
 public Cursor findFirstOrLast(Session session, boolean first) {
   throw DbException.throwInternalError();
 }
예제 #11
0
 public String getCreateSQLForCopy(Table table, String quotedName) {
   throw DbException.throwInternalError();
 }
예제 #12
0
 public void setIncrement(long inc) {
   if (inc == 0) {
     throw DbException.getInvalidValueException("INCREMENT", 0);
   }
   this.increment = inc;
 }
예제 #13
0
 /**
  * Restores database files.
  *
  * @param zipFileName the name of the backup file
  * @param directory the directory name
  * @param db the database name (null for all databases)
  * @throws DbException if there is an IOException
  */
 public static void execute(String zipFileName, String directory, String db) {
   InputStream in = null;
   try {
     if (!FileUtils.exists(zipFileName)) {
       throw new IOException("File not found: " + zipFileName);
     }
     String originalDbName = null;
     int originalDbLen = 0;
     if (db != null) {
       originalDbName = getOriginalDbName(zipFileName, db);
       if (originalDbName == null) {
         throw new IOException("No database named " + db + " found");
       }
       if (originalDbName.startsWith(SysProperties.FILE_SEPARATOR)) {
         originalDbName = originalDbName.substring(1);
       }
       originalDbLen = originalDbName.length();
     }
     in = FileUtils.newInputStream(zipFileName);
     ZipInputStream zipIn = new ZipInputStream(in);
     while (true) {
       ZipEntry entry = zipIn.getNextEntry();
       if (entry == null) {
         break;
       }
       String fileName = entry.getName();
       // restoring windows backups on linux and vice versa
       fileName = fileName.replace('\\', SysProperties.FILE_SEPARATOR.charAt(0));
       fileName = fileName.replace('/', SysProperties.FILE_SEPARATOR.charAt(0));
       if (fileName.startsWith(SysProperties.FILE_SEPARATOR)) {
         fileName = fileName.substring(1);
       }
       boolean copy = false;
       if (db == null) {
         copy = true;
       } else if (fileName.startsWith(originalDbName + ".")) {
         fileName = db + fileName.substring(originalDbLen);
         copy = true;
       }
       if (copy) {
         OutputStream o = null;
         try {
           o =
               FileUtils.newOutputStream(
                   directory + SysProperties.FILE_SEPARATOR + fileName, false);
           IOUtils.copy(zipIn, o);
           o.close();
         } finally {
           IOUtils.closeSilently(o);
         }
       }
       zipIn.closeEntry();
     }
     zipIn.closeEntry();
     zipIn.close();
   } catch (IOException e) {
     throw DbException.convertIOException(e, zipFileName);
   } finally {
     IOUtils.closeSilently(in);
   }
 }