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

📄 transaction.java

📁 用Java写的面相对象的数据库管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (env.logWriter.hasTarget( LogWriter.DEBUG )) {            env.logWriter.newEntry( this, "==> COMMIT() ", LogWriter.DEBUG );        }                 status = STATUS_COMMITING;        try {            env.store.commitTransaction( this );            // don't delete data in case of an exception            data = null;        } finally {            blocker = null;        }         status = STATUS_COMMITED;    }             /**     * Ones this method is called it MUST cleanup the entire transaction     * stuff without exception. An exception signals an internal server error.     * <p>     * Note: This may be called after/from prepareCommit() !     */    public synchronized void abort( DbCommand command ) throws Exception {        if (env.logWriter.hasTarget( LogWriter.DEBUG )) {            env.logWriter.newEntry( this, "==> ABORT() ", LogWriter.DEBUG );        }                 status = STATUS_ABORTING;        try {            env.store.abortTransaction( this );        } finally {            data = null;            blocker = null;        }         status = STATUS_ABORTED;    }             /**     * Helper method to implement the Locker interface to support deadlock     * recognition via core.dr package     */    public Lockable blockedBy() {        try {            return blocker != null ? (Lockable)env.store.containerForID( this, blocker ) : null;        } catch (Exception e) {            env.logWriter.newEntry( this, "blockedBy() ", e, LogWriter.ERROR );            throw new RuntimeException( "blockedBy() FAILED!" );        }     }             /**     * Create a new database object. If the className is null, an empty container     * is created.     *      *      * @param className     * @param access     * @param name     * @param id The ID of the new container or null.     * @exception PermissionDeniedExc If user in invalid, name is already in     * use, target is not OzoneCompatible...     */    public ObjectContainer createObject( String className, int access, String name, String sig, Object[] args,            ObjectID id ) throws Exception {        if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {            env.logWriter.newEntry( this, "createObject() ", LogWriter.DEBUG3 );        }                 // check (and wait) if a thread runs exclusively;        env.transactionManager.checkExclusion();                try {            Permissions perms = new Permissions( owner, access );            if (id == null) {                id = new ObjectID( env.nextID() );            }             ObjectContainer container = env.store.newContainer( this, null, id, perms );                        if (className != null) {                Class cl = env.classManager.classForName( className );                container.createTarget( env, cl, sig, args );                container.target().onCreate();            }                         acquireContainer( container, Lock.LEVEL_WRITE );                        if (name != null) {                nameObject( container.id(), name );            }                         return container;        } catch (OzoneRemoteExc e) {            throw e;        } catch (Exception e) {            env.logWriter.newEntry( this, "createObject()", e, LogWriter.WARN );            throw new OzoneInternalExc( e.toString() );        }     }             public ObjectContainer copyObject( ObjectID id ) throws Exception {        if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {            env.logWriter.newEntry( this, "copyObject() ", LogWriter.DEBUG3 );        }                 // check (and wait) if a thread runs exclusively;        env.transactionManager.checkExclusion();                try {            if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {                env.logWriter.newEntry( this, "copyObject(): " + id.toString(), LogWriter.DEBUG3 );            }                         ObjectContainer container = acquireObject( id, Lock.LEVEL_WRITE );            Object target = container.targetClone();                        Permissions perms = (Permissions)container.permissions().clone();            ObjectContainer copyContainer =                     env.store.newContainer( this, (OzoneCompatible)target, new ObjectID( env.nextID() ), perms );            acquireContainer( copyContainer, Lock.LEVEL_WRITE );            return copyContainer;        } catch (OzoneRemoteExc e) {            throw e;        } catch (Exception e) {            env.logWriter.newEntry( this, "copyObject()", e, LogWriter.WARN );            throw new OzoneInternalExc( e.toString() );        }     }             public void deleteObject( ObjectID id ) throws Exception {        if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {            env.logWriter.newEntry( this, "deleteObject(): " + id.toString(), LogWriter.DEBUG3 );        }                 try {            ObjectContainer container = acquireObject( id, Lock.LEVEL_WRITE );            container.target().onDelete();            container.deleteTarget();        } catch (OzoneRemoteExc e) {            throw e;        } catch (Exception e) {            env.logWriter.newEntry( this, "deleteObject()", e, LogWriter.WARN );            throw new OzoneInternalExc( e.toString() );        }     }             /**     * @param id     * @param methodName     * @param sig     * @param lockLevel     * @return     */    public Object invokeObject( ObjectID id, String methodName, String sig, Object[] args, int lockLevel )             throws Exception {        if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {            env.logWriter.newEntry( this, "invokeObject(): " + methodName, LogWriter.DEBUG3 );        }                 try {            ObjectContainer container = acquireObject( id, lockLevel );            return container.invokeTarget( env, methodName, sig, args );        // using the container after the invoke is dangerous because        // it's possibly deactivated meanwhile        } catch (InvocationTargetException e) {            Throwable ee = e.getTargetException();            if (ee instanceof RuntimeException) {                throw (RuntimeException)ee;            } else if (ee instanceof Exception) {                throw (Exception)ee;            } else if (ee instanceof Error) {                throw (Error)ee;            } else {                throw new Exception( "Unknown exception type " + ee.getClass().getName() );            }         } catch (OzoneRemoteExc e) {            env.logWriter.newEntry( this, "invokeObject()", e, LogWriter.WARN );            throw e;        } catch (Exception e) {            // since we throw away stack trace of the original exception we            // create a new log message here            env.logWriter.newEntry( this, "invokeObject()", e, LogWriter.WARN );            throw new OzoneInternalExc( e.toString() );        }     }             public Object invokeObject( ObjectID id, int methodIndex, Object[] args, int lockLevel ) throws Exception {        if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {            env.logWriter.newEntry( this, "invokeObject(): " + methodIndex, LogWriter.DEBUG3 );        }                 try {            ObjectContainer container = acquireObject( id, lockLevel );            return container.invokeTarget( env, methodIndex, args );                // using the container after the invoke is dangerous because        // it's possibly deactivated meanwhile        } catch (InvocationTargetException e) {            Throwable ee = e.getTargetException();            if (ee instanceof RuntimeException) {                throw (RuntimeException)ee;            } else if (ee instanceof Exception) {                throw (Exception)ee;            } else if (ee instanceof Error) {                throw (Error)ee;            } else {                throw new Exception( "Unknown exception type " + ee.getClass().getName() );            }         } catch (OzoneRemoteExc e) {            env.logWriter.newEntry( this, "invokeObject()", e, LogWriter.WARN );            throw e;        } catch (Exception e) {            // since we throw away stack trace of the original exception we            // create a new log message here            env.logWriter.newEntry( this, "invokeObject()", e, LogWriter.WARN );            throw new OzoneInternalExc( e.toString() );        }     }             public void nameObject( ObjectID id, String name ) throws Exception {        if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {            env.logWriter.newEntry( this, "nameObject()", LogWriter.DEBUG3 );        }                 try {            ObjectContainer container = acquireObject( id, Lock.LEVEL_WRITE );            if (env.store.containerForName( this, name ) != null) {                throw new PermissionDeniedExc( "Root object name '" + name + "' already exists." );            }                         env.store.nameContainer( this, container, name );        } catch (OzoneRemoteExc e) {            throw e;        } catch (Exception e) {            env.logWriter.newEntry( this, "nameObject()", e, LogWriter.WARN );            throw new OzoneInternalExc( e.toString() );        }     }             public OzoneProxy objectForName( String name ) throws Exception {        if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {            env.logWriter.newEntry( this, "objectForName()", LogWriter.DEBUG3 );        }                 // check (and wait) if a thread runs exclusively;        env.transactionManager.checkExclusion();                try {            ObjectContainer container = env.store.containerForName( this, name );            if (container != null) {                return container.ozoneProxy();            } else {                return null;            }         } catch (OzoneRemoteExc e) {            throw e;        } catch (Exception e) {            env.logWriter.newEntry( this, "objectForName()", e, LogWriter.WARN );            throw new OzoneInternalExc( e.toString() );        }     }             public void sleep( long millis ) {        try {            Thread.currentThread().sleep( millis );        } catch (Exception e) {        }     }             public TransactionID taID() {        return taID;    }             public boolean equals( Object obj ) {        return hashCode() == obj.hashCode();    }             public String toString() {        return "ta(" + (byte)taID.value() + ")";    }             public void finalize() throws Throwable {        env.logWriter.newEntry( this, "--- finalize()", LogWriter.DEBUG );    } }

⌨️ 快捷键说明

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