Explicitly enabling in-memory sorting for a view object

Sharing a tip that I learned while debugging an issue ;)
When you try to sort a UI component such as af:table bound to a view object, framework by default fire SQL ORDER BY clause if the selected column is not a transient one, otherwise framework will go for an in-memory sort by calling setSortCriteria(...) on the ViewObject.

You can override this default behavior by setting a custom property on the ViewObject. This make sense if your view object is a programmatic  or transient view object or if the view object contains uncommitted rows.To do this, you need to set a property named PROP_ALWAYS_USE_SORT to true (available in 11.1.1.7.0 release). When PROP_ALWAYS_USE_SORT is 'true', framework will always go for in-memory sorting.

Example:
empVO.setProperty(ViewObject.PROP_ALWAYS_USE_SORT, "true");

Warning: Note that when you enable in-memory sorting, framework will fetch all the records from the DB before performing the sort. So it makes sense only if you have limited number of rows.

Comments

  1. hi Jobinesh,

    May be this is what I was exactly looking for. But my ViewObject doesnot have that 'PROP_ALWAYS_USE_SORT' static variable. I am using Jdev 11.1.1.6.0.

    In which version it is supported.

    If you can , please see my forum thread. I need solution for this

    https://forums.oracle.com/forums/thread.jspa?threadID=2531973&tstart=0


    Regards,
    Neha..

    ReplyDelete
  2. Neha,
    This property is available in 11.1.1.7.0

    ReplyDelete
  3. Thanks for the info. I guess I am looking for a way to do this declaratively from ADF Faces. From what I can gather from section 27.5, I see a way to sort in memory if I am writing the code to interact with the view object. But I am trying to use af:table and data binding and not write the low-level code. Since the rich-client af:table has a sorting capability built-in, I want to have a way to tell the framework to sort in memory. To get more info please visit http://researchpapergiant.com/research-paper-examples/.

    ReplyDelete
  4. You can also use the view to set the query mode.

    vo.setQueryMode(ViewObject.QUERY_MODE_SCAN_VIEW_ROWS);

    ReplyDelete

Post a Comment