Changeset 7298


Ignore:
Timestamp:
Feb 21, 2017, 9:49:31 AM (6 years ago)
Author:
Nicklas Nordborg
Message:

References #2056: Improve API for project-specific annotations

The AnnotationBatcher should now have support for setting a specific project to work with. A single batcher may only work with one project (or with default values) during it's lifetime. It is not possible to switch strategy between items or annotation types.

Location:
trunk/src/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/common-queries.xml

    r7290 r7298  
    35833583      SELECT [annotationtype_id], [id], [version], [unit_id], [value_id], [last_update], [project_id], [override_id]
    35843584      FROM [Annotations]
    3585       WHERE [annotationset_id] = :annotationSet AND [source] = 0 AND ([project_id] = 0 OR [project_id] = :activeProject)
     3585      WHERE [annotationset_id] = :annotationSet AND [source] = 0 AND ([project_id] = :defaultProject OR [project_id] = :activeProject)
    35863586    </sql>
    35873587    <description>
  • trunk/src/core/net/sf/basedb/core/AnnotationBatcher.java

    r7259 r7298  
    7777  </ul>
    7878 
     79  The batcher support project-specific annotations. The default mode (setting projectId=null)
     80  makes the batcher to use the currently active project. Project-specific annotation values
     81  will only be created if they are different from the default values.
     82 
     83  Setting projectId to 0 or to a specific project makes the batcher to only consider
     84  default or the project-specific values. The currently active project is not taken into
     85  account.
     86 
    7987  @author nicklas
    8088  @since 3.8
     
    9098  private final Item itemType;
    9199  private final int activeProjectId;
     100  private final Integer projectId;
    92101 
    93102  // All updates through this batcher get the same date+time
     
    163172  private final Map<String, UnitConverter> unitConvertes;
    164173 
     174  public AnnotationBatcher(DbControl dc, Item itemType)
     175  {
     176    this(dc, itemType, null);
     177  }
     178 
    165179  /**
    166180    Create a new batcher instance.
    167181    @param dc A DbControl to use for database access
    168182    @param itemType The type of items to work with. This must be an annotatable item type.
     183    @param projectId Specify a project id to only consider values for that project
     184      when working with a project-specific annotation, or 0 to only consider default
     185      values, or null to automatically use the default or project-specific values for
     186      the currently active project
     187    @since 3.11
    169188  */
    170189  @SuppressWarnings({ "unchecked", "rawtypes" })
    171   public AnnotationBatcher(DbControl dc, Item itemType)
     190  public AnnotationBatcher(DbControl dc, Item itemType, Integer projectId)
    172191  {
    173192    if (dc == null) throw new NullPointerException("dc");
     
    179198   
    180199    this.itemType = itemType;
    181     this.activeProjectId = dc.getSessionControl().getActiveProjectId();
     200    this.projectId = projectId;
     201    this.activeProjectId = projectId == null ? dc.getSessionControl().getActiveProjectId() : projectId;
    182202    this.batchDate = new Date();
    183203   
     
    218238        PredefinedQuery.getQueryString("AB_LOAD_ANNOTATION_INFO"));
    219239      loadAnnotationInfo.setInteger("activeProject", activeProjectId);
     240      loadAnnotationInfo.setInteger("defaultProject", projectId == null ? 0 : projectId);
    220241      this.loadAnnotationValues = new org.hibernate.Query[types.length];
    221242      this.valueIds = new List[types.length];
     
    675696        {
    676697         
    677           if (info.useProjectAnnotations && info.projectId == 0 && activeProjectId != 0)
     698          if (projectId == null && info.useProjectAnnotations && info.projectId == 0 && activeProjectId != 0)
    678699          {
    679700            // Deleting a default value for a project-specific annotation type is only allowed
     
    787808            // If the current info is default values for a project-specific annotation
    788809            // type we need to create a new annotation that is overriding the default values
    789             if (info.useProjectAnnotations && info.projectId == 0 && activeProjectId != 0)
     810            if (projectId == null && info.useProjectAnnotations && info.projectId == 0 && activeProjectId != 0)
    790811            {
    791812              info.overrideId = info.annotationId;
Note: See TracChangeset for help on using the changeset viewer.