📄 log.java
字号:
Session[] sessions = database.sessionManager.getAllSessions(); try { for (int i = 0; i < sessions.length; i++) { Session session = sessions[i]; if (session.isAutoCommit() == false) { dbLogWriter.writeLogStatement( session, session.getAutoCommitStatement()); } } } catch (IOException e) { throw Trace.error(Trace.FILE_IO_ERROR, logFileName); } database.logger.appLog.logContext(SimpleLog.LOG_NORMAL, "end"); } /** * Returns true if lost space is above the threshold */ boolean forceDefrag() { long megas = properties.getIntegerProperty( HsqlDatabaseProperties.hsqldb_defrag_limit, 200); long defraglimit = megas * 1024 * 1024; long lostSize = cache.freeBlocks.getLostBlocksSize(); return lostSize > defraglimit; } /** * */ 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, fileName); cache.open(filesReadOnly); } return cache; } int getLogSize() { return (int) (maxLogSize / (1024 * 11024)); } void setLogSize(int megas) { properties.setProperty(HsqlDatabaseProperties.hsqldb_log_size, String.valueOf(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(HsqlDatabaseProperties.hsqldb_script_format, String.valueOf(scriptFormat)); if (needsCheckpoint) { database.logger.needsCheckpoint = true; } } /** * 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) { database.logger.needsCheckpoint = true; } } 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) { database.logger.needsCheckpoint = true; } } 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) { database.logger.needsCheckpoint = true; } } 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) { database.logger.needsCheckpoint = true; } } 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) { database.logger.needsCheckpoint = true; } } 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 { deleteNewScript(); //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, null); if (e instanceof HsqlException) { throw (HsqlException) e; } else if (e instanceof IOException) { throw Trace.error(Trace.FILE_IO_ERROR, e.toString()); } else if (e instanceof OutOfMemoryError) { throw Trace.error(Trace.OUT_OF_MEMORY); } else { throw Trace.error(Trace.GENERAL_ERROR, e.toString()); } } } /** * 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) { database.logger.needsCheckpoint = 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, fileName + ".data"); try { ZipUnzipFile.decompressFile(fileName + ".backup", fileName + ".data", database.getFileAccess()); } catch (Exception e) { throw Trace.error(Trace.FILE_IO_ERROR, Trace.Message_Pair, new Object[] { fileName + ".backup", e.toString() }); } }// 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 + -