Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Pass connection object to Talend job from Java program

We gave a try to pass connection object form Java program to talend job and found a way to do the same.
Any talend job will have two hash map namely globalMap(private) and parentContextMap(public).
To pass the object we wrote a wrapper class which will inturn extend the original talend job.
Java wrapper class:
public class wrapper extends FetchCustomer_Mainjob{
public static void invokeJob(){
parentContextMap.put("conn_tOracleConnection_1",Util.getConnection());
String[] contextParam = {.....}
String[][]=runJob(contextParam);
}
}

FetchCustomer_Mainjob:
tJavaRow -->tOracleInput--->tMap--->tOracleOutput
Code in tJavaRow:
globalMap.put("conn_tOracleConnection_1",parentContextMap.get("conn_tOracleConnection_1") 0683p000009MA9p.png
com.common.ThreadLocalMap.put("conn_tOracleConnection_1",parentContextMap.get("conn_tOracleConnection_1"));

FetchCustomer_SubJob1:
tJavaRow -->tOracleInput --->tFileOutputExcel
Code in tJavaRow:
com.common.ThreadLocalMap.put("conn_tOracleConnection_1",parentContextMap.get("conn_tOracleConnection_1"));
globalMap.put("conn_tOracleConnection_1",com.common.ThreadLocalMap.get("conn_tOracleConnection_1"));
Clear the ThreadLocalMap values in main job success/error.
Committ the transaction in talend job or in java code based on your businesss conditions.
Labels (3)
10 Replies
Anonymous
Not applicable
Author

Hi
Thanks for your topic here, I did not do the same thing before. I want to know will you still need to create the db connection on tOracleInput component?
Best regards
Shong
Anonymous
Not applicable
Author

Not really, The job which i have posted above is a sample to show you the flow.
Our basic requirement is to pass connection object from java program, to make the transaction commit/rollback using single connection instead of creating new connection in Talend job, because we are forced to call the job from java program which already holds db connection in thread local.
Anonymous
Not applicable
Author

hi
any takers?
_AnonymousUser
Specialist III
Specialist III

Hello,
I have a similar Requirement.
I have couple of Salesforce Input and output component. I want to use just 1 Salesforce connection instance and use that for all the salesforce input/output component.
I am able to do this by using a Salesforce connection Component first and then use the same connection in all the salesforce input/output component.
But I have another requirement " If the connection fails for the first time I need to retry for 5 times and see if it connect.
I am not able to find out how this can be implemented.
I saw TLoop, tforloop. - but all these does not seem to help in this scenario.
Please can any one guide me if you have come across such scenario..
Thanks,
Ravi
Anonymous
Not applicable
Author

Hi
@venkatesh, it is impossible to pass a connection object to the Talend job in a Java program, the input parameter must be string array. Talend supports the transaction commit/rollback in a job and the db connection must be created in the job.
@usertale, yes, it is possible, however, please report a new topic for better management, we will answer you in the new topic.
Best regards
Shong
Anonymous
Not applicable
Author

@shong..
I have created a new Topic.. plz respond to that
http://www.talendforge.org/forum/viewtopic.php?pid=70118#p70118
Anonymous
Not applicable
Author

depends on how you execute the talend job. If you're running it by loading it into the same process you can hack the global map, replacing it with an own implementation. There you can put the connection into it using the correct key. Your map implementation should take care of that this object won't be replaced by the matching talend component.
In case you're running the talend job in an independend process you'll need some sort of a wrapper which does exactly that.
Anonymous
Not applicable
Author

yes. we re running in the same process.
Anonymous
Not applicable
Author

you can access the globalMap by reflection (set accessible to true) and replace it by your implementation, seems to be the only way