Bytecoder icon indicating copy to clipboard operation
Bytecoder copied to clipboard

Question: Could Bytecoder be used to compile JDBC libraries for use in Javascript?

Open rathboma opened this issue 5 years ago • 6 comments

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!

rathboma avatar Oct 22 '20 22:10 rathboma

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.

mirkosertic avatar Nov 04 '20 20:11 mirkosertic

@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?

intrigus avatar Nov 05 '20 12:11 intrigus

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 avatar Nov 05 '20 21:11 rathboma

@rathboma You might have more luck with TeaVM - they support threading emulation via CPS transform.

mwisnicki avatar Nov 11 '20 20:11 mwisnicki

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 avatar Nov 12 '20 10:11 mirkosertic

@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.

mwisnicki avatar Nov 12 '20 19:11 mwisnicki

Closed due to no further feedback.

mirkosertic avatar Mar 29 '23 16:03 mirkosertic