We haven’t progressed this area as much as we will do in the future, so support for this will improve. It should be possible with the existing code though. Please take a look at the class HibernateObserver which is part of our vault code for creating ORM’d copies of the states in the vault. There’s a method in there called makeSessionFactoryForSchema that utilises a connection provider that hooks into our underlying database connectivity to H2 (Hikari via Exposed). You will need to do quite a bit of work, but it should be possible to follow that pattern and get something working.
If you’re willing to give that a go, then we’ll do our best to help out here if and when you have further questions.
Just going to add something here in case others have difficulty with the h2 interface - ensure you are using the correct client version to match the server side api we have used. Currently it’s at 1.4.192 so any 1.4 should be ok, but if you are having connectivity issues, then check the version of com.h2database:h2 located in build.gradle in the node directory
The Corda node provides regular JDBC access. If you want to write a program that stores data along-side the node data, setting up Hibernate in your own program and just pointing it at that JDBC URL should work. You don’t need to reuse the nodes internal connection pooling.
I already tried that Plain JDBC stuff. But the problem with that is, it will store in some different location.
We want to store the data in respective nodes.
For that we need the DB URL , but is changing when ever we modify and piece of code and build it.
Any approach we can get the DB URL which is being used internally by Nodes.
You can control the port that H2 exposes the node database on. It’s controlled via the node configuration file (node.conf) which you will find inside the node runtime directory. The dataSource.url setting has an option called AUTO_SERVER_PORT in the H2 URL. If that is set to zero it will use a random port. You can set it to a specific port number if you wish. How are you launching the node?
Where/when are you looking to do database access? From within the node or from outside?
Node will be running on different machines. Before Using those Nodes I want to implement some authentications logic which will be validated form DB.
As nodes will be running on different physical machines, As per my understanding they should have different DB . So here I want to use the inbuilt DB of the nodes.
So for this I am creating DB connection from some Flow.
So you want to do custom RPC authentication? RPC is the primary and soon to be only way to tell a node what to do, as we’re splitting the HTTP REST server out into a separate process that communicates with the node via RPC. The RPC authentication/authorization system already allows you to restrict what flows a user can start, so, I think there should not be any need to look up user credentials from within a flow.
RPC auth is handled by a regular JAAS module. You can find our simple config-file driven implementation in the file ArtemisMessagingServer.kt, it is called NodeLoginModule:
It works by delegating to an implementation of RPCUserService:
For now you could patch the Corda source to use your own implementation. This is probably a better way to go than trying to do it in your own custom flows.
Support for better user authentication schemes is on our roadmap. If it’d unblock you and help you move faster, we can talk about the Corda team prioritising authentication upgrades to allow the use of LDAP, Active Directory and JDBC.