In java service how to get java.sql.Connection created in IS

I’d like to get more information on how to get java.sql.Connection created in IS in java service.

So far I gathered some information like this

java.sql.Connection conn =
(java.sql.Connection)IDataUtil.get(pipeline.getCursor(),
com.wm.adapter.wmjdbc.services.ExecuteService.PIPELINE_CONNECTION);

Somehow I couldn’t find the class com.wm.adapter.wmjdbc.services.ExecuteService in my designer 10.1 env.

Also I found some other code like

try{
	ConnectionDataNode node = ConnectionDataNodeManager.getConnectionDataNode(connName);
	ConnectionResource resource = null;
	if (node != null) {
	resource = node.getConnectionResource();
	}

I couldn’t find ConnectionDataNode in my designer 10.1 either.

Please help.

regards,
Hwuii

You just have to use a special type of JDBC adapter. IIRC, it’s called “execute service”. Then, the connection managed by the IS is handed over under a special name in the pipeline. I don’t remember exactly the name, but it’s documented in the JDBC adapter docs. You don’t have to access the value via a constant field; just write its value as a string constant.

I wouldn’t use DataNode and NodeManager; I don’t think this is a supported way of doing things.

Create a new JDBC Adapter service with the template as “ExecuteService” on a connection that you want to use in your Java service. Inside the Java service use below code and you will be able to safely access the connection from Java service. In the adapter service that you created, you have to give your Java service as service name to invoke.

When you execute the adapter service, it will execute the Java service using the connection information from the adapter service.

Code:
java.sql.Connection conn = (java.sql.Connection)IDataUtil.get(pipeline.getCursor(), “$db_service_connection”);

1 Like

Thank you all!

Somehow I still got NullPointerException when I tried to get DB connection in pipeline.

I attached a screenshot. ExeSvc is the ExecuteService I created earlier.

Any idea?

Regards,

Hui

You need to run the adapter service(created using the exec service template) to invoke the Java service. If you run the Java service directly then it can’t find the connection details.

Thank you Akshith!

Invoking ExeSvc worked:-)

Thank you Akshith for your advise! However, that looks quite strange to me even though it works. Would there be an alternative way to get one of the currently open connections directly from the WmJDBCAdapter package in the Java Service?

Best regards,
Marcus

This might appear strange to you, but it’s a perfectly valid control flow. The idea is that the connections are allocated from the pool when an adapter service is executed. Inside the service, you don’t have to “open” a connection but just have to access an already open one. It is handed over to you unter a special and documented name in the pipeline.

Why would you want to get a connection “directly from the WmJDBCAdapter package”? Why would it be better than what you have now?

Do you let the engine control your car or do you drive it yourself?

Back to topic: I found the com.wm.app.jdbc.* library and the com.wm.app.b2b.server.* library with JDBC-related classes. While the latter is documented, it doesn’t seem to allow access the connections of the JDBC adapter package. Unfortunately, I couldn’t find any documentation on the former. Any hints?

Marcus,
You will have more luck using service in WmDB package to have more control over the connections. Its been almost 10 years since i used that package but i remember using the services in that package to open and close connections to database within the code.

Cheers,
Akshith

Do you repair you car by yourself? Have you heard of inversion of control?

I think I gave you a good advice. If you are not going to follow it, it’s your perfectly valid choice.

Dear Akshith,
thanks for your hint! Unfortunately, the WmDB is not part of our IS installation as it is deprecated. So I guess we have to look for other packages/libraries.

Best regards,
Marcus

Meanwhile SAG informed me that it is OK to still use the WmDB package and asked me to submit a feature request to ask for a successor, what I did. Anybody interested in the same functionality is welcome to vote for feature request 06635 on Brainstorm.

Best regards,
Marcus

Why not using the JDBC-Adapter-Service templates to create AdapterServices on top of the connections in the JDBC-Adapter?

Regards,
Holger

Hello Holger,
actually, SAG also suggested this workaround and I would be fine with it if handing over the results from the JDBC adapter service to the Java service was type-safe for all data structures. But it is only for string, not even for dates or boolean types. So I asked them for a solution to this question. At the moment, this is the state of affairs.

Best regards,
Marcus

Hi Marcus,

you might want to consider opening a feature request in Brainstorm (reachable via Empower) then.

Regards,
Holger

Hi Holger,
probably yes, but I want to await their answer first. Maybe they have got another solution ready. I’ll keep you posted.

Best regards,
Marcus