-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: EXPOSED-77 Support entity class for table with composite primar…
…y key - Extract logic between regular id columns and composite id columns to lower locations. - Add KDocs and change some object locations. - Flesh out unit tests
- Loading branch information
Showing
12 changed files
with
230 additions
and
114 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
33 changes: 33 additions & 0 deletions
33
exposed-core/src/main/kotlin/org/jetbrains/exposed/dao/id/CompositeID.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,33 @@ | ||
package org.jetbrains.exposed.dao.id | ||
|
||
import org.jetbrains.exposed.sql.Column | ||
|
||
/** Class representing a mapping of each composite primary key column to its stored identity value. */ | ||
class CompositeID( | ||
idMapping: Map<out Column<*>, Comparable<*>?> | ||
) : HashMap<Column<*>, Comparable<*>?>(idMapping), Comparable<CompositeID> { | ||
override fun toString(): String = "CompositeID(${entries.joinToString { "${it.key.name}=${it.value}" }})" | ||
|
||
override fun hashCode(): Int = entries.fold(0) { acc, entry -> | ||
(acc * 31) + entry.hashCode() | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (other !is CompositeID) return false | ||
|
||
return super.equals(other) | ||
} | ||
|
||
override fun compareTo(other: CompositeID): Int { | ||
val compareSize = compareValues(other.size, size) | ||
if (compareSize != 0) return compareSize | ||
|
||
entries.forEach { (column, idValue) -> | ||
if (!other.containsKey(column)) return -1 | ||
compareValues(idValue, other[column]).let { | ||
if (it != 0) return it | ||
} | ||
} | ||
return 0 | ||
} | ||
} |
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
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
Oops, something went wrong.