Class BaseSingleRowAttributeLoader<T>
- All Implemented Interfaces:
AttributeLoader<T>
,RowAttributeLoader<T>
,SingleRowAttributeLoader<T>
-
Constructor Summary
ConstructorsConstructorDescriptionBaseSingleRowAttributeLoader
(AttributeSpec<T> attributeSpec, Set<AttributeSpec<?>> dependencies, Set<AttributeContextDependency> contextDependencies, AttributeCachingStrategy cachingStrategy, TrailItemSet globalTrail, BiFunction<StructureRow, SingleRowAttributeContext, AttributeValue<T>> loadingFunction, RowPreloadFunction preloadFunction, boolean wholeForestDependent) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Allows the loader to declare dependency on the whole forest.loadValue
(StructureRow row, SingleRowAttributeContext context) The loading function.void
preload
(LongSet rowIds, ItemForest forest, AttributeContext context) Optional method to perform any bulk actions on a set of rows before the loading function is called for each row.Methods inherited from class BaseAttributeLoader
getAttributeDependencies, getAttributeSpec, getCachingStrategy, getContextDependencies, getGlobalTrail
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface AttributeLoader
getAttributeDependencies, getAttributeSpec, getCachingStrategy, getContextDependencies, getGlobalTrail
-
Constructor Details
-
BaseSingleRowAttributeLoader
public BaseSingleRowAttributeLoader(@NotNull AttributeSpec<T> attributeSpec, @Nullable Set<AttributeSpec<?>> dependencies, @Nullable Set<AttributeContextDependency> contextDependencies, @Nullable AttributeCachingStrategy cachingStrategy, @Nullable TrailItemSet globalTrail, @NotNull BiFunction<StructureRow, SingleRowAttributeContext, AttributeValue<T>> loadingFunction, @Nullable RowPreloadFunction preloadFunction, boolean wholeForestDependent)
-
-
Method Details
-
loadValue
@Nullable public AttributeValue<T> loadValue(@NotNull StructureRow row, @NotNull SingleRowAttributeContext context) Description copied from interface:SingleRowAttributeLoader
The loading function. The implementation is expected to take
row
and provide a value.Before this method is called,
RowAttributeLoader.preload(com.almworks.integers.LongSet, com.almworks.jira.structure.api.forest.item.ItemForest, com.almworks.jira.structure.api.attribute.loader.AttributeContext)
has been called for a set of rows that included this row, and that was a part of the same loading process, sharing the same context (so all values put into the context are still there).The exception to this rule is the super-root row, which is not included in the preload call. See
SuperRootRow
for more information about the super-root.If the value is missing or empty, the loader should return
AttributeValue.undefined()
. If for some reason this loader is not applicable for the given row, it should returnnull
.- Specified by:
loadValue
in interfaceSingleRowAttributeLoader<T>
- Parameters:
row
- the row to load the value forcontext
- loading context- Returns:
- attribute value, or
null
to pass on loading a value for this item
-
preload
public void preload(@NotNull LongSet rowIds, @NotNull ItemForest forest, @NotNull AttributeContext context) Description copied from interface:RowAttributeLoader
Optional method to perform any bulk actions on a set of rows before the loading function is called for each row.
The results of the preloading should be stored using
AttributeContext.putObject(java.lang.Object, java.lang.Object)
. Do not store the preloading results as loader's instance fields! All loaders should be stateless.Note that this method may be called several times during a single loading operation, for arbitrary sets of rows, including those that were already pre-loaded. Be careful not to overwrite one execution's result with another's.
The loader's dependencies may not be loaded at the time of the call. In fact, there's no way to access the dependency values.
Note that
rowIds
will never contain the super-root row id (-1
), even if the value for it is about to be loaded. SeeSuperRootRow
for details about the super-root.- Specified by:
preload
in interfaceRowAttributeLoader<T>
- Parameters:
rowIds
- set of row IDs for which attribute values are neededforest
- forest for which attribute values are being loadedcontext
- loading context
-
isWholeForestDependent
public boolean isWholeForestDependent()Description copied from interface:RowAttributeLoader
Allows the loader to declare dependency on the whole forest. In that case, the value loaded might depend on the forest and dependencies for the current row. (No dependencies on other values.)
The effect of such declaration is that the values of this attribute, as well as any other values depending on them, will be invalidated as soon as there's any forest or item changes.
You should almost never override this method. Introducing a whole-forest attribute takes toll on application performance.
- Specified by:
isWholeForestDependent
in interfaceRowAttributeLoader<T>
- Returns:
- true if the attribute is whole forest-dependent
-