ImmutableCachedEntityClass

abstract class ImmutableCachedEntityClass<ID : Any, out T : Entity<ID>>(table: IdTable<ID>, entityType: Class<T>? = null, ctor: (EntityID<ID>) -> T? = null) : ImmutableEntityClass<ID, T>

Base class responsible for the management of immutable Entity instances and the maintenance of their relation to the provided table. An internal cache is used to store entity loading states by the associated database, in order to guarantee that that entity updates are synchronized with this class as the lock object.

Parameters

table

The IdTable object that stores rows mapped to entities managed by this class.

entityType

The expected Entity class type. This can be left null if it is the class of type argument T provided to this EntityClass instance.

ctor

The function invoked to instantiate an Entity using a provided EntityID value. If a reference to a specific entity constructor or a custom function is not passed as an argument, reflection will be used to determine the primary constructor of the associated entity class on first access.

Samples

org.jetbrains.exposed.sql.tests.shared.entities.ImmutableEntityTest.Schema.Organizationorg.jetbrains.exposed.sql.tests.shared.entities.ImmutableEntityTest.ECachedOrganization

Constructors

Link copied to clipboard
constructor(table: IdTable<ID>, entityType: Class<T>? = null, ctor: (EntityID<ID>) -> T? = null)

Properties

Link copied to clipboard
open val dependsOnColumns: List<Column<out Any?>>

The columns that this EntityClass depends on when maintaining relations with managed Entity instances.

Link copied to clipboard

The IdTable that this EntityClass depends on when maintaining relations with managed Entity instances.

Link copied to clipboard

Functions

Link copied to clipboard
open override fun all(): SizedIterable<T>

Gets all the Entity instances associated with this EntityClass.

Link copied to clipboard
@JvmName(name = "backReferencedOnOpt")
infix fun <TargetID : Any, Target : Entity<TargetID>, REF : Any> EntityClass<TargetID, Target>.backReferencedOn(column: Column<REF?>): ReadOnlyProperty<Entity<ID>, Target>

Registers a reference as an immutable field of the parent entity class, which returns a child object of this EntityClass.

Link copied to clipboard
fun count(op: Op<Boolean>? = null): Long

Counts the amount of Entity instances that conform to the op conditional expression.

Link copied to clipboard

Clears either only values for the database associated with the current Transaction or the entire cache if a database transaction cannot be found.

Link copied to clipboard

Gets all the Entity instances that conform to the op conditional expression.

Link copied to clipboard
fun findById(id: ID): T?

Gets an Entity by its id value.

open fun findById(id: EntityID<ID>): T?

Gets an Entity by its EntityID value.

Link copied to clipboard
fun findByIdAndUpdate(id: ID, block: (it: T) -> Unit): T?

Gets an Entity by its id value and updates the retrieved entity.

Link copied to clipboard
fun findSingleByAndUpdate(op: Op<Boolean>, block: (it: T) -> Unit): T?

Gets a single Entity that conforms to the op conditional expression and updates the retrieved entity.

Link copied to clipboard
fun findWithCacheCondition(cacheCheckCondition: T.() -> Boolean, op: SqlExpressionBuilder.() -> Op<Boolean>): Sequence<T>

Searches the current EntityCache for all Entity instances that match the provided cacheCheckCondition. If the cache returns no matches, entities that conform to the provided op conditional expression will be retrieved from the database.

Link copied to clipboard
open override fun <T> forceUpdateEntity(entity: Entity<ID>, column: Column<T>, value: T)

Updates an entity field directly in the database, then removes this entity from the EntityCache in the current transaction scope. This is useful when needing to ensure that an entity is only updated with data retrieved directly from a database query.

Link copied to clipboard

Returns a SizedIterable containing all entities with EntityID values from the provided ids list.

Link copied to clipboard

Returns a SizedIterable containing all entities with id values from the provided ids list.

Link copied to clipboard
operator fun get(id: ID): T
operator fun get(id: EntityID<ID>): T
Link copied to clipboard
fun <ID : Any, T : Entity<ID>> isAssignableTo(entityClass: EntityClass<ID, T>): Boolean

Returns whether the entityClass type is equivalent to or a superclass of this EntityClass instance's klass.

Link copied to clipboard

Returns a EntityFieldWithTransform delegate that will cache the transformed value on first read of this same stored Unwrapped value.

Returns a EntityFieldWithTransform that extends transformation of existing EntityFieldWithTransform and caches the transformed value on first read.

Link copied to clipboard
open fun new(init: T.() -> Unit): T

Creates a new Entity instance with the fields that are set in the init block. The id will be automatically set.

open fun new(id: ID?, init: T.() -> Unit): T

Creates a new Entity instance with the fields that are set in the init block and with the provided id.

Link copied to clipboard

Registers an optional reference as an immutable field of the parent entity class, which returns a child object of this EntityClass.

Link copied to clipboard

Registers an optional reference as a field of the child entity class, which returns a parent object of this EntityClass.

Link copied to clipboard

Registers an optional reference as an immutable field of the parent entity class, which returns a collection of child objects of this EntityClass that all reference the parent.

Link copied to clipboard
infix fun referencedOn(table: IdTable<*>): Reference<Any, ID, T>
infix fun <REF : Any> referencedOn(column: Column<REF>): Reference<REF, ID, T>

Registers a reference as a field of the child entity class, which returns a parent object of this EntityClass.

Link copied to clipboard

Registers a reference as an immutable field of the parent entity class, which returns a collection of child objects of this EntityClass that all reference the parent.

Link copied to clipboard
fun reload(entity: Entity<ID>, flush: Boolean = false): T?

Reloads the fields of an entity from the database and returns the entity as a new object.

Link copied to clipboard
fun removeFromCache(entity: Entity<ID>)

Removes the specified entity from the current EntityCache, as well as any stored references to or from the removed entity.

Link copied to clipboard
open fun searchQuery(op: Op<Boolean>): Query

Returns a Query to select all columns in dependsOnTables with a WHERE clause that includes the provided op conditional expression.

Link copied to clipboard
fun testCache(cacheCheckCondition: T.() -> Boolean): Sequence<T>

Searches the current EntityCache for all Entity instances that match the provided cacheCheckCondition.

fun testCache(id: EntityID<ID>): T?

Searches the current EntityCache for an Entity by its EntityID value.

Link copied to clipboard
inline fun view(op: SqlExpressionBuilder.() -> Op<Boolean>): View<T>

Creates a View or subset of Entity instances, which are managed by this EntityClass and conform to the specified op conditional expression.

Link copied to clipboard
fun <SID : Any> warmUpLinkedReferences(references: List<EntityID<SID>>, linkTable: Table, forUpdate: Boolean? = null, optimizedLoad: Boolean = false): List<T>

Returns a list of retrieved Entity instances whose reference column matches any of the EntityID values in references. Both the entity's source and target reference columns should have been defined in linkTable.

Link copied to clipboard
fun <SID> warmUpOptReferences(references: List<SID>, refColumn: Column<SID?>, forUpdate: Boolean? = null): List<T>

Returns a list of retrieved Entity instances whose refColumn optionally matches any of the id values in references.

Link copied to clipboard
fun <SID> warmUpReferences(references: List<SID>, refColumn: Column<SID>, forUpdate: Boolean? = null): List<T>

Returns a list of retrieved Entity instances whose refColumn matches any of the id values in references.

Link copied to clipboard
fun wrap(id: EntityID<ID>, row: ResultRow?): T

Returns an Entity with the provided EntityID value, or, if an entity was not found in the current EntityCache, creates a new instance using the data in row.

Link copied to clipboard
fun wrapRow(row: ResultRow): T
fun wrapRow(row: ResultRow, alias: Alias<IdTable<*>>): T
fun wrapRow(row: ResultRow, alias: QueryAlias): T

Wraps the specified ResultRow data into an Entity instance.

Link copied to clipboard

Returns a SizedIterable containing entities generated using data retrieved from a database result set in rows.