Look Up is not working

Hi Jaro,
When iam trying to get look up object in the reformer then it is returing Null.

So please help me out how should i resolve this priblem.

My Graph code is :-

private boolean processUserAccounts(FeedController feedController){
String account_user_dbFields={“user_id”,“account_id”,“updated_by”,“updated_at”};

EngineInitializer.initEngine(null, null, null);
System.out.println(“…In side User_accounts loading…”);
boolean isDone = false;
DBConnection dbConnection;
DBConnection dbConnection1;
DBConnection dbConnection2;
Phase PHASE_0 = new Phase(1);
DataBaseConnection dbConn=new DataBaseConnection();
dbConnection= dbConn.getConnection();
dbConnection1= dbConn.getConnection();
dbConnection2= dbConn.getConnection();
DataRecordMetadata user_accounts_metadata;
DataRecordMetadataXMLReaderWriter reader0=new DataRecordMetadataXMLReaderWriter();

try{
user_accounts_metadata=reader0.read(new FileInputStream(“C:\\FeedVaidationTool\\src\\com\\mps\\pubstats\\metadata\\user_accounts.fmt”));
}catch(IOException ex){
System.err.println(“Error when reading metadata!!”);
throw new RuntimeException(ex);
}

if (user_accounts_metadata==null){
throw new RuntimeException(“No INPUT metadata”);
}

DataRecordMetadata lookupMetaData;
DataRecordMetadataXMLReaderWriter reader1=new DataRecordMetadataXMLReaderWriter();

try{
lookupMetaData=reader1.read(new FileInputStream(“C:\\FeedVaidationTool\\src\\com\\mps\\pubstats\\metadata\\lookup.fmt”));
}catch(IOException ex){
System.err.println(“Error when reading metadata!!”);
throw new RuntimeException(ex);
}

if (lookupMetaData==null){
throw new RuntimeException(“No INPUT metadata”);
}

TransformationGraph institutionGraph = new TransformationGraph(“user_accounts”);

//System.out.println(“TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT”+feedController.MetadataInput.getField(1).getName());

Edge egde1 = new Edge(“InEdge1”, feedController.MetadataInput);
Edge egde2 = new Edge(“OutEdge2”, user_accounts_metadata);

/*
System.out.println(“Input file name”+feedController.inputFileName);
System.out.println(“set no”+feedController.setno);
System.out.println(“table name”+feedController.tableName);*/

// //Nodes…
DelimitedDataReader deLimitedReader= new DelimitedDataReader(“DataParser”,
feedController.inputFileName);
deLimitedReader.setSkipFirstLine(feedController.headingIncluded);
//System.out.println(“Skip First Line :::”+feedController.headingIncluded);

Node nodeRead = deLimitedReader;

String query1=" select id from accounts where set_no=‘“+feedController.setno+”’ and code=? “;
String query2=” select id from users where code=? ";
DBLookupTable dbLookup1=new DBLookupTable(“LookupTable_Accounts”,dbConnection1.getConnection(dbConnection1.getId()),lookupMetaData,query1);
dbLookup1.setName(“LookupTable_Accounts”);

try {
dbLookup1.init();
//dbLookup1.setGraph(institutionGraph);
} catch (ComponentNotReadyException e1) {
System.out.println(“Cause of the error”+e1.getCause());
e1.printStackTrace();
}
System.out.println(“KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK”+dbLookup1.get(“10003”));

DBLookupTable dbLookup2=new DBLookupTable(“LookupTable_Users”,dbConnection2.getConnection(dbConnection2.getId()),lookupMetaData,query2);
dbLookup1.setName(“LookupTable_Users”);
try {
dbLookup2.init();
//dbLookup2.setGraph(institutionGraph);
} catch (ComponentNotReadyException e1) {
System.out.println(“Cause of the error”+e1.getCause());
e1.printStackTrace();
}
System.out.println(“KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK”+dbLookup2.get(“NRLUSAGE1”));

UserAccountsReformat userAccRef=new UserAccountsReformat(institutionGraph,feedController.setno);
userAccRef.setFieldDBMap(feedController.deDupFieldMap);
List fieldsNameList=feedController.columnNames;
String metaDataFields=(String )fieldsNameList.toArray(new String[fieldsNameList.size()]);
userAccRef.setMetaDataFields(metaDataFields);
userAccRef.setParentChildFields();

//childRef.setGraph(institutionGraph);
Reformat userAccountsReformat = new Reformat(“userAccReformat”, userAccRef);

//System.out.println(“Table Name:”+feedController.tableName);

DBOutputTable dbFilter = new DBOutputTable(“user_accounts”, dbConnection.getId(),
“user_accounts”);
dbFilter.setDBFields(account_user_dbFields);
dbFilter.setCloverFields(account_user_dbFields);
Node dbOutPut = dbFilter;

//String deDup1={“Field0”};

egde1.connectReader(nodeRead, 0);
egde1.connectWriter(userAccountsReformat, 0);
egde2.connectReader(userAccountsReformat, 0);
egde2.connectWriter(dbOutPut, 0);

nodeRead.addOutputPort(0, egde1);
userAccountsReformat.addInputPort(0,egde1);
userAccountsReformat.addOutputPort(0, egde2);

dbOutPut.addInputPort(0,egde2);

// add Edges & Nodes & Phases to graph
try {
institutionGraph.addConnection(dbConnection);
institutionGraph.addConnection(dbConnection1);
institutionGraph.addConnection(dbConnection2);
institutionGraph.addLookupTable(dbLookup1);
institutionGraph.addLookupTable(dbLookup2);

//institutionGraph.addEdge(egde2);
institutionGraph.addPhase(PHASE_0);
PHASE_0.addNode(nodeRead);
PHASE_0.addNode(userAccountsReformat);
PHASE_0.addNode(dbOutPut);
institutionGraph.addEdge(egde1);
institutionGraph.addEdge(egde2);
//childRef.setGraph(institutionGraph);
// institutionGraph.addEdge(egde6);

System.out.println(“Graph is created properly”);

} catch (GraphConfigurationException ex) {

System.out.println(“::::::::::::::::::::::::::File Not Found:::::::::::::::::::::::::::::::::::::::::::::::::::::::”);

ex.printStackTrace();
}

// prepare runtime parameters - JMX is turned off
GraphRuntimeContext runtimeContext = new GraphRuntimeContext();
runtimeContext.setUseJMX(false);

GraphExecutor executor = new GraphExecutor();

/* System.out.println(“Grapgh Executer…” + executor);
System.out.println(“Grapgh Executer…” + institutionGraph);*/
try {
GraphExecutor.initGraph(institutionGraph);
} catch (ComponentNotReadyException e) {
System.out.println(“::::::::::::::::::::::::::File Not Found in Compontnt not ready:::::::::::::::::::::::::::::::::::::::::::::::::::::::”);
System.out.println(“Failed graph initialization!!!\n”
+ e.getMessage());
return false;
}

Future result;
try {
result = executor.runGraph(institutionGraph, runtimeContext);

Result rs = result.get();
System.out.println(result.isDone() + “>>>>>>>>>>>>>>>>>>>>>>>”);
if (result.isDone()) {
System.out.println(“Done”);
isDone = true;
}
if (!result.get().equals(Result.FINISHED_OK)) {
System.out.println(result.get().message());
// System.out.println(“Failed graph execution!”);
// return false;
}
} catch (Exception e) {
System.out.println(“Failed graph execution!\n” + e.getMessage());
// return false;
}
return isDone;
// return true;

}

???/

and my Reformat code is:

package com.mps.pubstats.tool;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Hashtable;
import java.util.Map;

import org.jetel.component.DataRecordTransform;
import org.jetel.data.DataRecord;
import org.jetel.data.RecordKey;
import org.jetel.data.lookup.LookupTable;
import org.jetel.exception.ComponentNotReadyException;
import org.jetel.exception.JetelException;
import org.jetel.graph.TransformationGraph;

public class UserAccountsReformat extends DataRecordTransform{
TransformationGraph graph;
LookupTable mylookup1;
LookupTable mylookup2;
private String metaDataFields;
private Map metaData_DBField;
private String parentField;
private String childField;
private int setno;
private boolean flag=false;

public UserAccountsReformat(TransformationGraph institutionGraph , int setno) {
this.graph=institutionGraph;
System.out.println(“Graph::::”+graph);
this.setno=setno;
mylookup1 = graph.getLookupTable(“LookupTable_Accounts”);
mylookup2 = graph.getLookupTable(“LookupTable_Users”);
try {
mylookup1.init();
mylookup2.init();
} catch (ComponentNotReadyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

//metaData_DBField.put(“Field1”,“Field1”);
//metaData_DBField.put(“Field2”,“Field2”);

}

public void setParentChildFields(){
for(int k=0;k1){

if(“account_id”.equalsIgnoreCase(dbFieldArr[1].toString())){
flag=true;
parentField=metaDataFields[k];
childField=“password”;
}
}
}

try {
String lookupKeyStr1={parentField};
RecordKey key1=new RecordKey(lookupKeyStr1,sourceMetadata[0]);
key1.init();
mylookup1.setLookupKey(key1);
String lookupKeyStr2={childField};
RecordKey key2=new RecordKey(lookupKeyStr2,sourceMetadata[0]);
key2.init();
mylookup2.setLookupKey(key2);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public UserAccountsReformat(){

}

public boolean init() throws ComponentNotReadyException{

return true;
}

public boolean transform(DataRecord source, DataRecord target){

try{

DataRecord parent=null;
DataRecord child=null;
String str=null;
str=(source[0].getField(parentField).getValue()).toString();
System.out.println("lookup 1 "+mylookup1);
System.out.println(“parent value”+str);
parent=mylookup1.get(str.trim());
str=(source[0].getField(childField).getValue()).toString();
System.out.println("lookup 2 "+mylookup2);
System.out.println(“child value”+str);
System.out.println(“child field value”+str);
child=mylookup2.get(str.trim());

//System.out.println(“child:”+child);

if (parent==null) {// skip this one
errorMessage = “Order: " + source[0].getField(0).getValue() + " - no corresponding record in lookup table”;
return false;
}
if (child==null) {// skip this one
errorMessage = “Order: " + source[0].getField(0).getValue() + " - no corresponding record in lookup table”;
return false;
}

target[0].getField(“account_id”).setValue(parent.getField(0).getValue());
target[0].getField(“user_id”).setValue(child.getField(0).getValue());
//target[0].getField(“set_no”).setValue(setno);
target[0].getField(“updated_by”).setValue(“System”);
target[0].getField(“updated_at”).setValue(utilDateToSqlDate());

}
catch(Exception e){

e.printStackTrace();
}
return true;
}
public void setGraph(TransformationGraph graph){
this.graph=graph;
}
private void setKeys(String str){
System.out.println(“Look Key”+str);

}
public void setFieldDBMap(Map metaData_DBField){

this.metaData_DBField=metaData_DBField;
}
public void setMetaDataFields(String metaDataFields){

this.metaDataFields=metaDataFields;
}
private java.sql.Timestamp utilDateToSqlDate() throws ParseException
{DateFormat sqlDateFormatter = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
java.util.Date date = new java.util.Date();
System.out.println(“date time:”+sqlDateFormatter.format(date));
return java.sql.Timestamp.valueOf(sqlDateFormatter.format(date));

}
}

Please help me out because i am stuck with this problem.

Thanks,

Getting error while running lookup…

java.lang.RuntimeException: No operations allowed after statement closed.
at org.jetel.lookup.DBLookupTable.get(DBLookupTable.java:357)
at com.mps.pubstats.tool.UserAccountsReformat.transform(UserAccountsReformat.java:81)
at org.jetel.component.Reformat.execute(Reformat.java:196)
at org.jetel.graph.Node.run(Node.java:371)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)