FileStorage

data class FileStorage<T>(val folder: String, val serializer: Serializer<T, String>) : Storage<String, T, String>

Storage implementation via file + text strings.

This method was based from roby2014 - uni-projects/TDS

Parameters

T

Type of the domain entity

folder

Folder where the file will be stored

Constructors

Link copied to clipboard
constructor(folder: String, serializer: Serializer<T, String>)

Properties

Link copied to clipboard
private val folder: String
Link copied to clipboard
open override val serializer: Serializer<T, String>

The serializer responsible for converting entities to/from the storage format.

Functions

Link copied to clipboard
open override fun close()

Closes the file storage, releasing any held resources. For file storage, this is a no-op as there are no persistent resources to close.

Link copied to clipboard
open override fun delete(id: String)

Deletes an entity from file storage by its identifier.

Link copied to clipboard
open override fun lastModified(id: String): Long?

Gets the last modification timestamp for an entity in file storage.

Link copied to clipboard
open override fun load(id: String): T?

Retrieves an entity from file storage by its identifier.

Link copied to clipboard
open override fun loadAllIds(): List<String>

Loads all entity identifiers currently stored in this file storage.

Link copied to clipboard
open override fun new(id: String, factory: () -> T): T

Creates a new entity in file storage with the given identifier.

Link copied to clipboard
private fun path(id: String): Path

Computes the file path for an entity with the given ID.

Link copied to clipboard
open override fun save(id: String, obj: T)

Saves (persists) an entity in file storage under the given identifier.