Hi Grégoire,
I don't know if this will help or not. The problem I had is that in-memory
sorting treated nulls different that sorting in the database query. The
database in my case was ORACLE. To make in-memory sorting congruent with
ORACLE's sorting of nulls I had to do the following:
First , in my core services framework I added a principal class
(CoreServicesPrincipal.java) that looks something like this:
package com.mycompany.coreservices;
public class CoreServicesPrincipal extends ERXFrameworkPrincipal {
static {
setUpFrameworkPrincipalClass(CoreServicesPrincipal.class);
}
@Override
public void finishInitialization() {
// Setup in-memory sorting to treat null as greater than
non-null values
if (ERXProperties.booleanForKeyWithDefault("NullsAtEnd", true))
{
EOSortOrdering.ComparisonSupport.setSupportForClass(new
NullsAtEndComparisonSupport(), Object.class);
EOSortOrdering.ComparisonSupport.setSupportForClass(new
NullsAtEndComparisonSupport(), String.class);
}
}
}
Then in framework's build.properties file I added the following entry:
principalClass=com.mycompany.coreservices.CoreServicesPrincipal
This makes sure the class is setup as the principal class for the framework so
that code in the finishInitialization() gets called.
Then the remaining step is to implement the NullsAtEndComparisonSupport class:
/**
* This class in installed from within framework principal's
finishInitialization().
* See build.properties to find out the name of the principal class.
*
* This class makes sure that nulls are treated as greater than non-null values
* in order to be congruent with ORACLE's sorting behavior.
*
* If you want to disable this behavior set property NullsAtEnd to false
explicitly.
*
* @author ricardo
*
*/
public class NullsAtEndComparisonSupport extends
EOSortOrdering.ComparisonSupport {
private static final int NONE_NULL = -42;
/**
* Returns NONE_NULL when left and right are both non-null. Otherwise
* returns -1, 0 or 1 to achieve the null > non-null effect.
*/
private static int _handleNulls(Object left, Object right)
{
if (ERXValueUtilities.isNull(left)) {
return !ERXValueUtilities.isNull(right) ? 1 : 0;
} else {
return !ERXValueUtilities.isNull(right) ? NONE_NULL : -1;
}
}
/** Overrides super class implementation so that null > non-null */
protected int _genericCompareTo(Object left, Object right)
{
int nullCheck = _handleNulls(left, right);
if (nullCheck != NONE_NULL) {
return nullCheck;
}
// For none null values the behavior is as before so let the
// super class handle it.
return super._genericCompareTo(left, right);
}
/** Overrides super class implementation so that null > non-null */
protected int _genericCaseInsensitiveCompareTo(Object left, Object right)
{
int nullCheck = _handleNulls(left, right);
if (nullCheck != NONE_NULL) {
return nullCheck;
}
// For none null values the behavior is as before so let the
// super class handle it.
return super._genericCaseInsensitiveCompareTo(left, right);
}
}
On Jul 18, 2012, at 7:02 AM, ALEXANDRE Grégoire wrote:
> hi,
> i need to create fecth specification with my null element at the end of the
> response
>
> for example i need tu create this;
>
> select * from my_table order by my_date nulls first;
>
> thanks for reply.
> --
> Grégoire ALEXANDRE
> Développeur
> GIP Sym@ris
> Pavillon 1
> 27 rue du 4ème RSM B.P. 29
> F-68250 ROUFFACH
> tel : 0389787406
> Courriel : g.alexan...@symaris.com
> Web : http://www.symaris.com
> ___
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/rparada%40mac.com
>
> This email sent to rpar...@mac.com
___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com