Pass connection object to Talend job from Java program

One Star

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")Smiley Wink
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.
Community Manager

Re: Pass connection object to Talend job from Java program

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
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Pass connection object to Talend job from Java program

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.
One Star

Re: Pass connection object to Talend job from Java program

hi
any takers?
One Star

Re: Pass connection object to Talend job from Java program

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
Community Manager

Re: Pass connection object to Talend job from Java program

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
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Pass connection object to Talend job from Java program

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

Re: Pass connection object to Talend job from Java program

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.
One Star

Re: Pass connection object to Talend job from Java program

yes. we re running in the same process.
One Star

Re: Pass connection object to Talend job from Java program

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

Re: Pass connection object to Talend job from Java program

Hi while running my job it got stuck in between , so i tried running in debug mode , Talend got stuck while creating java object ... Can u pls tell me where m going wrong .