Changeset 5131


Ignore:
Timestamp:
Oct 14, 2009, 9:44:14 AM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1374 and #1403: Caching of annotations, etc...

Made some changes to the API to make it more useful in other contexts. For example, the ability to find annotation snapshots by annotation id is needed by #1404.

Location:
trunk
Files:
2 added
4 edited

Legend:

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

    r5124 r5131  
    3636import net.sf.basedb.core.data.AnnotationData;
    3737import net.sf.basedb.core.data.AnnotationSetData;
     38import net.sf.basedb.util.filter.Filter;
    3839import net.sf.basedb.util.units.UnitConverter;
    3940
     
    197198    Get the annotation values. NOTE! The values are only available
    198199    for primary annotations and for inherited annotations returned by
    199     {@link SnapshotManager#findAnnotations(DbControl, AnnotationSetSnapshot, AnnotationType, boolean)}
     200    {@link SnapshotManager#findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean)}
    200201   
    201202    @return A list with the values
     
    233234    Get the id of the item this annotation belongs to. NOTE! this value
    234235    is only available on annotations returned from the call to:
    235     {@link SnapshotManager#findAnnotations(DbControl, AnnotationSetSnapshot, AnnotationType, boolean)}
     236    {@link SnapshotManager#findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean)}
    236237  */
    237238  public int getItemId()
     
    252253    Get the item type of the item this annotation belongs to.
    253254    NOTE! this value is only available on annotations returned from the call to:
    254     {@link SnapshotManager#findAnnotations(DbControl, AnnotationSetSnapshot, AnnotationType, boolean)}
     255    {@link SnapshotManager#findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean)}
    255256
    256257    @return The item type, or null if not known
  • trunk/src/core/net/sf/basedb/core/snapshot/SnapshotManager.java

    r5130 r5131  
    3030import net.sf.basedb.core.Annotatable;
    3131import net.sf.basedb.core.AnnotationSet;
    32 import net.sf.basedb.core.AnnotationType;
    3332import net.sf.basedb.core.Application;
    3433import net.sf.basedb.core.DbControl;
    3534import net.sf.basedb.util.StaticCache;
     35import net.sf.basedb.util.filter.Filter;
     36import net.sf.basedb.util.filter.StaticFilter;
    3637
    3738/**
     
    110111  }
    111112
     113
    112114  /**
    113115    Search in a snapshot for all annotations of a specified annotation type.
     
    118120      exists for an inherited annotation set
    119121    @param snapshot The snapshot to search
    120     @param at The annotation type to look for, or null to return
    121       annotations of any type
     122    @param filter A filter that should match the wanted annotation snapshots
     123      or null to match all annotations
    122124    @param searchInherited TRUE if inherited annotations should be searched,
    123125      FALSE to only search primary annotations
     
    125127  */
    126128  public List<AnnotationSnapshot> findAnnotations(DbControl dc, AnnotationSetSnapshot snapshot,
    127     AnnotationType at, boolean searchInherited)
     129      Filter<? super AnnotationSnapshot> filter, boolean searchInherited)
    128130  {
    129131    List<AnnotationSnapshot> result = new ArrayList<AnnotationSnapshot>();
    130     int id = at == null ? 0 : at.getId();
     132    if (filter == null) filter = new StaticFilter<AnnotationSnapshot>(true);
    131133    for (AnnotationSnapshot shot : snapshot.getAnnotations())
    132134    {
     
    134136      {
    135137        if (!searchInherited) continue; // with the next snapshot in the list
    136         // Is this a specific inherited annotation or a complete annotation set?
    137         if (shot.getAnnotationTypeId() == id || shot.getAnnotationId() == 0)
     138       
     139        // If this is an inherited annotation set or if it matches the filter we
     140        // must recursively load the inherited annotations
     141        if (shot.getAnnotationId() == 0 || filter.evaluate(shot))
    138142        {
    139           // Load the snapshot for the inherited annotation set and search the
    140           // primary annotations only
    141143          AnnotationSetSnapshot recursive = getSnapshot(dc, shot.getAnnotationSetId());
    142144          if (recursive != null)
    143145          {
    144             for (AnnotationSnapshot primary : findAnnotations(dc, recursive, at, false))
     146            for (AnnotationSnapshot primary : findAnnotations(dc, recursive, filter, false))
    145147            {
    146148              AnnotationSnapshot copy = new AnnotationSnapshot();
     
    154156      {
    155157        // Primary annotation
    156         if (shot.getAnnotationTypeId() == id || id == 0)
     158        if (filter.evaluate(shot))
    157159        {
    158160          shot.setItem(snapshot.getItemId(), snapshot.getItemType());
     
    170172      item doesn't have any annotations)
    171173    @see #getSnapshot(DbControl, int)
    172     @see #findAnnotations(DbControl, AnnotationSetSnapshot, AnnotationType, boolean)
     174    @see #findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean)
    173175  */
    174176  public List<AnnotationSnapshot> findAnnotations(DbControl dc, Annotatable item,
    175     AnnotationType at, boolean searchInherited)
    176   {
    177     if (!item.isAnnotated()) return Collections.emptyList();
    178     AnnotationSetSnapshot snapshot = getSnapshot(dc, item.getAnnotationSet().getId());
    179     return findAnnotations(dc, snapshot, at, searchInherited);
    180   }
     177      Filter<? super AnnotationSnapshot> filter, boolean searchInherited)
     178    {
     179      if (!item.isAnnotated()) return Collections.emptyList();
     180      AnnotationSetSnapshot snapshot = getSnapshot(dc, item.getAnnotationSet().getId());
     181      return findAnnotations(dc, snapshot, filter, searchInherited);
     182    }
     183
    181184}
  • trunk/src/core/net/sf/basedb/util/BioAssaySetUtil.java

    r5130 r5131  
    3636import net.sf.basedb.core.query.Restriction;
    3737import net.sf.basedb.core.snapshot.AnnotationSnapshot;
     38import net.sf.basedb.core.snapshot.AnnotationTypeFilter;
    3839import net.sf.basedb.core.snapshot.SnapshotManager;
     40import net.sf.basedb.util.filter.Filter;
    3941import net.sf.basedb.util.jep.ChannelFunction;
    4042import net.sf.basedb.util.jep.ExtraValueFunction;
     
    109111    Set<Object> allValues = new TreeSet<Object>();
    110112    if (snapshotManager == null) snapshotManager = new SnapshotManager();
    111     for (AnnotationSnapshot a : snapshotManager.findAnnotations(dc, bioAssay, annotationType, true))
     113    Filter<AnnotationSnapshot> filter = new AnnotationTypeFilter(annotationType);
     114    for (AnnotationSnapshot a : snapshotManager.findAnnotations(dc, bioAssay, filter, true))
    112115    {
    113116      if (a != null) allValues.addAll(a.getValues());
     
    117120    for (RawBioAssay rb : rbaQuery.list(dc))
    118121    {
    119       for (AnnotationSnapshot a : snapshotManager.findAnnotations(dc, rb, annotationType, true))
     122      for (AnnotationSnapshot a : snapshotManager.findAnnotations(dc, rb, filter, true))
    120123      {
    121124        if (a != null) allValues.addAll(a.getValues());
  • trunk/www/views/experiments/view_experiment.jsp

    r5128 r5131  
    6060  import="net.sf.basedb.core.snapshot.AnnotationSetSnapshot"
    6161  import="net.sf.basedb.core.snapshot.AnnotationSnapshot"
     62  import="net.sf.basedb.core.snapshot.AnnotationTypeFilter"
    6263  import="net.sf.basedb.util.formatter.Formatter"
    6364  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
     
    532533      }
    533534      %>
    534      
    535535      <%
    536536      ItemQuery<RawBioAssay> rbaQuery = experiment.getRawBioAssays();
     
    579579        }
    580580        %>
    581        
    582581        <tbl:data>
    583582          <tbl:columns>
     
    586585          <%
    587586          SnapshotManager manager = new SnapshotManager();
     587          AnnotationTypeFilter annotationTypeFilter = new AnnotationTypeFilter();
    588588          for (RawBioAssay item : rawBioAssays)
    589589          {
    590             //System.out.println("processing rba: " + item);
    591590            AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null;
    592             //System.out.println("got annotation set: " + as);
    593591            AnnotationSetSnapshot snapshot = as == null ? null : manager.getSnapshot(dc, as.getId());
    594             //System.out.println("got snapshot: " + snapshot);
    595592            %>
    596593            <tbl:row>
     
    608605               
    609606                String value = "<i>- none -</i>";
    610                 //System.out.println("load annotations: " + at);
     607                annotationTypeFilter.setAnnotationType(at);
    611608                List<AnnotationSnapshot> all = snapshot == null ?
    612                     null : manager.findAnnotations(dc, snapshot, at, true);
    613                 //System.out.println("loaded annotations: " + at);
     609                    null : manager.findAnnotations(dc, snapshot, annotationTypeFilter, true);
    614610                Map<Annotatable, List> factorValues = new HashMap<Annotatable, List>();
    615611                if (all != null && all.size() > 0)
     
    623619                    try
    624620                    {
    625                       //System.out.println("load item: "+ a.getItemType() + a.getItemId());
    626621                      aItem = a.getItem(dc);
    627                       //System.out.println("loaded item: "+ a.getItemType() + a.getItemId());
    628622                    }
    629623                    catch (Throwable t)
     
    638632                  }
    639633                }
    640                
    641634                %>
    642635                <tbl:cell column="<%="at"+at.getId()%>"
Note: See TracChangeset for help on using the changeset viewer.