• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to write logic to insert multiple mappings

 
nalamati satyanarayana
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am facing the problem like I am reading the table relations from xml file for example tale 1 has reference to table2 and table 3 ,table 2 has reference 5and 6 similaru table3 has reference to 7 and 8 here i need to write the logic to insert the following order like first i need to insert table 1 then i need to insert table followed table 5 and 6 next table2 followed by 7 and 8 table here i written the logic like beloe
but it is not working

for (int i = 0; i < (dbprofile.getProfile("export").getTables().getTable()).size(); i++)
{
flag = false;
Table table = dbprofile.getProfile("export").getTables().getTable().get(i);
for (int cons = 0; cons < table.getConstraints().getConstraint().size(); cons++)
{
Constraint constraint = table.getConstraints().getConstraint().get(cons);
if (constraint.getReference() == null )
{
flag = true;
}
if (cons == table.getConstraints().getConstraint().size() - 1 && flag == true)
{
log.info("<<<<<< Table name : >>>>>>>>"+table.getName());
SQLOperations.dbimport(table);
if (tableIds == null)
{
tableIds = new StringBuilder();
tableIds.append(table.getId().toString());
} else
{
tableIds.append("," + table.getId().toString());
}
}
}// for cons
}// for i


canyone sujjest me
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags and punctuation. If I understand you correctly then you want to write the values from a xml-file to a database. Can't you just insert all the tables first and then add the relations? If not and the constraints are not ordered then you'll need to build a data-structure that houses the constraints and let's you extract the proper order of inserting them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic