Package net.sf.basedb.core
Class FastAnnotationLoader<T>
java.lang.Object
net.sf.basedb.core.FastAnnotationLoader<T>
- Type Parameters:
T
- The type of values for the annotation
public class FastAnnotationLoader<T> extends Object
Implements an API for simple and fast loading of annotation values optimized for
situations when a single annotation is needed for many (=thousands) of items.
The regular annotation API is typically very slow and requires multiple SQL queries
for each annotation. The
SnapshotManager
API is typically faster, but only if
the annotations have already been cached.
This API have limited filtering capabilities and can be used for reading only, but it
can be combined with the AnnotationBatcher
API for updating annotations.
The result is returned as an iterator with each entry corresponding
to a single annotation value. The values are not sorted in any particular
order. If the annotation type allows multiple values each value is returned
as separate iterator entries in no particular order.
If the annotation type supports project-specific values, only default values
and values for the current project are returned.- Since:
- 3.19.10
- See Also:
AnnotationType.getFastLoader(DbControl)
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FastAnnotationLoader.FastAnnotation<T>
Holds information about a single annotation value.(package private) static class
FastAnnotationLoader.FastIterator<T>
Iterator implementation that splits the query into multiple calls depending on the max number of parameters that can be used in a query. -
Field Summary
Fields Modifier and Type Field Description private DbControl
dc
private boolean
includeDefault
private int
projectId
private AnnotationType
type
-
Constructor Summary
Constructors Constructor Description FastAnnotationLoader(DbControl dc, AnnotationType type)
-
Method Summary
Modifier and Type Method Description Iterator<FastAnnotationLoader.FastAnnotation<T>>
load(Collection<? extends Annotatable> items)
Load the annotation values for all items in the given collection.Iterator<FastAnnotationLoader.FastAnnotation<T>>
load(Iterator<? extends Annotatable> items)
Load the annotation values for all items returned by the given iterator.Iterator<FastAnnotationLoader.FastAnnotation<T>>
load(ItemQuery<? extends Annotatable> query)
Load the annotation values for all items returned by the query.void
setIncludeDefault(boolean includeDefault)
If the annotation type supports project-specific annotations this method can be used to control which values that are loaded.void
setProject(Project p)
If the annotation type supports project-specific annotations this method can be used to control which values that are loaded.
-
Field Details
-
dc
-
type
-
projectId
private int projectId -
includeDefault
private boolean includeDefault
-
-
Constructor Details
-
FastAnnotationLoader
FastAnnotationLoader(DbControl dc, AnnotationType type)
-
-
Method Details
-
setProject
If the annotation type supports project-specific annotations this method can be used to control which values that are loaded. The default setting is to load default values and values for the currently active project.- Parameters:
p
- The project that values should belong to, or null to not load any project-specific values
-
setIncludeDefault
public void setIncludeDefault(boolean includeDefault)If the annotation type supports project-specific annotations this method can be used to control which values that are loaded. The default setting is to load default values and values for the currently active project.- Parameters:
includeDefault
- TRUE to include default values, FALSE to not include them
-
load
public Iterator<FastAnnotationLoader.FastAnnotation<T>> load(ItemQuery<? extends Annotatable> query)Load the annotation values for all items returned by the query. This method is typically faster than theload(Collection)
method since theAbstractEntityQuery.idList(DbControl)
is used to only load item ids and not full items. -
load
public Iterator<FastAnnotationLoader.FastAnnotation<T>> load(Collection<? extends Annotatable> items)Load the annotation values for all items in the given collection. Note! All items in the collection must be of the same type. -
load
public Iterator<FastAnnotationLoader.FastAnnotation<T>> load(Iterator<? extends Annotatable> items)Load the annotation values for all items returned by the given iterator. Note! All items returned by the iterator must be of the same type.
-