• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: EOSortOrdering first null
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EOSortOrdering first null


  • Subject: Re: EOSortOrdering first null
  • From: ALEXANDRE GrĂ©goire <email@hidden>
  • Date: Mon, 30 Jul 2012 10:01:33 +0200

Hi, thanks for your answer, but i don't understand what ERXFrameworkPrincipal work. when is it called?


Le 26/07/12 23:17, Ricardo J. Parada a écrit :
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 <email@hidden> 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 : email@hidden
Web : http://www.symaris.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden




--
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 : email@hidden
Web : http://www.symaris.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: EOSortOrdering first null (From: "Ricardo J. Parada" <email@hidden>)

  • Prev by Date: Re: didUpdate?
  • Next by Date: Re: didUpdate?
  • Previous by thread: Re: EOSortOrdering first null
  • Next by thread: AjaxProxy and AjaxUpdateContainer co-operation fails
  • Index(es):
    • Date
    • Thread