One Star

instance row1 inside tjavaflex (Urgent)

I am connecting a tjavaFlex to a tPostgreSQLOutput using a row main connection. I need to assign the values of the attributes of row1(instance of rowStruct) that will be inserted in the database in a class(routine) other than TjavaFlex. In other words, the same instance of rowStruct declared inside the tjavaflex is used in another routine , where the values of the attributes are filled and then the tjavaflex process resumes by inserting the values in the database. My problem is that when I use row1 in another routine it is no longer recognized, because it is a local variable inside a tjavaflex and because the routines package is different from the project package. How can I declare row1 so that it is recognized by the routine
25 REPLIES
One Star

Re: instance row1 inside tjavaflex (Urgent)

row1 refers to the output arrow connecting your components and my understanding is that after that step or your work flow is complete, the variable isn't in 'scope' any longer so you can't access it. You may need to use the row name for the current step your on, or if you need to access data specific to a previous step, write it out to a file to re-use later.
One Star

Re: instance row1 inside tjavaflex (Urgent)

row1 refers to the output arrow connecting your components and my understanding is that after that step or your work flow is complete, the variable isn't in 'scope' any longer so you can't access it. You may need to use the row name for the current step your on, or if you need to access data specific to a previous step, write it out to a file to re-use later.

row1 refers to the instance of rowstruct which is a private class generated by talend once the schema of the database is defined.
One Star

Re: instance row1 inside tjavaflex (Urgent)

Hello andy,
if I understand you right that you call a custom routine / class in tJavaFlex and try to get access to row1?
In this case I would say you have to pass the data with the method call (or constructor of your class, ...).
If I did not understand you: Can you please give us (me) a short screen shoot? Or give us some more information / examples?
Bye
Volker
One Star

Re: instance row1 inside tjavaflex (Urgent)

Hello andy,
if I understand you right that you call a custom routine / class in tJavaFlex and try to get access to row1?
In this case I would say you have to pass the data with the method call (or constructor of your class, ...).
If I did not understand you: Can you please give us (me) a short screen shoot? Or give us some more information / examples?
Bye
Volker

Here is an example: in the code generated by the job I have
package project.myproject;
import routines.SetAttributes;
public class myjob{
.
.
.
private class RowStruct{
String Name;
}
void tjavaflex_process(){
rowStruct row1 = new rowStruct();
SetAttributes s = new SetAttributes();
String name= john";
s.setName("john");
/*insert row in the databse*/
}
}
in the routine where I want to use row1 I have
package routines;
public class SetAttributes{
public setName (String Name){
row1.Name=name;
}
}
How can I make the class SetAtributes recognize the instance row1?
One Star

Re: instance row1 inside tjavaflex (Urgent)

For me it is not clear what you would like to archive.
setName is a function of a class which has no effect.
If you would like to set the name you can just write: row1.Name= "john";
If you would like to make same additional transformation in your routine you can use the following code:
public String setName(String name) {
// make some transformation to name
return name;
}

But in tJavaFlex you have to write again: row1.Name= s.setName("john");
If you would like to use the row itself in your function you need access to the RowStruct (your signature should be: public RowStruct setName(RowStruct row1)). But this does not work because RowStruct is defined as a private inner class. Possibly you can write a wrapper but this is, depending on your needs, too much work I think.
Bye
Volker
One Star

Re: instance row1 inside tjavaflex (Urgent)

For me it is not clear what you would like to archive.
setName is a function of a class which has no effect.
If you would like to set the name you can just write: row1.Name= "john";
If you would like to make same additional transformation in your routine you can use the following code:
public String setName(String name) {
// make some transformation to name
return name;
}

But in tJavaFlex you have to write again: row1.Name= s.setName("john");
If you would like to use the row itself in your function you need access to the RowStruct (your signature should be: public RowStruct setName(RowStruct row1)). But this does not work because RowStruct is defined as a private inner class. Possibly you can write a wrapper but this is, depending on your needs, too much work I think.
Bye
Volker

I want the code that I will right in the tjavaflex to be generic and work for any number and types of attributes. This is why I dont want to write in it row1.Name because it will be to specific to this case. So, For that code to be generic, I want the the user to only specify (in a constructor of a class for example declared in the tjavaflex)the methods to be used to set the attributes such as setName, and those setters will be implemented in a seperate class.
One Star

Re: instance row1 inside tjavaflex (Urgent)

For me it is not clear what you would like to archive.
setName is a function of a class which has no effect.
If you would like to set the name you can just write: row1.Name= "john";
If you would like to make same additional transformation in your routine you can use the following code:
public String setName(String name) {
// make some transformation to name
return name;
}

But in tJavaFlex you have to write again: row1.Name= s.setName("john");
If you would like to use the row itself in your function you need access to the RowStruct (your signature should be: public RowStruct setName(RowStruct row1)). But this does not work because RowStruct is defined as a private inner class. Possibly you can write a wrapper but this is, depending on your needs, too much work I think.
Bye
Volker

I want the code that I will right in the tjavaflex to be generic and work for any number and types of attributes. This is why I dont want to write in it row1.Name because it will be to specific to this case. So, For that code to be generic, I want the the user to only specify (in an array declared in the tjavaflex)the methods to be used to set the attributes such as setName, and those setters will be implemented in a seperate class. so that if the attribute all we have to modify is the class that implement the setters and the array in the tjavaflex
One Star

Re: instance row1 inside tjavaflex (Urgent)

Possibly you can write a wrapper but this is, depending on your needs, too much work I think.

What would that wrapper look like please?
One Star

Re: instance row1 inside tjavaflex (Urgent)

Hello andy,
you can, for example, write a own class to store the data and set there value in the tJavaFlex. After calling your function you can write back the new values. But I think this is not realy what you would like to have. Or?
// your own class
public class MyOwnRow {
private String name;
public MyOwnRow(String name) {
this.name= name;
}
public setName(String name) {
this.name= name;
}
public getName() {
return this.name;
}
}
// in tJavaFlex
private MyOwnRow myRow= new MyOwnRow(row1.name);
// now you can use the following for example:
myRow.setName("john");
// and after all you have to go back to row1:
row1.name= myRow.getname();

So you can use this to have a getter and setter for the row (with, for example enhanced functionality). The class YourOwnRow should, I think, externalized in a own jar and imported to work. To get more flexibility you can, for example give your class a object and analyze it with reflection.
But again:
Your are very limited. And the following parts:
I want the code that I will right in the tjavaflex to be generic and work for any number and types of attributes. This is why I dont want to write in it row1.Name because it will be to specific to this case. So, For that code to be generic, ...

There is no generic in this approach. For example myRow.setName(123) would not work because of the strong type safety of java. If you need the full flexibility you have to write a own component.
So back to the root: Can you be more clear what you would like to expect / your "business" requirements? Who is using the function and what should he do (or not).
Bye
Volker
One Star

Re: instance row1 inside tjavaflex (Urgent)

Hi,
I am new to TOS.
Could you pls tell me some code snippets showing how and when to use tJavaRow and tJavaRow?
I didnt get much documentation about these two components on net...
Many thanks.
-Sonal
One Star

Re: instance row1 inside tjavaflex (Urgent)

Hi sonal,
I think you will find many if yor use the forum search function.
In most cases you will use a tJavaRow if you have to do complex operations which will not supported by standard components. This could be something completely new or a more simple step which you wouldn't like to add into an existing component (for example a transformation).
To use tJavaRow, just add it in your flow. You can use input_row to address the input flow and output_row for the output. You must map all variables. If not they will have a null value at the end.
If you have any special problem to solve, please post an example (it's much easier to work with that).
Bye
Volker
And please create a new topic if you have a new question.
One Star

Re: instance row1 inside tjavaflex (Urgent)

Hi Experts,
Im a novice to TOS. Could you please tell me where is the link to post a new topic? I didnt get the link in the forum.
Also, please tell me the use of tJavaFlex component. And, a sample code snippet would be a great help.
Thanks in advance!
-Sonal.
One Star

Re: instance row1 inside tjavaflex (Urgent)

Please tell me what is the use of global context?
One Star

Re: instance row1 inside tjavaflex (Urgent)

What is the difference between tJavaRow and tJavaFlex?
Also, according to my understanding, tJava can do all the tasks done by tJavaRow and tJavaFlex... so what are the advantages of tJavaRow and tJavaFlex?
Please help me.
Thanks.
-Sonal
Community Manager

Re: instance row1 inside tjavaflex (Urgent)

Hello Sonal
I show you a simple code to explain the difference bettwen them. See my screenshots.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: instance row1 inside tjavaflex (Urgent)

Hi,
I have never took time to use these components.
I can see a difference between the "tJava" components and the others : "tJava" permits to "insert" some code in our jobs in order to perform some Java methods.
This is not a component to perform treatment on our data flow, contrary to "tJavaFlex" and "tJavaRow" in which we can define some schemas in order to do some operations on our data.
However, I can't see much difference between these last two components.
"tJavaFlex" only adds the possibility to perform some Java code before and after our operations on the data flow, but its behaviour on the data flow is exactly the same as the behaviour of "tJavaRow". Am I right ?
Best regards,

Nicolas
One Star

Re: instance row1 inside tjavaflex (Urgent)

thanks a lot experts Smiley Happy
Community Manager

Re: instance row1 inside tjavaflex (Urgent)

Hello
"tJavaFlex" only adds the possibility to perform some Java code before and after our operations on the data flow, but its behaviour on the data flow is exactly the same as the behaviour of "tJavaRow". Am I right ?

Yes, you are right. Another difference is that you can do some processing on the coming flows on tJavaRow. eg:
output_row.id=input_row.id*2
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: instance row1 inside tjavaflex (Urgent)

Hi Shong and Sonal,
So, if I sum up :
- With tJava : You can execute some Java code independently of the data flow.
- With tJavaFlex : It has to be inserted in a data flow. You can perform Java code before and after the data flow. You can also perform some Java code for each row, but you cannot do some processing on the incoming data.
- With tJavaRow : It has to be inserted in a data flow too. You can do some processing on the incoming flow (operations, complex mapping).
Regards,

Nicolas
One Star

Re: instance row1 inside tjavaflex (Urgent)

Thanks dear experts! Your replies are really a great help to me understanding the various capabilities of Talend and how to use them Smiley Happy
Could you please let me know where can we get the details of mapping in Talend? I mean, when we map tables in Talend using tMap component, then, where is the mapping details and in which format the information is stored?
Thanks a bunch in advance.
- Sonal
One Star

Re: instance row1 inside tjavaflex (Urgent)

Does the mapping table (formed internally while using tMap component) stored in the form of HTML or XML format?
Where can we retrieve it from?
Community Manager

Re: instance row1 inside tjavaflex (Urgent)

Hello Sonal
Your question is not related to this one. Please create a new topic, I will delete your last post.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: instance row1 inside tjavaflex (Urgent)

Hi Shong,
I dont know how to create new topic. I didnt get the link. Pls tell me where is the link to create new topic.
Apologies.
Community Manager

Re: instance row1 inside tjavaflex (Urgent)

Hello
I dont know how to create new topic. I didnt get the link. Pls tell me where is the link to create new topic.

Please see my screenshot.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: instance row1 inside tjavaflex (Urgent)

hello
how to connect talend with microsoft analysis services ?
Thanks Smiley Happy