Class SnapshotManager

java.lang.Object
net.sf.basedb.core.snapshot.SnapshotManager

public class SnapshotManager extends Object
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 Details

  • Constructor Details

    • SnapshotManager

      public SnapshotManager()
      Create a new snapshot manager.
  • Method Details

    • getCacheKey

      public static String getCacheKey(int annotationSetId)
      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

      public static int removeSnapshots(List<Integer> annotationSetIds)
      Since:
      3.5
      See Also:
    • removeSnapshots

      public static int removeSnapshots(Collection<Integer> annotationSetIds)
      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

      public 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). 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 calling setNoProject() or setAllProjects().
      Parameters:
      project - The project or null to only search for default values. Use setNoProject() 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

      public AnnotationSetSnapshot getSnapshot(DbControl dc, int annotationSetId)
      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 cache
      annotationSetId - 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.
      See Also:
    • 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 set
      snapshot - The snapshot to search
      filter - A filter that should match the wanted annotation snapshots or null to match all annotations
      searchPrimary - TRUE if primary annotations should be searched
      searchInherited - 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)
      See Also:
    • findAnnotations

      public List<AnnotationSnapshot> findAnnotations(DbControl dc, Annotatable item, Filter<? super AnnotationSnapshot> filter, boolean searchPrimary, boolean searchInherited)
      Utility method for calling getSnapshot and findAnnotations 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: