" question.questionId" +
" from Answer").list();
for (Object o : alist){
Object[] cols = (Object[]) o;
Answer answer = new Answer();
answer.setAnswerId((Integer) cols[0]);
answer.setContents((String) cols[1]);
answer.setAnswerInterpritation((String) cols[2]);
answer.setLetter((String) cols[3]);
Question question = qmap.get((Integer) cols[4]);
if (question!=null) {
question.getAnswers().add(answer);
answer.setQuestion(question);
}
amap.put(answer.getAnswerId(), answer);
}
getSession().createQuery(
"from DangerCategory").list();
getSession().createQuery(
"from ObjectType").list();
getSession().createQuery(
"from User u left join fetch u.roles").list();
String boHQL =
"select new BuildingObject(objectId," +
" technicalTask,wayToTechnicalTask, " +
"(select object(user) from User user " +
" where user.id=buildingObject.user.id), " +
" name, " +
" description, " +
" country, " +
" region, " +
" city, " +
" street, " +
" house, " +
" block, " +
" organizationName, " +
" organizationZip, " +
" organizationCountry, " +
" organizationRegion, " +
" organizationCity, " +
"organizationHouse,organizationStreet,organizationBlock,organizationFlat, " +
"headerFamily,headerMiddleName,headerName,organozationPhone, " +
"(select object(dangerCategory) from DangerCategory dangerCategory " +
" where dangerCategory.dangerCategoryId=buildingObject.dangerCategory.dangerCategoryId), " +
" (select object(objectType) from ObjectType objectType where objectType.objectTypeId=buildingObject.objectType.objectTypeId))" +
" from BuildingObject buildingObject";
List<?> buildingObjectList = null;
if (buildingObjectId ==null) {
buildingObjectList = getSession().createQuery(
boHQL).list();
} else {
boHQL = boHQL + " where buildingObject.objectId=?";
buildingObjectList = getSession().createQuery(
boHQL).setString(0, buildingObjectId.toString()).list();
}
Map<Integer, BuildingObject> boMap = new HashMap<Integer, BuildingObject>();
for(Object o : buildingObjectList){
BuildingObject bo = (BuildingObject) o;
List objectAnswers = getSession().createQuery("select new ObjectAnswer(objectAnswerId,objectConstructionId,answerContents,answerComment,buildingObjectId,question) from ObjectAnswer where objectId=?").setString(0, String.valueOf(bo.getObjectId())).list();
for (int j = 0; j < objectAnswers.size(); j++) {
ObjectAnswer objectAnswer = (ObjectAnswer) objectAnswers.get(j);
objectAnswer.setAnswers(super.getSession().createQuery("from Answer where answerId in (select answers.answerId from ObjectAnswer objectAnswer inner join objectAnswer.answers as answers where objectAnswer.objectAnswerId=?)").setString(0, objectAnswer.getObjectAnswerId().toString()).list());
}
bo.setDocumentationQuestions(objectAnswers);
//we have already lazy list
//bo.setDocQuestions(new ArrayList<ObjectAnswer>());
//bo.setObjectQuestions(new ArrayList<ObjectAnswer>());
//bo.setDocumentationQuestions(new ArrayList<ObjectAnswer>());
boMap.put(bo.getObjectId(), bo);
}
String oaHQL = "select objectAnswerId, " +
" buildingObjectId, " +
" answerContents, " +
" answerComment, " +
" question.questionId from ObjectAnswer";
List<?> oqustion = null;
if (buildingObjectId ==null) {
oqustion = getSession().createQuery(
oaHQL).list();
} else {
oaHQL = oaHQL + " where buildingObjectId=?";
oqustion = getSession().createQuery(
oaHQL).setString(0, buildingObjectId.toString()).list();
}
Map<Integer, ObjectAnswer> oaMap = new HashMap<Integer, ObjectAnswer>();
for (Object o : oqustion) {
Object[] cols = (Object[]) o;
ObjectAnswer oa = new ObjectAnswer();
oa.setObjectAnswerId((Integer) cols[0]);
oa.setBuildingObjectId((Integer) cols[1]);
oa.setAnswerContents((String) cols[2]);
oa.setAnswerComment((String) cols[3]);
// oa.setAnswers(new ArrayList<Answer>());
Question q = qmap.get((Integer) cols[4]);
if (q != null) {
oa.setQuestion(q);
BuildingObject bo = boMap.get(oa.getBuildingObjectId());
if (bo != null) {
oa.setBuildingObject(bo);
if (q.isForObjectStructure()) {
bo.getObjectQuestions().add(oa);
} else {
bo.getDocQuestions().add(oa);
}
if (q.getQuestionType().getQuestionTypeId() == 1){
bo.getDocumentationQuestions().add(oa);
}
}
}
oaMap.put(oa.getObjectAnswerId(), oa);
}
List<?> oanswer = null;
String oanswerHQL =
"select oa.objectAnswerId, " +
" a.answerId " +
" from ObjectAnswer oa left join oa.answers as a ";
if (buildingObjectId ==null) {
oanswer = getSession().createQuery(
oanswerHQL).list();
} else {
oanswerHQL = oanswerHQL + " where oa.buildingObjectId=?";
oanswer = getSession().createQuery(
oanswerHQL).setString(0, buildingObjectId.toString()).list();
}
for (Object o : oanswer) {
Object[] cols = (Object[]) o;
ObjectAnswer oa = oaMap.get((Integer) cols[0]);
if (oa != null) {
Answer a = amap.get((Integer) cols[1]);
if (a!=null){
oa.getAnswers().add(a);
}
}
}