New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: EXPOSED-77 Support entity class for table with composite primary key #1987
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check the comparison and let's discuss merging
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (other !is CompositeID) return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we compare CompositeId with one mapping with EntityId?
) : 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 -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single entry CompositeId will always have the same value as EntityId of same type
// SQLite excluded from all tests as it only allows auto-increment on single column PKs. | ||
// SQL Server is sometimes excluded because it doesn't allow inserting explicit values for identity columns. | ||
class CompositeIdTableEntityTest : DatabaseTestsBase() { | ||
object Publishers : CompositeIdTable("publishers") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking if we can try make CompositeIdTable to IdTable by default, let's discuss
…y key - Add base objects for new CompositeEntity and CompositeIdTable. - Use existing implementation via EntityID to wrap new comparable type, CompositeID. - Retain use of IdTable.id via a placeholder column that can deconstruct to its component columns in DSL and ResultRow accessors. - Add base unit tests.
…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
…y key - Remove changes to reference logic. - Small change to unit test. - Rebase from main.
…y key - Update KDocs to reflect merged changes - Add CompositeID equality comparison for EntityID<*>
…y key Clean up some logic Add first example of supporting a simple referencedOn relation to a composite primary key.
a0630fd
to
54b8d89
Compare
Phase 1:
CompositeIdTable
that allows id columns to be marked forEntityID
inclusion usingColumn.compositeEntityid()
.CompositeID
that will be wrapped byEntityID
for value comparison.CompositeIdTable.id
can be used in DSL in the same way anyIdTable.id
can (for example, in WHERE or SELECT clauses). This means users can easily include all deconstructed PK columns in their queries.ResultRow[CompositeIdTable.id]
is also possible. Even though the result set returns each PK column value separately, using the previous accessor returns a newEntityID<CompositeID>
, just as for a standard entity id column.IdTable
subtype has been extracted (in most places) to the lowest common point possible.Phase 2 - About References:
This PR currently includes minimal changes to Reference logic (only for
referencedOn
). The better option seems to be to add a property to all reference classes. This new property would provide the full set of reference columns, while leaving the original single columnreference
property as an internal delegate (like an ambassador for the other columns), especially when it comes to managing the reference entity in the cache.Ideally I'd split this PR into 2, but support isn't really complete until referencing is working, so I'd like for this to be an iterative process, if possible.
Once everything is agreed on with the first phase, I'll commit the improved reference changes for review.