Changeset 6733


Ignore:
Timestamp:
Feb 13, 2015, 12:55:05 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #1910: Disable annotation inheritance for annotation types

Do not return annotations for annotation types with inheritance disabled when using the SnapshotManager to find inherited annotations. This is needed when inheriting an annotation set, since all annotations would otherwise be included.

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

Legend:

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

    r6728 r6733  
    144144  }
    145145
     146  /**
     147    Load the IDs of all annotation types with the disable inheritance flag set.
     148    This method will return all such IDs without checking permissions of the
     149    current user. The returned set is not modifiable.
     150    @since 3.5
     151  */
     152  public static Set<Integer> getAllAnnotationTypesWithInheritanceDisabled(DbControl dc)
     153  {
     154    org.hibernate.Query query = HibernateUtil.createQuery(dc.getHibernateSession(),
     155      "SELECT at.id FROM AnnotationTypeData at WHERE at.disableInheritance=true");
     156    return Collections.unmodifiableSet(new HashSet<Integer>(HibernateUtil.loadList(Integer.class, query, dc.getSessionControl())));
     157  }
     158 
    146159  AnnotationType(AnnotationTypeData annotationTypeData)
    147160  {
  • trunk/src/core/net/sf/basedb/core/snapshot/SnapshotManager.java

    r6728 r6733  
    5151
    5252  private final Map<Integer, AnnotationSetSnapshot> snapshots;
     53  private DisabledInheritanceFilter disabledInheritanceFilter;
    5354 
    5455  /**
     
    164165   
    165166    if (filter == null) filter = new StaticFilter<AnnotationSnapshot>(true);
     167
    166168    // Needed for recursive searching of inherited annotations
    167     AnnotationFilter annotationFilter = new AnnotationFilter();
     169    AnnotationFilter annotationFilter = null;
     170    DisabledInheritanceFilter recursiveFilter = null;
     171    if (searchInherited)
     172    {
     173      if (disabledInheritanceFilter == null) disabledInheritanceFilter = new DisabledInheritanceFilter(dc);
     174      recursiveFilter = new DisabledInheritanceFilter(disabledInheritanceFilter);
     175      annotationFilter = new AnnotationFilter();
     176    }
    168177   
    169178    for (AnnotationSnapshot shot : snapshot.getAnnotations())
     
    181190          if (recursive != null)
    182191          {
    183             Filter<? super AnnotationSnapshot> recursiveFilter = filter;
    184192            if (annotationId != 0)
    185193            {
    186194              // The main filter has already matched this annotation
    187195              // Use the recursive filter to load the specific annotation only
    188               recursiveFilter = annotationFilter;
    189196              annotationFilter.setAnnotationId(annotationId);
     197              recursiveFilter.setParentFilter(annotationFilter);
    190198            }
     199            else
     200            {
     201              recursiveFilter.setParentFilter(filter);
     202            }
     203           
    191204            for (AnnotationSnapshot primary : findAnnotations(dc, recursive, recursiveFilter, false))
    192205            {
Note: See TracChangeset for help on using the changeset viewer.