Class ConcurrentHashMapStorage<K,V extends AbstractEntity & UpdatableEntity,M,CRUD extends CrudOperations<V,M>>
java.lang.Object
org.keycloak.models.map.storage.chm.ConcurrentHashMapStorage<K,V,M,CRUD>
- All Implemented Interfaces:
KeycloakTransaction
,HasRealmId
,MapStorage<V,
M>
- Direct Known Subclasses:
FileMapStorage
,HotRodUserSessionMapStorage
,SingleUseObjectMapStorage
public class ConcurrentHashMapStorage<K,V extends AbstractEntity & UpdatableEntity,M,CRUD extends CrudOperations<V,M>>
extends Object
implements MapStorage<V,M>, KeycloakTransaction, HasRealmId
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static enum
protected class
protected static final class
protected class
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected final DeepCloner
protected final Map<SearchableModelField<? super M>,
MapModelCriteriaBuilder.UpdatePredicatesFunc<K, V, M>> protected final StringKeyConverter<K>
protected final CRUD
protected final EntityField<V>
protected boolean
-
Constructor Summary
ConstructorDescriptionConcurrentHashMapStorage
(CRUD map, StringKeyConverter<K> keyConverter, DeepCloner cloner, Map<SearchableModelField<? super M>, MapModelCriteriaBuilder.UpdatePredicatesFunc<K, V, M>> fieldPredicates) ConcurrentHashMapStorage
(CRUD map, StringKeyConverter<K> keyConverter, DeepCloner cloner, Map<SearchableModelField<? super M>, MapModelCriteriaBuilder.UpdatePredicatesFunc<K, V, M>> fieldPredicates, EntityField<V> realmIdEntityField) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addTask
(String key, ConcurrentHashMapStorage<K, V, M, CRUD>.MapTaskWithValue task) Adds a given task if not exists for the given keyvoid
begin()
void
commit()
Instructs this storage to add a new value into the underlying store on commit in the context of the current transaction.boolean
Instructs this storage to delete a value associated with the identifierkey
from the underlying store upon commit.long
delete
(QueryParameters<M> queryParameters) Instructs this transaction to remove values (identified bymcb
filter) from the underlying store upon commit.boolean
Returnstrue
if the object with the givenkey
exists in the underlying storage with respect to changes done in the current transaction.long
getCount
(QueryParameters<M> queryParameters) Returns a number of values present in the underlying storage that fulfill the given criteria with respect to changes done in the current transaction.Returns realm ID of the entity.boolean
boolean
isActive()
Provides possibility to lookup for values by akey
in the underlying store with respect to changes done in current transaction.read
(QueryParameters<M> queryParameters) Returns the stream of records that match given criteria and includes changes made in this transaction, i.e.registerEntityForChanges
(V origEntity) Returns a deep clone of an entity.void
rollback()
void
setRealmId
(String realmId) Sets the realm ID of this object.void
updateIfChanged
(V value, Predicate<V> shouldPut) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.keycloak.models.map.storage.MapStorage
exists
-
Field Details
-
active
protected boolean active -
rollback
protected boolean rollback -
tasks
protected final ConcurrentHashMapStorage<K,V extends AbstractEntity & UpdatableEntity, tasksM, CRUD extends CrudOperations<V, M>>.TaskMap -
map
-
keyConverter
-
cloner
-
fieldPredicates
protected final Map<SearchableModelField<? super M>,MapModelCriteriaBuilder.UpdatePredicatesFunc<K, fieldPredicatesV extends AbstractEntity & UpdatableEntity, M>> -
realmIdEntityField
-
-
Constructor Details
-
ConcurrentHashMapStorage
public ConcurrentHashMapStorage(CRUD map, StringKeyConverter<K> keyConverter, DeepCloner cloner, Map<SearchableModelField<? super M>, MapModelCriteriaBuilder.UpdatePredicatesFunc<K, V, M>> fieldPredicates) -
ConcurrentHashMapStorage
public ConcurrentHashMapStorage(CRUD map, StringKeyConverter<K> keyConverter, DeepCloner cloner, Map<SearchableModelField<? super M>, MapModelCriteriaBuilder.UpdatePredicatesFunc<K, V, M>> fieldPredicates, EntityField<V> realmIdEntityField)
-
-
Method Details
-
begin
public void begin()- Specified by:
begin
in interfaceKeycloakTransaction
-
commit
public void commit()- Specified by:
commit
in interfaceKeycloakTransaction
-
rollback
public void rollback()- Specified by:
rollback
in interfaceKeycloakTransaction
-
setRollbackOnly
public void setRollbackOnly()- Specified by:
setRollbackOnly
in interfaceKeycloakTransaction
-
getRollbackOnly
public boolean getRollbackOnly()- Specified by:
getRollbackOnly
in interfaceKeycloakTransaction
-
isActive
public boolean isActive()- Specified by:
isActive
in interfaceKeycloakTransaction
-
addTask
Adds a given task if not exists for the given key -
registerEntityForChanges
Returns a deep clone of an entity. If the clone is already in the transaction, returns this one.Usually used before giving an entity from a source back to the caller, to prevent changing it directly in the data store, but to keep transactional properties.
- Parameters:
origEntity
- Original entity- Returns:
-
read
Description copied from interface:MapStorage
Provides possibility to lookup for values by akey
in the underlying store with respect to changes done in current transaction. Updates to the returned instance would be visible in the current transaction and will propagate into the underlying store upon commit. IfV
implementsExpirableEntity
this method should not return entities that are expired. SeeExpirableEntity
JavaDoc for more details.- Specified by:
read
in interfaceMapStorage<K,
V extends AbstractEntity & UpdatableEntity> - Parameters:
sKey
- identifier of a value- Returns:
- a value associated with the given
key
-
read
Returns the stream of records that match given criteria and includes changes made in this transaction, i.e. the result contains updates and excludes records that have been deleted in this transaction.- Specified by:
read
in interfaceMapStorage<K,
V extends AbstractEntity & UpdatableEntity> - Parameters:
queryParameters
-- Returns:
-
getCount
Description copied from interface:MapStorage
Returns a number of values present in the underlying storage that fulfill the given criteria with respect to changes done in the current transaction.- Specified by:
getCount
in interfaceMapStorage<K,
V extends AbstractEntity & UpdatableEntity> - Parameters:
queryParameters
- parameters for the query like firstResult, maxResult, requested ordering, etc.- Returns:
- number of values present in the storage that fulfill the given criteria
-
create
Description copied from interface:MapStorage
Instructs this storage to add a new value into the underlying store on commit in the context of the current transaction.Updates to the returned instances of
V
would be visible in the current transaction and will propagate into the underlying store upon commit. The ID of the entity passed in the parameter might change to a different value in the returned value if the underlying storage decided this was necessary. If the ID of the entity was null before, it will be set on the returned value.- Specified by:
create
in interfaceMapStorage<K,
V extends AbstractEntity & UpdatableEntity> - Parameters:
value
- the value- Returns:
- Entity representing the
value
in the store. It may or may not be the same instance asvalue
.
-
updateIfChanged
-
delete
Description copied from interface:MapStorage
Instructs this storage to delete a value associated with the identifierkey
from the underlying store upon commit.- Specified by:
delete
in interfaceMapStorage<K,
V extends AbstractEntity & UpdatableEntity> - Parameters:
key
- identifier of a value- Returns:
- Returns
true
if the object has been deleted or result cannot be determined,false
otherwise.
-
delete
Description copied from interface:MapStorage
Instructs this transaction to remove values (identified bymcb
filter) from the underlying store upon commit.- Specified by:
delete
in interfaceMapStorage<K,
V extends AbstractEntity & UpdatableEntity> - Parameters:
queryParameters
- parameters for the query like firstResult, maxResult, requested ordering, etc.- Returns:
- number of removed objects (might return
-1
if not supported)
-
exists
Description copied from interface:MapStorage
Returnstrue
if the object with the givenkey
exists in the underlying storage with respect to changes done in the current transaction.false
otherwise.- Specified by:
exists
in interfaceMapStorage<K,
V extends AbstractEntity & UpdatableEntity> - Parameters:
key
- Key of the object. Must not benull
.- Returns:
- See description
-
getRealmId
Description copied from interface:HasRealmId
Returns realm ID of the entity.- Specified by:
getRealmId
in interfaceHasRealmId
- Returns:
- See description
-
setRealmId
Description copied from interface:HasRealmId
Sets the realm ID of this object.- Specified by:
setRealmId
in interfaceHasRealmId
- Parameters:
realmId
- Realm ID.
-