Skip to Content
avatar image
Former Member

Retrieve Main table records with multiple lookup table values

Hi,

I have a 30 <b>Flat Table</b>s and 2 <b>Taxonomy table</b>.

Every time i iterate through each Table and set the setSelectFields it is retrieving only the first flat table/Taxonomy Table record value so the soln is to make this dynamic to collect 30 setSelectField and add to supportingResultDefinition[].

the sample snippet code is below:

//for loop to get all the 30 Flat tables

for (int j = 0; j < productLookUpQTables.size(); j++){

tableId3 = (TableId) productLookUpQTables.get(j);

GetFieldListCommand getFieldListCommand = new GetFieldListCommand(connPool);

getFieldListCommand.setSession(sessionId);

getFieldListCommand.setTableId(tableId3);

try{

getFieldListCommand.execute();

} catch (CommandException e){

e.printStackTrace();

}

//fieldproperties contain all the fields for the 30 flat tables

FieldProperties[] lookupQFlatFields = getFieldListCommand.getFields();

for (int m = 0; m < lookupQFlatFields.length; m++){

QflatTableFields = new FieldId[] {lookupQFlatFields[m].getId()};

}

} // 2 For

rdqFlat.setSelectFields(QflatTableFields); //all flat table fields adding it to Result set definition

//How to make this dynamic to collect 30 setSelectField and add to supportingResultDefinition[]

supportingMainResultDefinitions = new ResultDefinition[] ;

With Thanks,

Mary Joseph

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Oct 10, 2007 at 06:27 PM

    Mary it looks like in your second for loop you are trying to create a FieldId[] with all of the fields from the table, but each time through the loop it is overwriting everything so by the time you get to setSelectFields there is only one FieldId in your array.

    Try something like this after the line where you create the FieldProperties[]:

    FieldId[] QflatTableFields = new Fieldid[lookupQFlatFields.length];

    for(int m = 0; m < lookupQFlatFields.length; m++){

    QflatTableFields[m] = lookupQFlatFields[m].getId();

    }

    Now the FieldId[] has all of the fields so when you setSelectFields they will all be there.

    Hope this helps.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 12, 2007 at 04:51 AM

    Hi Auston

    Thank you Very much your reply Auston

    But when there is only one Qualified table, the above code works perfectly, and the problem i am facing is i'm having 3 Qualified Lookup table in a repository and from the for loop i'm getting all the fields of the first Qualified Lookup table set the rdqFlat.setSelectFields(fields); and passing this to a Supporting Result Definition.

    supportingMainResultDefinitions = new ResultDefinition[] ; and finally reterival of records, but here the code goes through only one Qualitied table and getting the Supporting resultset. How can this Resultset be hold to contain 3 Qualified LookUp Table? // Code for Reterieval of the records goes ....... Austin, I will place my code here, can point me where i am wrong. //To reterive all the tables and all Qualified LookuPTable, i'm checking the Type of the Table if this is Qualified Table I'm adding it to a Arraylist. TableProperties[] tabprop = tableComm.getTables(); for(int i=0;i<tabprop.length;i++){ if(tabprop<i>.getType() == TableProperties.MAIN){ productMainTable = tabprop<i>; productMainTableLookUp.add(productMainTable.getId()); System.out.println("MAIN Tables Code and Name is :"productMainTabletabprop<i>.getName()"size======="productMainTableLookUp.size()); }else (tabprop<i>.getType() == TableProperties.QUALIFIED_FLAT){ lookUpQTable = tabprop<i>; productLookUpQTables.add(lookUpQTable.getId()); System.out.println("Qualified Table Code and Name is :\t"lookUpQTabletabprop<i>.getName()"size======="productLookUpQTables.size()); } } Here i am gettinge MAIN Table fields(from the Arraylist). In the SOP you can see that it contains all the fields of the Main table. System.out.println(" MAIN TABLE :\n "); for (int j = 0; j < productMainTableLookUp.size(); j++){ tableId = (TableId) productMainTableLookUp.get(j); GetFieldListCommand getFieldListCommand = new GetFieldListCommand(connPool); getFieldListCommand.setSession(sessionId); getFieldListCommand.setTableId(tableId); try{ getFieldListCommand.execute(); } catch (CommandException e){ e.printStackTrace(); } rd = new ResultDefinition(tableId); FieldProperties[] lookupMainFields = getFieldListCommand.getFields(); //mainTableFields = new FieldId[lookupMainFields.length]; //System.out.println(" lookupMainFields[m].getId() :\t "+lookupMainFields[m].getCode()); FieldId[] fields = new FieldId [lookupMainFields.length]; for (int m = 0; m < lookupMainFields.length; m++){ fields[m] = lookupMainFields[m].getId(); System.out.println(" Main table feilds are 116"+fields[m]); // System.out.println(" Main table feilds are 116**********"+fields[0].getString()); rd.setSelectFields(fields); } } // 2 For // System.out.println(" QUALIFIED TABLE :\n "); for (int j = 0; j < productLookUpQTables.size(); j++){ tableId3 = (TableId) productLookUpQTables.get(j); GetFieldListCommand getFieldListCommand = new GetFieldListCommand(connPool); getFieldListCommand.setSession(sessionId); getFieldListCommand.setTableId(tableId3); try{ getFieldListCommand.execute(); } catch (CommandException e){ e.printStackTrace(); } // System.out.println("Qualified Table:"+ rdqFlat); FieldProperties[] lookupQFlatFields = getFieldListCommand.getFields(); FieldId[] QflatTableFields = new Fieldid[lookupQFlatFields.length]; for(int m = 0; m < lookupQFlatFields.length; m++){QflatTableFields[m] = lookupQFlatFields[m].getId();} } } // 2 For rdqFlat.setSelectFields(QflatTableFields); supportingMainResultDefinitions = new ResultDefinition[] ;

    retrieve Limited Records Command code follows:

    Please Help me with this Issue.

    With Thanks,

    Mary Joseph

    Add comment
    10|10000 characters needed characters exceeded