2.17.2: 2011-06-17

net.sf.basedb.core.snapshot
Class SnapshotManager

java.lang.Object
  extended by 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: 2010-04-20 10:02:16 +0200 (Tue, 20 Apr 2010) $

Field Summary
private  Map<Integer,AnnotationSetSnapshot> snapshots
           
 
Constructor Summary
SnapshotManager()
          Create a new snapshot manager.
 
Method Summary
 List<AnnotationSnapshot> findAnnotations(DbControl dc, Annotatable item, Filter<? super AnnotationSnapshot> filter, boolean searchInherited)
          Utility method for calling getSnapshot and findAnnotations in one go.
 List<AnnotationSnapshot> findAnnotations(DbControl dc, AnnotationSetSnapshot snapshot, Filter<? super AnnotationSnapshot> filter, boolean searchInherited)
          Search in a snapshot for all annotations of a specified annotation type.
static String getCacheKey(int annotationSetId)
          The static cache key under which the snapshot for the annotation set with the given id is cached.
 AnnotationSetSnapshot 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

snapshots

private final Map<Integer,AnnotationSetSnapshot> snapshots
Constructor Detail

SnapshotManager

public SnapshotManager()
Create a new snapshot manager.

Method Detail

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

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)
Search in a snapshot for all annotations of a specified annotation type. 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
searchInherited - TRUE if inherited annotations should be searched, FALSE to only search primary annotations
Returns:
A list with the found annotations

findAnnotations

public List<AnnotationSnapshot> findAnnotations(DbControl dc,
                                                Annotatable item,
                                                Filter<? super AnnotationSnapshot> filter,
                                                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)
See Also:
getSnapshot(DbControl, int), findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean)

2.17.2: 2011-06-17