VitalRepository

abstract class VitalRepository<T : VitalEntity<ID>, ID>

A volatile in-memory repository to store temporary data in a Spring-like repository implementation. It can store implementations of VitalEntity and the means to get, save and delete them.

Useful for temporary data that should be wiped when the server restarts.

@Component
public class MyRepository extends VitalRepository<MyEntity> {

}

DO NOT ANNOTATE YOUR IMPLEMENTATIONS WITH org.springframework.stereotype.Repository. THIS WILL BREAK INSTANCE INTERNALS.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun delete(entity: T)

Deletes the given entity from this repository and calls the onDelete lifecycle. If the given entity does not exist in this repository, this function does nothing.

Link copied to clipboard
Link copied to clipboard
inline fun <T : VitalEntity<ID>> find(predicate: Predicate<T> = Predicate { true }): T?

Gets the first VitalEntity that matches the given predicate.

fun <T : VitalEntity<ID>> find(type: Class<T>, predicate: Predicate<T> = Predicate { true }): T?

Gets the first VitalEntity that matches the given type and predicate.

Link copied to clipboard
inline fun <T : VitalEntity<ID>> findAll(): List<T>

Gets all entities from this repository that are an instance of the given type.

fun <T : VitalEntity<ID>> findAll(type: Class<T>): List<T>

Gets all entities from this repository that are an instance of the given type.

Link copied to clipboard
inline fun <T : VitalEntity<ID>> findById(id: ID): T?

Gets the first entity that is an instance of the given type and has the given id.

fun <T : VitalEntity<ID>> findById(type: Class<T>, id: ID): T?

Gets the first entity that is an instance of the given type and has the given id.

Link copied to clipboard
fun findRandom(predicate: Predicate<T> = Predicate { true }): T?

Gets a random entity from this repository that matches the given predicate. If no entity was found, this function returns null.

Link copied to clipboard
fun <X : T> save(entity: X): X

Saves the given entity to this repository. If an entity with the given entity id (VitalEntity.id) already exists in this repository, it will be deleted via delete and then overridden

Link copied to clipboard
fun saveAll(entities: List<T>)

Saves all given entities by calling save for each one. If an empty list is provided, this function does nothing.