Changeset 7299
- Timestamp:
- Feb 22, 2017, 12:59:59 PM (7 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/AnnotationBatcher.java
r7298 r7299 172 172 private final Map<String, UnitConverter> unitConvertes; 173 173 174 /** 175 Create a new batcher instance. Using this constructor creates a batcher 176 that, for project-specific annotation types, automatically handles either 177 the default or project-specific value depending on the currently active 178 project and wheter a value already exists or not. 179 180 @param dc A DbControl to use for database access 181 @param itemType The type of items to work with. This must be an annotatable item type. 182 */ 174 183 public AnnotationBatcher(DbControl dc, Item itemType) 175 184 { 176 this(dc, itemType, null); 177 } 178 185 this(dc, itemType, (Integer)null); 186 } 187 188 /** 189 Create a new batcher instance. Using this constructor creates a batcher 190 that, for project-specific annotation types, always work with the values 191 for the given project (or the default values if project=null). The currently 192 active project is ignored. 193 194 @param dc A DbControl to use for database access 195 @param itemType The type of items to work with. This must be an annotatable item type. 196 @param project Specify a project to only consider values for that project 197 when working with a project-specific annotation, or null to only consider default 198 values 199 @since 3.11 200 */ 201 public AnnotationBatcher(DbControl dc, Item itemType, Project project) 202 { 203 this(dc, itemType, project == null ? 0 : project.getId()); 204 } 205 179 206 /** 180 207 Create a new batcher instance. … … 188 215 */ 189 216 @SuppressWarnings({ "unchecked", "rawtypes" }) 190 p ublicAnnotationBatcher(DbControl dc, Item itemType, Integer projectId)217 private AnnotationBatcher(DbControl dc, Item itemType, Integer projectId) 191 218 { 192 219 if (dc == null) throw new NullPointerException("dc"); -
trunk/src/core/net/sf/basedb/core/AnnotationSet.java
r7296 r7299 602 602 603 603 /** 604 Get a value for a project-specific annotation using the specified project i d instead604 Get a value for a project-specific annotation using the specified project instead 605 605 of the currently active project. Note that this method behaves differently than 606 606 the {@link #getAnnotation(AnnotationType)} method. 607 607 608 * If the annotation type is not using project annotation , the project idis ignored609 * If project Id=0the default annotation value is returned (new or existing)610 * If project Id!=0a project-specific annotation value is returned (new or existing,608 * If the annotation type is not using project annotations, the project is ignored 609 * If project=null the default annotation value is returned (new or existing) 610 * If project!=null a project-specific annotation value is returned (new or existing, 611 611 the default value is never returned) 612 612 … … 617 617 618 618 @param annotationType The annotation type 619 @param project Id The project id or 0to get the default value619 @param project A project or null to get the default value 620 620 @since 3.11 621 621 */ 622 public Annotation getProjectAnnotation(AnnotationType annotationType, int projectId)622 public Annotation getProjectAnnotation(AnnotationType annotationType, Project project) 623 623 { 624 624 if (annotationType == null) throw new InvalidUseOfNullException("annotationType"); … … 626 626 627 627 int primary = Annotation.Source.PRIMARY.ordinal(); 628 i f (!annotationType.getProjectAnnotations()) projectId =0;628 int projectId = annotationType.getProjectAnnotations() && project != null ? project.getId() : 0; 629 629 630 630 // Search for an existing primary annotation … … 734 734 @param annotationType An <code>AnnotationType</code> object 735 735 @param source The source type of the annotation or null if it doesn't matter 736 @param project Id The project id or 0 to getthe default value736 @param project A project or null to check for the default value 737 737 738 738 @return TRUE if the annotation set contains an annotation of … … 740 740 @since 3.11 741 741 */ 742 public boolean hasProjectAnnotation(AnnotationType annotationType, Annotation.Source source, int projectId)742 public boolean hasProjectAnnotation(AnnotationType annotationType, Annotation.Source source, Project project) 743 743 { 744 744 if (annotationType == null) return false; 745 745 746 746 DbControl dc = getDbControl(); 747 i f (!annotationType.getProjectAnnotations()) projectId =0;747 int projectId = annotationType.getProjectAnnotations() && project != null ? project.getId() : 0; 748 748 749 749 AnnotationTypeData atd = annotationType.getData(); … … 780 780 throws PermissionDeniedException, InvalidDataException, BaseException 781 781 { 782 removeProjectAnnotation(annotationType, getSessionControl().getActiveProjectId()); 782 int projectId = getSessionControl().getActiveProjectId(); 783 removeProjectAnnotation(annotationType, projectId == 0 ? null : Project.getById(getDbControl(), projectId)); 783 784 } 784 785 … … 791 792 792 793 @param annotationType The type of the annotation to delete 793 @param project Id The project id or 0to remove the default value794 @param project A project or null to remove the default value 794 795 @throws PermissionDeniedException If the logged in user 795 796 doesn't have write permission … … 798 799 @since 3.11 799 800 */ 800 public void removeProjectAnnotation(AnnotationType annotationType, int projectId)801 public void removeProjectAnnotation(AnnotationType annotationType, Project project) 801 802 throws PermissionDeniedException, InvalidDataException, BaseException 802 803 { … … 804 805 if (annotationType == null) throw new InvalidUseOfNullException("annotationType"); 805 806 annotationType.checkPermission(Permission.USE); 806 i f (!annotationType.getProjectAnnotations()) projectId =0;807 int projectId = annotationType.getProjectAnnotations() && project != null ? project.getId() : 0; 807 808 808 809 DbControl dc = getDbControl(); … … 867 868 868 869 @param source A source or null to not filter on source 869 @param project Id The project id or 0to query default values870 @param project The project or null to query default values 870 871 @since 3.11 871 872 */ 872 public ItemQuery<Annotation> getProjectAnnotations(Annotation.Source source, int projectId)873 public ItemQuery<Annotation> getProjectAnnotations(Annotation.Source source, Project project) 873 874 { 874 875 ItemQuery<Annotation> query = Annotation.getQuery(); … … 881 882 Restrictions.eq( 882 883 Hql.property("projectId"), 883 Expressions.integer(project Id)884 Expressions.integer(project != null ? project.getId() : 0) 884 885 )); 885 886 if (source != null) -
trunk/src/core/net/sf/basedb/core/snapshot/SnapshotManager.java
r7297 r7299 37 37 import net.sf.basedb.core.DbControl; 38 38 import net.sf.basedb.core.Permission; 39 import net.sf.basedb.core.Project; 39 40 import net.sf.basedb.util.StaticCache; 40 41 import net.sf.basedb.util.filter.Filter; … … 121 122 122 123 /** 123 When a project i d is set, the snapshot manager will only124 When a project is set, the snapshot manager will only 124 125 search for project-specific annotations explicitely belonging 125 to that project (or default values if projectId=0). 126 127 Note that this parameter typically always need to be off (=null) 128 when searching for annotations to an annotation type that 129 doesn't have enabled project-specific annotations. 130 131 @param projectId The project id or 0 to only search for default 132 values or null to revert to the default behaviour 133 (which load default values if a project-specific values 126 to that project (or default values if project == null). 127 128 Note that this option typically always need to be off 129 ({@link #setNoProject()}) when searching for annotations to an 130 annotation type that doesn't have enabled project-specific annotations. 131 132 Calling this method with a null parameter IS NOT the same 133 as calling {@link #setNoProject()}. 134 135 @param project The project or null to only search for default 136 values. Use {@link #setNoProject()} to revert to the default 137 behaviour (which load default values if a project-specific values 134 138 doesn't exists) 135 139 @since 3.11 136 140 */ 137 public void setProjectId(Integer projectId) 138 { 139 this.projectId = projectId; 141 public void setProject(Project project) 142 { 143 this.projectId = project == null ? 0 : project.getId(); 144 } 145 146 /** 147 Revert to the default bahavior for loading project-specific annotations. 148 149 @since 3.11 150 */ 151 public void setNoProject() 152 { 153 this.projectId = null; 140 154 } 141 155 -
trunk/src/test/TestAnnotation.java
r7296 r7299 281 281 Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId); 282 282 AnnotationType at = AnnotationType.getById(dc, annotationTypeId); 283 Project project = projectId == 0 ? null : Project.getById(dc, projectId); 283 284 284 285 AnnotationSet as = annotatable.getAnnotationSet(); 285 Annotation a = as.getProjectAnnotation(at, project Id);286 Annotation a = as.getProjectAnnotation(at, project); 286 287 287 288 if (value != null)
Note: See TracChangeset
for help on using the changeset viewer.