JetBrains / Exposed

Kotlin SQL Framework
http://jetbrains.github.io/Exposed/
Apache License 2.0
8.37k stars 694 forks source link

Making reference delegates open classes #1299

Closed dmed256 closed 3 years ago

dmed256 commented 3 years ago

Hello!

I've been using Exposed and I'm trying to find a way to persist eager loaded values outside of a transaction

NOTE: References that are eagerly loaded are stored inside the Transaction Cache, this means that they are not available in other transactions and thus must be loaded and referenced inside the same transaction.

I found a way by creating a delegate that proxies Reference and caches the value but ran into an issue with eager loading due to refection checks here:

https://github.com/JetBrains/Exposed/blob/98bdca8a1563a34af9d3d7a357c9b0c0f5fae7e3/exposed-dao/src/main/kotlin/org/jetbrains/exposed/dao/References.kt#L111

I was curious if we could make Reference and OptionalReference open classes so I can create the cached delegate a Reference and reuse eager loading. I believe the change would be similar to #818. I'm more than happy to make a PR since it seems small enough but wanted to run it by ya'll first or get a second opinion on how to persist references outside of a transaction.

Thank you

dmed256 commented 3 years ago

I was able to do the cached preloading by manually building the inner join. Thanks for providing such great building blocks!