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

📄 wizardstore.java

📁 用Java写的面相对象的数据库管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }                         if (ta != null) {                ((TransactionData)ta.data).lrucid = cid;            }                         container = cluster.containerForID( id );            return container.isDeleted() ? null : container;        }     }             public synchronized ObjectContainer containerForName( Transaction ta, String name ) throws Exception {        if (name == null) {            return null;        }                 TransactionData taData = (TransactionData)ta.data;                if (ta == null || taData.nameTable == null) {            ObjectID oid = (ObjectID)nameTable.elementForKey( name );            return oid != null ? containerForID( ta, oid ) : null;        }                 if (ta != null) {            ObjectID oid = (ObjectID)taData.nameTable.elementForKey( name );            return oid != null ? containerForID( ta, oid ) : null;        }         return null;    }             public synchronized void nameContainer( Transaction ta, ObjectContainer container, String name )             throws PermissionDeniedExc {                if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {            env.logWriter.newEntry( this, "nameContainer()", LogWriter.DEBUG3 );        }                 TransactionData taData = (TransactionData)ta.data;        if (taData.nameTable == null) {            taData.nameTable = (DxMap)nameTable.clone();        }                 String oldName = container.name();        if (oldName != null) {            taData.nameTable.removeForKey( oldName );            taData.nameTableChanges_push( new NameTableChange( container.id(), oldName,                    NameTableChange.STATE_REMOVED ) );        }                 container.nameTarget( name );                if (name != null) {            taData.nameTable.addForKey( container.id(), name );            taData.nameTableChanges_push( new NameTableChange( container.id(), name, NameTableChange.STATE_ADDED ) );        }     }             public synchronized DxBag clusterOfID( ObjectID id ) throws Exception {        if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {            env.logWriter.newEntry( this, "clusterOfID()", LogWriter.DEBUG3 );        }                 ClusterID cid = (ClusterID)idTable.elementForKey( id );        if (cid == null) {            throw new ObjectNotFoundExc( "" );        }                 Cluster cluster = clusterStore.loadCluster( cid );                DxBag result = new DxArrayBag();        DxIterator it = cluster.containers.iterator();        while (it.next() != null) {            ObjectContainer container = (ObjectContainer)it.object();            result.add( container.id() );        }         return result;    }             public synchronized void prepareCommitTransaction( Transaction ta ) throws Exception {        if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {            env.logWriter.newEntry( this, "prepareCommitTransaction()", LogWriter.DEBUG3 );        }                 TransactionData taData = (TransactionData)ta.data;                // initialize transaction data fields        taData.commitClusterIDs = new DxHashSet( 64 );                DxIterator it = taData.idTable.iterator();        env.logWriter.newEntry( this, "idTable count: " + taData.idTable.count(), LogWriter.DEBUG );        ClusterID cid;                while ((cid = (ClusterID)it.next()) != null) {            if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {                env.logWriter.newEntry( this, "checking cluster: " + cid + " ...", LogWriter.DEBUG3 );            }                         if (!taData.commitClusterIDs.contains( cid )) {                env.logWriter.newEntry( this, "prepare commit cluster: " + cid, LogWriter.DEBUG );                taData.commitClusterIDs.add( cid );                                Cluster cluster = clusterStore.loadCluster( cid );                                // we don't need to do all the stuff if there is no WRITE                // lock                if (cluster.lock.level( ta ) >= Lock.LEVEL_WRITE) {                                        // delete containers from cluster and                    // prepare newID and deletedID tables                    DxIterator it2 = cluster.containers.iterator();                    WizardObjectContainer container;                    while ((container = (WizardObjectContainer)it2.next()) != null) {                                                if (container.isDeleted()) {                            clusterStore.invalidateContainer( container );                            taData.idTableChanges_push( new IDTableChange( container.id(), cid,                                    NameTableChange.STATE_REMOVED ) );                                                        if (container.name() != null) {                                taData.nameTableChanges_push( new NameTableChange( container.id(), container.name(),                                        NameTableChange.STATE_REMOVED ) );                            }                         }                         container.clearState();                    }                 }                 clusterStore.prepareCommitCluster( ta, cid );            }         }     }             protected void beginCommit( Transaction ta ) throws Exception {        env.logWriter.newEntry( this, "beginCommit...", LogWriter.DEBUG );                // do nothing if this was just a read transaction        if (ta.maxLockLevel() < Lock.LEVEL_WRITE) {            return;        }                int commitCount = 0;        // read the current commitCount from file        File f = new File( env.dir + COMMIT_FLAG_NAME );        if (f.exists()) {            DataInputStream in = null;            try {                in = new DataInputStream( new FileInputStream( f ) );                commitCount = in.readInt();            }            finally {                if (in != null) {                    in.close();                }            }        }        commitCount ++;                DataOutputStream out = null;        try {            out = new DataOutputStream( new FileOutputStream( f ) );            out.writeInt( commitCount );        }        finally {            if (out != null) {                out.close();            }        }    }            protected void endCommit( Transaction ta ) throws Exception {        env.logWriter.newEntry( this, "endCommit...", LogWriter.DEBUG );        // do nothing if this was just a read transaction        if (ta.maxLockLevel() < Lock.LEVEL_WRITE) {            return;        }                int commitCount = 0;        // read the current commitCount from file        File f = new File( env.dir + COMMIT_FLAG_NAME );        if (f.exists()) {            DataInputStream in = null;            try {                in = new DataInputStream( new FileInputStream( f ) );                commitCount = in.readInt();            }            finally {                if (in != null) {                    in.close();                }            }        }        else {            throw new RuntimeException( "No commit flag file present." );        }        commitCount --;                if (commitCount > 0) {            DataOutputStream out = null;            try {                out = new DataOutputStream( new FileOutputStream( f ) );                out.writeInt( commitCount );            }            finally {                if (out != null) {                    out.close();                }            }        }        else {            if (!(f.delete())) {                throw new RuntimeException( "Unable to delete commit flag file. " );            }        }    }            public synchronized void commitTransaction( Transaction ta ) throws Exception {        if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {            env.logWriter.newEntry( this, "commitTransaction()", LogWriter.DEBUG3 );        }                 beginCommit( ta );                TransactionData taData = (TransactionData)ta.data;                // actually write changed clusters to disk        DxIterator it = taData.commitClusterIDs.iterator();        ClusterID cid;        while ((cid = (ClusterID)it.next()) != null) {            if (env.logWriter.hasTarget( LogWriter.DEBUG )) {                env.logWriter.newEntry( this, "commit cluster: " + cid, LogWriter.DEBUG );            }                         clusterStore.commitCluster( ta, cid );        }                 // update global idTable        boolean isIDTableChanged = false;        IDTableChange idChange = taData.idTableChanges_pop();        while (idChange != null) {            isIDTableChanged = true;                        switch (idChange.state) {            case IDTableChange.STATE_ADDED: {                idTable.addForKey( idChange.cid, idChange.oid );                break;                }             case IDTableChange.STATE_REMOVED: {                idTable.removeForKey( idChange.oid );                break;                }             default: {                throw new RuntimeException( "ID change table entry has inproper state." );                }             }            idChange = (IDTableChange)taData.idTableChanges_pop();        }                // write changes to disk        if (isIDTableChanged) {            commitIDTable();        }                // update global nameTable        boolean isNameTableChanged = false;        NameTableChange nameChange = taData.nameTableChanges_pop();        while (nameChange != null) {            isNameTableChanged = true;                        switch (nameChange.state) {            case NameTableChange.STATE_ADDED: {                nameTable.addForKey( nameChange.oid, nameChange.name );                break;                }             case NameTableChange.STATE_REMOVED: {                nameTable.removeForKey( nameChange.name );                break;                }             default: {                throw new RuntimeException( "Name change table entry has inproper state." );                }             }            nameChange = taData.nameTableChanges_pop();        }        // write changes to disk        if (isNameTableChanged) {            commitNameTable();        }        endCommit( ta );                if (env.logWriter.hasTarget( LogWriter.DEBUG )) {            env.logWriter.newEntry( this, "    idTable.count(): " + idTable.count(), LogWriter.DEBUG );            env.logWriter.newEntry( this, "    nameTable.count(): " + nameTable.count(), LogWriter.DEBUG );        }     }             /**     * @param ta ID of the comitting transaction.     * @param created     * @param modified     */    public synchronized void abortTransaction( Transaction ta ) throws Exception {        if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {            env.logWriter.newEntry( this, "abortTransaction()", LogWriter.DEBUG3 );        }                 TransactionData taData = (TransactionData)ta.data;        taData.commitClusterIDs = new DxHashSet( 64 );                DxIterator it = taData.idTable.iterator();        ClusterID cid;        while ((cid = (ClusterID)it.next()) != null) {            if (!taData.commitClusterIDs.contains( cid )) {                if (env.logWriter.hasTarget( LogWriter.DEBUG )) {                    env.logWriter.newEntry( this, "abort cluster: " + cid, LogWriter.DEBUG );                }                                 taData.commitClusterIDs.add( cid );                clusterStore.abortCluster( ta, cid );            }         }    }     }

⌨️ 快捷键说明

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