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

📄 currentdatabase.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
/* CurrentDatabase.java*/package org.ozoneDB;import org.ozoneDB.data.SimpleArrayList;/**    A method for maintaining an implicit reference to the current database        @author <A HREF="http://www.medium.net/">Xu鈔 Baldauf,Medium.net</A>*/public class CurrentDatabase {        protected static ThreadLocal instances = new ThreadLocal() {        protected Object initialValue() {            return new CurrentDatabase();        }    };        protected SimpleArrayList stack;        protected CurrentDatabase() {        stack = new SimpleArrayList(6);    }        protected void addCurrentDatabase(OzoneInterface newCurrentDatabase) {        stack.push(newCurrentDatabase);    }        protected void removeCurrentDatabase() {        Object result = stack.pop();                assert result!=null;    }        protected OzoneInterface getCurrentDatabase() {        OzoneInterface currentDatabase = (OzoneInterface) stack.peek();                // Maybe we should asserts instead?        if (currentDatabase==null) {            throw new IllegalStateException("There is no current database defined for this thread "+Thread.currentThread()+".");        }                return currentDatabase;    }        /**        Registers a new current database.        Every call to this method must be matched by a call to {@link #unregister}.        Thus, the usage should be as following:                <PRE>          CurrentDatabase.register(database);                        try {                ... do something useful ...            } finally {                CurrentDatabase.unregister();            }        </PRE>                <DIV>            Registering current databases may be nested. If already a current database is registered,            registering a new one hides the old one until {@link #unregister} is called.        </DIV>        <DIV>                   Registered current databases only apply to the current thread. Each thread has to register            its current database separately.        </DIV>    */    public static void register(OzoneInterface newCurrentDatabase) {        assert newCurrentDatabase!=null;                ((CurrentDatabase) instances.get()).addCurrentDatabase(newCurrentDatabase);    }    /**        Unregisters the current database. The database which was current before the matching call to        {@link #register} will be the new current database.      */      public static void unregister() {        ((CurrentDatabase) instances.get()).removeCurrentDatabase();    }        /**        Returns a reference to the current database.                @return            a reference to the current database        @throws IllegalStateException            If no current database is set.    */    public static OzoneInterface get() throws IllegalStateException {        return ((CurrentDatabase) instances.get()).getCurrentDatabase();    }}// :indentSize=4:tabSize=4:noTabs=true:

⌨️ 快捷键说明

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