optimization of storable properties (now there are 4 object slots so handlers do not need to use heavy weight map to store private info) BLD200210070100
authormmatula@netbeans.org
Sun, 06 Oct 2002 21:41:11 +0000
changeset 10695371ca0cfc02
parent 1068 4acb7ecd1266
child 1070 0d429dff88f4
optimization of storable properties (now there are 4 object slots so handlers do not need to use heavy weight map to store private info)
(increased version number of the storage as this changes the storage incompatibly)
mdr/src/org/netbeans/mdr/storagemodel/MdrStorage.java
mdr/src/org/netbeans/mdr/storagemodel/StorableBaseObject.java
mdr/src/org/netbeans/mdr/util/IOUtils.java
     1.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/MdrStorage.java	Fri Oct 04 19:55:30 2002 +0000
     1.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/MdrStorage.java	Sun Oct 06 21:41:11 2002 +0000
     1.3 @@ -49,7 +49,7 @@
     1.4      /* -- Private static constants ---------------------------------------- */
     1.5      /* -------------------------------------------------------------------- */
     1.6  
     1.7 -    private static final int STORAGE_VERSION = 16;
     1.8 +    private static final int STORAGE_VERSION = 17;
     1.9      
    1.10      // names of global storage indexes
    1.11      static final String IDX_OBJECTS_BY_CLASSES = "ObjectsByClasses";
     2.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/StorableBaseObject.java	Fri Oct 04 19:55:30 2002 +0000
     2.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/StorableBaseObject.java	Sun Oct 06 21:41:11 2002 +0000
     2.3 @@ -42,7 +42,14 @@
     2.4      // semaphore to avoid calls to "objectStateChanged" before the object is added to the primary index
     2.5      protected boolean initFinished;
     2.6      
     2.7 -    private Map handlerProperties;
     2.8 +    // slots for storing handler's private information
     2.9 +    private Object slot1 = null;
    2.10 +    private Object slot2 = null;
    2.11 +    private Object slot3 = null;
    2.12 +    private Object slot4 = null;
    2.13 +    private Map propertiesSlot = null;
    2.14 +    // number of used slots (to optimize storage)
    2.15 +    private int slotsCount = 0;
    2.16  
    2.17      /** Creates new StorableBaseObject.
    2.18       * This default constructor is to be called only when deserializing
    2.19 @@ -184,7 +191,14 @@
    2.20  //        if (id == null || meta == null || storageID == null || context == null) throw new NullPointerException();
    2.21          try {
    2.22              IOUtils.writeMOFID (outputStream, id,this.getMdrStorage(), this.id);
    2.23 -            IOUtils.write (outputStream, this.handlerProperties, this);
    2.24 +            outputStream.write(slotsCount);
    2.25 +            switch (slotsCount) {
    2.26 +                case 5: IOUtils.write(outputStream, this.propertiesSlot, this);
    2.27 +                case 4: IOUtils.write(outputStream, slot4, this);
    2.28 +                case 3: IOUtils.write(outputStream, slot3, this);
    2.29 +                case 2: IOUtils.write(outputStream, slot2, this);
    2.30 +                case 1: IOUtils.write(outputStream, slot1, this);
    2.31 +            }
    2.32          } catch (java.io.IOException e) {
    2.33              throw (DebugException) Logger.getDefault().annotate(new RuntimeException(), e);
    2.34          }
    2.35 @@ -196,7 +210,14 @@
    2.36      public void read (java.io.InputStream inputStream) {
    2.37          try {
    2.38              id = IOUtils.readMOFID (inputStream, storage);
    2.39 -            this.handlerProperties = (Map) IOUtils.read (inputStream, this, null);
    2.40 +            slotsCount = inputStream.read();
    2.41 +            switch (slotsCount) {
    2.42 +                case 5: this.propertiesSlot = (Map) IOUtils.read (inputStream, this, null);
    2.43 +                case 4: slot4 = IOUtils.read(inputStream, this, null);
    2.44 +                case 3: slot3 = IOUtils.read(inputStream, this, null);
    2.45 +                case 2: slot2 = IOUtils.read(inputStream, this, null);
    2.46 +                case 1: slot1 = IOUtils.read(inputStream, this, null);
    2.47 +            }
    2.48              outermostPackage = null; // not inited
    2.49          } catch (java.io.IOException e) {
    2.50              throw (DebugException) Logger.getDefault().annotate(new RuntimeException(), e);
    2.51 @@ -222,16 +243,18 @@
    2.52       *  or is not serializable by IOUtils.write method.
    2.53       */
    2.54      public void putProperty (Object key, Object value) {
    2.55 -        if (key == null || value == null || !IOUtils.checkObjectValidity (key) || !IOUtils.checkObjectValidity (value))
    2.56 +        // commented out - we cannot afford to do such an expensive checks
    2.57 +        if (key == null || value == null /* || !IOUtils.checkObjectValidity (key) || !IOUtils.checkObjectValidity (value)*/)
    2.58              throw new IllegalArgumentException ();
    2.59          this.objectWillChange();
    2.60 -        if (this.handlerProperties == null) {
    2.61 -            this.handlerProperties = new HashMap ();
    2.62 +        if (this.propertiesSlot == null) {
    2.63 +            this.propertiesSlot = new HashMap ();
    2.64 +            slotsCount = 5;
    2.65          }
    2.66          boolean failed = true;
    2.67          try {
    2.68              this.mdrStorage.getRepositoryMutex ().enter (true);
    2.69 -            this.handlerProperties.put (key, value);
    2.70 +            this.propertiesSlot.put (key, value);
    2.71              this.objectChanged ();
    2.72              failed = false;
    2.73          } finally {
    2.74 @@ -244,18 +267,18 @@
    2.75       *  @return associated value or null, if no value is associated with given key
    2.76       */
    2.77      public Object removeProperty (Object key) {
    2.78 -        if (this.handlerProperties == null)
    2.79 +        if (this.propertiesSlot == null)
    2.80              return null;
    2.81          boolean failed = true;
    2.82          try {
    2.83              this.mdrStorage.getRepositoryMutex ().enter (true);
    2.84              this.objectWillChange();
    2.85 -            Object result = this.handlerProperties.remove (key);
    2.86 +            Object result = this.propertiesSlot.remove (key);
    2.87              if (result != null) {
    2.88                  this.objectChanged ();
    2.89              }
    2.90 -            if (this.handlerProperties.size () == 0)
    2.91 -                this.handlerProperties = null;
    2.92 +            if (this.propertiesSlot.size () == 0)
    2.93 +                this.propertiesSlot = null;
    2.94              failed = false;
    2.95              return result;
    2.96          } finally {
    2.97 @@ -268,10 +291,62 @@
    2.98       *  @return associated value or null, if no value is associated with given key
    2.99       */
   2.100      public Object getProperty (Object key) {
   2.101 -        if (this.handlerProperties == null)
   2.102 +        if (this.propertiesSlot == null)
   2.103              return null;
   2.104          else
   2.105 -            return this.handlerProperties.get (key);
   2.106 +            return this.propertiesSlot.get (key);
   2.107 +    }
   2.108 +    
   2.109 +    public Object setSlot1(Object value) {
   2.110 +        Object result = slot1;
   2.111 +        objectWillChange();
   2.112 +        slot1 = value;
   2.113 +        if (slotsCount < 1) slotsCount = 1;
   2.114 +        objectChanged();
   2.115 +        return result;
   2.116 +    }
   2.117 +    
   2.118 +    public Object getSlot1() {
   2.119 +        return slot1;
   2.120 +    }
   2.121 +    
   2.122 +    public Object setSlot2(Object value) {
   2.123 +        Object result = slot2;
   2.124 +        objectWillChange();
   2.125 +        slot2 = value;
   2.126 +        if (slotsCount < 2) slotsCount = 2;
   2.127 +        objectChanged();
   2.128 +        return result;
   2.129 +    }
   2.130 +    
   2.131 +    public Object getSlot2() {
   2.132 +        return slot2;
   2.133 +    }
   2.134 +    
   2.135 +    public Object setSlot3(Object value) {
   2.136 +        Object result = slot3;
   2.137 +        objectWillChange();
   2.138 +        slot3 = value;
   2.139 +        if (slotsCount < 3) slotsCount = 3;
   2.140 +        objectChanged();
   2.141 +        return result;
   2.142 +    }
   2.143 +    
   2.144 +    public Object getSlot3() {
   2.145 +        return slot3;
   2.146 +    }
   2.147 +    
   2.148 +    public Object setSlot4(Object value) {
   2.149 +        Object result = slot4;
   2.150 +        objectWillChange();
   2.151 +        slot4 = value;
   2.152 +        if (slotsCount < 4) slotsCount = 4;
   2.153 +        objectChanged();
   2.154 +        return result;
   2.155 +    }
   2.156 +    
   2.157 +    public Object getSlot4() {
   2.158 +        return slot4;
   2.159      }
   2.160      
   2.161      /** Replaces MOFIDs using the passed map. (This method is used when rebuilding metaobjects.)
     3.1 --- a/mdr/src/org/netbeans/mdr/util/IOUtils.java	Fri Oct 04 19:55:30 2002 +0000
     3.2 +++ b/mdr/src/org/netbeans/mdr/util/IOUtils.java	Sun Oct 06 21:41:11 2002 +0000
     3.3 @@ -492,7 +492,8 @@
     3.4              }
     3.5          }
     3.6      }
     3.7 -    
     3.8 +
     3.9 +    /* commented out - we cannot affort to make such an expensive checks
    3.10      public static boolean checkObjectValidity(Object obj) {
    3.11          if (obj == null
    3.12          || obj instanceof String
    3.13 @@ -528,4 +529,5 @@
    3.14          }
    3.15          else return false;
    3.16      }
    3.17 +     */
    3.18  }