HI All
I have a search query for which the sql statemanet i m using is
String lowerPriceLimit = null;
String higherPriceLimit = null;
if(searchForm.getSearchType().equalsIgnoreCase(QuarksConstants.RENT)){
lowerPriceLimit = searchForm.getPriceLowerRent();
higherPriceLimit = searchForm.getPriceHigherRent();
}else{
lowerPriceLimit = searchForm.getPriceLowerBuy();
higherPriceLimit = searchForm.getPriceHigherBuy();
}
final double lowerPrice = Double.parseDouble(lowerPriceLimit);
final double higherPrice = Double.parseDouble(higherPriceLimit);
StringBuffer query = new StringBuffer
("from " + getEntityBeanType().getName() + " p where ");
if(!StringUtils.isEmpty(searchForm.getNumberOfBedrooms())){
final int bedRoom = Integer.parseInt(searchForm.getNumberOfBedrooms());
query.append(" p.numberOfBedrooms >= '"+ bedRoom +"' and");
}
if(!StringUtils.isEmpty(searchForm.getPropertyCategory())){
Long propertyCategory = (Long.valueOf(searchForm.getPropertyCategory()));
query.append(" p.propertyCategoryReferenceCode = '"+ propertyCategory +"' and");
}
if(!StringUtils.isEmpty(searchForm.getResidentialPropertyType())){
Long residentialPropertyType = (Long.valueOf(searchForm.getResidentialPropertyType()));
query.append(" p.propertyTypeReferenceCode = '"+ residentialPropertyType +"' and");
}
if(!StringUtils.isEmpty(searchForm.getCommercialPropertyType())){
Long commercialPropertyType = (Long.valueOf(searchForm.getCommercialPropertyType()));
query.append(" p.propertyTypeReferenceCode = '"+ commercialPropertyType +"' and");
}
if(!StringUtils.isEmpty(searchForm.getCity())){
Long city = (Long.valueOf(searchForm.getCity()));
query.append(" p.city = '"+ city +"' and");
}
if(!StringUtils.isEmpty(searchForm.getLocation())){
query.append(" p.location= '"+searchForm.getLocation()+"' and");
}
query.append(" p.price between '" + lowerPrice +"' and '" + higherPrice +"'");
Now i need to write named queery for the search sql querry.
Well there can be some values which are null in the form so how 2 go for those values?
Do i need to create multiple named queriers?