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

📄 gammastore.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Core License version 1 published by ozone-db.org.//// Copyright (C) 2003-@year@, Leo Mekenkamp. All rights reserved.//// $Id: GammaStore.java,v 1.4 2004/03/21 21:05:51 leomekenkamp Exp $package org.ozoneDB.core.storage.gammaStore;import java.io.IOException;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Properties;import java.util.logging.Level;import java.util.logging.Logger;import org.ozoneDB.ObjectNotFoundException;import org.ozoneDB.OzoneCompatible;import org.ozoneDB.PermissionDeniedException;import org.ozoneDB.DxLib.DxBag;import org.ozoneDB.DxLib.DxHashSet;import org.ozoneDB.DxLib.DxIterator;import org.ozoneDB.DxLib.DxSet;import org.ozoneDB.core.Env;import org.ozoneDB.core.GarbageCollector;import org.ozoneDB.core.ObjectContainer;import org.ozoneDB.core.ObjectID;import org.ozoneDB.core.Permissions;import org.ozoneDB.core.ServerComponent;import org.ozoneDB.core.StoreManager;import org.ozoneDB.core.Transaction;import org.ozoneDB.core.User;import org.ozoneDB.core.storage.Cache;import org.ozoneDB.core.storage.PropertyConfigurableFactory;import org.ozoneDB.core.storage.PropertyInfo;/** * @author <a href="mailto:leoATmekenkampD0Tcom">Leo Mekenkamp (mind the anti sp@m)</a> * @version $Id: GammaStore.java,v 1.4 2004/03/21 21:05:51 leomekenkamp Exp $ */public class GammaStore extends ServerComponent implements StoreManager {    private static final Logger log = Logger.getLogger(GammaStore.class.getName());    // TODO: move this somewhere else    public static final String OZONE_BASE = "org.ozoneDB";    public static final String GAMMASTORE_BASE = OZONE_BASE + ".core.gammaStore";    public static final PropertyInfo DIRECTORY = new PropertyInfo(        ".directory",        "String (path)",        null,        "main database directory, must be an absolute path",        new String[] {            "/var/ozone (*nix absolute path)",            "c:\\ozoneFiles (windows absolute path)",        }    );    public static final PropertyInfo TXSTORAGEFACTORY = new PropertyInfo(        ".txStorageFactory",        "String (path)",        null,        "main database directory, must be an absolute path",        new String[] {            "/var/ozone/tx (*nix absolute path)",            "c:\\ozoneFiles\\tx (windows absolute path)",        }    );    private static final String PROP_STORAGEFACTORY = ".storageFactory";    private static final String PROP_NUMCONFIGS = ".numConfigs";    private static final String PROP_STREAMFACTORY = ".streamFactory";    private static final String PROP_CONTAINERCACHE = GAMMASTORE_BASE + ".containerCache";    private StorageFactory[] storageFactories;    private StreamFactory[] streamFactories;    private Cache containerCache;    private IndexManager indexManager;    private Properties properties;    private Map containerNames = new HashMap();    /**     * The garbage collector. It should be notified in the event     * <ul><li>that a formerly unnamed object receives a name.</li>     * <li>that an object is freshly created</li>     * </ul>     */    private GarbageCollector garbageCollector;    private StorageFactory txStorageFactory;        /**     * ozoneDB.gammaStore.numConfigs=1     * ozoneDB.gammaStore.0.clusterFactory=org.ozoneDB.core.gammaStore.RandomAccessFileCluster.Factory     * ozoneDB.gammaStore.0.maxClusterSize=65536     * ozoneDB.gammaStore.0.streamFactory=org.ozoneDB.core.gammaStore.GZIPStreamFactory     * ozoneDB.gammaStore.containerCache=org.ozoneDB.core.gammaStore.SoftReferenceCache     *     * While not yet supported there is a possiblility to have multiple     * configurations. These could be used to for instance save instances of a     * specific class to a different disk because of performance reasons     * Because different configurations allow for different streams to be used     * during (de)serialization, this could also be used to encrypt only certain     * objects.     */    public GammaStore(Properties properties) {        // FIXME: dirty hack, but the whole Env thing is begging to be refactored        super(Env.currentEnv());        int numConfigs = Integer.parseInt(properties.getProperty(PROP_NUMCONFIGS, "1"));        if (numConfigs != 1) {            throw new RuntimeException("currently only 1 config supported");        }        // initialize the container cache        setContainerCache((Cache) PropertyConfigurableFactory.create(Cache.class, properties, PROP_CONTAINERCACHE));        // initialize all configs        storageFactories = new StorageFactory[numConfigs];        streamFactories = new StreamFactory[numConfigs];        for (int i = 0; i < numConfigs; i++) {            String prop = GAMMASTORE_BASE + "." + i + PROP_STORAGEFACTORY;            storageFactories[i] = (StorageFactory) PropertyConfigurableFactory.create(StorageFactory.class, properties, prop);//            prop = GAMMASTORE_BASE + "." + i + PROP_STREAMFACTORY;//            streamFactories[i] = (StreamFactory) PropertyConfigurableFactory.create(StreamFactory.class, properties, prop);        }        txStorageFactory = (StorageFactory) PropertyConfigurableFactory.create(StorageFactory.class, properties, GAMMASTORE_BASE + TXSTORAGEFACTORY.getKey());                this.properties = properties;    }        public GammaStore(Env env) {        this(env.config);    }    // private so it can be inlined    public Cache getContainerCache() {        return containerCache;    }    // private so it can be inlined    public void setContainerCache(Cache containerCache) {        this.containerCache = containerCache;    }    private void abortObjectId(ObjectID objectId) {        // delete container from cache        // if object newly created: delete (new) image from disk        // if existing object: delete (new) image from disk    }    public void abortTransaction(Transaction ta) throws IOException, ClassNotFoundException {        GammaTransaction transaction = (GammaTransaction) ta;        for (Iterator i = transaction.getContainerCache().copyToMap().values().iterator(); i.hasNext(); ) {            GammaContainer gammaContainer = (GammaContainer) i.next();            abortObjectId(gammaContainer.getObjectId());        }        transaction.getLogStorage().close();//        ObjectInputStream logStream = new ObjectInputStream(transaction.getLogStorageFactory().createInputStream(transaction.logFilename()));//        ObjectID objectId;//        while((objectId = (ObjectID) logStream.readObject()) != null) {//            abortObjectId(objectId);//        }    }    /** Force the Store to make a guess which objects are used together with the     * container with the specified id.     * @param id The ObjectID if the container.     *     */    public DxBag clusterOfID(ObjectID id) throws Exception {        return null;    }    public void commitTransaction(Transaction ta) throws IOException, ClassNotFoundException {    }    public ObjectContainer containerForID(Transaction ta, ObjectID id) throws ObjectNotFoundException, IOException, ClassNotFoundException {        GammaContainer result = (GammaContainer) containerCache.get(id);        if (result == null) {            // ask indexmanager for location and read from disk        }        return result;    }    /** @param name The object name to search for.     * @param ta     * @return The object container for the name or null.     *     */    public ObjectContainer containerForName(Transaction ta, String name) throws Exception {        return null;    }    /** Aid constructor, because a store is instantiated with 'newInstance',     * where we've got no arguments.     *     */    public void init(Env env) {        setGarbageCollector(env.getGarbageCollector());    }    /** @param ta     * @param container     * @param name     *     */    public void nameContainer(Transaction ta, ObjectContainer container, String name) throws PermissionDeniedException {    }    /** Creates a new object container and initializes it with the specified     * target object. The new container is immediatly accessible from the calling     * transaction via containerByID but it is not joined to this transaction.     * It needs to be joined and commited afterwards.     *     * Iff this method returns normally, the returned container is pinned and thus has to be unpinned.     * Iff this method returns normally, the returned container is locked with the given lock level.     *     * @param ta     * @param target     * @param objectId     * @param permissions     * @param lockLevel     * @return An container-proxy for the created container.     *     */    public ObjectContainer newContainerAndLock(Transaction ta, OzoneCompatible target, ObjectID objectId, Permissions permissions, int lockLevel) throws Exception {        GammaContainer result = new GammaContainer(objectId, this);        getContainerCache().put(objectId, result);        if (target != null) {            result.setTarget(target);        }        if (log.isLoggable(Level.FINEST)) log.finest("created new container " + result);        getGarbageCollector().notifyNewObjectContainer(result);        GammaTransaction gammaTransaction = (GammaTransaction) ta;        gammaTransaction.getContainerCache().put(result.getObjectId(), result);        return result;    }    public Object newTransactionData() {        // not needed since transactions are created by a StoreManager        return null;    }    public DxIterator objectIDIterator() {        // TODO: find some way to have the IndexManager return an iterator        // over all its object entries        return null;    }    /** @param ta the running transaction     * @return a String array of the all object names defined     *     */    public DxSet objectNames(Transaction ta) {        DxSet result = new DxHashSet();        for(Iterator i = getContainerNames().entrySet().iterator(); i.hasNext(); ) {            result.add(i.next());        }        return result;    }    /** Prepare the specified transaction for commit. All operations that may     * fail during the commit process should be done here. However, this method     * must not change any global data structures such as the idTable that     * are used by other transactions too.<p>     *     * The {@link org.ozoneDB.core.TransactionManager} let this method run exclusivly. However,     * {@link #prepareCommitTransaction} and {@link #commitTransaction} are not     * an atomar operation.     *     *     * @param ta Transaction that will be commited.     *     */    public void prepareCommitTransaction(Transaction ta) throws IOException, ClassNotFoundException {    }    /**      Tells this StoreManager to report every named object to the garbage collector.     *     */    public void reportNamedObjectsToGarbageCollector() {    }    public void shutdown() throws Exception {    }    public void startup() throws Exception {        indexManager = new IndexManager(properties, "org.ozoneDB.core.gammaStore.IndexManager", true);    }    /** Update lock level of the given container according to the leve of the     * containers lock object.     * TODO: is this right?     */    public void updateLockLevel(Transaction ta, ObjectContainer container) throws IOException {        if (log.isLoggable(Level.FINEST)) log.finest("updateLockLevel()");        GammaContainer gammaContainer = (GammaContainer) container;        getContainerCache().put(gammaContainer.getObjectId(), gammaContainer);    }    public Transaction createTransaction(Env env, User user) {        return new GammaTransaction(this, getTxStorageFactory(), env, user);    }    private StorageFactory getTxStorageFactory() {        return txStorageFactory;    }        // private so it can be inlined    private Map getContainerNames() {        return containerNames;    }    // private so it can be inlined    private GarbageCollector getGarbageCollector() {        return garbageCollector;    }    // private so it can be inlined    private void setGarbageCollector(GarbageCollector garbageCollector) {        this.garbageCollector = garbageCollector;    }    public void save() throws Exception {    }    }

⌨️ 快捷键说明

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