cancel
Showing results for 
Search instead for 
Did you mean: 

How to specialize a query regarding fetch type

Former Member
0 Kudos

Hi experts, I need some guidance about flexible search. Can we set fetching type for a specific flexible search query considering performance issue. Because, while getting and handling lazy collection after getting query result collection on web server side to prepare heavy data, it asks to db for onetomany lazy relations, therefore it tries to reach persistence layer for every bag again and again. So i need to set as eager just for specified query to get rid of this situation, in this way i intend to go to db only one time. Is there a solution for that or anything else? Any comments are welcome...

Former Member
0 Kudos

Any comments?

Former Member
0 Kudos

Hi Mustafa,

Could you please provide some query examples?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Mustafa,

You can't set fetch type for flexiblesearch queries. But you can use FlexibleSearchService to translate flexiblesearch queries to SQL Query and you can execute with hybris' jdbc wrapper. here is a code example:

 final FlexibleSearchQuery flexibleSearchQuery = new FlexibleSearchQuery("SELECT {pk} from {Product}");
 final TranslationResult result = flexibleSearchService.translate(flexibleSearchQuery);
 final String sqlQuery = result.getSQLQuery();
 final List<Object> params = result.getSQLQueryParameters();
 
 final Connection connection = Registry.getCurrentTenant().getDataSource().getConnection();
 PreparedStatement stmt = connection.prepareStatement(sqlQuery);
 
 for (int i = 0; i < params.size(); ++i) {
     stmt.setString(i + 1, params.get(i).toString());
 }
 final ResultSet resultSet = stmt.executeQuery();



Now you have a result set based on flexiblesearch query.

But you have to use it carefully. if your query retrieves 1 million rows, the JVM heap memory may not be good enough to hold that large amount of data. You may want to set fetch size for the result set.

 stmt.setFetchSize(1000);

You may also want to look at https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html#setFetchSize-int- and please note that the JDBC drivers have different default fetch size.

regards, Seref

Former Member
0 Kudos

Thank you. Maybe we have to consider a pagination implementation regarding fetchSize..

Answers (1)

Answers (1)

former_member632755
Active Contributor
0 Kudos

Hi,

can you post your data model and the problematic query? Collection types and relations are quite different. You may limit search results by forcing the flexible search not to search subtypes. I guess w/o more details it may be hard to answer.

Cheers, Wojtek