Changeset 3905


Ignore:
Timestamp:
Nov 5, 2007, 10:59:06 AM (14 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #810: Implement query options for Include.ANNOTATED and Include.NOT_ANNOTATED

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

Legend:

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

    r3679 r3905  
    156156    this.optionalFilter = optionalFilter;
    157157    super.selectPermanent(Selects.expression(Hql.alias(itemType.getAlias()), null, true));
    158     this.includes = EnumSet.of(Include.NOT_REMOVED, Include.MINE, Include.IN_PROJECT);
     158    this.includes = EnumSet.of(Include.NOT_REMOVED, Include.MINE, Include.IN_PROJECT,
     159      Include.ANNOTATED, Include.NOT_ANNOTATED);
    159160    this.permission = Permission.READ;
    160161  }
  • trunk/src/core/net/sf/basedb/core/HibernateUtil.java

    r3900 r3905  
    2626package net.sf.basedb.core;
    2727
     28import net.sf.basedb.core.data.AnnotatableData;
    2829import net.sf.basedb.core.data.BasicData;
    2930import net.sf.basedb.core.data.MessageData;
     
    404405        log.info("Adding 'isRemoved' filter to "+c.getName());
    405406        pc.addFilter("isRemoved", ":removed = `removed`");
     407      }
     408      if (AnnotatableData.class.isAssignableFrom(c))
     409      {
     410        log.info("Adding 'isAnnotatated' filter to "+c.getName());
     411        pc.addFilter("isAnnotated", ":annotated = (`annotationset_id` IS NOT NULL)");
    406412      }
    407413      if (OwnableData.class.isAssignableFrom(c))
  • trunk/src/core/net/sf/basedb/core/QueryRuntimeFilterFactory.java

    r3679 r3905  
    2626package net.sf.basedb.core;
    2727
     28import net.sf.basedb.core.data.AnnotatableData;
    2829import net.sf.basedb.core.data.RemovableData;
    2930import net.sf.basedb.core.data.OwnableData;
     
    5859  static final QueryRuntimeFilter DENY_ALL_FILTER = new DenyAllFilter();
    5960  static final QueryRuntimeFilter REMOVABLE_FILTER = new RemovableFilter();
     61  static final QueryRuntimeFilter ANNOTATABLE_FILTER = new AnnotatableFilter();
    6062  static final QueryRuntimeFilter BASIC_FILTER = new BasicFilter();
    6163  static final QueryRuntimeFilter OWNABLE_FILTER = new OwnableFilter();
     
    8183          requiredChain.add(REMOVABLE_FILTER);
    8284        }
     85        if (AnnotatableData.class.isAssignableFrom(c))
     86        {
     87          requiredChain.add(ANNOTATABLE_FILTER);
     88        }
    8389        if (ShareableData.class.isAssignableFrom(c))
    8490        {
     
    176182  }
    177183
     184  /**
     185    A required filter for {@link Annotatable} items. The filter checks the query
     186    for the {@link Include#ANNOTATED} and {@link Include#NOT_ANNOTATED} options
     187    and enabled the <code>isAnnotated</code> filter if neccessary. If none of
     188    the options are set this is the same as if both options are set.
     189    @since 2.5
     190  */
     191  private static class AnnotatableFilter
     192    implements QueryRuntimeFilter
     193  {
     194    public void enableFilters(QueryRuntimeFilterManager manager, EntityQuery query, DbControl dc)
     195    {
     196      boolean annotated = query.isIncluded(Include.ANNOTATED);
     197      boolean notAnnotated = query.isIncluded(Include.NOT_ANNOTATED);
     198      if (annotated ^ notAnnotated)
     199      {
     200        // Only one option is set (both or none requires no filter)
     201        org.hibernate.Filter filter = manager.enableFilter("isAnnotated");
     202        if (filter != null)
     203        {
     204          filter.setParameter("annotated", annotated);
     205        }
     206      }
     207    }
     208  }
     209 
    178210  /**
    179211    An optional default filter for {@link BasicItem}:s that are not
  • trunk/src/core/net/sf/basedb/core/filter-def.hbm.xml

    r3679 r3905  
    4949  <filter-def name="isRemoved">
    5050    <filter-param name="removed" type="boolean" />
     51  </filter-def>
     52 
     53  <!--
     54    Filter Annotatable items on the presense/absense of annotations
     55    Typical condition is ":annotated = (`annotationset_id` IS NULL)"
     56  -->
     57  <filter-def name="isAnnotated">
     58    <filter-param name="annotated" type="boolean" />
    5159  </filter-def>
    5260 
Note: See TracChangeset for help on using the changeset viewer.