Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with named Query for a search

 
Divy Prakash
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Francois Nadeau
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Divy,

Yes, if I had to write named queries I would write multiple. Instead you may want to clean up your code by using a Criteria.



Hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic