Skip to content

sickfar/exposed-dao-composite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

exposed-dao-composite

Exposed extension to add limited support of composite primary and foreign keys.

Based on exposed-dao source code with added support of composite primary keys.

Installation

Use in you maven or gradle project

<repositories>
    <repository>
        <id>gitlab-maven</id>
        <url>https://gitlab.com/api/v4/projects/25805171/packages/maven</url>
    </repository>
</repositories>
...
<dependencies>
    <dependency>
        <groupId>one.uclass.exposed</groupId>
        <artifactId>exposed-dao-composite</artifactId>
        <version>0.1.3</version>
    </dependency>
</dependencies>

Limitations

This extension supports only one specific subset of composite keys. This library can help you if you have composite primary keys, constructed of two parts: constant classifier ID and variable main ID. Classifier ID cannot be generated by the database, so you must provide it every time you create or search an entity.

Referencing another composite ID entity

If you refer another composite entity, you should refer only variable ID column. Classifier ID column will be referenced implicitly during reference resolution process.

Usage

object BaseCompositeTable : LongLongIdTable("base_table", "const_id", "gen_id") {
    val data = text("some_data")
}

object ReferencedCompositeTable: LongLongIdTable("second_table", "const_id", "gen_id") {
    val data = text("some_data")
    val base = reference("base_ref", BaseCompositeTable.id)
}

object BackReferencedCompositeTable: LongLongIdTable("list_table", "const_id", "ref_gen_id") {
    init {
        id.references(BaseCompositeTable.id)
    }
    val value = varchar("value", 100)
}

class ListEntity(id: CompositeEntityID<Long, Long>): LongLongEntity(id) {
    companion object: LongLongEntityClass<ListEntity>(BackReferencedCompositeTable)
    var value by BackReferencedCompositeTable.value
}

class BaseEntity(id: CompositeEntityID<Long, Long>): LongLongEntity(id) {
    companion object: LongLongEntityClass<BaseEntity>(BaseCompositeTable)
    var data by BaseCompositeTable.data
    val list by ListEntity referrersOn BackReferencedCompositeTable.id
}

class ReferencedEntity(id: CompositeEntityID<Long, Long>): LongLongEntity(id) {
    companion object: LongLongEntityClass<ReferencedEntity>(ReferencedCompositeTable)
    var base by BaseEntity referencedOn ReferencedCompositeTable.base
    var data by ReferencedCompositeTable.data
}

About

Composite module for exposed dao

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages