Changeset 5124


Ignore:
Timestamp:
Oct 9, 2009, 1:20:25 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1374: Caching of experimental factors

Implements our own serialization code. The file sizes shrink considerably and so does the loading time. I hope we can get another factor 2 in loading time :). The important thing now is that we must remember to synchronize everything if the number/types of internal variables change in the future.

Location:
trunk/src/core/net/sf/basedb/core/snapshot
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/snapshot/AnnotationSetSnapshot.java

    r5120 r5124  
    2222package net.sf.basedb.core.snapshot;
    2323
     24import java.io.IOException;
    2425import java.io.Serializable;
    2526import java.util.ArrayList;
     
    5354  when an annotation has been modified. We only have to delete the file
    5455  that is associated with the primary annotation set.
     56  <p>
     57  <b>IMPORTANT NOTE TO DEVELOPERS!!</b>
     58  <p>
     59  Do not forget to synchronize all serialization code and to increment
     60  the {@link #FILE_VERSION} in case the number of variables that needs
     61  serialization in this class or in the {@link AnnotationSnapshot} changes.
    5562
    5663  @author Nicklas
     
    7279  public static final int FILE_VERSION = 1;
    7380 
    74   private long created;
    75   private int annotationSetId;
    76   private int itemId;
    77   private Item itemType;
    78   private List<AnnotationSnapshot> annotations;
     81  private transient long created;
     82  private transient int annotationSetId;
     83  private transient int itemId;
     84  private transient Item itemType;
     85  private transient List<AnnotationSnapshot> annotations;
    7986 
    8087  /**
     
    188195  }
    189196 
     197  private void writeObject(java.io.ObjectOutputStream out)
     198    throws IOException
     199   {
     200    out.writeLong(created);
     201    out.writeInt(annotationSetId);
     202    out.writeInt(itemId);
     203    out.writeInt(itemType.getValue());
     204    out.writeInt(annotations == null ? 0 : annotations.size());
     205    if (annotations != null)
     206    {
     207      for (AnnotationSnapshot tmp : annotations)
     208      {
     209        tmp.writeObject(out);
     210      }
     211    }
     212   }
     213  private void readObject(java.io.ObjectInputStream in)
     214    throws IOException, ClassNotFoundException
     215  {
     216    created = in.readLong();
     217    annotationSetId = in.readInt();
     218    itemId = in.readInt();
     219    itemType = Item.fromValue(in.readInt());
     220    int numAnnotations = in.readInt();
     221    annotations = new ArrayList<AnnotationSnapshot>(numAnnotations);
     222    for (int i = 0; i < numAnnotations; ++i)
     223    {
     224      AnnotationSnapshot tmp = new AnnotationSnapshot();
     225      tmp.readObject(in);
     226      annotations.add(tmp);
     227    }
     228  }
     229 
    190230}
  • trunk/src/core/net/sf/basedb/core/snapshot/AnnotationSnapshot.java

    r5123 r5124  
    2222package net.sf.basedb.core.snapshot;
    2323
     24import java.io.IOException;
    2425import java.io.Serializable;
    2526import java.util.ArrayList;
     
    4142  annotation or an inherited annotation set. Actual
    4243  annotation values are only stored for primary annotations.
     44  <p>
     45  <b>IMPORTANT NOTE TO DEVELOPERS!!</b>
     46  <p>
     47  Do not forget to synchronize all serialization code and to increment
     48  the {@link AnnotationSetSnapshot#FILE_VERSION} in case the number of variables
     49  that needs serialization in this class or in the {@link AnnotationSetSnapshot}
     50  changes.
    4351
    4452  @author Nicklas
     
    5260  private static final long serialVersionUID = -4919156087324273194L;
    5361
    54   private boolean inherited;
    55   private int annotationId;
    56   private int annotationSetId;
    57   private int annotationTypeId;
    58   private List<? extends Serializable> values;
     62  private transient boolean inherited;
     63  private transient int annotationId;
     64  private transient int annotationSetId;
     65  private transient int annotationTypeId;
     66  private transient List<? extends Serializable> values;
    5967  private transient int itemId;
    6068  private transient Item itemType;
     
    259267  }
    260268
     269  void writeObject(java.io.ObjectOutputStream out)
     270    throws IOException
     271  {
     272    out.writeBoolean(inherited);
     273    out.writeInt(annotationId);
     274    out.writeInt(annotationSetId);
     275    out.writeInt(annotationTypeId);
     276    out.writeInt(values == null ? 0 : values.size());
     277    if (values != null)
     278    {
     279      for (Serializable tmp : values)
     280      {
     281        out.writeObject(tmp);
     282      }
     283    }
     284  }
     285  void readObject(java.io.ObjectInputStream in)
     286    throws IOException, ClassNotFoundException
     287  {
     288    inherited = in.readBoolean();
     289    annotationId = in.readInt();
     290    annotationSetId = in.readInt();
     291    annotationTypeId = in.readInt();
     292    int numValues = in.readInt();
     293    if (numValues > 0)
     294    {
     295      List<Serializable> values = new ArrayList<Serializable>(numValues);
     296      for (int i = 0; i < numValues; ++i)
     297      {
     298        values.add((Serializable)in.readObject());
     299      }
     300      this.values = values;
     301    }
     302  }
     303 
    261304}
Note: See TracChangeset for help on using the changeset viewer.