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

📄 hsqldatabaseproperties.java

📁 纯Java的数据库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                when the application runs out of memory it runs the gc AND                requests more memory from the OS. Setting this property                forces the DB to live inside its memory budget but the                maximum amount of memory can still be set with the                java -Xmx argument to provide the memory needed by other                parts of the app to do graphics and networking.                Of course there is a speed penalty for setting the value                too low and doing garbage collection too often.                This was introduced as a result of tests by Karl Meissner                (meissnersd@users)         */        // garbage collect per Record or Cache Row objects created        // the default, "0" means no garbage collection is forced by        // hsqldb (the Java Runtime will do it's own garbage collection        // in any case).        setProperty(runtime_gc_interval, 0);        // this property is either 1 or 8        setProperty(hsqldb_cache_file_scale, 1);        // this property is between 6 - 20, default 8        setProperty(hsqldb_cache_size_scale, 8);        // number of rows from CACHED tables kept constantly in memory        // the number of rows in up to 3 * (2 to the power of        // cache_scale value).        // reduce the default 14 (3*16K rows) if memory is limited and rows        // are large.        // values between 8-16 are allowed        setProperty(hsqldb_cache_scale, 14);        // maximum size of .log file in megabytes        setProperty(hsqldb_log_size, 200);        // type of logging (0 : text , 1 : binary, 3 : compressed)        setProperty(hsqldb_script_format, 0);        setProperty(db_readonly, false);        setProperty(db_modified, "no-new-files");        // initial method of data file access        setProperty(hsqldb_nio_data_file, true);        // set default table type to MEMORY        setProperty(hsqldb_default_table_type, "memory");        // the property "version" is also set to the current version        //        // the following properties can be set by the user as defaults for        // text tables. the default values are shown.        // "textdb.fs", ","        // "textdb.vs", ",";        // "textdb.lvs", ","        // "textdb.ignore_first", false        // "textdb.quoted", true        // "textdb.all_quoted", false        // "textdb.encoding", "ASCII"        // "textdb.cache_scale", 10  -- allowed range 8-16        // "textdb.cache_size_scale", 10  -- allowed range 8-20        //        // OOo related code        if (db.isStoredFileAccess()) {            setProperty(hsqldb_default_table_type, "cached");            setProperty(hsqldb_cache_scale, 13);            setProperty(hsqldb_log_size, 10);            setProperty(sql_enforce_strict_size, true);            setProperty(hsqldb_nio_data_file, false);        }        // OOo end    }    /**     * Creates file with defaults if it didn't exist.     * Returns false if file already existed.     */    public boolean load() throws HsqlException {        boolean exists;        if (!DatabaseURL.isFileBasedDatabaseType(database.getType())) {            return true;        }        try {            exists = super.load();        } catch (Exception e) {            throw Trace.error(Trace.FILE_IO_ERROR, Trace.LOAD_SAVE_PROPERTIES,                              new Object[] {                fileName, e            });        }        if (!exists) {            return false;        }        filterLoadedProperties();        String version = getProperty(hsqldb_compatible_version);        // do not open if the database belongs to a later (future) version        int check = version.substring(0, 5).compareTo(THIS_VERSION);        if (check > 0) {            throw Trace.error(Trace.WRONG_DATABASE_FILE_VERSION);        }        version = getProperty(db_version);        if (version.charAt(2) == '6') {            setProperty(hsqldb_cache_version, "1.6.0");        }        JavaSystem.gcFrequency = getIntegerProperty(runtime_gc_interval, 0);        return true;    }    /**     * Sets the database member variables after creating the properties object,     * openning a properties file, or changing a property with a command     */    public void setDatabaseVariables() {        if (isPropertyTrue(db_readonly)) {            database.setReadOnly();        }        if (isPropertyTrue(hsqldb_files_readonly)) {            database.setFilesReadOnly();        }        database.sqlEnforceStrictSize =            isPropertyTrue(sql_enforce_strict_size);        if (isPropertyTrue(sql_compare_in_locale)) {            stringProps.remove(sql_compare_in_locale);            database.collation.setCollationAsLocale();        }        database.txManager.setReWriteProtection(            isPropertyTrue(sql_tx_no_multi_write));        database.setMetaDirty(false);    }    public void save() throws HsqlException {        if (!DatabaseURL.isFileBasedDatabaseType(database.getType())                || database.isFilesReadOnly() || database.isFilesInJar()) {            return;        }        try {            super.save(fileName + ".properties" + ".new");            fa.renameElement(fileName + ".properties" + ".new",                             fileName + ".properties");        } catch (Exception e) {            database.logger.appLog.logContext(SimpleLog.LOG_ERROR, "failed");            throw Trace.error(Trace.FILE_IO_ERROR, Trace.LOAD_SAVE_PROPERTIES,                              new Object[] {                fileName, e            });        }    }    void filterLoadedProperties() {        Enumeration en = stringProps.propertyNames();        while (en.hasMoreElements()) {            String  key    = (String) en.nextElement();            boolean accept = meta.containsKey(key);            if (!accept) {                stringProps.remove(key);            }        }    }    /**     *  overload file database properties with any passed on URL line     *  do not store password etc     */    public void setURLProperties(HsqlProperties p) {        if (p != null) {            for (Enumeration e = p.propertyNames(); e.hasMoreElements(); ) {                String   propertyName = (String) e.nextElement();                Object[] row          = (Object[]) meta.get(propertyName);                if (row != null                        && (db_readonly.equals(propertyName)                            || ((Integer) row[indexAccess]).intValue()                               == SET_PROPERTY)) {                    // can add error checking with defaults                    setProperty(propertyName, p.getProperty(propertyName));                }            }        }    }    public Set getUserDefinedPropertyData() {        Set      set = new HashSet();        Iterator it  = meta.values().iterator();        while (it.hasNext()) {            Object[] row = (Object[]) it.next();            if (((Integer) row[indexAccess]).intValue() == SET_PROPERTY) {                set.add(row);            }        }        return set;    }    public boolean isUserDefinedProperty(String key) {        Object[] row = (Object[]) meta.get(key);        return row != null               && ((Integer) row[indexAccess]).intValue() == SET_PROPERTY;    }    public boolean isBoolean(String key) {        Object[] row = (Object[]) meta.get(key);        return row != null && row[indexClass].equals("boolean")               && ((Integer) row[indexAccess]).intValue() == SET_PROPERTY;    }    public boolean isIntegral(String key) {        Object[] row = (Object[]) meta.get(key);        return row != null && row[indexClass].equals("int")               && ((Integer) row[indexAccess]).intValue() == SET_PROPERTY;    }    public boolean isString(String key) {        Object[] row = (Object[]) meta.get(key);        return row != null && row[indexClass].equals("java.lang.String")               && ((Integer) row[indexAccess]).intValue() == SET_PROPERTY;    }    public String setDatabaseProperty(String key,                                      String value) throws HsqlException {        Object[] row = (Object[]) meta.get(key);        // can check bounds here        value = super.setProperty(key, value);        return value;    }    public int getDefaultWriteDelay() {        // OOo related code        if (database.isStoredFileAccess()) {            return 2000;        }        // OOo end        return 10000;    }    public void setDBModified(int mode) throws HsqlException {        String value = MODIFIED_NO;        if (mode == FILES_MODIFIED) {            value = MODIFIED_YES;        } else if (mode == FILES_NEW) {            value = MODIFIED_NEW;        }        setProperty(db_modified, value);        save();    }    public int getDBModified() throws HsqlException {        String value = getProperty("modified");        if (MODIFIED_YES.equals(value)) {            return FILES_MODIFIED;        } else if (MODIFIED_NEW.equals(value)) {            return FILES_NEW;        }        return FILES_NOT_MODIFIED;    }    private static Object[] getMeta(String name, int accessLevel,                                    String defaultValue) {        Object[] row = new Object[indexLimit];        row[indexName]         = name;        row[indexAccess]       = ValuePool.getInt(accessLevel);        row[indexClass]        = "java.lang.String";        row[indexDefaultValue] = defaultValue;        return row;    }    private static Object[] getMeta(String name, int accessLevel,                                    boolean defaultValue) {        Object[] row = new Object[indexLimit];        row[indexName]         = name;        row[indexAccess]       = ValuePool.getInt(accessLevel);        row[indexClass]        = "boolean";        row[indexDefaultValue] = defaultValue ? Boolean.TRUE                                              : Boolean.FALSE;        return row;    }    private static Object[] getMeta(String name, int accessLevel,                                    int defaultValue, byte[] values) {        Object[] row = new Object[indexLimit];        row[indexName]         = name;        row[indexAccess]       = ValuePool.getInt(accessLevel);        row[indexClass]        = "int";        row[indexDefaultValue] = ValuePool.getInt(defaultValue);        row[indexValues]       = values;        return row;    }    private static Object[] getMeta(String name, int accessLevel,                                    int defaultValue, int rangeLow,                                    int rangeHigh) {        Object[] row = new Object[indexLimit];        row[indexName]         = name;        row[indexAccess]       = ValuePool.getInt(accessLevel);        row[indexClass]        = "int";        row[indexDefaultValue] = ValuePool.getInt(defaultValue);        row[indexIsRange]      = Boolean.TRUE;        row[indexRangeLow]     = ValuePool.getInt(rangeLow);        row[indexRangeHigh]    = ValuePool.getInt(rangeHigh);        return row;    }}

⌨️ 快捷键说明

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