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
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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Holds information about a single annotation value.(package private) static class
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
Modifier and TypeFieldDescriptionprivate final DbControl
private boolean
private int
private final AnnotationType
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionload
(Collection<? extends Annotatable> items) Load the annotation values for all items in the given collection.load
(Iterator<? extends Annotatable> items) Load the annotation values for all items returned by the given iterator.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
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
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.
-