memory storage cleanup, preparation for "fast load" BLD200306300655
authormmatula@netbeans.org
Sun, 29 Jun 2003 19:24:08 +0000
changeset 130429482ae3910d
parent 1303 b6b4c6fe3952
child 1305 edd7a36c33aa
memory storage cleanup, preparation for "fast load"
mdr/src/org/netbeans/mdr/NBMDRepositoryImpl.java
mdr/src/org/netbeans/mdr/persistence/memoryimpl/MultivaluedIndexImpl.java
mdr/src/org/netbeans/mdr/persistence/memoryimpl/SinglevaluedIndexImpl.java
mdr/src/org/netbeans/mdr/persistence/memoryimpl/StorageFactoryImpl.java
mdr/src/org/netbeans/mdr/persistence/memoryimpl/StorageImpl.java
mdr/src/org/netbeans/mdr/persistence/memoryimpl/Utils.java
mdr/src/org/netbeans/mdr/storagemodel/MdrStorage.java
mdr/src/org/netbeans/mdr/util/IOUtils.java
     1.1 --- a/mdr/src/org/netbeans/mdr/NBMDRepositoryImpl.java	Sun Jun 29 14:09:41 2003 +0000
     1.2 +++ b/mdr/src/org/netbeans/mdr/NBMDRepositoryImpl.java	Sun Jun 29 19:24:08 2003 +0000
     1.3 @@ -105,14 +105,22 @@
     1.4       * </table>
     1.5       */
     1.6      public NBMDRepositoryImpl() {
     1.7 -        String storageClass = System.getProperty("org.netbeans.mdr.storagemodel.StorageFactoryClassName", "org.netbeans.mdr.persistence.btreeimpl.btreestorage.BtreeFactory");
     1.8 -        String storageFile = System.getProperty("org.netbeans.mdr.persistence.Dir");
     1.9 +        Properties props = System.getProperties();
    1.10 +        String storageClass = props.getProperty("org.netbeans.mdr.storagemodel.StorageFactoryClassName", "org.netbeans.mdr.persistence.btreeimpl.btreestorage.BtreeFactory");
    1.11 +        String storageFile = props.getProperty("org.netbeans.mdr.persistence.Dir");
    1.12          
    1.13          Logger.getDefault().log("Storage factory: " + storageClass);
    1.14          
    1.15          parameters = new HashMap();
    1.16          parameters.put("storage", storageClass);
    1.17          parameters.put(BtreeFactory.STORAGE_FILE_NAME, storageFile);
    1.18 +        
    1.19 +        for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
    1.20 +            String name = (String) e.nextElement();
    1.21 +            if (name.startsWith("MDRStorageProperty.")) {
    1.22 +                parameters.put(name.substring(19), props.getProperty(name));
    1.23 +            }
    1.24 +        }
    1.25          //        instances.add(this);
    1.26      }
    1.27      
     2.1 --- a/mdr/src/org/netbeans/mdr/persistence/memoryimpl/MultivaluedIndexImpl.java	Sun Jun 29 14:09:41 2003 +0000
     2.2 +++ b/mdr/src/org/netbeans/mdr/persistence/memoryimpl/MultivaluedIndexImpl.java	Sun Jun 29 19:24:08 2003 +0000
     2.3 @@ -154,7 +154,7 @@
     2.4              IOUtils.writeString(out, name);
     2.5              out.write(keyType.encode());
     2.6              out.write(valueType.encode());
     2.7 -            IOUtils.write(out, entries);
     2.8 +            Utils.write(out, entries, storage);
     2.9          } catch (java.io.IOException e) {
    2.10              throw new StorageIOException(e);
    2.11          }
    2.12 @@ -168,7 +168,7 @@
    2.13              name = IOUtils.readString(is);
    2.14              keyType = Storage.EntryType.decodeEntryType((byte) is.read());
    2.15              valueType = Storage.EntryType.decodeEntryType((byte) is.read());
    2.16 -            entries = (Map) IOUtils.read(is);
    2.17 +            entries = (Map) Utils.read(is, storage);
    2.18          } catch (java.io.IOException e) {
    2.19              throw new StorageIOException(e);
    2.20          }
     3.1 --- a/mdr/src/org/netbeans/mdr/persistence/memoryimpl/SinglevaluedIndexImpl.java	Sun Jun 29 14:09:41 2003 +0000
     3.2 +++ b/mdr/src/org/netbeans/mdr/persistence/memoryimpl/SinglevaluedIndexImpl.java	Sun Jun 29 19:24:08 2003 +0000
     3.3 @@ -240,7 +240,7 @@
     3.4              IOUtils.writeString(out, name);
     3.5              out.write(keyType.encode());
     3.6              out.write(valueType.encode());
     3.7 -            IOUtils.write(out, table);
     3.8 +            Utils.write(out, table, storage);
     3.9          } catch (java.io.IOException e) {
    3.10              throw new StorageIOException(e);
    3.11          }
    3.12 @@ -254,7 +254,7 @@
    3.13              name = IOUtils.readString(is);
    3.14              keyType = Storage.EntryType.decodeEntryType((byte) is.read());
    3.15              valueType = Storage.EntryType.decodeEntryType((byte) is.read());
    3.16 -            table = (Map) IOUtils.read(is);
    3.17 +            table = (Map) Utils.read(is, storage);
    3.18          } catch (java.io.IOException e) {
    3.19              throw new StorageIOException(e);
    3.20          }
     4.1 --- a/mdr/src/org/netbeans/mdr/persistence/memoryimpl/StorageFactoryImpl.java	Sun Jun 29 14:09:41 2003 +0000
     4.2 +++ b/mdr/src/org/netbeans/mdr/persistence/memoryimpl/StorageFactoryImpl.java	Sun Jun 29 19:24:08 2003 +0000
     4.3 @@ -22,12 +22,14 @@
     4.4   * @version 
     4.5   */
     4.6  public class StorageFactoryImpl extends Object implements StorageFactory {
     4.7 -    public static final String STORAGE_NAME = "org.netbeans.mdr.persistence.memoryimpl.name";
     4.8 +    public static final String STORAGE_ID = "org.netbeans.mdr.persistence.memoryimpl.id";
     4.9 +    public static final String STORAGE_NAME = "org.netbeans.mdr.persistence.memoryimpl.fileName";
    4.10      static final String NULL_STORAGE_ID = ".";
    4.11      private static final MOFID NULL_MOFID = new MOFID(0, NULL_STORAGE_ID);
    4.12  
    4.13      private StorageImpl nullStorage; 
    4.14 -    private final HashMap storages = new HashMap();
    4.15 +    
    4.16 +    private static final HashMap storages = new HashMap();
    4.17  
    4.18      /** Creates new StorageFactoryImpl */
    4.19      public StorageFactoryImpl() {
    4.20 @@ -37,22 +39,39 @@
    4.21       * throws StorageException if the name is not valid name of a Storage
    4.22       */
    4.23      public synchronized Storage createStorage(Map properties) throws StorageException {
    4.24 -        String name = (String) properties.get(NULL_STORAGE_ID);  // Not mandatory
    4.25 +        String name = (String) properties.get(STORAGE_ID);  // Not mandatory
    4.26          if (name == null || name.equals(NULL_STORAGE_ID)) {
    4.27              if (nullStorage == null) {
    4.28 -                nullStorage = new StorageImpl(NULL_STORAGE_ID, false);
    4.29 +                nullStorage = new StorageImpl(NULL_STORAGE_ID, null);
    4.30              }
    4.31              return nullStorage;
    4.32          } else {
    4.33 -            Storage result = (Storage) storages.get(name);
    4.34 -            if (result == null) {
    4.35 -                result = new StorageImpl(NULL_STORAGE_ID, true);
    4.36 -                storages.put(name, result);
    4.37 +            synchronized (storages) {
    4.38 +                if (storages.containsKey(name)) {
    4.39 +                    throw new RuntimeException("Storage '" + name + "' already created.");
    4.40 +                } else {
    4.41 +                    Storage result = new StorageImpl(name, (String) properties.get(STORAGE_NAME));
    4.42 +                    storages.put(name, result);
    4.43 +                    return result;
    4.44 +                }                
    4.45              }
    4.46 -            return result;
    4.47          }
    4.48      }
    4.49      
    4.50 +    /** Serializes content of the given storage. Returns false if the storage was not found. 
    4.51 +     */
    4.52 +    public static boolean serialize(String storageId) throws StorageException {
    4.53 +        StorageImpl storage;
    4.54 +        synchronized (storages) {
    4.55 +            storage = (StorageImpl) storages.get(storageId);
    4.56 +        }
    4.57 +        if (storage == null) {
    4.58 +            return false;
    4.59 +        }
    4.60 +        storage.serialize();
    4.61 +        return true;
    4.62 +    }
    4.63 +    
    4.64      public org.netbeans.mdr.persistence.MOFID createNullMOFID() throws StorageException {
    4.65          return NULL_MOFID;
    4.66      }
     5.1 --- a/mdr/src/org/netbeans/mdr/persistence/memoryimpl/StorageImpl.java	Sun Jun 29 14:09:41 2003 +0000
     5.2 +++ b/mdr/src/org/netbeans/mdr/persistence/memoryimpl/StorageImpl.java	Sun Jun 29 19:24:08 2003 +0000
     5.3 @@ -34,10 +34,9 @@
     5.4  
     5.5      private final HashMap maps = new HashMap();
     5.6      private final String storageId;
     5.7 -    private final boolean persistent;
     5.8 +    private final String fileName;
     5.9      
    5.10      private PrimaryIndexImpl primaryIndex;
    5.11 -    private boolean saveOnClose = false;
    5.12      private int lastMofId = 0;
    5.13      
    5.14      // variables related to transaction support
    5.15 @@ -45,9 +44,9 @@
    5.16      private HashMap removedIndexes = new HashMap (); // maps names to indexes created before the current transaction and dropped during the transaction
    5.17      
    5.18      /** Creates new StorageImpl */
    5.19 -    public StorageImpl(String name, boolean persistent) {
    5.20 +    public StorageImpl(String name, String fileName) {
    5.21          this.storageId = name;
    5.22 -        this.persistent = persistent;
    5.23 +        this.fileName = fileName;
    5.24      }
    5.25      
    5.26      public void writeMOFID (OutputStream outputStream, MOFID mofid) throws StorageException {
    5.27 @@ -76,16 +75,11 @@
    5.28  
    5.29      // used to pre-boot the storage
    5.30      public synchronized void create(boolean replace, ObjectResolver resolver) throws StorageException {
    5.31 -        if (persistent) {
    5.32 +        if (fileName != null) {
    5.33              if (!replace && exists()) {
    5.34                  throw new StorageBadRequestException("Storage already exists");
    5.35              }
    5.36 -            try {
    5.37 -                new File(getName()).createNewFile();
    5.38 -            } catch (IOException e) {
    5.39 -                throw new StorageIOException(e);
    5.40 -            }
    5.41 -            saveOnClose = true;
    5.42 +            new File(getName()).delete();
    5.43          }
    5.44          createPrimaryIndex();
    5.45      }
    5.46 @@ -99,7 +93,7 @@
    5.47      }
    5.48      
    5.49      public String getName() {
    5.50 -        return this.storageId;
    5.51 +        return this.fileName + ".mem";
    5.52      }
    5.53      
    5.54      public String getStorageId() {
    5.55 @@ -117,21 +111,18 @@
    5.56      public synchronized void open(boolean createOnNoExist, ObjectResolver resolver) throws StorageException {
    5.57  //        Logger.getDefault().log("Reading storage from XML document ...");
    5.58          createPrimaryIndex();
    5.59 -        if (this.persistent) {
    5.60 +        if (fileName != null) {
    5.61              try {
    5.62 -                if (!exists()) {
    5.63 -                    if (createOnNoExist) {
    5.64 -                        new File(getName()).createNewFile();
    5.65 -                        saveOnClose = true;
    5.66 -                        return;
    5.67 -                    } else {
    5.68 -                        throw new StorageBadRequestException("Storage " + getName() + " does not exist.");
    5.69 -                    }
    5.70 +                if (!exists() && !createOnNoExist) {
    5.71 +                    throw new StorageBadRequestException("Storage " + getName() + " does not exist.");
    5.72                  }
    5.73  
    5.74                  InputStream is = new BufferedInputStream(new FileInputStream(getName()));
    5.75                  lastMofId = IOUtils.readInt(is);
    5.76 -                primaryIndex = new PrimaryIndexImpl(this);
    5.77 +                String id = IOUtils.readString(is);
    5.78 +                if (!storageId.equals(id)) {
    5.79 +                    throw new StoragePersistentDataException("Invalid storage id in the persistent file: " + id + " (expected: " + storageId + ")");
    5.80 +                }
    5.81                  primaryIndex.read(is);
    5.82                  int size = IOUtils.readInt(is);
    5.83                  for (int i = 0; i < size; i++) {
    5.84 @@ -153,6 +144,9 @@
    5.85                      maps.put(((Index) index).getName(), index);
    5.86                  }
    5.87              } catch ( java.io.IOException e ) {
    5.88 +                if (e instanceof java.io.FileNotFoundException && createOnNoExist) {
    5.89 +                    return;
    5.90 +                }
    5.91                  throw (StorageIOException) Logger.getDefault().annotate(new StorageIOException(e), e);
    5.92              }
    5.93          }
    5.94 @@ -191,33 +185,37 @@
    5.95          }
    5.96      }
    5.97      
    5.98 +    synchronized void serialize() throws StorageException {
    5.99 +        if (fileName == null) {
   5.100 +            throw new StorageBadRequestException("No storage file name specified");
   5.101 +        }
   5.102 +        try {
   5.103 +            OutputStream out = new BufferedOutputStream(new FileOutputStream(getName()));
   5.104 +            IOUtils.writeInt(out, lastMofId);
   5.105 +            IOUtils.writeString(out, storageId);
   5.106 +            primaryIndex.write(out);
   5.107 +            IOUtils.writeInt(out, maps.size());
   5.108 +            for (Iterator it = maps.values().iterator(); it.hasNext();){
   5.109 +                Index index = (Index) it.next();
   5.110 +                if (index instanceof SinglevaluedIndexImpl) {
   5.111 +                    out.write(INDEX_SINGLEVALUED);
   5.112 +                } else if (index instanceof MultivaluedOrderedIndexImpl) {
   5.113 +                    out.write(INDEX_ORDERED);
   5.114 +                } else if (index instanceof MultivaluedIndexImpl) {
   5.115 +                    out.write(INDEX_MULTIVALUED);
   5.116 +                } else {
   5.117 +                    throw new DebugException("Invalid index class: " + index.getClass().getName());
   5.118 +                }
   5.119 +                ((Streamable) index).write(out);
   5.120 +            }
   5.121 +            out.close();
   5.122 +        } catch (IOException e) {
   5.123 +            throw (StorageIOException) Logger.getDefault().annotate(new StorageIOException(e), e);
   5.124 +        }
   5.125 +    }
   5.126 +    
   5.127      public synchronized void shutDown() throws StorageException {
   5.128          commitChanges();
   5.129 -        if (this.saveOnClose) {
   5.130 -            try {
   5.131 -                OutputStream out = new BufferedOutputStream(new FileOutputStream(getName()));
   5.132 -                IOUtils.writeInt(out, lastMofId);
   5.133 -                primaryIndex.write(out);
   5.134 -                IOUtils.writeInt(out, maps.size());
   5.135 -                for (Iterator it = maps.values().iterator(); it.hasNext();){
   5.136 -                    Index index = (Index) it.next();
   5.137 -                    if (index instanceof SinglevaluedIndexImpl) {
   5.138 -                        out.write(INDEX_SINGLEVALUED);
   5.139 -                    } else if (index instanceof MultivaluedOrderedIndexImpl) {
   5.140 -                        out.write(INDEX_ORDERED);
   5.141 -                    } else if (index instanceof MultivaluedIndexImpl) {
   5.142 -                        out.write(INDEX_MULTIVALUED);
   5.143 -                    } else {
   5.144 -                        throw new DebugException("Invalid index class: " + index.getClass().getName());
   5.145 -                    }
   5.146 -//                    Logger.getDefault().log("Save index:" + index.getName());
   5.147 -                    ((Streamable) index).write(out);
   5.148 -                }
   5.149 -                out.close();
   5.150 -            } catch (IOException e) {
   5.151 -                throw (StorageIOException) Logger.getDefault().annotate(new StorageIOException(e), e);
   5.152 -            }
   5.153 -        }
   5.154      }
   5.155      
   5.156      public synchronized void commitChanges() throws StorageException {
   5.157 @@ -309,7 +307,7 @@
   5.158       */
   5.159      private void createPrimaryIndex() throws StorageException {
   5.160          this.primaryIndex = new PrimaryIndexImpl(this);
   5.161 -        addIndex(PRIMARY_INDEX_NAME, this.primaryIndex);
   5.162 +        //addIndex(PRIMARY_INDEX_NAME, this.primaryIndex);
   5.163      }
   5.164      
   5.165      /** Retrieve index by name.
   5.166 @@ -319,5 +317,4 @@
   5.167      public synchronized Index getIndex(String name) throws StorageException {
   5.168          return (Index) maps.get(name);
   5.169      }
   5.170 -    
   5.171  }
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/mdr/src/org/netbeans/mdr/persistence/memoryimpl/Utils.java	Sun Jun 29 19:24:08 2003 +0000
     6.3 @@ -0,0 +1,89 @@
     6.4 +/*
     6.5 + *                 Sun Public License Notice
     6.6 + *
     6.7 + * The contents of this file are subject to the Sun Public License
     6.8 + * Version 1.0 (the "License"). You may not use this file except in
     6.9 + * compliance with the License. A copy of the License is available at
    6.10 + * http://www.sun.com/
    6.11 + *
    6.12 + * The Original Code is NetBeans. The Initial Developer of the Original
    6.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
    6.14 + * Microsystems, Inc. All Rights Reserved.
    6.15 + */
    6.16 +package org.netbeans.mdr.persistence.memoryimpl;
    6.17 +
    6.18 +import java.io.*;
    6.19 +import java.util.*;
    6.20 +import java.lang.reflect.Field;
    6.21 +
    6.22 +import javax.jmi.reflect.*;
    6.23 +
    6.24 +import org.netbeans.mdr.storagemodel.*;
    6.25 +import org.netbeans.mdr.persistence.MOFID;
    6.26 +import org.netbeans.mdr.persistence.Storage;
    6.27 +import org.netbeans.mdr.persistence.StorageException;
    6.28 +import org.netbeans.mdr.util.DebugException;
    6.29 +import org.netbeans.mdr.handlers.*;
    6.30 +import org.netbeans.mdr.util.IOUtils;
    6.31 +import org.openide.util.io.NbObjectInputStream;
    6.32 +
    6.33 +/**
    6.34 + *
    6.35 + * @author  mmatula
    6.36 + * @version
    6.37 + */
    6.38 +public class Utils extends Object {
    6.39 +    public static void write(OutputStream outputStream, Object object, Storage storage) throws IOException {
    6.40 +        if (object instanceof Map) {
    6.41 +            outputStream.write(IOUtils.T_MAP);
    6.42 +            Map temp = (Map) object;
    6.43 +            IOUtils.writeInt(outputStream, temp.size());
    6.44 +            Map.Entry key;
    6.45 +            for (Iterator it = temp.entrySet().iterator(); it.hasNext();) {
    6.46 +                key = (Map.Entry) it.next();
    6.47 +                write(outputStream, key.getKey(), storage);
    6.48 +                write(outputStream, key.getValue(), storage);
    6.49 +            }
    6.50 +        } else if (object instanceof Collection) {
    6.51 +            outputStream.write(IOUtils.T_COLLECTION);
    6.52 +            Collection col = (Collection) object;
    6.53 +            IOUtils.writeInt(outputStream, col.size());
    6.54 +            for (Iterator it = col.iterator(); it.hasNext();) {
    6.55 +                write(outputStream, it.next(), storage);
    6.56 +            }
    6.57 +        } else if (object instanceof MOFID) {
    6.58 +            outputStream.write(IOUtils.T_MOFID);
    6.59 +            IOUtils.writeMOFID(outputStream, (MOFID)object, storage);
    6.60 +        } else {
    6.61 +            IOUtils.write(outputStream, object);
    6.62 +        }
    6.63 +    }
    6.64 +    
    6.65 +    public static Object read(InputStream inputStream, Storage storage) throws IOException {
    6.66 +        int type = inputStream.read();
    6.67 +        switch (type) {
    6.68 +            case IOUtils.T_MAP: {
    6.69 +                int size = IOUtils.readInt(inputStream);
    6.70 +                Map result = new HashMap(size);
    6.71 +                for (int i = 0; i < size; i++) {
    6.72 +                    result.put(read(inputStream, storage), read(inputStream, storage));
    6.73 +                }
    6.74 +                return result;
    6.75 +            } 
    6.76 +            case IOUtils.T_COLLECTION: {
    6.77 +                int size = IOUtils.readInt(inputStream);
    6.78 +                java.util.List result = new java.util.ArrayList(size);
    6.79 +                for (int i = 0; i < size; i++) {
    6.80 +                    result.add(read(inputStream, storage));
    6.81 +                }
    6.82 +                return result;
    6.83 +            }
    6.84 +            case IOUtils.T_MOFID: {
    6.85 +                return IOUtils.readMOFID(inputStream, storage);
    6.86 +            } 
    6.87 +            default: {
    6.88 +                return IOUtils.read(inputStream, null, null, type);
    6.89 +            }
    6.90 +        }
    6.91 +    }
    6.92 +}
     7.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/MdrStorage.java	Sun Jun 29 14:09:41 2003 +0000
     7.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/MdrStorage.java	Sun Jun 29 19:24:08 2003 +0000
     7.3 @@ -73,6 +73,9 @@
     7.4      /** instances of MdrStorage by storage ID */
     7.5      private static final Hashtable instances = new Hashtable();
     7.6      
     7.7 +//    private static MdrStorage currentMdrStorage = null;
     7.8 +//    private static Storage currentStorage = null;
     7.9 +    
    7.10      /* -------------------------------------------------------------------- */
    7.11      /* -- Static methods -------------------------------------------------- */
    7.12      /* -------------------------------------------------------------------- */
    7.13 @@ -82,7 +85,9 @@
    7.14       * @return <code>MdrStorage</code> wrapping <code>storage</code>
    7.15       */
    7.16      public static MdrStorage getInstance(Storage storage) {
    7.17 -        return (MdrStorage) instances.get(storage);
    7.18 +        MdrStorage result = (MdrStorage) instances.get(storage);
    7.19 +//        if (result == null) result = currentMdrStorage;
    7.20 +        return result;
    7.21      }
    7.22      
    7.23      /* -------------------------------------------------------------------- */
    7.24 @@ -394,21 +399,28 @@
    7.25          String storageId = null;
    7.26          try {
    7.27              // try to open the storage (if open fails, exception is thrown and program continues in catch block
    7.28 -            storage.open(false, this);
    7.29 +//            currentMdrStorage = this;
    7.30 +//            currentStorage = storage;
    7.31 +            storage.open(true, this);
    7.32 +//            currentStorage = null;
    7.33 +//            currentMdrStorage = null;
    7.34              storageId = storage.getStorageId();
    7.35              // read indexes
    7.36              initializeIndexes(storage, defaultStorage, false);
    7.37              // everything succeeded -> return true
    7.38              result = true;
    7.39          } catch (Exception e) {
    7.40 -            Logger.getDefault().notify(Logger.INFORMATIONAL - 1, e);
    7.41 +            if (e instanceof StorageException) {
    7.42 +                Logger.getDefault().notify(Logger.INFORMATIONAL, e);
    7.43 +            }
    7.44 +            Logger.getDefault().log("Rebooting storage. Reason: " + e);
    7.45              // storage not found or corrupted -> create new one
    7.46              try {
    7.47                  // in case the storage is already open, try to close it
    7.48                  storage.close();
    7.49              } catch (StorageException ex) {
    7.50              }
    7.51 -            
    7.52 +
    7.53              // create a new storage
    7.54              storage.create(true, this);
    7.55              storageId = storage.getStorageId();
    7.56 @@ -446,34 +458,38 @@
    7.57       * @throws DebugExceptions if any of the global indices was not found or
    7.58       *
    7.59       */
    7.60 -    private void initializeIndexes(Storage storage, boolean defaultStorage, boolean rollBack) throws StorageException {
    7.61 -        // get the primary index
    7.62 -        String storageId = storage.getStorageId();
    7.63 -        SinglevaluedIndex objectsIndex = storage.getPrimaryIndex();
    7.64 -        MultivaluedIndex objByClsIndex = storage.getMultivaluedIndex(IDX_OBJECTS_BY_CLASSES);
    7.65 -        SinglevaluedIndex contextsIndex = storage.getSinglevaluedIndex(IDX_CONTEXTS + STORAGE_VERSION);
    7.66 -        if (objByClsIndex==null || objectsIndex==null || contextsIndex==null) {
    7.67 -            throw new DebugException("Different storage version.");
    7.68 +    private void initializeIndexes(Storage storage, boolean defaultStorage, boolean rollBack) {
    7.69 +        try {
    7.70 +            // get the primary index
    7.71 +            String storageId = storage.getStorageId();
    7.72 +            SinglevaluedIndex objectsIndex = storage.getPrimaryIndex();
    7.73 +            MultivaluedIndex objByClsIndex = storage.getMultivaluedIndex(IDX_OBJECTS_BY_CLASSES);
    7.74 +            SinglevaluedIndex contextsIndex = storage.getSinglevaluedIndex(IDX_CONTEXTS + STORAGE_VERSION);
    7.75 +            if (objByClsIndex==null || objectsIndex==null || contextsIndex==null) {
    7.76 +                throw new DebugException("Missing storage files or different storage version.");
    7.77 +            }
    7.78 +            if (!defaultStorage && !rollBack && !silent) {
    7.79 +                // Fire events for adding all extents
    7.80 +                for (Iterator it = contextsIndex.keySet().iterator(); it.hasNext();) {
    7.81 +                    String extentName = (String) it.next();
    7.82 +                    org.netbeans.api.mdr.events.ExtentEvent event = new org.netbeans.api.mdr.events.ExtentEvent(this.repository,
    7.83 +                    org.netbeans.api.mdr.events.ExtentEvent.EVENT_EXTENT_CREATE, extentName,
    7.84 +                    null, null,false);
    7.85 +                    this.getEventNotifier().REPOSITORY.firePlannedChange(this, event);
    7.86 +                }
    7.87 +            }
    7.88 +            this.objects.put(storageId, objectsIndex);
    7.89 +            this.contexts.put(storageId, contextsIndex);
    7.90 +            this.objByCls.put(storageId, objByClsIndex);
    7.91 +            SinglevaluedIndex props = storage.getSinglevaluedIndex(IDX_MDR_STORAGE_PROPERTIES);
    7.92 +            if (props == null) {
    7.93 +                throw new DebugException("Different storage version.");
    7.94 +            }
    7.95 +            this.properties.put(storageId, props);
    7.96 +            this.valuesObjects.put(storageId, objectsIndex.get(props.get(VALUES_ID)));
    7.97 +        } catch (StorageException e) {
    7.98 +            throw new DebugException("Missing storage files or different storage version.");
    7.99          }
   7.100 -        if (!defaultStorage && !rollBack && !silent) {
   7.101 -            // Fire events for adding all extents
   7.102 -            for (Iterator it = contextsIndex.keySet().iterator(); it.hasNext();) {
   7.103 -                String extentName = (String) it.next();
   7.104 -                org.netbeans.api.mdr.events.ExtentEvent event = new org.netbeans.api.mdr.events.ExtentEvent(this.repository,
   7.105 -                org.netbeans.api.mdr.events.ExtentEvent.EVENT_EXTENT_CREATE, extentName,
   7.106 -                null, null,false);
   7.107 -                this.getEventNotifier().REPOSITORY.firePlannedChange(this, event);
   7.108 -            }
   7.109 -        }
   7.110 -        this.objects.put(storageId, objectsIndex);
   7.111 -        this.contexts.put(storageId, contextsIndex);
   7.112 -        this.objByCls.put(storageId, objByClsIndex);
   7.113 -        SinglevaluedIndex props = storage.getSinglevaluedIndex(IDX_MDR_STORAGE_PROPERTIES);
   7.114 -        if (props == null) {
   7.115 -            throw new DebugException("Different storage version.");
   7.116 -        }
   7.117 -        this.properties.put(storageId, props);
   7.118 -        this.valuesObjects.put(storageId, objectsIndex.get(props.get(VALUES_ID)));
   7.119      }
   7.120      
   7.121      /* -------------------------------------------------------------------- */
   7.122 @@ -1510,7 +1526,9 @@
   7.123          if (storageId == null) {
   7.124              return null;
   7.125          }
   7.126 -        return (Storage) this.storages.get(storageId);
   7.127 +        Storage result = (Storage) this.storages.get(storageId);
   7.128 +//        if (result == null) result = currentStorage;
   7.129 +        return result;
   7.130      }
   7.131      
   7.132      private SinglevaluedIndex getObjectsIndexByMofId (org.netbeans.mdr.persistence.MOFID mofId) {
   7.133 @@ -1518,7 +1536,16 @@
   7.134          if (storageId == null) {
   7.135              return null;
   7.136          }
   7.137 -        return (SinglevaluedIndex) this.objects.get(storageId);
   7.138 +        SinglevaluedIndex result = (SinglevaluedIndex) this.objects.get(storageId);
   7.139 +        if (result == null) {
   7.140 +            Storage s = getStorageById(mofId.getStorageID());
   7.141 +            if (s != null) try {
   7.142 +                result = s.getPrimaryIndex();
   7.143 +            } catch (StorageException e) {
   7.144 +                result = null;
   7.145 +            }
   7.146 +        }
   7.147 +        return result;
   7.148      }
   7.149      
   7.150      private MultivaluedIndex getObjectsByClassesByMofId (org.netbeans.mdr.persistence.MOFID mofId) {
     8.1 --- a/mdr/src/org/netbeans/mdr/util/IOUtils.java	Sun Jun 29 14:09:41 2003 +0000
     8.2 +++ b/mdr/src/org/netbeans/mdr/util/IOUtils.java	Sun Jun 29 19:24:08 2003 +0000
     8.3 @@ -33,30 +33,30 @@
     8.4   */
     8.5  public class IOUtils extends Object {
     8.6      
     8.7 -    private static final int T_NULL = 0;
     8.8 -    private static final int T_STRING = 1;
     8.9 -    private static final int T_BOOLEAN = 2;
    8.10 -    private static final int T_MAP = 3;
    8.11 -    private static final int T_INTEGER = 4;
    8.12 -    private static final int T_COLLECTION = 5;
    8.13 -    private static final int T_STRUCT = 6;
    8.14 -    private static final int T_ENUM = 7;
    8.15 -    //    private static final int T_SERIALIZABLE = 8;
    8.16 -    private static final int T_MOF_REFERENCE = 10;
    8.17 -    private static final int T_LIST_IMMUTABLE = 11;
    8.18 -    private static final int T_LIST_MUTABLE = 12;
    8.19 -    private static final int T_LIST_U_IMMUTABLE = 13;
    8.20 -    private static final int T_LIST_U_MUTABLE = 14;
    8.21 -    private static final int T_COLL_U_MUTABLE = 15;
    8.22 -    private static final int T_COLL_MUTABLE = 16;
    8.23 -    private static final int T_CLASS = 17;
    8.24 -    private static final int T_FLOAT = 18;
    8.25 -    private static final int T_DOUBLE = 19;
    8.26 -    private static final int T_OBJECT = 20;
    8.27 -    private static final int T_LONG = 21;
    8.28 +    public static final int T_NULL = 0;
    8.29 +    public static final int T_STRING = 1;
    8.30 +    public static final int T_BOOLEAN = 2;
    8.31 +    public static final int T_MAP = 3;
    8.32 +    public static final int T_INTEGER = 4;
    8.33 +    public static final int T_COLLECTION = 5;
    8.34 +    public static final int T_STRUCT = 6;
    8.35 +    public static final int T_ENUM = 7;
    8.36 +    //    public static final int T_SERIALIZABLE = 8;
    8.37 +    public static final int T_MOF_REFERENCE = 10;
    8.38 +    public static final int T_LIST_IMMUTABLE = 11;
    8.39 +    public static final int T_LIST_MUTABLE = 12;
    8.40 +    public static final int T_LIST_U_IMMUTABLE = 13;
    8.41 +    public static final int T_LIST_U_MUTABLE = 14;
    8.42 +    public static final int T_COLL_U_MUTABLE = 15;
    8.43 +    public static final int T_COLL_MUTABLE = 16;
    8.44 +    public static final int T_CLASS = 17;
    8.45 +    public static final int T_FLOAT = 18;
    8.46 +    public static final int T_DOUBLE = 19;
    8.47 +    public static final int T_OBJECT = 20;
    8.48 +    public static final int T_LONG = 21;
    8.49      
    8.50 -    private static final int T_SHORT = 22;
    8.51 -    private static final int T_MOFID = 23;
    8.52 +    public static final int T_SHORT = 22;
    8.53 +    public static final int T_MOFID = 23;
    8.54      
    8.55      /** Creates new IOUtils */
    8.56      public IOUtils() {
    8.57 @@ -175,13 +175,12 @@
    8.58              outputStream.write(T_MAP);
    8.59              Map temp = (Map) object;
    8.60              writeInt(outputStream, temp.size());
    8.61 -            Object key;
    8.62 -            for (Iterator it = temp.keySet().iterator(); it.hasNext();) {
    8.63 -                key = it.next();
    8.64 -                write(outputStream, key, storable);
    8.65 -                write(outputStream, temp.get(key), storable);
    8.66 +            Map.Entry key;
    8.67 +            for (Iterator it = temp.entrySet().iterator(); it.hasNext();) {
    8.68 +                key = (Map.Entry) it.next();
    8.69 +                write(outputStream, key.getKey(), storable);
    8.70 +                write(outputStream, key.getValue(), storable);
    8.71              }
    8.72 -            
    8.73          } else if (object instanceof AttrCollection) {
    8.74              if (object instanceof AttrUList) {
    8.75                  outputStream.write(T_LIST_U_MUTABLE);
    8.76 @@ -195,8 +194,7 @@
    8.77              ((AttrCollection) object).write(outputStream);
    8.78              
    8.79          } else if (object instanceof AttrImmutList) {
    8.80 -            MdrStorage storage = storable.getMdrStorage();
    8.81 -            if (storage == null) Logger.getDefault().notify(Logger.INFORMATIONAL, new DebugException());
    8.82 +            if (storable == null) Logger.getDefault().notify(Logger.INFORMATIONAL, new DebugException());
    8.83              if (object instanceof AttrImmutUList) {
    8.84                  outputStream.write(T_LIST_U_IMMUTABLE);
    8.85              } else {
    8.86 @@ -373,10 +371,12 @@
    8.87          }
    8.88      }
    8.89      
    8.90 -    
    8.91 -    
    8.92      public static Object read(InputStream inputStream, StorableBaseObject storable, String className) throws IOException {
    8.93          int type = inputStream.read();
    8.94 +        return read(inputStream, storable, className, type);
    8.95 +    }
    8.96 +    
    8.97 +    public static Object read(InputStream inputStream, StorableBaseObject storable, String className, int type) throws IOException {
    8.98          switch (type) {
    8.99              case T_NULL:
   8.100                  return null;