MongoDBStorage

data class MongoDBStorage<T>(val mongoDBConnection: MongoDBConnection, val databaseName: String, val collectionName: String, val serializer: Serializer<T, String>) : Storage<String, T, String>

Storage implementation via MongoDB + text strings.

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

Parameters

T

Type of the domain entity

Constructors

Link copied to clipboard
constructor(mongoDBConnection: MongoDBConnection, databaseName: String, collectionName: String, serializer: Serializer<T, String>)

Properties

Link copied to clipboard
private val collection: MongoCollection<Document>
Link copied to clipboard
private val collectionName: String
Link copied to clipboard
private val database: MongoDatabase
Link copied to clipboard
private val databaseName: String
Link copied to clipboard
private val mongoClient: MongoClient
Link copied to clipboard
Link copied to clipboard
open override val serializer: Serializer<T, String>

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

Link copied to clipboard
private val uri: String

Functions

Link copied to clipboard
open override fun close()

Closes the storage, releasing any held resources.

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

Deletes an entity from storage by its identifier.

Link copied to clipboard
private fun ensureIdExists(id: String, shouldExist: Boolean)
Link copied to clipboard
open override fun lastModified(id: String): Long?

Gets the last modification timestamp for an entity.

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

Retrieves an entity from storage by its identifier.

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

Loads all identifiers currently stored in this storage.

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

Creates a new entity in storage with the given identifier.

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

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