⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 log.java

📁 hsql是很有名的嵌入式数据库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    boolean hasCache() {        return cache != null;    }    /**     * Responsible for creating the cache instance.     */    DataFileCache getCache() throws HsqlException {/*        if (database.isFilesInJar()) {            return null;        }*/        if (cache == null) {            cache = new DataFileCache(database, cacheFileName,                                      backupFileName);            cache.open(filesReadOnly);        }        return cache;    }    int getLogSize() {        return (int) (maxLogSize / (1024 * 11024));    }    void setLogSize(int megas) {        properties.setProperty("hsqldb.log_size", megas);        maxLogSize = megas * 1024 * 1024;    }    int getScriptType() {        return scriptFormat;    }    /**     * Changing the script format results in a checkpoint, with the .script     * file written in the new format.     */    void setScriptType(int type) throws HsqlException {        if (database.isStoredFileAccess()) {            return;        }        boolean needsCheckpoint = scriptFormat != type;        scriptFormat = type;        properties.setProperty("hsqldb.script_format", scriptFormat);        if (needsCheckpoint) {            checkpoint(false);        }    }    /**     * Write delay specifies the frequency of FileDescriptor.sync() calls.     */    int getWriteDelay() {        return writeDelay;    }    void setWriteDelay(int delay) {        writeDelay = delay;        if (dbLogWriter != null) {            synchLog();            dbLogWriter.setWriteDelay(delay);        }    }    /**     * Various writeXXX() methods are used for logging statements.     */    void writeStatement(Session session, String s) throws HsqlException {        if (s == null || s.length() == 0) {            return;        }        try {            dbLogWriter.writeLogStatement(session, s);        } catch (IOException e) {            throw Trace.error(Trace.FILE_IO_ERROR, logFileName);        }        if (maxLogSize > 0 && dbLogWriter.size() > maxLogSize) {            checkpoint(false);        }    }    void writeInsertStatement(Session session, Table t,                              Object[] row) throws HsqlException {        try {            dbLogWriter.writeInsertStatement(session, t, row);        } catch (IOException e) {            throw Trace.error(Trace.FILE_IO_ERROR, logFileName);        }        if (maxLogSize > 0 && dbLogWriter.size() > maxLogSize) {            checkpoint(false);        }    }    void writeDeleteStatement(Session session, Table t,                              Object[] row) throws HsqlException {        try {            dbLogWriter.writeDeleteStatement(session, t, row);        } catch (IOException e) {            throw Trace.error(Trace.FILE_IO_ERROR, logFileName);        }        if (maxLogSize > 0 && dbLogWriter.size() > maxLogSize) {            checkpoint(false);        }    }    void writeSequenceStatement(Session session,                                NumberSequence s) throws HsqlException {        try {            dbLogWriter.writeSequenceStatement(session, s);        } catch (IOException e) {            throw Trace.error(Trace.FILE_IO_ERROR, logFileName);        }        if (maxLogSize > 0 && dbLogWriter.size() > maxLogSize) {            checkpoint(false);        }    }    void writeCommitStatement(Session session) throws HsqlException {        try {            dbLogWriter.writeCommitStatement(session);        } catch (IOException e) {            throw Trace.error(Trace.FILE_IO_ERROR, logFileName);        }        if (maxLogSize > 0 && dbLogWriter.size() > maxLogSize) {            checkpoint(false);        }    }    void synchLog() {        if (dbLogWriter != null) {            dbLogWriter.sync();        }    }    /**     * Wrappers for openning-starting / stoping-closing the log file and     * writer.     */    private void openLog() throws HsqlException {        if (filesReadOnly) {            return;        }        try {            dbLogWriter = ScriptWriterBase.newScriptWriter(database,                    logFileName, false, false,                    ScriptWriterBase.SCRIPT_TEXT_170);            dbLogWriter.setWriteDelay(writeDelay);            dbLogWriter.start();        } catch (Exception e) {            throw Trace.error(Trace.FILE_IO_ERROR, logFileName);        }    }    private synchronized void closeLog() throws HsqlException {        if (dbLogWriter != null) {            dbLogWriter.close();        }    }    /**     * Write the .script file as .script.new.     */    private void writeScript(boolean full) throws HsqlException {        String sNewName = scriptFileName + ".new";        try {            if (fa.isStreamElement(sNewName)) {                fa.removeElement(sNewName);            }        } catch (IOException e) {            database.logger.appLog.logContext(e);        }        //fredt - to do - flag for chache set index        ScriptWriterBase scw = ScriptWriterBase.newScriptWriter(database,            scriptFileName + ".new", full, true, scriptFormat);        scw.writeAll();        scw.close();    }    /**     * Performs all the commands in the .script file.     */    private void processScript() throws HsqlException {        ScriptReaderBase scr = null;        try {            if (database.isFilesInJar()                    || fa.isStreamElement(scriptFileName)) {                scr = ScriptReaderBase.newScriptReader(database,                                                       scriptFileName,                                                       scriptFormat);                scr.readAll(database.sessionManager.getSysSession(null,                        true));                scr.close();            }        } catch (Throwable e) {            if (scr != null) {                scr.close();                if (cache != null) {                    cache.close(false);                }                closeAllTextCaches(false);            }            database.logger.appLog.logContext(e);            if (e instanceof HsqlException) {                throw (HsqlException) e;            } else if (e instanceof IOException) {                throw Trace.error(Trace.FILE_IO_ERROR, e.getMessage());            } else if (e instanceof OutOfMemoryError) {                throw Trace.error(Trace.OUT_OF_MEMORY);            } else {                throw Trace.error(Trace.GENERAL_ERROR, e.getMessage());            }        }    }    /**     * Defrag large data files when the sum of .log and .data files is large.     */    private void processDataFile() throws HsqlException {        if (cache == null || filesReadOnly || database.isStoredFileAccess()                ||!fa.isStreamElement(logFileName)) {            return;        }        File file       = new File(logFileName);        long logLength  = file.length();        long dataLength = cache.getFileFreePos();        if (logLength + dataLength > cache.maxDataFileSize) {            checkpoint(true);        }    }    /**     * Performs all the commands in the .log file.     */    private void processLog() throws HsqlException {        if (!database.isFilesInJar() && fa.isStreamElement(logFileName)) {            ScriptRunner.runScript(database, logFileName,                                   ScriptWriterBase.SCRIPT_TEXT_170);        }    }    /**     * Restores a compressed backup or the .data file.     */    private void restoreBackup() throws HsqlException {        // in case data file cannot be deleted, reset it        DataFileCache.deleteOrResetFreePos(database, cacheFileName);        try {            ZipUnzipFile.decompressFile(backupFileName, cacheFileName,                                        database.getFileAccess());        } catch (Exception e) {            throw Trace.error(Trace.FILE_IO_ERROR, Trace.Message_Pair,                              new Object[] {                backupFileName, e.getMessage()            });        }    }// fredt@users 20020221 - patch 513005 by sqlbob@users (RMP) - text tables    private HashMap textCacheList = new HashMap();    DataFileCache openTextCache(Table table, String source,                                boolean readOnlyData,                                boolean reversed) throws HsqlException {        closeTextCache(table);        if (!properties.isPropertyTrue("textdb.allow_full_path")) {            if (source.indexOf("..") != -1) {                throw (Trace.error(Trace.ACCESS_IS_DENIED, source));            }            String path = new File(                new File(                    database.getPath()                    + ".properties").getAbsolutePath()).getParent();            if (path != null) {                source = path + File.separator + source;            }        }        TextCache c;        int       type;        if (reversed) {            c = new TextCache(table, source);        } else {            c = new TextCache(table, source);        }        c.open(readOnlyData || filesReadOnly);        textCacheList.put(table.getName(), c);        return c;    }    void closeTextCache(Table table) throws HsqlException {        TextCache c = (TextCache) textCacheList.remove(table.getName());        if (c != null) {            c.close(true);        }    }    private void closeAllTextCaches(boolean compact) throws HsqlException {        Iterator it = textCacheList.values().iterator();        while (it.hasNext()) {            if (compact) {                ((TextCache) it.next()).purge();            } else {                ((TextCache) it.next()).close(true);            }        }    }    private void reopenAllTextCaches() throws HsqlException {        Iterator it = textCacheList.values().iterator();        while (it.hasNext()) {            ((TextCache) it.next()).reopen();        }    }    private boolean isAnyTextCacheModified() {        Iterator it = textCacheList.values().iterator();        while (it.hasNext()) {            if (((TextCache) it.next()).isFileModified()) {                return true;            }        }        return false;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -