[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Best way to support case insensitive alphanumeric sorting..
|
I am assuming you are using the DescriptorCustomizer suggested below. (Here's
some doc:
http://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/a_customizer.htm#CHDCCDGC)
If that is not the case, let me know.
When you are in the DescriptorCustomizer's customize method, you will be given
an instance of a descriptor. From the descriptor, you can operate on mappings.
I provided code earlier to alter the ordering of your OneToMany.
> OneToManyMapping oneToManyMapping =
(OneToOneMapping)descriptor.__getMappingForAttributeName("__attributeName");
ExpressionBuilder builder =
oneToManyMapping.__getSelectionQuery().__getExpressionBuilder();
If you want to make some decisions based on the postalCode mapping, you can
get it roughly like this:
ClassDescriptor referenceDescriptor = oneToManyMapping.getReferenceDescriptor();
DirectToFieldMapping dtfMapping =
(DirectToFieldMapping)referenceDescriptor.getMappingForAttributeName("postalCode");
Class attributeClassification = dtfMapping.getAttributeClassification();
// attributeClassification will be a java class, you can put some condtional
logic here to help you build the expression. The expression could be something
like this:
Expression orderExpression =
builder.get("postalCode").__toLowerCase().ascending();
oneToManyMapping.__getSelectionQuery().__addOrdering(orderExpression);
On 11/06/2013 3:48 PM, vaidya nathan wrote:
Thanx Tom,
I am not very conversant with the descriptor. How do i initialize that ..
Tried
RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.setJavaClass(eb.getQueryClass()); // eb is the expressionbuilder
descriptor.setPrimaryKeyFieldName("ID");
descriptor.setTableName(<<Table name>>);
DirectToFieldMapping dtfMapping = (DirectToFieldMapping)
descriptor.getMappingForAttributeName(order);
Class mappingType = dtfMapping.getAttributeClassification();
Here the descriptor is always coming as null .. i tried going through the
samples and documentation but couldnt find how to initialize the mappings . Can
you please point me / let me know how i need to populate the mappings. Also i am
using RelationalDescriptory .. is that the right descriptor.
Thx a lot
Vaidya
On Tue, Jun 11, 2013 at 12:29 PM, Tom Ware <tom.ware@xxxxxxxxxx
<mailto:tom.ware@xxxxxxxxxx>> wrote:
You can get the type from the mapping for a particular attribute like this:
DirectToFieldMapping dtfMapping =
descriptor.__getMappingForAttributeName(<__directAttributeName>);
Class mappingType = dtfMapping.__getAttributeClassification();
Notice that the type will be a java class rather than a database type.
-Tom
On 11/06/2013 9:45 AM, vaidya nathan wrote:
From the documentation , I see that we cant use this for non String
columns
like say Numeric columns.
For eg, if the column is a numeric , then this will not work ..
Expression exp = (ascending ? exp.toLowerCase().ascending() :
exp.toLowerCase().descending()__) ;
Is there a way in which we can get meta data information about the
column and
then have this sort something like
if (column is String)
{
Expression exp = (ascending ? exp.toLowerCase().ascending() :
exp.toLowerCase().descending()__) ;
}
else
{
Expression exp = (ascending ? exp.ascending() : exp.descending()) ;
}
Or is there any other way in which we can do this. If possible please
furnish me
some sample codes too or point me to some samples where we are doing this .
Also Dennis you said that didn't work . Can you elaborate please? What
issues
did you have ?
Thx for all your response
Vaidya
On Thu, Jun 6, 2013 at 9:11 AM, Dennis Fuglsang
<dennis.fuglsang@xxxxxxxxxx <mailto:dennis.fuglsang@xxxxxxxxxx>
<mailto:dennis.fuglsang@__oracle.com
<mailto:dennis.fuglsang@xxxxxxxxxx>>> wrote:
I had a similar requirement and initially tried using the UPPER
operator in
the ORDER BY clause but that did not work for me. For example:
"SELECT
a.ID, a.name <http://a.name> <http://a.name> FROM Table a ORDER BY
UPPER(a.name <http://a.name>
<http://a.name>)"
What did work for me was specifying an upper-cased form of the
column to
sort on in the SELECT clause. For example: "SELECT a.ID, a.name
<http://a.name>
<http://a.name>, UPPER(a.name <http://a.name> <http://a.name>) AS
name_order FROM Table a
ORDER BY name_order"
-----Original Message-----
From: Tom Ware
Sent: Thursday, June 06, 2013 9:05 AM
To: eclipselink-users@xxxxxxxxxxx
<mailto:eclipselink-users@xxxxxxxxxxx>
<mailto:eclipselink-users@__eclipse.org
<mailto:eclipselink-users@xxxxxxxxxxx>>
Subject: Re: [eclipselink-users] Best way to support case insensitive
alphanumeric sorting..
EclipseLink provides toUpperCase() and toLowerCase() expressions
and JPA
provides UPPER and LOWER operators. For queries I expect you could use
those operators in the ORDER BY part of your query to sort.
If you are talking about a mapping, you could use an EclipseLink
DescriptorCustomizer to add ordering by an EclipseLink expression
to the
selection query. Roughly:
OneToManyMapping oneToManyMapping =
(OneToOneMapping)descriptor.__getMappingForAttributeName("__attributeName");
ExpressionBuilder builder =
oneToManyMapping.__getSelectionQuery().__getExpressionBuilder();
Expression orderExpression =
builder.get("postalCode").__toLowerCase().ascending();
oneToManyMapping.__getSelectionQuery().__addOrdering(orderExpression);
-Tom
On 05/06/2013 11:54 AM, vaidya nathan wrote:
> Hi,
>
> What is the best way to support case insensitive alphanumeric
sorting
> using jpa2 and eclipselink ? An example of what i would like to
> achieve is to sort on something similiar to the canada zips
which could
be alphanumeric..
>
> We are using Eclipselinks ReadAllQuery and Expression language to
> build our queries and the queries that we have so far is like this..
>
> SELECT * FROM
> (SELECT a.*, ROWNUM rnum FROM
> (SELECT DISTINCT t1.ID AS a1,<colname>
> FROM <Table> ORDER BY t0.<colname> ASC) a WHERE ROWNUM <= ?)
WHERE
rnum > ?
> )a
>
>
> Thx
>
>
>
>
> _________________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
<mailto:eclipselink-users@xxxxxxxxxxx>
<mailto:eclipselink-users@__eclipse.org
<mailto:eclipselink-users@xxxxxxxxxxx>>
> https://dev.eclipse.org/__mailman/listinfo/eclipselink-__users
<https://dev.eclipse.org/mailman/listinfo/eclipselink-users>
>
_________________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx <mailto:eclipselink-users@xxxxxxxxxxx>
<mailto:eclipselink-users@__eclipse.org
<mailto:eclipselink-users@xxxxxxxxxxx>>
https://dev.eclipse.org/__mailman/listinfo/eclipselink-__users
<https://dev.eclipse.org/mailman/listinfo/eclipselink-users>
_________________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx <mailto:eclipselink-users@xxxxxxxxxxx>
<mailto:eclipselink-users@__eclipse.org
<mailto:eclipselink-users@xxxxxxxxxxx>>
https://dev.eclipse.org/__mailman/listinfo/eclipselink-__users
<https://dev.eclipse.org/mailman/listinfo/eclipselink-users>
_________________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx <mailto:eclipselink-users@xxxxxxxxxxx>
https://dev.eclipse.org/__mailman/listinfo/eclipselink-__users
<https://dev.eclipse.org/mailman/listinfo/eclipselink-users>
_________________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx <mailto:eclipselink-users@xxxxxxxxxxx>
https://dev.eclipse.org/__mailman/listinfo/eclipselink-__users
<https://dev.eclipse.org/mailman/listinfo/eclipselink-users>
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users