0

When using TornadoFX, TableView columns are established like this:

tableview(list<ObjectType>) {
   column("ColumnName", ObjectType::property)
   ...
}

This is normally fine, but in my case I'm using a Kotlin Exposed entity that's using a reference to another entity. When that happens, if you want to use that reference, you have to surround it in a transaction.

Example:

val company = transaction { employeeObject.companyObject }

If you don't wrap a call like that in a transaction, an error gets thrown. There doesn't seem to be an obvious way to override how a column accesses a property, so I'd like to know if it exists.

Now, I've already tried to wrap my entity in another class that would do all the necessary transactions up front but when the amount of entities that need to be mapped gets in the thousands, it causes my program to basically go into a stand still. If need be, I can go back to how it used to be, which was to not have a reference, but just the plain old ID number to the other entity. Then the cellformat of the column would try to match the company to all companies in a list that was grabbed earlier. I don't really like that solution though, it seems uglier and less elegant, but it's a lot faster than mapping entities. There's also the chance that what I'm trying to achieve might also cause its own slow-down. I'd just like to know if this is possible so I could at least see how fast it is.

Steph
  • 831
  • 6
  • 19
  • By doing "all the necessary transactions up front", I think you mean calling a function that returns a list. Have you considered streaming the data returned from the DB, possibly with coroutine channels? – George Leung Aug 15 '19 at 04:53
  • 2
    You should absolutely fetch your data up front. Even if you made sure to start a transaction when the data is retrieved after the fact, this would happen on the ui thread, which would be a violation of contract - you should not do any heavy work on the ui thread. Instead of chasing a solution here, just load the data you want up front. – Edvin Syse Aug 15 '19 at 08:23

1 Answers1

0

Thanks, Edvin, for reminding me that columns work on the UI thread and that it shouldn't be doing the heavy lifting! I tried a few other things with mapping, hoping that the choke point was the amount of transactions I was doing, but it didn't help with speed. So I think having my View retrieve a list of all companies up front, then having my columns find the companies in that list is the way to go. Not as pretty, but no slow down!

But to officially answer my own question: It doesn't matter, don't try it in the UI thread. It's bad practice and will kill performance.

Steph
  • 831
  • 6
  • 19