Map<Integer, ConstructionExample> ceMap =
new HashMap<Integer, ConstructionExample>();
for (Object n : rowList){
Object[] cols = (Object[]) n;
ConstructionExample ce = new ConstructionExample();
ce.setExampleId((Integer) cols[0]);
ce.setExampleRelativeNumber((Integer) cols[1]);
ce.setExampleName((String) cols[2]);
ce.setDangerCategory((DangerCategory) cols[3]);
ce.setNoDeffects((Boolean) cols[4]);
if (ce.getRecommendedDangerCategory() == null){
DangerCategory dc = new DangerCategory();
dc.setDangerCategoryId(-1);
dc.setCategoryName("В");
ce.setRecommendedDangerCategory(dc);
}
ce.setExampleDefects(null);
ce.setDefectCount(new Integer(0));
ce.setExampleDefects(new ArrayList<ConstructionDefect>());
ceMap.put(ce.getExampleId(), ce);
ceList.add(ce);
}
String hql2 =
"select "+
" cd.constructionDefectId, "+
" cd.comment, "+
" dt.defectTypeId, "+
" dt.defectTypeName,"+
" dv.varityId, "+
" dv.varityName,"+
" dz.defectZoneId, "+
" dz.defectZoneName,"+
" cd.dangerCategory,"+
" cd.exampleId"+
" from ConstructionDefectZone as cd left join cd.defectType as dt " +
" left join cd.defectZone as dz left join cd.defectVarity as dv " +
" left join cd.dangerCategory";
if (objectId != null || typeId != null) {
hql2 = hql2 + " where cd.exampleId in (select ce.exampleId " +
" from ConstructionExample as ce where ";
hql2 = hql2 + buildCondition(objectId, typeId) +")";
}
q = getSession().createQuery(hql2);
presetParams(q, objectId, typeId);
List res = q.list();
for (Object r : res){
Object[] rescolumns = (Object[]) r;
ConstructionDefect cd = new ConstructionDefect(
(Integer) rescolumns[0], (String) rescolumns[1]);
DefectType dt = new DefectType(
(Integer) rescolumns[2], (String) rescolumns[3]);
DefectVarity dv = new DefectVarity(
(Integer) rescolumns[4], (String) rescolumns[5]);
DefectZone dz = new DefectZone(
(Integer) rescolumns[6], (String) rescolumns[7]);
cd.setDefectType(dt);
cd.setDefectVarity(dv);
cd.setDefectZone(dz);
cd.setDangerCategory((DangerCategory)rescolumns[8]);
ConstructionExample ce =
ceMap.get((Integer) rescolumns[9]);
if (ce != null) {
if (compareDangerCategory(cd.getDangerCategory(), ce.getRecommendedDangerCategory()) > 0){
ce.setRecommendedDangerCategory(cd.getDangerCategory());
}
ce.getExampleDefects().add(cd);
System.out.println("EXample defects size:"+ce.getExampleDefects().size());
ce.setDefectCount(new Integer(ce.getExampleDefects().size()));
}
}
return ceList;
}