Package net.sf.basedb.core.snapshot
Class AnnotationSnapshot
java.lang.Object
net.sf.basedb.core.snapshot.AnnotationSnapshot
- All Implemented Interfaces:
Serializable
Stores information about a single primary or inherited
annotation or an inherited annotation set. Actual
annotation values are only stored for primary annotations.
IMPORTANT NOTE TO DEVELOPERS!!
Do not forget to synchronize all serialization code and to increment
the AnnotationSetSnapshot.FILE_VERSION
in case the number of variables
that needs serialization in this class or in the AnnotationSetSnapshot
changes.
- Version:
- 2.14
- Author:
- Nicklas
- See Also:
- Last modified
- $Date: 2022-07-28 14:30:36 +0200 (Thu, 28 Jul 2022) $
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
Comparator implementation for sorting snapshots by name of annotation type.(package private) static class
Comparator implementation for sorting snapshots by name of project. -
Field Summary
Modifier and TypeFieldDescriptionprivate int
private int
private int
private AnnotationSnapshot
private int
private int
private int
private Item
private long
private int
private int
private static final long
private Annotation.Source
private int
private List<? extends Serializable>
private Type
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription(package private) void
Get the unit that is most relevant for this annotation.<T extends Serializable>
List<T>Get the annotation values that are most relevant for this annotation.<T extends Serializable>
List<T>getActualValues
(UnitConverter converter, Type valueType) Get the annotations values, optionally converted to some specific unit and type of values.Get the annotation type.int
Get the id of the annotation type.Get the parent annotation this annotation is inherited from.int
Get the ID of the annotation this annotation is inherited from.Get the annotation set this annotation is inherited from.int
Get the ID of the annotation set this annotation is inherited from.Get a snapshot for the annotation this is inherited from.int
Get the id of the default annotation that this project-specific annotation is overriding.getProject
(DbControl dc) Get the project that a project-specific annotation belongs to.int
Get the id of the project that this project-specific annotation belongs to.(package private) String
Get the name of project if the annotation is a project-specific value.Get the source of the annotation.Get the annotation this is a snapshot of.int
Get the id of the annotation this is a snapshot of.Get the annotation set this annotation belongs to.int
Get the id of the annotation set this is a snapshot of.getThisItem
(DbControl dc) Get the item that this annotation belongs to.int
Get the id of the item this annotation belongs to.Get the item type of the item this annotation belongs to.Get the date+time this annotation was last updated.getThisUnit
(DbControl dc) Get the unit the annotatation values should use for display.int
Get the id of the unit that the annotation values should use when displayed.<T extends Serializable>
List<T>Get the annotation values for this annotation.boolean
hasPermission
(DbControl dc, Permission permission) Check if the logged in user has the request permission on this annotation or annotation set.(package private) void
Initialize the snapshot with information from the given annotation.boolean
A primary or inherited annotation is always up-to-date.private void
(package private) void
(package private) void
setInheritedFrom
(AnnotationSnapshot inheritedFrom) Set the primary annotation for an inherited annotation.(package private) void
static Comparator<AnnotationSnapshot>
Create a comparator for sorting annotation snapshots by the name of the annotation type.static Comparator<AnnotationSnapshot>
sortByProject
(DbControl dc, boolean defaultFirst) Create a comparator for sorting annotation snapshots by the name of the project.private void
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
source
-
annotationId
private transient int annotationId -
annotationSetId
private transient int annotationSetId -
annotationTypeId
private transient int annotationTypeId -
inheritedFromId
private transient int inheritedFromId -
inheritedFromSetId
private transient int inheritedFromSetId -
unitId
private transient int unitId -
projectId
private transient int projectId -
overrideId
private transient int overrideId -
valueType
-
lastUpdate
private transient long lastUpdate -
values
-
itemId
private transient int itemId -
itemType
-
inheritedFrom
-
-
Constructor Details
-
AnnotationSnapshot
public AnnotationSnapshot()Create a new, empty annotation snapshot.
-
-
Method Details
-
sortByAnnotationType
Create a comparator for sorting annotation snapshots by the name of the annotation type.- Since:
- 3.6
-
sortByProject
Create a comparator for sorting annotation snapshots by the name of the project. Default values can be sorted first or last.- Since:
- 3.19.4
-
init
Initialize the snapshot with information from the given annotation.- Parameters:
a
- An annotation
-
getSource
Get the source of the annotation.- Since:
- 3.6
-
getThisAnnotationId
public int getThisAnnotationId()Get the id of the annotation this is a snapshot of.- Returns:
- The id of this annotation
- Since:
- 3.6
-
getInheritedAnnotationId
public int getInheritedAnnotationId()Get the ID of the annotation this annotation is inherited from. NOTE! This may return 0 for cloned annotations that has lost their parent annotation.- Returns:
- The id of the inherited annotation or 0 if this is primary annotation (or a cloned annotation that has lost it's parent)
- Since:
- 3.6
-
getThisAnnotation
Get the annotation this is a snapshot of.- Returns:
- An Annotation object
- Since:
- 3.6
-
getInheritedAnnotation
Get the parent annotation this annotation is inherited from. NOTE! This may return null for cloned annotations that has lost their parent annotation.- Returns:
- The inherited annotation or null if this is primary annotation (or a cloned annotation that has lost it's parent)
- Since:
- 3.6
-
hasPermission
Check if the logged in user has the request permission on this annotation or annotation set.- Parameters:
dc
- The DbControl to use for database accesspermission
- The requested permission- Returns:
- TRUE if the logged in user has the requested permission, FALSE otherwise
- Since:
- 3.1.1
-
getThisAnnotationSetId
public int getThisAnnotationSetId()Get the id of the annotation set this is a snapshot of.- Returns:
- The id of this annotation set
- Since:
- 3.6
-
getInheritedAnnotationSetId
public int getInheritedAnnotationSetId()Get the ID of the annotation set this annotation is inherited from. NOTE! This may return 0 for cloned annotations that has lost their parent annotation.- Returns:
- The id of the inherited annotation set or 0 if this is primary annotation (or a cloned annotation that has lost it's parent)
- Since:
- 3.6
-
getThisAnnotationSet
Get the annotation set this annotation belongs to.- Since:
- 3.6
-
getInheritedAnnotationSet
Get the annotation set this annotation is inherited from. NOTE! This may return null for cloned annotations that has lost their parent annotation.- Since:
- 3.6
-
getAnnotationTypeId
public int getAnnotationTypeId()Get the id of the annotation type.- Returns:
- The annotation type id, or 0 if this snapshot is from an inherited annotation set
-
getAnnotationType
Get the annotation type.- Returns:
- An AnnotationType object or null if this snapshot is from an inherited annotation set
-
getInheritedFrom
Get a snapshot for the annotation this is inherited from. NOTE! This is only available for inherited annotations returned bySnapshotManager.findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean)
but may be missing for cloned annotations if the parent has been deleted.- Since:
- 3.6
-
getProjectId
public int getProjectId()Get the id of the project that this project-specific annotation belongs to.- Returns:
- The project id, or 0 if this a default annotation
- Since:
- 3.10
-
getProject
Get the project that a project-specific annotation belongs to. Returns null if the annotation is a default value or if the project no longer exists.- Throws:
PermissionDeniedException
- If the logged in user doesn't have access to the project- Since:
- 3.19.4
-
getProjectName
Get the name of project if the annotation is a project-specific value. -
getOverrideId
public int getOverrideId()Get the id of the default annotation that this project-specific annotation is overriding.- Since:
- 3.10
-
getThisUnitId
public int getThisUnitId()Get the id of the unit that the annotation values should use when displayed.- Since:
- 3.6
-
getThisUnit
Get the unit the annotatation values should use for display. NOTE! The unit is only available for primary and cloned annotations. UsegetActualUnit(DbControl)
orgetInheritedFrom()
.getThisUnit() to get the unit also for inherited annotations.- Returns:
- A Unit object or null if this annotation doesn't use units
- Since:
- 3.6
-
getActualUnit
Get the unit that is most relevant for this annotation. Eg. a unit that is defined by this annotation (primary and cloned) are used before inherited unit.- Since:
- 3.6
-
getThisValues
Get the annotation values for this annotation. NOTE! The values are only available for primary and cloned annotations. UsegetActualValues()
orgetInheritedFrom()
.getThisValues() to get values also for inherited annotations.- Returns:
- A list with the values or null
-
getActualValues
Get the annotation values that are most relevant for this annotation. Eg. values that are defined by this annotation (primary and cloned) are used before inherited values.- Since:
- 3.6
-
getActualValues
Get the annotations values, optionally converted to some specific unit and type of values. NOTE! To create a unit converter that converts that values to the unit specified bygetActualUnit(DbControl)
: this.getActualUnit(dc).getUnitConverter(this.getAnnotationType(dc).getDefaultUnit())- Parameters:
converter
- A converter for converting (numerical) values, or null to not convert the valuesvalueType
- The return type of the converted values (ignored if no converter is specified)- Returns:
- A list with the values
- Since:
- 3.6
-
getThisLastUpdate
Get the date+time this annotation was last updated.- Returns:
- The date or null if this annotation doesn't contain any values
- Since:
- 3.6
-
isUpToDate
public boolean isUpToDate()A primary or inherited annotation is always up-to-date. A cloned annotation is up-to-date if the link to the source annotation exists and the source annotation has a date equal to or before the cloned annotation.- Since:
- 3.6
-
getThisItemId
public int getThisItemId()Get the id of the item this annotation belongs to. NOTE! this value is only available on annotations returned from the call to:SnapshotManager.findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean)
-
getThisItem
Get the item that this annotation belongs to.- Returns:
- The item, or null if the item is not know
- Since:
- 3.6
-
getThisItemType
Get the item type of the item this annotation belongs to. NOTE! this value is only available on annotations returned from the call to:SnapshotManager.findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean)
- Returns:
- The item type, or null if not known
- Since:
- 3.6
-
setItem
-
setInheritedFrom
Set the primary annotation for an inherited annotation. -
serializeObject
- Throws:
IOException
-
writeObject
- Throws:
IOException
-
deserializeObject
- Throws:
IOException
ClassNotFoundException
-
readObject
- Throws:
IOException
ClassNotFoundException
-