• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with named Query for a search

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic