[JVM-B] The best way to use a JVMBridge-based module.
Status: Beta
Brought to you by:
ashley-y
|
From: Artem Gr <ar...@bi...> - 2006-12-22 13:48:17
|
Attached is my latest development in using JVMBridge as a "thin"
database driver.
It took me time to figure that
a) Explicit "getMethod" and "toCharArray :: JString -> () -> JVM
[Jchar]" signature are required to invoke the magic decoding the String
to "[Jchar]" instead of "ArrayRef.Jchar".
b) That MakeClassModule and MakeJVMModule boilerplate is unnecesary, and
we can write a Haskell module that compiles automatically with "ghc
--make" providing that boilerplate isn't used.
Somehow, explicit use of "Class.forName" throws ClassNotFoundException,
while the "findClassByName" function works and does what it is required
to do: registers the driver.
What i'm currently bothered with, is the imposing requirement of the JVM
monad on the user of the module.
Is it possible to do (in the user code):
main = runWithClasspath cp do
jdbc <- jdbcDriverConnection ...
callIO (mainProg jdbc)
mainProg jdbc = do
rs <- query "select 0 from dual" jdbc
close jdbc
That is, to wrap the created JVM monad in the "jdbc" variable and wrap
all the JDBC functions except the jdbcDriverConnection in the IO monad,
but make them do the JVM monad work inside. I suppose it is somehow
possible by merging the IO and JVM monads into another monad, but i
haven't yet used such mechanics.
That is, is it possible to write the "callJVM" function, which, like
"callIO", invokes the code inside the JVM monad (without trying to
create a second JVM every time).
And is the better way to wrap the JVM monad in the thread and do the
functions of JDBC module communicate with that hidden JVM thread?
|