package com.chenyang.nse.bussiness.engine.infa.powercenter961.simplesubdata;

import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TARGET;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TARGETFIELD;
import com.chenyang.nse.bussiness.engine.infa.powercenter961.pubbean.TargetBean;
import java.util.ArrayList;
import java.util.List;

public class ChildSeTargetUtil {
   public List<TARGET> getSeChildTarget(List<TargetBean> tb) {
      List<TARGET> tar_list = new ArrayList();
      if (tb != null && tb.size() > 0) {
         for(int i = 0; i < tb.size(); ++i) {
            TARGET target = new TARGET();
            target.setBUSINESSNAME("");
            target.setCONSTRAINT("");
            target.setDATABASETYPE(((TargetBean)tb.get(i)).getDatabasetype());
            target.setDESCRIPTION("");
            target.setNAME(((TargetBean)tb.get(i)).getTar_name());
            target.setOBJECTVERSION("1");
            target.setTABLEOPTIONS("");
            target.setVERSIONNUMBER("1");

            for(TARGETFIELD targetfield : this.getConvertTableInfoToTARGETFIELD(((TargetBean)tb.get(i)).getCb().getKeytype(), ((TargetBean)tb.get(i)).getCb().getNameList(), ((TargetBean)tb.get(i)).getCb().getTypeList(), ((TargetBean)tb.get(i)).getCb().getLengthList(), ((TargetBean)tb.get(i)).getCb().getScalelist(), ((TargetBean)tb.get(i)).getCb().getPrecisionList())) {
               target.getTARGETFIELD().add(targetfield);
            }

            tar_list.add(target);
         }
      }

      return tar_list;
   }

   public List<TARGETFIELD> getConvertTableInfoToTARGETFIELD(List<String> keytype, List<String> nameList, List<String> typeList, List<String> lengthList, List<String> scaleList, List<String> precisionlist) {
      List targetFieldList = new ArrayList();
      String[] targetFieldInfoStr = null;

      for(int i = 0; i < nameList.size(); ++i) {
         TARGETFIELD targetfield = new TARGETFIELD();
         targetfield.setBUSINESSNAME("");
         targetfield.setDATATYPE((String)typeList.get(i));
         targetfield.setDESCRIPTION("");
         targetfield.setFIELDNUMBER("" + (i + 1));
         targetfield.setKEYTYPE((String)keytype.get(i));
         targetfield.setNAME((String)nameList.get(i));
         if ("PRIMARY KEY".equals(keytype.get(i))) {
            targetfield.setNULLABLE("NOTNULL");
         } else {
            targetfield.setNULLABLE("NULL");
         }

         targetfield.setPICTURETEXT("");
         targetfield.setPRECISION((String)precisionlist.get(i));
         targetfield.setSCALE((String)scaleList.get(i));
         targetFieldList.add(targetfield);
      }

      return targetFieldList;
   }
}
