/[Apache-SVN]
ViewVC logotype

Revision 950901


Jump to revision: Previous Next
Author: jleroux
Date: Thu Jun 3 07:39:19 2010 UTC (13 years, 10 months ago)
Changed paths: 4
Log Message:
A patch from Bob Morley "Support for order by nulls first/last " (https://issues.apache.org/jira/browse/OFBIZ-3740) - OFBIZ-3740

This patch provides the fundamentals to resolve an issue where the sorting of null values were inconsistent (sometimes sorting first and other times sorting last). Specifically, this patch allows one to create an order-by clause via any of the order-by elements of "-myField NULLS LAST" where this text parses out the - (as descending) and the "nulls last".

Since not all databases support the "nulls" argument on an order by clause (it was introduced as part of the OLAP support specification) , our entity-engine.xml file allows each data source to indicate if it has this support. If the support does not exist and nulls first/last is specified, the sql that is generated uses native sql to simulate the nulls first/last intent. At this time, the derby, postgres, and oracle databases are marked to use the nulls first grammar.

Right now, if you do not specify "NULLS XXX" in the field-name for the order-by it makes no change whatsever (naturally this assumption could be changed to have a default).

It should be noted, that my intent here was ultimately to "properly" model the order by into something whose xml representation could look something like ...
<entity-order-by field-name="fieldName" ascending="true" nulls-first="true" />

Divesh Dutta added a comment - 07/May/10 01:44 AM HI Bob, This patch works as expected for derby, postgres, and oracle databases as you have already mentioned. Cant we have some generic solution which supports all the databases. Or we can have some conditional code, where we can check which datasource is being used, and then generate the sql accordingly. Please let me know your views on this.

Bob Morley added a comment - 07/May/10 08:07 AM
Hi Divesh,
I added a more detailed description in the forum thread; but in brief this is a generic solution which supports all databases which generates the sql accordingly. What this patch does not do is apply a standard default order for all databases; it just adds support for one to dictate how they want the nulls sorted.
For example, when one sets the order-by they can set it to "lastName DESC NULLS FIRST" which should apply to all databases.


The thread Bob was referring above ends at http://markmail.org/message/47z7fwtawehuem6b


Changed paths

Path Details
Directoryofbiz/trunk/framework/entity/config/entityengine.xml modified , text changed
Directoryofbiz/trunk/framework/entity/dtd/entity-config.xsd modified , text changed
Directoryofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java modified , text changed
Directoryofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/DatasourceInfo.java modified , text changed

infrastructure at apache.org
ViewVC Help
Powered by ViewVC 1.1.26