0

I'm using below flexible query in HMC and it's working fine.

The same query needs to convert the DAO layer and input is a data parameter. Please any help on this?

SELECT * FROM {Product} WHERE {creationtime} >= TO_DATE('2020/02/19','YYYY/MM/DD')

HybrisHelp
  • 5,518
  • 2
  • 27
  • 65

2 Answers2

1

Refer DefaultProductDao and create one for your requirement or you can extend it if you want to reuse any function. I hope by looking at the class, you'll have an understanding of how to write and execute the flexi query in the SAP Hybris.

Converting your query to DAO
Here, I would suggest avoiding using TO_DATE or any DB function to ensure that the query is not DB dependent. In your case, you can parse string date to Java Date object and pass it to the query something like below

String query = "SELECT * FROM {"+ ProductModel._TYPECODE +"} WHERE {"+ ProductModel.CREATIONTIME +"} >= ?"+ProductModel.CREATIONTIME;

final FlexibleSearchQuery searchQuery = new FlexibleSearchQuery(query);
        final Map<String, Object> params = new HashMap<String, Object>();
        params.put(ProductModel.CREATIONTIME, getDateObject("2020/02/19"));
        searchQuery.addQueryParameters(params);
        final SearchResult searchResult = getFlexibleSearchService().search(searchQuery);
        return searchResult.getResult();

Method

private Date getDateObject(String date)
{
 // logic to parse your string date (YYYY/MM/DD) to java Date object
 return new Date(); //return your parsed date object here
}
HybrisHelp
  • 5,518
  • 2
  • 27
  • 65