Changeset 5132


Ignore:
Timestamp:
Oct 14, 2009, 1:55:03 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1404: Use cached annotations in "item overview"

This should fix the ticket. But there are so many different error-handling cases to test that I want to keep it open a bit more...

Location:
trunk
Files:
7 edited

Legend:

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

    r5131 r5132  
    6767    @param a A specific annotation, or null to match any annotation
    6868  */
    69   public void setAnnotationType(Annotation a)
     69  public void setAnnotation(Annotation a)
    7070  {
    7171    this.annotationId = a == null ? 0 : a.getId();
  • trunk/src/core/net/sf/basedb/util/overview/GenericOverview.java

    r5076 r5132  
    3535import net.sf.basedb.core.query.Order;
    3636import net.sf.basedb.core.query.Orders;
     37import net.sf.basedb.core.snapshot.SnapshotManager;
    3738import net.sf.basedb.util.overview.cache.NodeCache;
    3839import net.sf.basedb.util.overview.loader.NodeLoader;
     
    9293  private final Project project;
    9394  private final BasicItem rootItem;
     95  private final SnapshotManager snapshotManager;
    9496  private Node rootNode;
    9597  private Map<String, Node> allNodes;
     
    114116    this.rootItem = rootItem;
    115117    this.project = project;
     118    this.snapshotManager = new SnapshotManager();
    116119    reset(dc);
    117120  }
     
    137140  {
    138141    return nodeValidatorFactory;
     142  }
     143
     144  /**
     145    Get the current snapshot manager.
     146    @since 2.14
     147  */
     148  @Override
     149  public SnapshotManager getSnapshotManager()
     150  {
     151    return snapshotManager;
    139152  }
    140153
  • trunk/src/core/net/sf/basedb/util/overview/Node.java

    r4789 r5132  
    2222package net.sf.basedb.util.overview;
    2323
     24import java.util.Collections;
     25import java.util.Comparator;
    2426import java.util.LinkedList;
    2527import java.util.List;
     
    5153*/
    5254public class Node
     55  implements Comparable<Node>
    5356{
    5457  private final String name;
     
    310313 
    311314  /**
     315    Sorts the list of child nodes.
     316    @param comparator A comparator that determines the sort order,
     317      if not specifed, they children are sorted according to their
     318      title
     319    @since 2.14
     320   */
     321  public void sortChildren(Comparator<? super Node> comparator)
     322  {
     323    if (children == null) return;
     324    Collections.sort(children, comparator);
     325  }
     326 
     327  /**
    312328    Sets a flag to indicate that all children has been loaded.
    313329    @since 2.10
     
    495511  }
    496512 
     513  @Override
     514  public int compareTo(Node o)
     515  {
     516    return title.compareTo(o.title);
     517  }
     518
     519 
    497520  public String toString()
    498521  {
  • trunk/src/core/net/sf/basedb/util/overview/OverviewContext.java

    r5076 r5132  
    2727import net.sf.basedb.core.Project;
    2828import net.sf.basedb.core.query.Order;
     29import net.sf.basedb.core.snapshot.SnapshotManager;
    2930import net.sf.basedb.util.overview.cache.NodeCache;
    3031import net.sf.basedb.util.overview.loader.NodeLoader;
     
    6061  public NodeValidatorFactory getNodeValidatorFactory();
    6162
     63  /**
     64    Get the snapshot manager that is used to load annotation
     65    values.
     66    @since 2.14
     67  */
     68  public SnapshotManager getSnapshotManager();
     69 
    6270  /**
    6371    Get the project the overview is using as the "current" project.
  • trunk/src/core/net/sf/basedb/util/overview/loader/AnnotationLoader.java

    r5014 r5132  
    2222package net.sf.basedb.util.overview.loader;
    2323
     24import java.util.List;
     25
    2426import net.sf.basedb.core.Annotatable;
    2527import net.sf.basedb.core.Annotation;
     
    2729import net.sf.basedb.core.DbControl;
    2830import net.sf.basedb.core.Item;
    29 import net.sf.basedb.core.ItemQuery;
    30 import net.sf.basedb.core.ItemResultIterator;
    3131import net.sf.basedb.core.PermissionDeniedException;
    3232import net.sf.basedb.core.Protocol;
    33 import net.sf.basedb.core.query.Hql;
    34 import net.sf.basedb.core.query.Orders;
     33import net.sf.basedb.core.snapshot.AnnotationSnapshot;
     34import net.sf.basedb.core.snapshot.SnapshotManager;
    3535import net.sf.basedb.util.overview.OverviewContext;
    3636import net.sf.basedb.util.overview.node.AnnotationNameGenerator;
     
    8282      folderNode = new Node("annotations", "Annotations", parentNode, ChildNodeDirection.NONE);
    8383      AnnotationSet as = parent.getAnnotationSet();
    84      
    85       // Primary annotations
    86       ItemQuery<Annotation> query = context.initQuery(as.getAnnotations(), "annotationType.name");
    87       ItemResultIterator<Annotation> it = query.iterate(dc);
    88       while (it.hasNext())
     84      SnapshotManager snapshotManager = context.getSnapshotManager();
     85           
     86      List<AnnotationSnapshot> all = snapshotManager.findAnnotations(dc, parent, null, true);
     87      for (AnnotationSnapshot a : all)
    8988      {
    90         Annotation a = it.next();
    91              
     89        Annotation ann = a.getAnnotation(dc);
    9290        // Annotations that are protocol parameters are handled by ProtocolParameterLoader       
    93         if (protocol != null && protocol.isParameter(a))
     91        if (!a.isInherited() && protocol != null && protocol.isParameter(ann))
    9492        {
    9593          /* #### CONTINUE-STATEMENT #### */
    9694          continue;       
    9795        }
    98         createItemNode(nf, a, null, false, folderNode, ChildNodeDirection.NONE);
     96        createItemNode(nf, ann, null, false, folderNode, ChildNodeDirection.NONE);
    9997      }
    100      
    101       // Inherited annotations
    102       query = context.initQuery(as.getAllInheritedAnnotations(),
    103           Orders.asc(Hql.property("at", "name")));
    104       query.join(Hql.innerJoin(null, "annotationType", "at", true));
    105       it = query.iterate(dc);
    106       while (it.hasNext())
    107       {
    108         Annotation a = it.next();
    109         createItemNode(nf, a, null, false, folderNode, ChildNodeDirection.NONE);
    110       }
     98      folderNode.sortChildren(null);
    11199    }
    112100    postValidateFolder(nf, folderNode, parentNode, false);
  • trunk/src/core/net/sf/basedb/util/overview/validator/AnnotationValidator.java

    r4823 r5132  
    2828import net.sf.basedb.core.Annotatable;
    2929import net.sf.basedb.core.Annotation;
    30 import net.sf.basedb.core.AnnotationSet;
    3130import net.sf.basedb.core.AnnotationType;
    3231import net.sf.basedb.core.BasicItem;
     
    3837import net.sf.basedb.core.ItemResultIterator;
    3938import net.sf.basedb.core.PermissionDeniedException;
     39import net.sf.basedb.core.snapshot.AnnotationFilter;
     40import net.sf.basedb.core.snapshot.AnnotationSnapshot;
     41import net.sf.basedb.core.snapshot.SnapshotManager;
    4042import net.sf.basedb.util.overview.Fix;
    4143import net.sf.basedb.util.overview.OverviewContext;
     
    8587    Annotatable parent = (Annotatable)parentNode.getItem(dc);
    8688    Item parentItemType = parentNode.getItemType();
    87     AnnotationSet annotationSet = parent.getAnnotationSet();
    8889   
    8990    Annotation a = (Annotation)node.getItem();
    90     boolean isPrimary = a.belongsTo(annotationSet);
     91    SnapshotManager manager = context.getSnapshotManager();
     92    // The primary use of the snapshot is to load the values if the annotation is a primary annotation
     93    // Thus, we do not search inherited annotations
     94    List<AnnotationSnapshot> snapshots = manager.findAnnotations(dc, parent, new AnnotationFilter(a), false);
     95    AnnotationSnapshot snapshot = snapshots.size() > 0 ? snapshots.get(0) : null;
     96    boolean isPrimary = snapshot != null && !snapshot.isInherited();
    9197
    9298    AnnotationType at = null;
     
    120126        try
    121127        {
    122           List<?> values = a.getValues();
     128          List<?> values = snapshot.getValues();
    123129          if (values != null)
    124130          {
  • trunk/www/common/overview/info.jsp

    r5104 r5132  
    3131  import="net.sf.basedb.core.AnnotationType"
    3232  import="net.sf.basedb.core.Annotation"
     33  import="net.sf.basedb.core.Protocol"
    3334  import="net.sf.basedb.core.FileStoreEnabled"
    3435  import="net.sf.basedb.core.FileSetMember"
     
    3940  import="net.sf.basedb.core.PermissionDeniedException"
    4041  import="net.sf.basedb.core.ItemNotFoundException"
     42  import="net.sf.basedb.core.snapshot.SnapshotManager"
     43  import="net.sf.basedb.core.snapshot.AnnotationSetSnapshot"
     44  import="net.sf.basedb.core.snapshot.AnnotationSnapshot"
     45  import="net.sf.basedb.core.snapshot.AnnotationTypeFilter"
     46  import="net.sf.basedb.core.snapshot.AnnotationFilter"
    4147  import="net.sf.basedb.clients.web.Base"
    4248  import="net.sf.basedb.clients.web.util.HTML"
     
    9298try
    9399{
    94   GenericOverview overview = OverviewUtil.getCurrentOverview(sc);
     100  final GenericOverview overview = OverviewUtil.getCurrentOverview(sc);
     101  final SnapshotManager snapshotManager = overview.getSnapshotManager();
     102  final AnnotationTypeFilter annotationTypeFilter = new AnnotationTypeFilter();
     103  final AnnotationFilter annotationFilter = new AnnotationFilter();
    95104  ValidationOptions options = overview.getValidationOptions();
    96105  String nodeId = request.getParameter("nodeId");
     
    278287     
    279288      <%
    280       List<Annotation> annotations = null;
     289      List<AnnotationSnapshot> annotations = new LinkedList<AnnotationSnapshot>();
    281290      String annotationsTitle = "";
    282291      Annotatable annotatable = null;
     
    285294        Annotation a = (Annotation)item;
    286295        dc.reattachItem(a, false);
    287         annotations = Collections.singletonList(a);
    288         try
    289         {
    290           annotatable = a.getAnnotationSet().getItem();
    291         }
    292         catch (Throwable t)
    293         {}
     296        AnnotationSetSnapshot snapshot = snapshotManager.getSnapshot(dc, a.getAnnotationSet().getId());
     297        annotationFilter.setAnnotationType(a);
     298        annotations.addAll(snapshotManager.findAnnotations(dc, snapshot, annotationFilter, true));
     299       
     300        // Find the annotatable parent node
     301        Node parentNode = node;
     302        while (parentNode != null)
     303        {
     304          BasicItem parentItem = parentNode.getItem();
     305          if (parentItem instanceof Annotatable)
     306          {
     307            annotatable = (Annotatable)parentItem;
     308            break;
     309          }
     310          parentNode = parentNode.getParent();
     311        }
    294312        annotationsTitle = "Annotation values";
    295313      }
     
    301319        {
    302320          BasicItem parentItem = parentNode.getItem();
    303           if (parentItem instanceof Annotatable)
     321          if (parentItem instanceof Annotatable && !(parentItem instanceof Protocol))
    304322          {
    305323            annotatable = (Annotatable)parentItem;
     
    307325            if (annotatable.isAnnotated())
    308326            {
    309               annotations = annotatable.getAnnotationSet().findAnnotations(dc, (AnnotationType)item, true);
     327              annotationTypeFilter.setAnnotationType((AnnotationType)item);
     328              annotations.addAll(snapshotManager.findAnnotations(dc, annotatable, annotationTypeFilter, true));
    310329            }
    311330            annotationsTitle = "Annotation values";
     
    322341        {
    323342          dc.reattachItem((BasicItem)annotatable, false);
    324  
    325           // Load annotations & protocol parameters
    326           List<Node> nodes = new LinkedList<Node>();
    327           Node folder = node.getChild("annotations");
    328           if (folder != null && folder.getChildren() != null) nodes.addAll(folder.getChildren());
    329           Node protocolNode = node.getChild("protocol");
    330           if (protocolNode != null && protocolNode.getChildren() != null) nodes.addAll(protocolNode.getChildren());
    331           if (nodes.size() > 0)
    332           {
    333             annotations = new LinkedList<Annotation>();
    334             for (Node n : nodes)
    335             {
    336               BasicItem aItem = n.getItem();
    337               if (aItem instanceof Annotation)
    338               {
    339                 annotations.add((Annotation)aItem);
    340               }
    341               else if (aItem instanceof AnnotationType)
    342               {
    343                 annotations.addAll(annotatable.getAnnotationSet().findAnnotations(dc, (AnnotationType)aItem, true));
    344               }
    345             }
    346           }
     343          annotations.addAll(snapshotManager.findAnnotations(dc, annotatable, null, true));
    347344        }
    348345      }
     
    353350        <table border=0 cellspacing=0 cellpadding=0>
    354351        <%
    355         for (Annotation a : annotations)
    356         {
    357           a = Annotation.getById(dc, a.getId());
     352        for (AnnotationSnapshot snapshot : annotations)
     353        {
     354          Annotation a = snapshot.getAnnotation(dc);
    358355          String unitSymbol = a.hasUnit() ? "&nbsp;" + a.getUnitSymbol(null) : "";
    359356          AnnotationType at = null;
     
    361358          try
    362359          {
    363             at = a.getAnnotationType();
     360            at = snapshot.getAnnotationType(dc);
    364361          }
    365362          catch (Throwable t)
     
    367364          try
    368365          {
    369             annotationOwner = a.getAnnotationSet().getItem();
     366            annotationOwner = snapshot.getItem(dc);
    370367          }
    371368          catch (Throwable t)
Note: See TracChangeset for help on using the changeset viewer.