Class FileCrudOperations<V extends AbstractEntity & UpdatableEntity,M>
- java.lang.Object
-
- org.keycloak.models.map.storage.file.FileCrudOperations<V,M>
-
- All Implemented Interfaces:
HasRealmId
,CrudOperations<V,M>
public abstract class FileCrudOperations<V extends AbstractEntity & UpdatableEntity,M> extends Object implements CrudOperations<V,M>, HasRealmId
-
-
Field Summary
Fields Modifier and Type Field Description static org.snakeyaml.engine.v2.api.DumpSettings
DUMP_SETTINGS
static String
FILE_SUFFIX
static String
SEARCHABLE_FIELD_REALM_ID_FIELD_NAME
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static boolean
canParseFile(Path p)
protected abstract void
checkIsSafeToModify(Path path)
Hook to validate that it is safe to modify the file identified by the suppliedPath
.V
create(V value)
Creates an object in the storage.MapModelCriteriaBuilder<String,V,M>
createCriteriaBuilder()
boolean
delete(String key)
Deletes object with the givenkey
from the storage, if exists, no-op otherwise.long
delete(QueryParameters<M> queryParameters)
Deletes objects that match the given criteria.String
determineKeyFromValue(V value, boolean forCreate)
Returns escaped ID - relative file name in the file system with path separatorID_COMPONENT_SEPARATOR
.long
getCount(QueryParameters<M> queryParameters)
Returns the number of objects satisfying givencriteria
from the storage.protected abstract FileTime
getLastModifiedTime(Path path)
Hook to obtain the last modified time of the file identified by the suppliedPath
.protected Path
getPathForEscapedId(String escapedId)
protected Path
getPathForEscapedId(String[] escapedIdPathArray)
static <V extends AbstractEntity & UpdatableEntity,M>
Map<SearchableModelField<? super M>,MapModelCriteriaBuilder.UpdatePredicatesFunc<String,V,M>>getPredicates(Class<V> entityClass)
String
getRealmId()
Returns realm ID of the entity.protected abstract String
getTxId()
protected V
parse(Path fileName)
V
read(String key)
Returns object with the givenkey
from the storage ornull
if object does not exist.Stream<V>
read(QueryParameters<M> queryParameters)
Returns stream of objects satisfying givencriteria
from the storage.protected abstract void
registerRenameOnCommit(Path tempSp, Path sp)
protected abstract boolean
removeIfExists(Path sp)
void
setRealmId(String realmId)
Sets the realm ID of this object.protected abstract void
touch(Path sp)
V
update(V value)
Updates the object with the key of thevalue
's ID in the storage if it already exists.-
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.CrudOperations
exists, exists
-
-
-
-
Field Detail
-
SEARCHABLE_FIELD_REALM_ID_FIELD_NAME
public static final String SEARCHABLE_FIELD_REALM_ID_FIELD_NAME
-
FILE_SUFFIX
public static final String FILE_SUFFIX
- See Also:
- Constant Field Values
-
DUMP_SETTINGS
public static final org.snakeyaml.engine.v2.api.DumpSettings DUMP_SETTINGS
-
-
Method Detail
-
getPredicates
public static <V extends AbstractEntity & UpdatableEntity,M> Map<SearchableModelField<? super M>,MapModelCriteriaBuilder.UpdatePredicatesFunc<String,V,M>> getPredicates(Class<V> entityClass)
-
canParseFile
public static boolean canParseFile(Path p)
-
create
public V create(V value)
Description copied from interface:CrudOperations
Creates an object in the storage.
ID of thevalue
may be prescribed in id of thevalue
. If the id isnull
or its format is not matching the store internal format for ID, then thevalue
's ID will be generated and returned in the id of the return value.- Specified by:
create
in interfaceCrudOperations<V extends AbstractEntity & UpdatableEntity,M>
- Parameters:
value
- Entity to create in the store- Returns:
- Entity representing the
value
in the store. It may or may not be the same instance asvalue
- See Also:
AbstractEntity.getId()
-
determineKeyFromValue
public String determineKeyFromValue(V value, boolean forCreate)
Returns escaped ID - relative file name in the file system with path separatorID_COMPONENT_SEPARATOR
.- Specified by:
determineKeyFromValue
in interfaceCrudOperations<V extends AbstractEntity & UpdatableEntity,M>
- Parameters:
value
- ObjectforCreate
- Whether this is for create operation (true
) or- Returns:
-
read
public V read(String key)
Description copied from interface:CrudOperations
Returns object with the givenkey
from the storage ornull
if object does not exist.
IfV
implementsExpirableEntity
this method should not return entities that are expired. SeeExpirableEntity
JavaDoc for more details. TODO: Consider returningOptional<V>
instead.- Specified by:
read
in interfaceCrudOperations<V extends AbstractEntity & UpdatableEntity,M>
- Parameters:
key
- Key of the object. Must not benull
.- Returns:
- See description
-
createCriteriaBuilder
public MapModelCriteriaBuilder<String,V,M> createCriteriaBuilder()
-
read
public Stream<V> read(QueryParameters<M> queryParameters)
Description copied from interface:CrudOperations
Returns stream of objects satisfying givencriteria
from the storage. The criteria are specified in the given criteria builder based on model properties.
IfV
implementsExpirableEntity
this method should not return entities that are expired. SeeExpirableEntity
JavaDoc for more details.- Specified by:
read
in interfaceCrudOperations<V extends AbstractEntity & UpdatableEntity,M>
- Parameters:
queryParameters
- parameters for the query like firstResult, maxResult, requested ordering, etc.- Returns:
- Stream of objects. Never returns
null
.
-
update
public V update(V value)
Description copied from interface:CrudOperations
Updates the object with the key of thevalue
's ID in the storage if it already exists.- Specified by:
update
in interfaceCrudOperations<V extends AbstractEntity & UpdatableEntity,M>
- Parameters:
value
- Updated value- Returns:
- the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)
- See Also:
AbstractEntity.getId()
-
delete
public boolean delete(String key)
Description copied from interface:CrudOperations
Deletes object with the givenkey
from the storage, if exists, no-op otherwise.- Specified by:
delete
in interfaceCrudOperations<V extends AbstractEntity & UpdatableEntity,M>
- Returns:
- Returns
true
if the object has been deleted or result cannot be determined,false
otherwise.
-
delete
public long delete(QueryParameters<M> queryParameters)
Description copied from interface:CrudOperations
Deletes objects that match the given criteria.- Specified by:
delete
in interfaceCrudOperations<V extends AbstractEntity & UpdatableEntity,M>
- Parameters:
queryParameters
- parameters for the query like firstResult, maxResult, requested ordering, etc.- Returns:
- Number of removed objects (might return
-1
if not supported)
-
getCount
public long getCount(QueryParameters<M> queryParameters)
Description copied from interface:CrudOperations
Returns the number of objects satisfying givencriteria
from the storage. The criteria are specified in the given criteria builder based on model properties.- Specified by:
getCount
in interfaceCrudOperations<V extends AbstractEntity & UpdatableEntity,M>
- Parameters:
queryParameters
- parameters for the query like firstResult, maxResult, requested ordering, etc.- Returns:
- Number of objects. Never returns
null
.
-
getRealmId
public String getRealmId()
Description copied from interface:HasRealmId
Returns realm ID of the entity.- Specified by:
getRealmId
in interfaceHasRealmId
- Returns:
- See description
-
setRealmId
public void setRealmId(String realmId)
Description copied from interface:HasRealmId
Sets the realm ID of this object.- Specified by:
setRealmId
in interfaceHasRealmId
- Parameters:
realmId
- Realm ID.
-
touch
protected abstract void touch(Path sp) throws IOException
- Throws:
IOException
-
removeIfExists
protected abstract boolean removeIfExists(Path sp)
-
getTxId
protected abstract String getTxId()
-
getLastModifiedTime
protected abstract FileTime getLastModifiedTime(Path path)
Hook to obtain the last modified time of the file identified by the suppliedPath
.
-
checkIsSafeToModify
protected abstract void checkIsSafeToModify(Path path)
Hook to validate that it is safe to modify the file identified by the suppliedPath
. The primary goal is to identify if other transactions have modified the file after it was read by the current transaction, preventing updates to a stale entity.- Parameters:
path
- thePath
to the file that is to be modified.
-
-