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

Announcements
AWS Degraded - You may experience Community slowness, timeouts, or trouble accessing: LATEST HERE
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

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
Labels (3)
25 Replies
Anonymous
Not applicable

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.
_AnonymousUser
Specialist III
Specialist III
Author

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.
Anonymous
Not applicable

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
_AnonymousUser
Specialist III
Specialist III
Author

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?
Anonymous
Not applicable

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
_AnonymousUser
Specialist III
Specialist III
Author

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.
_AnonymousUser
Specialist III
Specialist III
Author

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
_AnonymousUser
Specialist III
Specialist III
Author

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?
Anonymous
Not applicable

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