# EntityClass

abstract class EntityClass<ID : Any, out T : Entity<ID>>(val table: IdTable<ID>, entityType: Class<T>? = null, entityCtor: (EntityID<ID>) -> T? = null)

Base class responsible for the management of Entity instances and the maintenance of their relation to the provided table.

#### 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.

entityCtor

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 (which can be slower).

#### Inheritors

CompositeEntityClass
ImmutableEntityClass
IntEntityClass
LongEntityClass
UIntEntityClass
ULongEntityClass
UUIDEntityClass

## Constructors

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

## Properties

dependsOnColumns
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.

dependsOnTables
Link copied to clipboard
open val dependsOnTables: ColumnSet

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

table
Link copied to clipboard
val table: IdTable<ID>

## Functions

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

Gets all the Entity instances associated with this EntityClass.

backReferencedOn
Link copied to clipboard
infix fun <TargetID : Any, Target : Entity<TargetID>> EntityClass<TargetID, Target>.backReferencedOn(table: IdTable<*>): ReadOnlyProperty<Entity<ID>, Target>
@JvmName(name = "backReferencedOnOpt")
infix fun <TargetID : Any, Target : Entity<TargetID>, REF : Any> EntityClass<TargetID, Target>.backReferencedOn(column: Column<REF?>): ReadOnlyProperty<Entity<ID>, Target>
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`.

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

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

find
Link copied to clipboard
fun find(op: SqlExpressionBuilder.() -> Op<Boolean>): SizedIterable<T>
fun find(op: Op<Boolean>): SizedIterable<T>

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

findById
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.

findByIdAndUpdate
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.

findSingleByAndUpdate
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.

findWithCacheCondition
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.

forEntityIds
Link copied to clipboard
open fun forEntityIds(ids: List<EntityID<ID>>): SizedIterable<T>

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

forIds
Link copied to clipboard
fun forIds(ids: List<ID>): SizedIterable<T>

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

get
Link copied to clipboard
operator fun get(id: ID): T
operator fun get(id: EntityID<ID>): T
isAssignableTo
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.

memoizedTransform
Link copied to clipboard
fun <Unwrapped, Wrapped> Column<Unwrapped>.memoizedTransform(transformer: ColumnTransformer<Unwrapped, Wrapped>): EntityFieldWithTransform<Unwrapped, Wrapped>
fun <Unwrapped, Wrapped> Column<Unwrapped>.memoizedTransform(unwrap: (Wrapped) -> Unwrapped, wrap: (Unwrapped) -> Wrapped): EntityFieldWithTransform<Unwrapped, Wrapped>

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

fun <TColumn, Unwrapped, Wrapped> EntityFieldWithTransform<TColumn, Unwrapped>.memoizedTransform(unwrap: (Wrapped) -> Unwrapped, wrap: (Unwrapped) -> Wrapped): EntityFieldWithTransform<TColumn, Wrapped>

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

new
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.

optionalBackReferencedOn
Link copied to clipboard
infix fun <TargetID : Any, Target : Entity<TargetID>> EntityClass<TargetID, Target>.optionalBackReferencedOn(table: IdTable<*>): OptionalBackReference<TargetID, Target, ID, Entity<ID>, Any>
@JvmName(name = "optionalBackReferencedOnOpt")
infix fun <TargetID : Any, Target : Entity<TargetID>, REF : Any> EntityClass<TargetID, Target>.optionalBackReferencedOn(column: Column<REF?>): OptionalBackReference<TargetID, Target, ID, Entity<ID>, REF>
infix fun <TargetID : Any, Target : Entity<TargetID>, REF : Any> EntityClass<TargetID, Target>.optionalBackReferencedOn(column: Column<REF>): OptionalBackReference<TargetID, Target, ID, Entity<ID>, REF>

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

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

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

optionalReferrersOn
Link copied to clipboard
infix fun <TargetID : Any, Target : Entity<TargetID>> EntityClass<TargetID, Target>.optionalReferrersOn(table: IdTable<*>): OptionalReferrers<ID, Entity<ID>, TargetID, Target, Any>
infix fun <TargetID : Any, Target : Entity<TargetID>, REF : Any> EntityClass<TargetID, Target>.optionalReferrersOn(column: Column<REF?>): OptionalReferrers<ID, Entity<ID>, TargetID, Target, REF>
fun <TargetID : Any, Target : Entity<TargetID>> EntityClass<TargetID, Target>.optionalReferrersOn(table: IdTable<*>, cache: Boolean = false): OptionalReferrers<ID, Entity<ID>, TargetID, Target, Any>
fun <TargetID : Any, Target : Entity<TargetID>, REF : Any> EntityClass<TargetID, Target>.optionalReferrersOn(column: Column<REF?>, cache: Boolean = false): OptionalReferrers<ID, Entity<ID>, TargetID, Target, REF>

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.

referencedOn
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`.

referrersOn
Link copied to clipboard
infix fun <TargetID : Any, Target : Entity<TargetID>> EntityClass<TargetID, Target>.referrersOn(table: IdTable<*>): Referrers<ID, Entity<ID>, TargetID, Target, Any>
infix fun <TargetID : Any, Target : Entity<TargetID>, REF : Any> EntityClass<TargetID, Target>.referrersOn(column: Column<REF>): Referrers<ID, Entity<ID>, TargetID, Target, REF>
fun <TargetID : Any, Target : Entity<TargetID>> EntityClass<TargetID, Target>.referrersOn(table: IdTable<*>, cache: Boolean): Referrers<ID, Entity<ID>, TargetID, Target, Any>
fun <TargetID : Any, Target : Entity<TargetID>, REF : Any> EntityClass<TargetID, Target>.referrersOn(column: Column<REF>, cache: Boolean): Referrers<ID, Entity<ID>, TargetID, Target, REF>

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.

reload
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.

removeFromCache
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.

searchQuery
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.

testCache
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.

transform
Link copied to clipboard
fun <Unwrapped, Wrapped> Column<Unwrapped>.transform(transformer: ColumnTransformer<Unwrapped, Wrapped>): EntityFieldWithTransform<Unwrapped, Wrapped>
fun <Unwrapped, Wrapped> Column<Unwrapped>.transform(unwrap: (Wrapped) -> Unwrapped, wrap: (Unwrapped) -> Wrapped): EntityFieldWithTransform<Unwrapped, Wrapped>

Returns a EntityFieldWithTransform delegate that transforms this stored Unwrapped value on every read.

fun <TColumn, Unwrapped, Wrapped> EntityFieldWithTransform<TColumn, Unwrapped>.transform(unwrap: (Wrapped) -> Unwrapped, wrap: (Unwrapped) -> Wrapped): EntityFieldWithTransform<TColumn, Wrapped>

Returns a EntityFieldWithTransform that extends transformation of existing EntityFieldWithTransform.

view
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.

warmUpLinkedReferences
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.

warmUpOptReferences
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.

warmUpReferences
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.

wrap
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.

wrapRow
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.

wrapRows
Link copied to clipboard
fun wrapRows(rows: SizedIterable<ResultRow>): SizedIterable<T>
fun wrapRows(rows: SizedIterable<ResultRow>, alias: Alias<IdTable<*>>): SizedIterable<T>
fun wrapRows(rows: SizedIterable<ResultRow>, alias: QueryAlias): SizedIterable<T>

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