Package com.evolveum.midpoint.repo.sqale
Class UriCache
- java.lang.Object
-
- com.evolveum.midpoint.repo.sqale.UriCache
-
public class UriCache extends Object
Component hiding details of how QNames are stored inQUri
. Following prefixes are used for its methods: * `get` returns URI or ID for ID or URI, may return null, accesses DB if not found (multi-node safety); * `search` like `get` but returnsUNKNOWN_ID
instead of null, used for query predicates, accesses DB if not found (multi-node safety); * `resolve` returns URI/ID for ID/URI or throws exception if not found, this is for situations where the entry for URI is expected to exist already, accesses DB if not found in cache (multi-node safety); * finally,processCacheableUri(Object)
accesses the database if the URI is not found in the cache in order to write it there. URIs are stored either as is when provided as a String or usingQNameUtil.qNameToUri(QName)
when provided as aQName
. This component does not know anything about relations (represented as QName-s), but these are systematically normalized before they get here (if not, it's surely a bug). [NOTE] URI is added in the database in its own separate transaction. It is tempting to add cached URI as part of the existing transaction, but when the provided transaction is rolled back, the cache still thinks the URI row is already there. This could be avoided if the runtime maps were updated *only* after the row was successfully read from the DB in other operations - which beats the purposes of those fast operations. Instead, we risk adding the row that is not used, it is no harm; it will likely be used later.
-
-
Field Summary
Fields Modifier and Type Field Description static int
UNKNOWN_ID
Unknown id placeholder, not actually in DB but returned when URI is not in the cache and returning `null` or throwing exception would not make sense.
-
Constructor Summary
Constructors Constructor Description UriCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @Nullable Integer
getId(@NotNull String uri)
Returns ID for string, possiblynull
- does not work with underlying database.@Nullable Integer
getId(@NotNull QName qName)
Returns ID for QName, possiblynull
- does not work with underlying database.String
getUri(Integer id)
Returns URI string for ID ornull
- does not work with underlying database.void
initialize(Supplier<JdbcSession> jdbcSessionSupplier)
Initializes the URI cache.@Nullable Integer
processCacheableUri(@Nullable Object uri)
Returns ID for URI creating new cache row in DB as needed.@NotNull String
resolveToUri(Integer id)
Returns URI string for ID or throws exception - does not work with underlying database.@NotNull Integer
resolveUriToId(@NotNull String uri)
Returns ID for QName or throws exception - does not work with underlying database.@NotNull Integer
resolveUriToId(@NotNull QName qName)
Returns ID for QName or throws exception - does not work with underlying database.@NotNull Integer
searchId(@NotNull Object uri)
Returns ID for provided URI value of `QName/String/Object#toString`.@NotNull Integer
searchId(@NotNull String uri)
Returns ID for string orUNKNOWN_ID
- does not work with underlying database.
-
-
-
Field Detail
-
UNKNOWN_ID
public static final int UNKNOWN_ID
Unknown id placeholder, not actually in DB but returned when URI is not in the cache and returning `null` or throwing exception would not make sense. Typical case is using it for query predicate when searching for unknown URI should result in a condition comparing URI ID attribute (e.g. relationId) to id that will not be found. This is completely transient and can be changed if the need arises.- See Also:
- Constant Field Values
-
-
Method Detail
-
initialize
public void initialize(Supplier<JdbcSession> jdbcSessionSupplier)
Initializes the URI cache. ProvidedJdbcSession
supplier will be used for later writes as well.
-
getId
@Nullable public @Nullable Integer getId(@NotNull @NotNull QName qName)
Returns ID for QName, possiblynull
- does not work with underlying database.
-
resolveUriToId
@NotNull public @NotNull Integer resolveUriToId(@NotNull @NotNull QName qName)
Returns ID for QName or throws exception - does not work with underlying database.
-
getId
@Nullable public @Nullable Integer getId(@NotNull @NotNull String uri)
Returns ID for string, possiblynull
- does not work with underlying database.
-
searchId
@NotNull public @NotNull Integer searchId(@NotNull @NotNull Object uri)
Returns ID for provided URI value of `QName/String/Object#toString`.
-
searchId
@NotNull public @NotNull Integer searchId(@NotNull @NotNull String uri)
Returns ID for string orUNKNOWN_ID
- does not work with underlying database.
-
resolveUriToId
@NotNull public @NotNull Integer resolveUriToId(@NotNull @NotNull String uri)
Returns ID for QName or throws exception - does not work with underlying database.
-
getUri
public String getUri(Integer id)
Returns URI string for ID ornull
- does not work with underlying database.
-
resolveToUri
@NotNull public @NotNull String resolveToUri(Integer id)
Returns URI string for ID or throws exception - does not work with underlying database.
-
-