-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: EXPOSED-320 Many-to-many relation with extra columns
- Add more tests (particularly for update) & rename test classes - Refactor cache to ensure no overlap with wrapped type. Each link entity is now stored by its target column, source column, and target id (stored in entity) - Move new entity classes to own file - Refactor logic for deleting cached entities
- Loading branch information
Showing
7 changed files
with
194 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
exposed-dao/src/main/kotlin/org/jetbrains/exposed/dao/InnerTableLinkEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.jetbrains.exposed.dao | ||
|
||
import org.jetbrains.exposed.dao.id.EntityID | ||
import org.jetbrains.exposed.dao.id.IdTable | ||
import org.jetbrains.exposed.sql.Column | ||
import org.jetbrains.exposed.sql.ResultRow | ||
|
||
/** | ||
* Base class for an [Entity] instance identified by a [wrapped] entity comprised of any ID value. | ||
* | ||
* Instances of this base class should be used when needing to represent referenced entities in a many-to-many relation | ||
* from fields defined using `via`, which require additional columns in the intermediate table. These additional | ||
* columns should be added as constructor properties and the property-column mapping should be defined by | ||
* [getInnerTableLinkValue]. | ||
* | ||
* @param WID ID type of the [wrapped] entity instance. | ||
* @property wrapped The referenced (parent) entity whose unique ID value identifies this [InnerTableLinkEntity] instance. | ||
* @sample org.jetbrains.exposed.sql.tests.shared.entities.ViaTests.ProjectWithApproval | ||
*/ | ||
abstract class InnerTableLinkEntity<WID : Comparable<WID>>(val wrapped: Entity<WID>) : Entity<WID>(wrapped.id) { | ||
/** | ||
* Returns the initial column-property mapping for an [InnerTableLinkEntity] instance | ||
* before being flushed and inserted into the database. | ||
* | ||
* @sample org.jetbrains.exposed.sql.tests.shared.entities.ViaTests.ProjectWithApproval | ||
*/ | ||
abstract fun getInnerTableLinkValue(column: Column<*>): Any? | ||
} | ||
|
||
/** | ||
* Base class representing the [EntityClass] that manages [InnerTableLinkEntity] instances and | ||
* maintains their relation to the provided [table] of the wrapped entity. | ||
* | ||
* This should be used, as a companion object to [InnerTableLinkEntity], when needing to represent referenced entities | ||
* in a many-to-many relation from fields defined using `via`, which require additional columns in the intermediate table. | ||
* These additional columns will be retrieved as part of a query's [ResultRow] and the column-property mapping to create | ||
* new instances should be defined by [createInstance]. | ||
* | ||
* @param WID ID type of the wrapped entity instance. | ||
* @param E The [InnerTableLinkEntity] type that is managed by this class. | ||
* @param [table] The [IdTable] object that stores rows mapped to the wrapped entity of this class. | ||
* @sample org.jetbrains.exposed.sql.tests.shared.entities.ViaTests.ProjectWithApproval | ||
*/ | ||
abstract class InnerTableLinkEntityClass<WID : Comparable<WID>, out E : InnerTableLinkEntity<WID>>( | ||
table: IdTable<WID> | ||
) : EntityClass<WID, E>(table, null, null) { | ||
/** | ||
* Creates a new [InnerTableLinkEntity] instance by using the provided [row] to both create the wrapped entity | ||
* and any additional columns. | ||
* | ||
* @sample org.jetbrains.exposed.sql.tests.shared.entities.ViaTests.ProjectWithApproval | ||
*/ | ||
abstract override fun createInstance(entityId: EntityID<WID>, row: ResultRow?): E | ||
} |
Oops, something went wrong.