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

📄 wizardstore.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }    public synchronized ObjectContainer newContainerAndLock(Transaction ta, OzoneCompatible target, ObjectID objID,                                                                  Permissions permissions, int lockLevel) throws Exception {        StorageObjectContainer container = new WizardObjectContainer(objID);        if (target != null) {            container.setTarget(target);        }        clusterStore.registerContainerAndLock(container, permissions, ta, lockLevel);        boolean alright = false;        try {            garbageCollector.notifyNewObjectContainer(container);            WizardTransaction wizardTa = (WizardTransaction) ta;            ClusterID cid = container.getCluster().clusterID();            ObjectID oid = container.id();            if (env.logWriter.hasTarget(LogWriter.DEBUG3)) {                env.logWriter.newEntry(this, "newContainer(): cid=" + cid + ",oid=" + oid + ".", LogWriter.DEBUG3);            }            wizardTa.idTable.addForKey(cid, oid);            wizardTa.idTableChanges_push(new IDTableChange(oid, cid, IDTableChange.STATE_ADDED));            alright = true;            return container;        } finally {            if (!alright) {                container.getCluster().lock().release(ta);                container.unpin();            }        }    }    //    public synchronized void deleteContainer (Transaction ta, ObjectContainer _container)    //            throws Exception {    //        if (env.logWriter.hasTarget (LogWriter.DEBUG3))    //            env.logWriter.newEntry (this, "deleteContainer()", LogWriter.DEBUG3);    //    //        WizardObjectContainer container = (WizardObjectContainer)_container;    //        taData.idTableChanges.push (new IDTableChange (oid, cid, IDTableChange.STATE_ADDED));    public void updateLockLevel(Transaction _ta, ObjectContainer _container) throws IOException {        if (env.logWriter.hasTarget(LogWriter.DEBUG3)) {            env.logWriter.newEntry(this, "updateLockLevel()", LogWriter.DEBUG3);        }        if (_container instanceof WizardObjectContainer) {            StorageObjectContainer container = (StorageObjectContainer) _container;            container.getCluster().updateLockLevel(_ta);            WizardTransaction wizardTa = (WizardTransaction) _ta;            wizardTa.idTable.addForKey(container.getCluster().clusterID(), container.id());        }    }    /**     * Returns the ObjectContainer for the given ObjectID or null if there is     * no such container.<p>     If an ObjectContainer is returned, it is pinned once.     Thus, the caller has to ensure that the ObjectContainer is unpinned as soon as it is not needed anymore.     *     * @param ta the Transaction for within the container is requested or null.     *     * Impl. Note: For performance reasons this is the only method of this Store     * that is not synchronized. This will not cause problems because the only     * field that is updated inside the method (currentContainer) does not need     * to be stable while this method is running.     */    public ObjectContainer containerForID(Transaction ta, ObjectID id) throws ObjectNotFoundException, IOException, ClassNotFoundException {        StorageObjectContainer container = null;        WizardTransaction wizardTa = (WizardTransaction) ta;        // search the LRU cluster to speed things up; since this is not        // synchronized, checking and accessing currentCluster must be done in        // one line to avoid other thread to change the variable in between        //        container = (currentCluster != null && currentCluster.lock != null) ? currentCluster.containerForID (id) : null;        //        if (container != null) {        //           // System.out.print ("+");        //            return container.isDeleted() ? null : container;        //            }        ClusterID cid = null;        // search members of current ta first        if (ta != null) {            DxMap taDataIDTable = wizardTa.idTable;            cid = (ClusterID) taDataIDTable.elementForKey(id);            if (cid == null && wizardTa.lrucid != null) {                org.ozoneDB.core.storage.Cluster lru = clusterStore.loadCluster(wizardTa.lrucid, true);                if (lru != null) {                    try {                        container = lru.lock() != null ? lru.containerForID(id) : null;                        if (container != null) {                            // System.out.print ("+");                            if (container.isDeleted()) {                                return null;                            } else {                                container.pin();                                return container;                            }                        }                    } finally {                        if (lru instanceof WizardCluster) {                            ((WizardCluster)lru).unpin();                        }                    }                }            }        }        // search global table ONLY if ta doesn't contain the container        if (cid == null) {            cid = (ClusterID) idTable.elementForKey(id);        }//				env.logWriter.newEntry( this, "containerForID(): id="+id+",cid="+cid+".", LogWriter.DEBUG3 );        if (cid == null) {            return null;        } else {            // System.out.println ("-");            org.ozoneDB.core.storage.Cluster cluster = clusterStore.loadCluster(cid, true);            if (cluster == null) {                throw new ObjectNotFoundException("No object registered for ID: " + id);            }            try {                if (wizardTa != null) {                    wizardTa.lrucid = cid;                }                try {                    container = cluster.containerForID(id);                    if (container.isDeleted()) {                        return null;                    } else {                        container.pin();                        return container;                    }                } catch (NullPointerException e) {                    env.logWriter.newEntry(this, "NullPointerException during " + cluster + ".containerForID(" + id + "). We were able to load a cluster for that ID but the cluster did not contain the container. This is an inconsistent view.", e, LogWriter.ERROR);                    throw e;                }            } finally {                if (cluster instanceof WizardCluster) {                    ((WizardCluster)cluster).unpin();                }            }        }    }    public DxSet objectNames(Transaction ta) {        env.logWriter.newEntry(this, "Returning objectnames", LogWriter.DEBUG);        return nameTable.keySet();    }    public synchronized ObjectContainer containerForName(Transaction ta, String name) throws Exception {        if (name == null) {            return null;        }        WizardTransaction wizardTa = (WizardTransaction) ta;        if (ta == null || wizardTa.nameTable == null) {            ObjectID oid = (ObjectID) nameTable.elementForKey(name);            return oid != null ? containerForID(ta, oid) : null;        }        if (ta != null) {            ObjectID oid = (ObjectID) wizardTa.nameTable.elementForKey(name);            return oid != null ? containerForID(ta, oid) : null;        }        return null;    }    public synchronized void nameContainer(Transaction ta, ObjectContainer container, String name)            throws PermissionDeniedException {        if (env.logWriter.hasTarget(LogWriter.DEBUG3)) {            env.logWriter.newEntry(this, "nameContainer(), nameTable=" + nameTable + ".", LogWriter.DEBUG3);        }        WizardTransaction wizardTa = (WizardTransaction) ta;        if (wizardTa.nameTable == null) {            Object o = null;            try {                java.lang.reflect.Method method = nameTable.getClass().getDeclaredMethod("clone", null);                if (env.logWriter.hasTarget(LogWriter.DEBUG)) {                    env.logWriter.newEntry(this, "nameContainer(), nameTable=" + nameTable + ", nameTable.getClass().getDeclaredMethod(\"clone\",null)=" + method + ".", LogWriter.DEBUG);                }                o = method.invoke(nameTable, null);            } catch (Exception e) {                env.logWriter.newEntry(this, "nameContainer(): caught: ", e, LogWriter.INFO);            }            if (o == null) {                o = nameTable.clone();            }            wizardTa.nameTable = (DxMap) o;        }        String oldName = container.name();        if (oldName != null) {            wizardTa.nameTable.removeForKey(oldName);            wizardTa.nameTableChanges_push(new NameTableChange(container.id(), oldName,                                                             NameTableChange.STATE_REMOVED));        }        container.nameTarget(name);        if (name != null) {            if (oldName == null) {                garbageCollector.notifyNewObjectName(container);            }            wizardTa.nameTable.addForKey(container.id(), name);            wizardTa.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 ObjectNotFoundException("");        }        org.ozoneDB.core.storage.Cluster cluster = clusterStore.loadCluster(cid, true);        try {            DxBag result = new DxArrayBag();            DxIterator it = cluster.containers().iterator();            while (it.next() != null) {                ObjectContainer container = (ObjectContainer) it.object();                result.add(container.id());            }            return result;        } finally {            if (cluster instanceof WizardCluster) {                ((WizardCluster)cluster).unpin();            }        }    }    public synchronized void prepareCommitTransaction(Transaction ta) throws IOException, ClassNotFoundException {        if (env.logWriter.hasTarget(LogWriter.DEBUG3)) {            env.logWriter.newEntry(this, "prepareCommitTransaction()", LogWriter.DEBUG3);        }        WizardTransaction wizardTa = (WizardTransaction) ta;        // initialize transaction data fields        wizardTa.commitClusterIDs = new DxHashSet(64);        DxIterator it = wizardTa.idTable.iterator();//      env.logWriter.newEntry( this, "idTable count: " + taData.idTable.count(), LogWriter.DEBUG2 );        ClusterID cid;        while ((cid = (ClusterID) it.next()) != null) {            if (env.logWriter.hasTarget(LogWriter.DEBUG3)) {

⌨️ 快捷键说明

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