Changeset 6686


Ignore:
Timestamp:
Jan 20, 2015, 1:55:44 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #1906: Display inherited annotations in list views

Prepared query functionality and annotation loader so that they work well with inherited annotations. In most cases this means that another parameter is needed so we can specify if primary and/or inherited annotations should be searched independently of each other.

Location:
trunk/src/core/net/sf/basedb/core
Files:
9 edited

Legend:

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

    r6127 r6686  
    4545
    4646  /**
     47    @since 2.4
     48    @deprecated In 3.5; Use {@link #AnnotationBetweenRestriction(String, AnnotationType, Object, Object, boolean, boolean)} instead
     49  */
     50  @Deprecated
     51  public AnnotationBetweenRestriction(String alias, AnnotationType annotationType, Object lowValue, Object highValue, boolean includeInheriting)
     52    throws InvalidDataException
     53  {
     54    this(alias, annotationType, lowValue, highValue, true, includeInheriting);
     55  }
     56
     57
     58  /**
     59    @since 3.0
     60    @deprecated In 3.5; Use {@link #AnnotationBetweenRestriction(String, int, Type, Object, Object, boolean, boolean)} instead
     61  */
     62  @Deprecated
     63  public AnnotationBetweenRestriction(String alias, int annotationTypeId, Type valueType, Object lowValue, Object highValue,
     64    boolean includeInheriting)
     65    throws InvalidDataException
     66  {
     67    this(alias, annotationTypeId, valueType, lowValue, highValue, true, includeInheriting);
     68  }
     69
     70  /**
    4771    Create a new annotation restriction.
    4872   
     
    5680      correct value type for the annotation as defined by the
    5781      {@link AnnotationType#getValueType()} property
     82    @param includePrimary If items with this annotation as a primary annotation
     83      should be returned by the query or not
    5884    @param includeInheriting If items inherting the annotation should be returned
    5985      by the query or not
    6086    @throws InvalidDataException If any of the parameters are null
    6187      or not follow the rules above.
    62     @since 2.4
    63   */
    64   public AnnotationBetweenRestriction(String alias, AnnotationType annotationType, Object lowValue, Object highValue, boolean includeInheriting)
     88    @since 3.5
     89  */
     90  public AnnotationBetweenRestriction(String alias, AnnotationType annotationType, Object lowValue, Object highValue,
     91    boolean includePrimary, boolean includeInheriting)
    6592    throws InvalidDataException
    6693  {
    6794    this(alias, annotationType.getId(), annotationType.getValueType(), lowValue, highValue, includeInheriting);
    6895  }
    69 
    70 
     96 
     97 
    7198  /**
    7299    Create a new annotation restriction.
     
    82109      correct value type for the annotation as defined by the
    83110      valueType property
     111    @param includePrimary If items with this annotation as a primary annotation
     112      should be returned by the query or not
    84113    @param includeInheriting If items inherting the annotation should be returned
    85114      by the query or not
    86115    @throws InvalidDataException If any of the parameters are null
    87116      or not follow the rules above.
    88     @since 3.0
     117    @since 3.5
    89118  */
    90119  public AnnotationBetweenRestriction(String alias, int annotationTypeId, Type valueType, Object lowValue, Object highValue,
    91     boolean includeInheriting)
    92     throws InvalidDataException
    93   {
    94     super(alias, annotationTypeId, valueType, includeInheriting);
     120    boolean includePrimary, boolean includeInheriting)
     121    throws InvalidDataException
     122  {
     123    super(alias, annotationTypeId, valueType, includePrimary, includeInheriting);
    95124    if (lowValue == null) throw new InvalidUseOfNullException("lowValue");
    96125    if (highValue == null) throw new InvalidUseOfNullException("highValue");
     
    109138  }
    110139
    111  
    112140  /*
    113141    From the AnnotationRestriction class
  • trunk/src/core/net/sf/basedb/core/AnnotationInRestriction.java

    r6127 r6686  
    4646
    4747  /**
    48     Create a new annotation restriction.
     48    @since 2.4
     49    @deprecated In 3.5; use {@link #AnnotationInRestriction(String, AnnotationType, boolean, boolean, Object...) instead
     50  */
     51  @Deprecated
     52  public AnnotationInRestriction(String alias, AnnotationType annotationType, boolean includeInheriting, Object... values)
     53    throws InvalidDataException
     54  {
     55    this(alias, annotationType, true, includeInheriting, values);
     56  }
     57 
     58  /**
     59    Create a new annotation restriction. At least one of
     60    includePrimary and includeInheriting must be true.
    4961   
    5062    @param alias The alias to use in the restriction.   
    5163    @param annotationType The annotation type to use in the query
     64    @param includePrimary If items with primary annotation should be returned or not
    5265    @param includeInheriting If items inherting the annotation should be returned
    5366      by the query or not
     
    5770    @throws InvalidDataException If any of the parameters are null
    5871      or the array is empty or not follow the rules above.
    59     @since 2.4
     72    @since 3.5
    6073  */
    61   public AnnotationInRestriction(String alias, AnnotationType annotationType, boolean includeInheriting, Object... values)
     74  public AnnotationInRestriction(String alias, AnnotationType annotationType, boolean includePrimary, boolean includeInheriting, Object... values)
    6275    throws InvalidDataException
    6376  {
    64     super(alias, annotationType, includeInheriting);
     77    super(alias, annotationType, includePrimary, includeInheriting);
    6578    if (values == null || values.length == 0) throw new InvalidUseOfNullException("values");
    6679    for (int i = 0; i < values.length; ++i)
     
    7588    this.values = Arrays.asList(values);
    7689  }
     90 
    7791  /*
    7892    From the AnnotationRestriction class
  • trunk/src/core/net/sf/basedb/core/AnnotationRestriction.java

    r6444 r6686  
    6363  final Type valueType;
    6464  final int annotationTypeId;
     65  final boolean includePrimary;
    6566  final boolean includeInheriting;
    6667  final String alias;
     
    7071    @param annotationType The annotation type to use in the query
    7172  */
    72   AnnotationRestriction(String alias, AnnotationType annotationType, boolean includeInheriting)
     73  AnnotationRestriction(String alias, AnnotationType annotationType, boolean includePrimary, boolean includeInheriting)
    7374    throws InvalidDataException
    7475  {
    7576    if (annotationType == null) throw new InvalidUseOfNullException("annotationType");
     77    if (!includePrimary && !includeInheriting)
     78    {
     79      throw new InvalidDataException("Both includePrimary and includeInheriting parameters are FALSE");
     80    }
    7681    this.annotationTypeId = annotationType.getId();
    7782    this.valueType = annotationType.getValueType();
     83    this.includePrimary = includePrimary;
    7884    this.includeInheriting = includeInheriting;
    7985    this.alias = alias;
     
    8995    @param valueType The type of values for annotations
    9096  */
    91   AnnotationRestriction(String alias, int annotationTypeId, Type valueType, boolean includeInheriting)
     97  AnnotationRestriction(String alias, int annotationTypeId, Type valueType, boolean includePrimary, boolean includeInheriting)
    9298    throws InvalidDataException
    9399  {
     100    if (!includePrimary && !includeInheriting)
     101    {
     102      throw new InvalidDataException("Both includePrimary and includeInheriting parameters are FALSE");
     103    }
    94104    this.annotationTypeId = annotationTypeId;
    95105    this.valueType = valueType;
     106    this.includePrimary = includePrimary;
    96107    this.includeInheriting = includeInheriting;
    97108    this.alias = alias;
     
    193204        if (debugSqlEnabled) logSql.debug("Executing annotation query: " + sql);
    194205        List<Integer> ids = HibernateUtil.loadList(Integer.class, sqlQuery, sc);
    195         annotationSets = new StringBuilder(annotationSetIds);
     206        annotationSets = new StringBuilder(includePrimary ? annotationSetIds : "0");
    196207        for (Integer id : ids)
    197208        {
  • trunk/src/core/net/sf/basedb/core/AnnotationSimpleRestriction.java

    r6127 r6686  
    5252
    5353  /**
     54    @since 2.4
     55    @deprecated In 3.5; Use {@link #AnnotationSimpleRestriction(String, AnnotationType, Operator, Object, boolean, boolean)} instead
     56  */
     57  @Deprecated
     58  public AnnotationSimpleRestriction(String alias, AnnotationType annotationType, Operator operator, Object value, boolean includeInheriting)
     59    throws InvalidDataException
     60  {
     61    this(alias, annotationType, operator, value, true, includeInheriting);
     62  }
     63 
     64  /**
    5465    Create a new annotation restriction using a simple expression:
    5566    <code>annotation operator value</code>.
     
    6374      correct value type for the annotation as defined by the
    6475      {@link AnnotationType#getValueType()} property
     76    @param includePrimary If items with primary annotation should be returned or not
    6577    @param includeInheriting If items inherting the annotation should be returned
    6678      by the query or not
    6779    @throws InvalidDataException If any of the parameters are null
    6880      or not follow the rules above.
    69     @since 2.4
    70   */
    71   public AnnotationSimpleRestriction(String alias, AnnotationType annotationType, Operator operator, Object value, boolean includeInheriting)
    72     throws InvalidDataException
    73   {
    74     super(alias, annotationType, includeInheriting);
     81    @since 3.5
     82  */
     83  public AnnotationSimpleRestriction(String alias, AnnotationType annotationType, Operator operator, Object value,
     84    boolean includePrimary, boolean includeInheriting)
     85    throws InvalidDataException
     86  {
     87    super(alias, annotationType, includePrimary, includeInheriting);
    7588    if (operator == null) throw new InvalidUseOfNullException("operator");
    7689    if (value == null) throw new InvalidUseOfNullException("value");
     
    89102  }
    90103
     104 
     105  /**
     106    @since 2.4
     107    @deprecated in 3.5; Use {@link #AnnotationSimpleRestriction(String, int, Type, Operator, Object, boolean, boolean)} instead
     108  */
     109  public AnnotationSimpleRestriction(String alias, int annotationTypeId, Type valueType, Operator operator, Object value, boolean includeInheriting)
     110    throws InvalidDataException
     111  {
     112    this(alias, annotationTypeId, valueType, operator, value, true, includeInheriting);
     113  }
    91114 
    92115  /**
     
    102125      correct value type for the annotation as defined by the
    103126      {@link AnnotationType#getValueType()} property
     127    @param includePrimary If items with primary annotation should be returned or not
    104128      @param includeInheriting TRUE if items inheriting the annotation should be returned by the query, FALSE otherwise
    105129      @throws InvalidDataException If any of the parameters are null
    106130      or not follow the rules above
    107     @since 2.4
    108   */
    109   public AnnotationSimpleRestriction(String alias, int annotationTypeId, Type valueType, Operator operator, Object value, boolean includeInheriting)
    110     throws InvalidDataException
    111   {
    112     super(alias, annotationTypeId, valueType, includeInheriting);
     131    @since 3.5
     132  */
     133  public AnnotationSimpleRestriction(String alias, int annotationTypeId, Type valueType, Operator operator, Object value,
     134    boolean includePrimary, boolean includeInheriting)
     135    throws InvalidDataException
     136  {
     137    super(alias, annotationTypeId, valueType, includePrimary, includeInheriting);
    113138    if (valueType == null) throw new InvalidUseOfNullException("valueType");
    114139    if (operator == null) throw new InvalidUseOfNullException("operator");
     
    126151    this.value = value;
    127152    this.values = null;
     153  }
     154
     155 
     156  /**
     157    @since 2.5
     158    @deprecated In 3.5; Use {@link #AnnotationSimpleRestriction(String, int, Type, Operator, List, boolean, boolean)} instead
     159  */
     160  @Deprecated
     161  public AnnotationSimpleRestriction(String alias, int annotationTypeId, Type valueType, Operator operator, List<Object> values, boolean includeInheriting)
     162    throws InvalidDataException
     163  {
     164    this(alias, annotationTypeId, valueType, operator, values, true, includeInheriting);
    128165  }
    129166 
     
    141178      correct value type for the annotation as defined by the
    142179      {@link AnnotationType#getValueType()} property.
     180    @param includePrimary If items with primary annotation should be returned or not
    143181      @param includeInheriting TRUE if items inheriting the annotation should be returned by the query, FALSE otherwise
    144182      @throws InvalidDataException If any of the parameters are null
    145183      or not follow the rules above
    146     @since 2.5
    147   */
    148   public AnnotationSimpleRestriction(String alias, int annotationTypeId, Type valueType, Operator operator, List<Object> values, boolean includeInheriting)
    149     throws InvalidDataException
    150   {
    151     super(alias, annotationTypeId, valueType, includeInheriting);
     184    @since 3.5
     185  */
     186  public AnnotationSimpleRestriction(String alias, int annotationTypeId, Type valueType, Operator operator, List<Object> values,
     187    boolean includePrimary, boolean includeInheriting)
     188    throws InvalidDataException
     189  {
     190    super(alias, annotationTypeId, valueType, includePrimary, includeInheriting);
    152191    if (valueType == null) throw new InvalidUseOfNullException("valueType");
    153192    if (operator == null) throw new InvalidUseOfNullException("operator");
     
    169208    this.value = null;
    170209  }
    171  
     210
    172211  /*
    173212    From the AnnotationRestriction class
  • trunk/src/core/net/sf/basedb/core/HasAnnotationRestriction.java

    r6127 r6686  
    4343 
    4444  /**
     45    @deprecated In 3.5; Use {@link #HasAnnotationRestriction(String, AnnotationType, boolean, boolean, boolean)} instead
     46  */
     47  @Deprecated
     48  public HasAnnotationRestriction(String alias, AnnotationType annotationType,
     49    boolean hasBeenAnnotatated, boolean includeInheriting)
     50  {
     51    this(alias, annotationType.getId(), hasBeenAnnotatated, true, includeInheriting);
     52  }
     53 
     54  /**
     55    @deprecated In 3.5; Use {@link #HasAnnotationRestriction(String, int, boolean, boolean, boolean)} instead
     56  */
     57  @Deprecated
     58  public HasAnnotationRestriction(String alias, int annotationTypeId,
     59    boolean hasBeenAnnotatated, boolean includeInheriting)
     60  {
     61    this(alias, annotationTypeId, hasBeenAnnotatated, true, includeInheriting);
     62  }
     63 
     64  /**
    4565    Create a new restriction that checks if an item has been annotatated
    4666    or not.
     
    5171    @param hasBeenAnnotatated TRUE to look for items that has been annotated with the given
    5272      annotation type, FALSE to look for items that hasn't
     73    @param includePrimary If items with this annotation as a primary annotation
     74      should be returned by the query or not
    5375    @param includeInheriting If items inherting the annotation should be returned
    5476      by the query or not
     77    @since 3.5
    5578  */
    5679  public HasAnnotationRestriction(String alias, AnnotationType annotationType,
    57     boolean hasBeenAnnotatated, boolean includeInheriting)
     80    boolean hasBeenAnnotatated, boolean includePrimary, boolean includeInheriting)
    5881  {
    59     this(alias, annotationType.getId(), hasBeenAnnotatated, includeInheriting);
     82    this(alias, annotationType.getId(), hasBeenAnnotatated, includePrimary, includeInheriting);
    6083  }
    6184 
    6285  /**
    63     @see #HasAnnotationRestriction(String, AnnotationType, boolean, boolean)
     86    @see #HasAnnotationRestriction(String, AnnotationType, boolean, boolean, boolean)
     87    @since 3.5
    6488  */
    6589  public HasAnnotationRestriction(String alias, int annotationTypeId,
    66     boolean hasBeenAnnotatated, boolean includeInheriting)
     90    boolean hasBeenAnnotatated, boolean includePrimary, boolean includeInheriting)
    6791  {
    68     super(alias, annotationTypeId, null, includeInheriting);
     92    super(alias, annotationTypeId, null, includePrimary, includeInheriting);
    6993    this.hasBeenAnnotatated = hasBeenAnnotatated;
    7094  }
  • trunk/src/core/net/sf/basedb/core/PropertyFilter.java

    r6684 r6686  
    492492      // Property is id of annotation type: #id
    493493      // If prefixed with two ## inherited annotations should be searched
     494      // We always search for one or the other; never both
    494495      boolean searchInherited = property.startsWith("##");
     496      boolean searchPrimary = !searchInherited;
     497     
    495498      int annotationTypeId = (Integer)Type.INT.parseString(property.substring(searchInherited ? 2 : 1));
    496499     
     
    551554            }
    552555            restriction = new AnnotationBetweenRestriction(alias, annotationTypeId, getValueType(),
    553                 objects.get(0), objects.get(1), searchInherited);
     556                objects.get(0), objects.get(1), searchPrimary, searchInherited);
    554557          }
    555558          else
    556559          {
    557560            restriction = new AnnotationSimpleRestriction(alias,annotationTypeId, getValueType(),
    558                 operator, objects, searchInherited);
     561                operator, objects, searchPrimary, searchInherited);
    559562          }
    560563         
     
    567570          {
    568571            restriction = new HasAnnotationRestriction(alias, annotationTypeId,
    569               operator != Operator.EQ, searchInherited);
     572              operator != Operator.EQ, searchPrimary, searchInherited);
    570573          }
    571574          else
    572575          {
    573576            restriction = new AnnotationSimpleRestriction(alias, annotationTypeId, getValueType(),
    574                 operator, value, searchInherited);
     577                operator, value, searchPrimary, searchInherited);
    575578          }
    576579        }
  • trunk/src/core/net/sf/basedb/core/query/Annotations.java

    r6132 r6686  
    5454    @throws InvalidDataException If annotationType or value are null.
    5555    @since 2.4
    56   */
     56    @deprecated In 3.5; Use{@link AnnotationSimpleRestriction} instead
     57  */
     58  @Deprecated
    5759  public static Restriction eq(String alias, AnnotationType annotationType, Object value, boolean includeInheriting)
    5860    throws InvalidDataException
     
    7476    @throws InvalidDataException If annotationType or value are null.
    7577    @since 2.4
    76   */
     78    @deprecated In 3.5; Use{@link AnnotationSimpleRestriction} instead
     79  */
     80  @Deprecated
    7781  public static Restriction neq(String alias, AnnotationType annotationType, Object value, boolean includeInheriting)
    7882    throws InvalidDataException
     
    9498    @throws InvalidDataException If annotationType parameter or value parameter are null.
    9599    @since 2.4
    96   */
     100    @deprecated In 3.5; Use{@link AnnotationSimpleRestriction} instead
     101  */
     102  @Deprecated
    97103  public static Restriction lt(String alias, AnnotationType annotationType, Object value, boolean includeInheriting)
    98104    throws InvalidDataException
     
    114120    @throws InvalidDataException If annotationType parameter or value parameter are null.
    115121    @since 2.4
    116   */
     122    @deprecated In 3.5; Use{@link AnnotationSimpleRestriction} instead
     123  */
     124  @Deprecated
    117125  public static Restriction lteq(String alias, AnnotationType annotationType, Object value, boolean includeInheriting)
    118126    throws InvalidDataException
     
    134142    @throws InvalidDataException If annotationType parameter or value parameter are null.
    135143    @since 2.4
    136   */
     144    @deprecated In 3.5; Use{@link AnnotationSimpleRestriction} instead
     145  */
     146  @Deprecated
    137147  public static Restriction gt(String alias, AnnotationType annotationType, Object value, boolean includeInheriting)
    138148    throws InvalidDataException
     
    154164    @throws InvalidDataException If annotationType parameter or value parameter are null.
    155165    @since 2.4
    156   */
     166    @deprecated In 3.5; Use{@link AnnotationSimpleRestriction} instead
     167  */
     168  @Deprecated
    157169  public static Restriction gteq(String alias, AnnotationType annotationType, Object value, boolean includeInheriting)
    158170    throws InvalidDataException
     
    174186    @throws InvalidDataException If annotationType parameter or value parameter are null.
    175187    @since 2.4
    176   */
     188    @deprecated In 3.5; Use{@link AnnotationSimpleRestriction} instead
     189  */
     190  @Deprecated
    177191  public static Restriction like(String alias, AnnotationType annotationType, Object value, boolean includeInheriting)
    178192    throws InvalidDataException
     
    195209    @throws InvalidDataException If any of the required parameters are null.
    196210    @since 2.4, 3.0 (specified that low/high values are included)
    197   */
     211    @deprecated In 3.5; Use{@link AnnotationBetweenRestriction} instead
     212  */
     213  @Deprecated
    198214  public static Restriction between(String alias, AnnotationType annotationType, Object lowValue, Object highValue, boolean includeInheriting)
    199215    throws InvalidDataException
     
    215231    @throws InvalidDataException If annotationType parameter or values parameter are null
    216232    @since 2.4
    217   */
     233    @deprecated In 3.5; Use{@link AnnotationInRestriction} instead
     234  */
     235  @Deprecated
    218236  public static Restriction in(String alias, AnnotationType annotationType, boolean includeInheriting, Object... values)
    219237    throws InvalidDataException
  • trunk/src/core/net/sf/basedb/core/snapshot/AnnotationLoaderUtil.java

    r6539 r6686  
    2323
    2424import java.io.Serializable;
     25import java.util.ArrayList;
    2526import java.util.List;
    2627
     
    4849  private final Type valueType;
    4950  private final Unit defultUnit;
    50  
    51   private AnnotationSnapshot snapshot;
     51  private final boolean searchPrimary;
     52  private final boolean searchInherited;
     53 
     54  private List<AnnotationSnapshot> snapshots;
    5255  private UnitConverter converter;
    5356  private Unit unit;
     
    5659  /**
    5760    Create a loder that uses the given snapshot manager to load annotations
    58     for a single annotation type.
     61    for a single annotation type. The loader will load only primary annotations.
    5962  */
    6063  public AnnotationLoaderUtil(DbControl dc, SnapshotManager manager, AnnotationType at)
     64  {
     65    this(dc, manager, at, true, false);
     66  }
     67 
     68  /**
     69    Create a loder that uses the given snapshot manager to load annotations
     70    for a single annotation type. The loader can be configured to load primary
     71    and/or inherited annotations.
     72    @since 3.5
     73  */
     74  public AnnotationLoaderUtil(DbControl dc, SnapshotManager manager, AnnotationType at, boolean searchPrimary, boolean searchInherited)
    6175  {
    6276    this.dc = dc;
    6377    this.manager = manager;
    6478    this.at = at;
     79    this.searchPrimary = searchPrimary;
     80    this.searchInherited = searchInherited;
    6581    this.atId = at.getId();
    6682    this.valueType = at.getValueType();
    6783    this.defultUnit = at.getDefaultUnit();
    6884  }
     85
    6986 
    7087  /*
     
    96113 
    97114  /**
    98     Find and load annotations from the given annotation set snapshot. The
    99     loader will only load primary annotations.
     115    Is this loader searching for primary annotations?
     116    @since 3.5
     117  */
     118  public boolean isSearchingPrimaryAnnotations()
     119  {
     120    return searchPrimary;
     121  }
     122
     123  /**
     124    Is this loader searching for inherited annotations?
     125    @since 3.5
     126  */
     127  public boolean isSearchingInheritedAnnotations()
     128  {
     129    return searchInherited;
     130  }
     131
     132 
     133  /**
     134    Same as findAll but only return a boolean instead of the number
     135    of snapshots found.
     136   
    100137    @return TRUE if an annotation was found, FALSE if not
     138    @see #findAll(AnnotationSetSnapshot)
    101139  */
    102140  public boolean find(AnnotationSetSnapshot setSnapshot)
    103141  {
    104     List<AnnotationSnapshot> list = manager.findAnnotations(dc, setSnapshot, this, false);
    105     if (list.size() > 0)
    106     {
    107       snapshot = list.get(0);
    108       unit = snapshot.getUnit(dc);
     142    return findAll(setSnapshot) > 0;
     143  }
     144 
     145  /**
     146    Find and load annotations from the given annotation set snapshot.
     147    @return The number of snapshots found
     148    @since 3.5
     149  */
     150  public int findAll(AnnotationSetSnapshot setSnapshot)
     151  {
     152    snapshots = manager.findAnnotations(dc, setSnapshot, this, searchPrimary, searchInherited);
     153    int size = snapshots.size();
     154    if (size > 1)
     155    {
     156      unit = defultUnit;
     157    }
     158    else if (size == 1)
     159    {
     160      unit = snapshots.get(0).getUnit(dc);
    109161    }
    110162    else
    111163    {
    112       snapshot = null;
    113164      unit = null;
    114165    }
    115166    if (unit != null)
    116167    {
    117       converter = unit.getUnitConverter(defultUnit);
     168      converter = unit.equals(defultUnit) ? null : unit.getUnitConverter(defultUnit);
    118169      unitSymbol = unit.getDisplaySymbol();
     170      System.out.println(at + "; unit:" + unit + "; default: " + defultUnit + "; converter: "+ converter + "; symbol:"+unitSymbol);
    119171    }
    120172    else
     
    123175      unitSymbol = null;
    124176    }
    125     return snapshot != null;
     177    return snapshots.size();
    126178  }
    127179 
    128180  /**
    129181    Get the snapshot for the last annotation found when calling
    130     {@link #find(AnnotationSetSnapshot)}
     182    {@link #findAll(AnnotationSetSnapshot)}. Note! If multiple
     183    annotation snapshots were found, this will only return the
     184    first hit.
     185   
    131186    @return A snapshot or null if no annotations are found
    132187  */
    133188  public AnnotationSnapshot getSnapshot()
    134189  {
    135     return snapshot;
     190    return snapshots.size() > 0 ? snapshots.get(0) : null;
     191  }
     192 
     193  /**
     194    Get all snapshots found by the last {@link #findAll(AnnotationSetSnapshot)}
     195    call.
     196    @return A list with AnnotationSnapshot objects
     197  */
     198  public List<AnnotationSnapshot> getSnapshots()
     199  {
     200    return snapshots;
    136201  }
    137202 
     
    143208  public List<? extends Serializable> getValues()
    144209  {
    145     return snapshot.getValues(converter, valueType);
     210    List<Serializable> values = new ArrayList<Serializable>();
     211    for (AnnotationSnapshot s : snapshots)
     212    {
     213      values.addAll(s.getValues(converter, valueType));
     214    }
     215    return values;
    146216  }
    147217 
    148218  /**
    149219    Get the unit of the last annotation values that was found
    150     by {@link #find(AnnotationSetSnapshot)}.
     220    by {@link #find(AnnotationSetSnapshot)}. Note that if
     221    multiple annotations was found with different units the default
     222    unit of the annotation type is used.
    151223    @return A string or null if the annotation doesn't use units
    152224  */
  • trunk/src/core/net/sf/basedb/core/snapshot/SnapshotManager.java

    r6037 r6686  
    114114  }
    115115
     116  /**
     117    Find annotations. Alwasys search primary and optionally inherited.
     118    @see #findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean, boolean)
     119  */
     120  public List<AnnotationSnapshot> findAnnotations(DbControl dc, AnnotationSetSnapshot snapshot,
     121      Filter<? super AnnotationSnapshot> filter, boolean searchInherited)
     122  {
     123    return findAnnotations(dc, snapshot, filter, true, searchInherited);
     124  }
    116125
    117126  /**
     
    125134    @param filter A filter that should match the wanted annotation snapshots
    126135      or null to match all annotations
    127     @param searchInherited TRUE if inherited annotations should be searched,
    128       FALSE to only search primary annotations
     136    @param searchPrimary TRUE if primary annotations should be searched
     137    @param searchInherited TRUE if inherited annotations should be searched
    129138    @return A list with the found annotations
     139    @since 3.5
    130140  */
    131141  public List<AnnotationSnapshot> findAnnotations(DbControl dc, AnnotationSetSnapshot snapshot,
    132       Filter<? super AnnotationSnapshot> filter, boolean searchInherited)
     142      Filter<? super AnnotationSnapshot> filter, boolean searchPrimary, boolean searchInherited)
    133143  {
    134144    List<AnnotationSnapshot> result = new ArrayList<AnnotationSnapshot>();
     145    if (!searchPrimary && !searchInherited) return result;
     146   
    135147    if (filter == null) filter = new StaticFilter<AnnotationSnapshot>(true);
    136148    // Needed for recursive searching of inherited annotations
     
    168180        }
    169181      }
    170       else if (shot.hasPermission(dc, Permission.READ))
     182      else
    171183      {
    172184        // Primary annotation
    173         if (filter.evaluate(shot))
     185        if (!searchPrimary) continue; // with the next snapshot in the list
     186       
     187        if (shot.hasPermission(dc, Permission.READ) && filter.evaluate(shot))
    174188        {
    175189          shot.setItem(snapshot.getItemId(), snapshot.getItemType());
     
    182196 
    183197  /**
     198    @see #findAnnotations(DbControl, Annotatable, Filter, boolean, boolean)
     199  */
     200  public List<AnnotationSnapshot> findAnnotations(DbControl dc, Annotatable item,
     201      Filter<? super AnnotationSnapshot> filter, boolean searchInherited)
     202  {
     203    return findAnnotations(dc, item, filter, true, searchInherited);
     204  }
     205 
     206  /**
    184207    Utility method for calling <code>getSnapshot</code> and <code>findAnnotations</code>
    185208    in one go.
     
    187210      item doesn't have any annotations)
    188211    @see #getSnapshot(DbControl, int)
    189     @see #findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean)
     212    @see #findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean, boolean)
     213    @since 3.5
    190214  */
    191215  public List<AnnotationSnapshot> findAnnotations(DbControl dc, Annotatable item,
    192       Filter<? super AnnotationSnapshot> filter, boolean searchInherited)
    193     {
    194       if (!item.isAnnotated()) return Collections.emptyList();
    195       AnnotationSetSnapshot snapshot = getSnapshot(dc, item.getAnnotationSet().getId());
    196       return findAnnotations(dc, snapshot, filter, searchInherited);
    197     }
     216    Filter<? super AnnotationSnapshot> filter, boolean searchPrimary, boolean searchInherited)
     217  {
     218    if (!item.isAnnotated()) return Collections.emptyList();
     219    AnnotationSetSnapshot snapshot = getSnapshot(dc, item.getAnnotationSet().getId());
     220    return findAnnotations(dc, snapshot, filter, searchPrimary, searchInherited);
     221  }
    198222
    199223}
Note: See TracChangeset for help on using the changeset viewer.