Package com.evolveum.midpoint.repo.sqale
Class UriCache
java.lang.Object
com.evolveum.midpoint.repo.sqale.UriCache
Component hiding details of how QNames are stored in
QUri
.
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 returns UNKNOWN_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 using QNameUtil.qNameToUri(QName)
when provided as a QName
.
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
Modifier and TypeFieldDescriptionstatic final int
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
-
Method Summary
Modifier and TypeMethodDescription@Nullable Integer
Returns ID for string, possiblynull
- does not work with underlying database.@Nullable Integer
Returns ID for QName, possiblynull
- does not work with underlying database.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
Returns ID for provided URI value of `QName/String/Object#toString`.@NotNull Integer
Returns ID for string orUNKNOWN_ID
- does not work with underlying database.
-
Field Details
-
UNKNOWN_ID
public static final int UNKNOWN_IDUnknown 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:
-
-
Constructor Details
-
UriCache
public UriCache()
-
-
Method Details
-
initialize
Initializes the URI cache. ProvidedJdbcSession
supplier will be used for later writes as well. -
getId
Returns ID for QName, possiblynull
- does not work with underlying database. -
resolveUriToId
Returns ID for QName or throws exception - does not work with underlying database. -
getId
Returns ID for string, possiblynull
- does not work with underlying database. -
searchId
Returns ID for provided URI value of `QName/String/Object#toString`. -
searchId
Returns ID for string orUNKNOWN_ID
- does not work with underlying database. -
resolveUriToId
Returns ID for QName or throws exception - does not work with underlying database. -
getUri
Returns URI string for ID ornull
- does not work with underlying database. -
resolveToUri
Returns URI string for ID or throws exception - does not work with underlying database. -
processCacheableUri
Returns ID for URI creating new cache row in DB as needed. Returns null for null URI parameter.
-