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

📄 database.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *  Returns the type of the database: "mem", "file", "res"     */    public String getType() {        return sType;    }    /**     *  Returns the path of the database     */    public String getPath() {        return sPath;    }    /**     *  Returns the database properties.     */    public HsqlDatabaseProperties getProperties() {        return databaseProperties;    }    /**     * Returns the SessionManager for the database.     */    public SessionManager getSessionManager() {        return sessionManager;    }    /**     *  Returns true if database has been shut down, false otherwise     */    synchronized boolean isShutdown() {        return dbState == DATABASE_SHUTDOWN;    }    /**     *  Constructs a new Session that operates within (is connected to) the     *  context of this Database object. <p>     *     *  If successful, the new Session object initially operates on behalf of     *  the user specified by the supplied user name.     *     * Throws if username or password is invalid.     */    synchronized Session connect(String username,                                 String password) throws HsqlException {        User user = userManager.getUser(username, password);        Session session = sessionManager.newSession(this, user,            databaseReadOnly, false);        logger.logConnectUser(session);        return session;    }    /**     *  Puts this Database object in global read-only mode. After     *  this call, all existing and future sessions are limited to read-only     *  transactions. Any following attempts to update the state of the     *  database will result in throwing an HsqlException.     */    public void setReadOnly() {        databaseReadOnly = true;        filesReadOnly    = true;    }    /**     * After this call all CACHED and TEXT tables will be set to read-only     * mode. Changes to MEMORY tables will NOT     * be stored or updated in the script file. This mode is intended for     * use with read-only media where data should not be persisted.     */    public void setFilesReadOnly() {        filesReadOnly = true;    }    /**     * Is this in filesReadOnly mode?     */    public boolean isFilesReadOnly() {        return filesReadOnly;    }    /**     * Is this in filesInJar mode?     */    public boolean isFilesInJar() {        return filesInJar;    }    /**     *  Returns the UserManager for this Database.     */    UserManager getUserManager() {        return userManager;    }    /**     *  Returns the GranteeManager for this Database.     */    GranteeManager getGranteeManager() {        return granteeManager;    }    /**     *  Sets the isReferentialIntegrity attribute.     */    public void setReferentialIntegrity(boolean ref) {        bReferentialIntegrity = ref;    }    /**     *  Is referential integrity currently enforced?     */    boolean isReferentialIntegrity() {        return bReferentialIntegrity;    }    /**     *  Returns a map from Java method-call name aliases to the     *  fully-qualified names of the Java methods themsleves.     */    HashMap getAliasMap() {        return hAlias;    }    /**     *  Returns the fully qualified name for the Java method corresponding to     *  the given method alias. If there is no Java method, then returns the     *  alias itself.     */    String getJavaName(String s) {        String alias = (String) hAlias.get(s);        return (alias == null) ? s                               : alias;    }    /**     * Sets the database to treat any new VARCHAR column declarations as     * VARCHAR_IGNORECASE.     */    void setIgnoreCase(boolean b) {        bIgnoreCase = b;    }    /**     *  Does the database treat any new VARCHAR column declarations as     * VARCHAR_IGNORECASE.     */    boolean isIgnoreCase() {        return bIgnoreCase;    }    /**     * Obtain default table types from database properties     */    int getDefaultTableType() {        String dttName = getProperties().getProperty(            HsqlDatabaseProperties.hsqldb_default_table_type);        return Token.T_CACHED.equalsIgnoreCase(dttName) ? Table.CACHED_TABLE                                                        : Table.MEMORY_TABLE;    }    /**     *  Called by the garbage collector on this Databases object when garbage     *  collection determines that there are no more references to it.     */    protected void finalize() {        if (getState() != DATABASE_ONLINE) {            return;        }        try {            close(CLOSEMODE_IMMEDIATELY);        } catch (HsqlException e) {    // it's too late now        }    }    void closeIfLast() {        if (shutdownOnNoConnection && sessionManager.isEmpty()                && dbState == this.DATABASE_ONLINE) {            try {                close(CLOSEMODE_NORMAL);            } catch (HsqlException e) {}        }    }    /**     *  Closes this Database using the specified mode. <p>     *     * <ol>     *  <LI> closemode -1 performs SHUTDOWN IMMEDIATELY, equivalent     *       to a poweroff or crash.     *     *  <LI> closemode 0 performs a normal SHUTDOWN that     *      checkpoints the database normally.     *     *  <LI> closemode 1 performs a shutdown compact that scripts     *       out the contents of any CACHED tables to the log then     *       deletes the existing *.data file that contains the data     *       for all CACHED table before the normal checkpoint process     *       which in turn creates a new, compact *.data file.     * </ol>     */    void close(int closemode) throws HsqlException {        HsqlException he = null;        setState(DATABASE_CLOSING);        sessionManager.closeAllSessions();        sessionManager.clearAll();        if (filesReadOnly) {            closemode = CLOSEMODE_IMMEDIATELY;        }        // fredt - impact of possible error conditions in closing the log        // should be investigated for the CLOSEMODE_COMPACT mode        logger.closeLog(closemode);        try {            if (closemode == CLOSEMODE_COMPACT) {                clearStructures();                reopen();                setState(DATABASE_CLOSING);                logger.closeLog(CLOSEMODE_NORMAL);            }        } catch (Throwable t) {            if (t instanceof HsqlException) {                he = (HsqlException) t;            } else {                he = Trace.error(Trace.GENERAL_ERROR, t.toString());            }        }        classLoader = null;        logger.releaseLock();        setState(DATABASE_SHUTDOWN);        clearStructures();        // fredt - this could change to avoid removing a db from the        // DatabaseManager repository if there are pending getDatabase()        // calls        DatabaseManager.removeDatabase(this);        if (he != null) {            throw he;        }    }    /**     * Ensures system table producer's table cache, if it exists, is set dirty.     * After this call up-to-date versions are generated in response to     * system table requests. <p>     *     * Also resets all prepared statements if a change to database structure     * can possibly affect any existing prepared statement's validity.<p>     *     * The argument is false if the change to the database structure does not     * affect the prepared statement, such as when a new table is added.<p>     *     * The argument is typically true when a database object is dropped,     * altered or a permission was revoked.     *     * @param  resetPrepared If true, reset all prepared statements.     */    public void setMetaDirty(boolean resetPrepared) {        if (dbInfo != null) {            dbInfo.setDirty();        }        if (resetPrepared) {            compiledStatementManager.resetStatements();        }    }    private synchronized void setState(int state) {        dbState = state;    }    synchronized int getState() {        return dbState;    }    String getStateString() {        int state = getState();        switch (state) {            case DATABASE_CLOSING :                return "DATABASE_CLOSING";            case DATABASE_ONLINE :                return "DATABASE_ONLINE";            case DATABASE_OPENING :                return "DATABASE_OPENING";            case DATABASE_SHUTDOWN :                return "DATABASE_SHUTDOWN";            default :                return "UNKNOWN";        }    }// boucherb@users - 200403?? - patch 1.7.2 - metadata//------------------------------------------------------------------------------    /**     * Retrieves the uri portion of this object's in-process JDBC url.     *     * @return the uri portion of this object's in-process JDBC url     */    public String getURI() {        return sName;    }// oj@openoffice.org - changed to file access api    public HsqlProperties getURLProperties() {        return urlProperties;    }    private FileAccess fileaccess;    private boolean    isStoredFileAccess;    public synchronized FileAccess getFileAccess() {        return fileaccess;    }    public synchronized boolean isStoredFileAccess() {        return isStoredFileAccess;    }}

⌨️ 快捷键说明

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