String aMarital = pDTO.getMaritalStatus();
if( aMarital != null ){
aMarital = aMarital.trim();
}
DataTranslator aTranslator = new DataTranslator();
StringBuilder aQuery = new StringBuilder();
aQuery.append("SELECT u ");
aQuery.append("FROM Userrecord u LEFT JOIN u.job j LEFT JOIN j.occupation o LEFT JOIN u.education e ");
if(aZipCode != null && aZipCode.trim().length() > 0) {
aQuery.append(" WHERE ");
aQuery.append("u.zip = '" + aZipCode + "' ");
isSet = true;
}
if (anEducation != null && anEducation.trim().length() > 0) {
if (isSet) {
aQuery.append(" AND ");
} else {
aQuery.append(" WHERE ");
}
aQuery.append(" UPPER(TRIM( e.education )) like '%" + anEducation.toUpperCase() + "%' ");
isSet = true;
}
if(anOccupation != null && anOccupation.trim().length() > 0 ) {
int anOccupationCode = this.findOccupationCode(anOccupation);
if(isSet) {
aQuery.append(" AND " );
} else {
aQuery.append(" WHERE ");
}
aQuery.append(" o.occupationcode = " + anOccupationCode + " ");
isSet = true;
}
if(aMarital != null && aMarital.trim().length() > 0) {
if(isSet) {
aQuery.append(" AND " );
}
else {
aQuery.append(" WHERE ");
}
aQuery.append(" UPPER(TRIM( u.marital )) like '%" + aMarital.toUpperCase() + "%' ");
isSet = true;
}
Query aQueryObject = manager.createQuery(aQuery.toString());
Collection<?> theUserDetails = aQueryObject.getResultList();
return aTranslator.translateToUserDTO(theUserDetails);
}