Package net.sf.basedb.core.snapshot
Class SnapshotManager
java.lang.Object
net.sf.basedb.core.snapshot.SnapshotManager
Manager for annotation snapshots. The manager keeps an internal cache in memory
of snapshots that has been loaded. If an unload snapshot is needed the manager
will first look in the static cache. If it is not found there the last resort
is to generate a new snapshot.
- Version:
- 2.14
- Author:
- Nicklas
- Last modified
- $Date: 2024-05-16 09:07:06 +0200 (Thu, 16 May 2024) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate boolean
private DisabledInheritanceFilter
private Integer
private final Map<Integer,
AnnotationSetSnapshot> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear the manager from all memory-cached information.findAnnotations
(DbControl dc, Annotatable item, Filter<? super AnnotationSnapshot> filter, boolean searchInherited) findAnnotations
(DbControl dc, Annotatable item, Filter<? super AnnotationSnapshot> filter, boolean searchPrimary, boolean searchInherited) Utility method for callinggetSnapshot
andfindAnnotations
in one go.findAnnotations
(DbControl dc, AnnotationSetSnapshot snapshot, Filter<? super AnnotationSnapshot> filter, boolean searchInherited) Find annotations.findAnnotations
(DbControl dc, AnnotationSetSnapshot snapshot, Filter<? super AnnotationSnapshot> filter, boolean searchPrimary, boolean searchInherited) Search in a snapshot for all annotations matching a given filter.static String
getCacheKey
(int annotationSetId) The static cache key under which the snapshot for the annotation set with the given id is cached.getSnapshot
(DbControl dc, int annotationSetId) Get the annotation snapshot for the annotation set with the given id.static boolean
removeSnapshot
(int annotationSetId) Removes a snapshot from the static cache.static int
removeSnapshots
(Collection<Integer> annotationSetIds) Removes a list of snapshots from the static cache.static int
removeSnapshots
(List<Integer> annotationSetIds) void
Search for project-specific annotations for all projects including the default values.void
Revert to the default bahavior for loading project-specific annotations.void
setProject
(Project project) When a project is set, the snapshot manager will only search for project-specific annotations explicitely belonging to that project (or default values if project == null).
-
Field Details
-
snapshots
-
disabledInheritanceFilter
-
projectId
-
allProjects
private boolean allProjects
-
-
Constructor Details
-
SnapshotManager
public SnapshotManager()Create a new snapshot manager.
-
-
Method Details
-
getCacheKey
The static cache key under which the snapshot for the annotation set with the given id is cached.- Parameters:
annotationSetId
- The ID of an annotation set
-
removeSnapshot
public static boolean removeSnapshot(int annotationSetId) Removes a snapshot from the static cache.- Parameters:
annotationSetId
- The ID of the annotation set- Returns:
- TRUE if the snapshot was removed or didn't exists to begin with, FALSE if it existed and could not be removed
-
removeSnapshots
- Since:
- 3.5
- See Also:
-
removeSnapshots
Removes a list of snapshots from the static cache.- Parameters:
annotationSetIds
- A list with IDs of annotation set s- Returns:
- The number of successfully removed snapshots
- Since:
- 3.10
-
clear
public void clear()Clear the manager from all memory-cached information.- Since:
- 3.16
-
setProject
When a project is set, the snapshot manager will only search for project-specific annotations explicitely belonging to that project (or default values if project == null). Note that this option typically always need to be off (setNoProject()
) when searching for annotations to an annotation type that doesn't have enabled project-specific annotations. Calling this method with a null parameter IS NOT the same as callingsetNoProject()
orsetAllProjects()
.- Parameters:
project
- The project or null to only search for default values. UsesetNoProject()
to revert to the default behaviour (which load default values if a project-specific values doesn't exists)- Since:
- 3.11
-
setNoProject
public void setNoProject()Revert to the default bahavior for loading project-specific annotations.- Since:
- 3.11
-
setAllProjects
public void setAllProjects()Search for project-specific annotations for all projects including the default values.- Since:
- 3.19.4
-
getSnapshot
Get the annotation snapshot for the annotation set with the given id.- Parameters:
dc
- A DbControl to use if the snapshot has to be created from the database cacheannotationSetId
- The id of the annotation set- Returns:
- A snapshot, or null if the annotation set with the given id doesn't exists
-
findAnnotations
public List<AnnotationSnapshot> findAnnotations(DbControl dc, AnnotationSetSnapshot snapshot, Filter<? super AnnotationSnapshot> filter, boolean searchInherited) Find annotations. Alwasys search primary and optionally inherited. -
findAnnotations
public List<AnnotationSnapshot> findAnnotations(DbControl dc, AnnotationSetSnapshot snapshot, Filter<? super AnnotationSnapshot> filter, boolean searchPrimary, boolean searchInherited) Search in a snapshot for all annotations matching a given filter. If the snapshot inherits annotations and/or annotation sets from other annotations sets, those snapshots are search recursively one level down.- Parameters:
dc
- A DbControl to use for database access if a snapshot doesn't exists for an inherited annotation setsnapshot
- The snapshot to searchfilter
- A filter that should match the wanted annotation snapshots or null to match all annotationssearchPrimary
- TRUE if primary annotations should be searchedsearchInherited
- TRUE if inherited annotations should be searched- Returns:
- A list with the found annotations
- Since:
- 3.5
-
findAnnotations
public List<AnnotationSnapshot> findAnnotations(DbControl dc, Annotatable item, Filter<? super AnnotationSnapshot> filter, boolean searchInherited) -
findAnnotations
public List<AnnotationSnapshot> findAnnotations(DbControl dc, Annotatable item, Filter<? super AnnotationSnapshot> filter, boolean searchPrimary, boolean searchInherited) Utility method for callinggetSnapshot
andfindAnnotations
in one go.- Returns:
- A list with the annotation snapshots (an empty list is returned if the item doesn't have any annotations)
- Since:
- 3.5
- See Also:
-