Bytecoder
Bytecoder copied to clipboard
Question: Could Bytecoder be used to compile JDBC libraries for use in Javascript?
I'm fairly sure the answer to this will be 'not really', but here we go.
I run Beekeeper Studio. Many databases the app needs to connect to only provide JDBC libraries (grr).
This can be solved by using node-jdbc and using a Java process as a proxy for the connection.
As an alternative, I'd love to use Bytecoder to build a JavaScript package of JDBC drivers that I could use directly, without any futzing around with external JVMs.
Would this work?
I've no idea as to the complexities inherent in JDBC drivers to have an opinion, so thought I'd ask you and your community :-).
Keep up the amazing work!
Hi!
thank you for posting this question. I'am afraid your guessed answer "not really" is correct, so let me explain.
It would be only possible to compile jdbc type 4 drivers, as they are pure Java without any native code dependencies. The limitation here is that the Bytecoder JDK Runtime Emulation Classes currently do not support any kind of socket communication, and this is the foundation of most JDBC connectivity. Even if socket communication would work, we would run into the next problem: thread pools, which are used by most JDBC drivers. Bytecoder does not support native threads, and JavaScript also does not. So threads must be emulated by some kind of green threads / promise mechanism, but this is not implemented in the Bytecoder compiler.
I'm really sorry, but this is not possible with the current state of Bytecoder.
@rathboma I don't know whether I understood the question correctly, but would it not be possible to use graalvm to run both javascript and Java together?
Thanks for the response. I figured the threading would be a sticking point. Thanks for the detailed response!
@intrigus I'm running in the Electron runtime environment so I don't really have the option to use Graalvm unfortunately.
@rathboma You might have more luck with TeaVM - they support threading emulation via CPS transform.
TeaVM is indeed a great project. The compiler emulates native Threads by converting the Bytecode to a Continuation Passing Style form. But this are still green threads, there is no real parallel processing here. The next challenge will be to enable true Socket Connections to other hosts, this also requires a good emulation layer, and you will maybe end with some kind of http to JDBC brige. And if you are already at this point, you maybe want to look at GraphQL, which gives you a JSON API to a database, and there are already some good projects available exposing any database as a GraphQL API.
@mirkosertic I think @rathboma use case is Electron so you can wrap node sockets.
@rathboma Ultimately for now I think it's easier to stick with node-jdbc. Since packaged Electron apps are platform specific you can just bundle JVM inside to avoid external dependency. It's even recommended nowadays for desktop java apps.
Closed due to no further feedback.