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

📄 database.java

📁 一个用java写的开源的数据库系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            System.gc();            Trace.printSystemOut("gc at " + Record.memoryRecords);            Record.memoryRecords = 0;        }        if (Trace.TRACE) {            Trace.trace(statement);        }        Result rResult = null;        try {            Tokenizer c = new Tokenizer(statement);            Parser    p = new Parser(this, c, session);            logger.cleanUp();            if (Trace.DOASSERT) {                Trace.doAssert(!session.isNestedTransaction());            }            Trace.check(session != null, Trace.ACCESS_IS_DENIED);            Trace.check(!bShutdown, Trace.DATABASE_IS_SHUTDOWN);            while (true) {                c.setPartMarker();// fredt@users 20020221 - patch 513005 by sqlbob@users (RMP)                session.setScripting(false);                String sToken = c.getString();                if (sToken.length() == 0) {                    break;                }// boucherb@users 20020306 - patch 1.7.0 - use lookup for tokens                Integer command = (Integer) hCommands.get(sToken);                if (command == null) {                    throw Trace.error(Trace.UNEXPECTED_TOKEN, sToken);                }                int cmd = command.intValue();                switch (cmd) {                    case SELECT :                        rResult = p.processSelect();                        break;                    case INSERT :                        rResult = p.processInsert();                        break;                    case UPDATE :                        rResult = p.processUpdate();                        break;                    case DELETE :                        rResult = p.processDelete();                        break;                    case CALL :                        rResult = p.processCall();                        break;                    case SET :                        rResult = processSet(c, session);                        break;                    case COMMIT :                        rResult = processCommit(c, session);                        session.setScripting(true);                        break;                    case ROLLBACK :                        rResult = processRollback(c, session);                        session.setScripting(true);                        break;                    case SAVEPOINT :                        rResult = processSavepoint(c, session);                        session.setScripting(true);                        break;                    case CREATE :                        rResult = processCreate(c, session);                        break;                    case ALTER :                        rResult = processAlter(c, session);                        break;                    case DROP :                        rResult = processDrop(c, session);                        break;                    case GRANT :                        rResult = processGrantOrRevoke(c, session, true);                        break;                    case REVOKE :                        rResult = processGrantOrRevoke(c, session, false);                        break;                    case CONNECT :                        rResult = processConnect(c, session);                        break;                    case DISCONNECT :                        rResult = processDisconnect(session);                        break;                    case SCRIPT :                        rResult = processScript(c, session);                        break;                    case SHUTDOWN :                        rResult = processShutdown(c, session);                        break;                    case CHECKPOINT :                        rResult = processCheckpoint(session);                        break;                    case SEMICOLON :                        break;                }                if (session.getScripting()) {                    logger.writeToLog(session, c.getLastPart());                }            }        } catch (SQLException e) {            // e.printStackTrace();// fredt@users 20020221 - patch 513005 by sqlbob@users (RMP)// tony_lai@users 20020820 - patch 595073//            rResult = new Result(Trace.getMessage(e) + " in statement ["            rResult = new Result(e.getMessage() + " in statement ["                                 + statement + "]", e.getErrorCode());        } catch (Exception e) {            e.printStackTrace();            String s = Trace.getMessage(Trace.GENERAL_ERROR) + " " + e;            rResult = new Result(s + " in statement [" + statement + "]",                                 Trace.GENERAL_ERROR);        } catch (java.lang.OutOfMemoryError e) {            e.printStackTrace();            rResult = new Result("out of memory", Trace.GENERAL_ERROR);        }        return rResult == null ? new Result()                               : rResult;    }    /**     *  Puts this Database object in global read-only mode. That is, 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 a SQLException.     */    void setReadOnly() {        bReadOnly = true;    }    /**     *  Retrieves a Vector containing references to all registered non-system     *  tables and views. This includes all tables and views registered with     *  this Database object via a call to {@link #linkTable linkTable}.     *     * @return  a Vector of all registered non-system tables and views     */    Vector getTables() {        return tTable;    }    /**     *  Retrieves the UserManager object for this Database.     *     * @return  UserManager object     */    UserManager getUserManager() {        return aAccess;    }    /**     *  isReferentialIntegrity attribute setter.     *     * @param  ref if true, this Database object enforces referential     *      integrity, else not     */    void setReferentialIntegrity(boolean ref) {        bReferentialIntegrity = ref;    }    /**     *  isReferentialIntegrity attribute getter.     *     * @return  indicates whether this Database object is currently enforcing     *      referential integrity     */    boolean isReferentialIntegrity() {        return bReferentialIntegrity;    }    /**     *  Retrieves a map from Java method-call name aliases to the     *  fully-qualified names of the Java methods themsleves.     *     * @return  a map in the form of a Hashtable     */    Hashtable getAlias() {        return hAlias;    }    /**     *  Retieves a Java method's fully qualified name, given a String that is     *  supposedly an alias for it. <p>     *     *  This is somewhat of a misnomer, since it is not an alias that is being     *  retrieved, but rather what the supplied alias maps to. If the     *  specified alias does not map to any registered Java method     *  fully-qualified name, then the specified String itself is returned.     *     * @param  s a call name alias that supposedly maps to a registered Java     *      method     * @return  a Java method fully-qualified name, or null if no method is     *      registered with the given alias     */    String getAlias(String s) {        String alias = (String) hAlias.get(s);        return (alias == null) ? s                               : alias;    }// fredt@users 20020221 - patch 513005 by sqlbob@users (RMP)// temp tables should be accessed by the owner and not scripted in the log    /**     *  Retrieves the specified user defined table or view visible within the     *  context of the specified Session, or any system table of the given     *  name. This excludes any temp tables created in different Sessions.     *     * @param  name of the table or view to retrieve     * @param  session the Session within which to search for user tables     * @return  the user table or view, or system table     * @throws  SQLException if there is no such table or view     */    Table getTable(String name, Session session) throws SQLException {        Table t = findUserTable(name, session);        if (t == null) {            t = dInfo.getSystemTable(name, session);        }        if (t == null) {            throw Trace.error(Trace.TABLE_NOT_FOUND, name);        }        return t;    }    /**     *  get a user     *     * @param  name     * @param  session     * @return     * @throws  SQLException     */    Table getUserTable(String name, Session session) throws SQLException {        Table t = findUserTable(name, session);        if (t == null) {            throw Trace.error(Trace.TABLE_NOT_FOUND, name);        }        return t;    }    Table getUserTable(String name) throws SQLException {        Table t = findUserTable(name);        if (t == null) {            throw Trace.error(Trace.TABLE_NOT_FOUND, name);        }        return t;    }    Table findUserTable(String name) {        for (int i = 0, tsize = tTable.size(); i < tsize; i++) {            Table t = (Table) tTable.elementAt(i);            if (t.equals(name)) {                return t;            }        }        return null;    }// fredt@users 20020221 - patch 513005 by sqlbob@users (RMP)    Table findUserTable(String name, Session session) {        for (int i = 0, tsize = tTable.size(); i < tsize; i++) {            Table t = (Table) tTable.elementAt(i);            if (t.equals(name, session)) {                return t;            }        }        return null;    }    /**     *  Generates a SQL script containing all or part of the SQL statements     *  required to recreate the current state of this Database object.     *     * @param  drop if true, include drop statements for each droppable     *      database object     * @param  insert if true, include the insert statements required to     *      populate each of this Database object's memory tables to match     *      their current state.     * @param  cached if true, include the insert statement required to     *      populate each of this Database object's CACHED tables to match     *      their current state.     * @param  session the Session in which to generate the requested SQL     *      script     * @return  A Result object consisting of one VARCHAR column with a row     *      for each statement in the generated script     * @throws  SQLException if the specified Session's currently connected     *      User does not have the right to call this method or there is some     *      problem generating the result     */    Result getScript(boolean drop, boolean insert, boolean cached,                     Session session) throws SQLException {        return DatabaseScript.getScript(this, drop, insert, cached, session);    }    /**     *  Attempts to register the specified table or view with this Database     *  object.     *     * @param  t the table of view to register     * @throws  SQLException if there is a problem     */    void linkTable(Table t) throws SQLException {        tTable.addElement(t);    }    /**     *  isIgnoreCase attribute getter.     *     * @return  the value of this Database object's isIgnoreCase attribute     */    boolean isIgnoreCase() {        return bIgnoreCase;    }    /**     *  Responsible for parsing and executing the SCRIPT SQL statement     *     * @param  c the tokenized representation of the statement being processed     * @param  session     * @return     * @throws  SQLException     */    private Result processScript(Tokenizer c,                                 Session session) throws SQLException {        String sToken = c.getString();        if (c.wasValue()) {            sToken = (String) c.getAsValue();            Log.scriptToFile(this, sToken, true, session);            return new Result();        } else {

⌨️ 快捷键说明

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