Changeset 5123


Ignore:
Timestamp:
Oct 9, 2009, 12:37:32 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1374: Caching of experimental factors

The 'Annotations & parameters' tab on single-item view pages is now using the cached snapshots as well. The main reason is that this will re-create the snapshot immediately after a change has been made and it should improve performance on pages that needs to list lots of annotations.

NOTE! This change also affect the change made in [5102] for ticket #1373 (due to be released in BASE 2.13.1). The changes are incompatible and changes for list_annotations.jsp that was made in 5102 SHOULD NOT be merged back to the trunk.

Location:
trunk
Files:
3 edited

Legend:

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

    r5120 r5123  
    3232import net.sf.basedb.core.DbControl;
    3333import net.sf.basedb.core.Item;
     34import net.sf.basedb.core.Type;
    3435import net.sf.basedb.core.data.AnnotationData;
    3536import net.sf.basedb.core.data.AnnotationSetData;
     37import net.sf.basedb.util.units.UnitConverter;
    3638
    3739/**
     
    197199 
    198200  /**
     201    Get the annotations values, optionally converted to some specific unit
     202    and type of values.
     203    @param converter A converter for converting (numerical) values,
     204      or null to not convert the values
     205    @param valueType The return type of the converted values (ignored if
     206      no converter is specified)
     207    @return A list with the values
     208  */
     209  public List<? extends Serializable> getValues(UnitConverter converter, Type valueType)
     210  {
     211    if (converter == null) return values;
     212    List<Serializable> convertedValues = new ArrayList<Serializable>(values.size());
     213    for (Serializable value : values)
     214    {
     215      if (value instanceof Number)
     216      {
     217        value = valueType.convertNumber(converter.convertToSpecificUnit(((Number)value).doubleValue()));
     218      }
     219      convertedValues.add(value);
     220    }
     221    return convertedValues;
     222  }
     223 
     224  /**
    199225    Get the id of the item this annotation belongs to. NOTE! this value
    200226    is only available on annotations returned from the call to:
  • trunk/src/core/net/sf/basedb/core/snapshot/SnapshotManager.java

    r5121 r5123  
    4848  private final Map<Integer, AnnotationSetSnapshot> snapshots;
    4949 
     50  /**
     51    The static cache key under which the snapshot for the
     52    annotation set with the given id is cached.
     53    @param annotationSetId The ID of an annotation set
     54  */
    5055  public static String getCacheKey(int annotationSetId)
    5156  {
     
    111116      exists for an inherited annotation set
    112117    @param snapshot The snapshot to search
    113     @param at The annotation type to look fo
     118    @param at The annotation type to look for, or null to return
     119      annotations of any type
    114120    @param searchInherited TRUE if inherited annotations should be searched,
    115121      FALSE to only search primary annotations
     
    120126  {
    121127    List<AnnotationSnapshot> result = new ArrayList<AnnotationSnapshot>();
    122     int id = at.getId();
     128    int id = at == null ? 0 : at.getId();
    123129    for (AnnotationSnapshot shot : snapshot.getAnnotations())
    124130    {
     
    146152      {
    147153        // Primary annotation
    148         if (shot.getAnnotationTypeId() == id)
     154        if (shot.getAnnotationTypeId() == id || id == 0)
    149155        {
    150156          shot.setItem(snapshot.getItemId(), snapshot.getItemType());
  • trunk/www/common/annotations/list_annotations.jsp

    r5074 r5123  
    4141  import="net.sf.basedb.core.query.Orders"
    4242  import="net.sf.basedb.core.query.Hql"
     43  import="net.sf.basedb.core.snapshot.AnnotationSetSnapshot"
     44  import="net.sf.basedb.core.snapshot.AnnotationSnapshot"
     45  import="net.sf.basedb.core.snapshot.SnapshotManager"
    4346  import="net.sf.basedb.clients.web.Base"
    4447  import="net.sf.basedb.clients.web.util.HTML"
     
    4851  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
    4952  import="net.sf.basedb.util.Values"
     53  import="java.util.ArrayList"
    5054  import="java.util.List"
    5155  import="java.util.Set"
     
    6872Set<AnnotationType> annotationTypes = null;
    6973Set<AnnotationType> protocolParameters = null;
    70 Map<AnnotationType, Annotation> existing = null;
     74Map<AnnotationType, AnnotationSnapshot> existing = null;
    7175
    7276try
     
    7478  final Annotatable item = (Annotatable)itemType.getById(dc, itemId);
    7579  final boolean writePermission = item.hasPermission(Permission.WRITE);
    76 
     80  final SnapshotManager manager = new SnapshotManager();
     81 
    7782  ItemQuery<AnnotationType> annotationTypeQuery = null;
    7883  String message = null;
     
    9398  annotationTypes.addAll(annotationTypeQuery.list(dc));
    9499
    95   final AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null;
    96   ItemResultList<Annotation> inheritedAnnotations = null;
    97   if (as != null)
    98   {
    99     // Load the existing annotations on the item
    100     existing = new HashMap<AnnotationType, Annotation>();
    101     List<Annotation> annotations = as.getAnnotations().list(dc);
    102     for (Annotation a : annotations)
     100  final AnnotationSetSnapshot snapshot = item.isAnnotated() ?
     101      manager.getSnapshot(dc, item.getAnnotationSet().getId()) : null;
     102  List<AnnotationSnapshot> inheritedAnnotations = null;
     103  if (snapshot != null)
     104  {
     105    // Load the existing primary and inherited annotations
     106    existing = new HashMap<AnnotationType, AnnotationSnapshot>();
     107    inheritedAnnotations = new ArrayList<AnnotationSnapshot>();
     108    for (AnnotationSnapshot a : manager.findAnnotations(dc, snapshot, null, true))
    103109    {
    104110      try
    105111      {
    106         existing.put(a.getAnnotationType(), a);
     112        AnnotationType at = a.getAnnotationType(dc);
     113        if (!a.isInherited())
     114        {
     115          existing.put(a.getAnnotationType(dc), a);
     116        }
     117        else
     118        {
     119          inheritedAnnotations.add(a);
     120        }
    107121      }
    108122      catch (PermissionDeniedException ex)
     
    110124    }
    111125    annotationTypes.addAll(existing.keySet());
    112    
    113     // Load inherited annotations
    114     ItemQuery<Annotation> inheritedQuery = as.getAllInheritedAnnotations();
    115     // Need FETCH JOIN because Postgres don't like the DISTINCT keyword
    116     // if we sort on a non-selected column See ticket #731
    117     inheritedQuery.join(Hql.innerJoin(null, "annotationType", "at", true));
    118     inheritedQuery.order(Orders.asc(Hql.property("annotationSet")));
    119     inheritedQuery.order(Orders.asc(Hql.property("at", "name")));
    120     inheritedAnnotations = inheritedQuery.list(dc);
    121126  }
    122127 
     
    202207              for (AnnotationType at : annotationTypes)
    203208              {
    204                 Annotation a = existing != null ? existing.get(at) : null;
     209                AnnotationSnapshot a = existing != null ? existing.get(at) : null;
    205210                List<?> values = null;
    206211                Formatter formatter = null;
    207212                if (a != null)
    208213                {
    209                   values = a.getValues(null);
    210                   formatter = FormatterFactory.getAnnotationFormatter(sc, a, null);
     214                  Annotation ann = a.getAnnotation(dc);
     215                  values = a.getValues(ann.getUnitConverter(null), ann.getValueType());
     216                  formatter = FormatterFactory.getAnnotationFormatter(sc, ann, null);
    211217                }
    212218                if (values != null || !at.isRemoved())
     
    286292                for (AnnotationType at : protocolParameters)
    287293                {
    288                   Annotation a = existing != null ? existing.get(at) : null;
     294                  AnnotationSnapshot a = existing != null ? existing.get(at) : null;
    289295                  Formatter formatter = null;
    290296                  List<?> values = null;
    291297                  if (a != null)
    292298                  {
    293                     values = a.getValues(null);
    294                     formatter = FormatterFactory.getAnnotationFormatter(sc, a, null);
     299                    Annotation ann = a.getAnnotation(dc);
     300                    values = a.getValues(ann.getUnitConverter(null), ann.getValueType());
     301                    formatter = FormatterFactory.getAnnotationFormatter(sc, ann, null);
    295302                  }
    296303                  if (values != null || !at.isRemoved())
     
    339346        <h4>Inherited annotations and protocol parameters</h4>
    340347        No annotations are inherited by this item.
     348        (or you don't have permission to view them).
    341349        <%
    342350      }
     
    374382              <tbl:rows>
    375383              <%
    376               String denied = "<i>- denied -</i>";
    377               for (Annotation a : inheritedAnnotations)
     384              for (AnnotationSnapshot a : inheritedAnnotations)
    378385              {
    379                 AnnotationType at = null;
    380                 int annotationTypeId = 0;
    381                 String name = denied;
    382                 String description = "";
     386                Annotation ann = a.getAnnotation(dc);
     387                AnnotationType at = a.getAnnotationType(dc);
     388                String name = HTML.encodeTags(at.getName());
     389                String description = HTML.encodeTags(at.getDescription());
    383390                boolean writeInherited = false;
    384391                String icon = "joust/annotation.gif";
    385                 Formatter formatter = FormatterFactory.getAnnotationFormatter(sc, a, null);
     392                if (at.isRemoved())
     393                {
     394                  icon = "deleted.gif";
     395                }
     396                else if (at.isProtocolParameter())
     397                {
     398                  icon = "parameter.gif";
     399                }
     400                List<?> values = a.getValues(ann.getUnitConverter(null), ann.getValueType());
     401                Formatter formatter = FormatterFactory.getAnnotationFormatter(sc, ann, null);
     402                Nameable aItem = null;
    386403                try
    387404                {
    388                   at = a.getAnnotationType();
    389                   annotationTypeId = at.getId();
    390                   name = HTML.encodeTags(at.getName());
    391                   if (at.isRemoved())
    392                   {
    393                     icon = "deleted.gif";
    394                   }
    395                   else if (at.isProtocolParameter())
    396                   {
    397                     icon = "parameter.gif";
    398                   }
    399                   description = HTML.encodeTags(at.getDescription());
     405                  aItem = (Nameable)a.getItem(dc);
     406                  writeInherited = aItem.hasPermission(Permission.WRITE);
    400407                }
    401408                catch (PermissionDeniedException ex)
    402409                {}
    403                 Nameable aItem = null;
    404                 try
    405                 {
    406                   aItem = (Nameable)a.getAnnotationSet().getItem();
    407                   writeInherited = aItem.hasPermission(Permission.WRITE);
    408                 }
    409                 catch (PermissionDeniedException ex)
    410                 {}
    411                 List<?> values = a.getValues(null);
    412410                %>
    413411                <tbl:row>
Note: See TracChangeset for help on using the changeset viewer.