@PublicApi public enum AttributeContextDependency extends Enum<AttributeContextDependency>
Allows the attribute loader to declare that the value it produces is calculated using some of the values from the context.
Different context dependencies may have different effects. Some, like USER_LOCALE
, provide "compartments" for values,
allowing to efficiently cache values for each locale. Some, like CURRENT_TIME
, declare the dependency on time and the corresponding
caching rules will be applied.
Context dependencies propagate through dependencies. Making an attribute dependent on the current user will also make all dependent attribute dependent on the current user.
AttributeLoader.getContextDependencies()
Enum Constant and Description |
---|
CURRENT_TIME
The values depend on the current time.
|
STRUCTURE
The values depend on the structure that they are being shown in.
|
TRAIL
The values depend on some items, which will be added via
AttributeLoaderContext.addTrail(com.almworks.jira.structure.api.attribute.loader.TrailItemSet) . |
USER
The values depend on the current user.
|
USER_LOCALE
The values depend on the current user's locale.
|
USER_TIMEZONE
The values depend on the current user's time zone.
|
Modifier and Type | Method and Description |
---|---|
static Set<AttributeContextDependency> |
guessContextDependencies(AttributeSpec<?> spec) |
static Set<AttributeContextDependency> |
union(Set<AttributeContextDependency> set,
AttributeContextDependency... additional) |
static AttributeContextDependency |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static AttributeContextDependency[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final AttributeContextDependency USER
The values depend on the current user.
The values will be calculated separately for each individual user (including anonymous user).
Use AttributeContext.getUser()
when calculating the value to get the current user.
This context dependency supersedes USER_LOCALE
and USER_TIMEZONE
. No need to declare these context dependencies, since
the user compartment already provides the necessary separation for different locales and time zones.
All values with this context dependency will be invalidated when the user itself is changed.
public static final AttributeContextDependency USER_LOCALE
The values depend on the current user's locale. Typically this is used when calculating a HTML-rendered value.
The values will be calculated separately for each locale. If two users have the same locale, they will share the same value.
Use AttributeContext.getLocale()
or AttributeContext.getI18nHelper()
when calculating the value.
public static final AttributeContextDependency USER_TIMEZONE
The values depend on the current user's time zone.
The values will be calculated separately for each time zone. If two users have the same time zone, they will share the same value.
Use AttributeContext.getTimeZone()
when calculating the value.
public static final AttributeContextDependency STRUCTURE
The values depend on the structure that they are being shown in.
The values may depend only on the structure ID, without any transformations. When calculating the values for a query-based forest,
the structure ID will be equal to 0
, and so all the values calculated for queries will be shared.
Note that forest-dependent attributes will naturally be stored in a forest-specific cache. There's no need to declare structure dependency for aggregates, for example. You only need to declare the dependency if you actively use the structure ID for calculating the value. For example, you can store different values for the same items in different structures.
Use AttributeContext.getBaseStructureId()
when calculating the value.
public static final AttributeContextDependency CURRENT_TIME
The values depend on the current time.
Declaring this context dependency will cause the values to expire after some time and get recalculated. You can define the expiration
time by calling AttributeLoaderContext.valueExpires(long, java.util.concurrent.TimeUnit)
, or just declare the context dependency and go with the default expiration.
You can use AttributeContext.getLoadTimeMillis()
and AttributeContext.getLoadTimeNanos()
when calculating
the value. These methods will return a consistent number for all values loaded in the same loading process. But you can also use
System.currentTimeMillis()
and System.nanoTime()
.
public static final AttributeContextDependency TRAIL
The values depend on some items, which will be added via AttributeLoaderContext.addTrail(com.almworks.jira.structure.api.attribute.loader.TrailItemSet)
.
You need to declare this dependency in order for the system to be prepared for the addTrail()
call. In particular, multi-row
attributes that declare this dependency will not be eligible for pre-validation (reusing a previously calculated value if nothing has
changed in the inputs).
Note that you don't need to declare this dependency if you're declaring a global trail via AttributeLoader.getGlobalTrail()
.
public static AttributeContextDependency[] values()
for (AttributeContextDependency c : AttributeContextDependency.values()) System.out.println(c);
public static AttributeContextDependency valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static Set<AttributeContextDependency> guessContextDependencies(AttributeSpec<?> spec)
@NotNull public static Set<AttributeContextDependency> union(@Nullable Set<AttributeContextDependency> set, @Nullable AttributeContextDependency... additional)
Copyright © 2024 Tempo Software. All Rights Reserved.