Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 384223 - likeIgnoreCase does not work for german ß
Summary: likeIgnoreCase does not work for german ß
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: David Minsky CLA
QA Contact: Project Inbox CLA
URL:
Whiteboard: submitted_patch
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-04 03:43 EDT by Jörg Schömer CLA
Modified: 2022-06-09 10:07 EDT (History)
2 users (show)

See Also:


Attachments
Patch-File for 2.2.0 (1.45 KB, patch)
2012-07-31 03:57 EDT, Jörg Schömer CLA
david.minsky: iplog+
Details | Diff
Patch-File for 2.5.0-M1 (1.22 KB, patch)
2012-07-31 04:29 EDT, Jörg Schömer CLA
no flags Details | Diff
Patch for 2.5.0-M1 (1.45 KB, patch)
2012-07-31 04:33 EDT, Jörg Schömer CLA
david.minsky: iplog+
Details | Diff
Test Case for Java String.toUpperCase() (1.68 KB, text/plain)
2012-07-31 11:56 EDT, Jörg Schömer CLA
no flags Details
Java Test Case with all available locales (4.75 KB, application/octet-stream)
2012-07-31 13:51 EDT, Jörg Schömer CLA
no flags Details
Java Test Case with all available locales (4.61 KB, text/plain)
2012-08-07 13:40 EDT, Jörg Schömer CLA
no flags Details
Proposed / Potential fix (13.92 KB, patch)
2012-08-13 18:53 EDT, David Minsky CLA
no flags Details | Diff
Proposed / Potential fix & testcase (13.02 KB, patch)
2012-08-17 17:51 EDT, David Minsky CLA
no flags Details | Diff
Proposed fix & regression testcase (12.40 KB, patch)
2012-08-20 15:49 EDT, David Minsky CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jörg Schömer CLA 2012-07-04 03:43:56 EDT
In java toUpperCase("ß") results in "SS", e.g. oracle UPPER('ß') results in 'ß'.
The best way to get it working use lower instead of upper.

No Entities with a name containing an ß can be found.

current:

    /**
     * PUBLIC:
     * Return an expression that compares if the receivers value is like the other value, ignoring case.
     * This is a case in-sensitive like.
     * <p>Example:
     * <pre><blockquote>
     *     EclipseLink: employee.get("firstName").likeIgnoreCase("%Bob%")
     *     Java: none
     *     SQL: UPPER(F_NAME) LIKE '%BOB%'
     * </blockquote></pre>
     */
    public Expression likeIgnoreCase(String theValue) {
        return toUpperCase().like(theValue.toUpperCase());
    }

new:

    /**
     * PUBLIC:
     * Return an expression that compares if the receivers value is like the other value, ignoring case.
     * This is a case in-sensitive like.
     * <p>Example:
     * <pre><blockquote>
     *     EclipseLink: employee.get("firstName").likeIgnoreCase("%Bob%")
     *     Java: none
     *     SQL: LOWER(F_NAME) LIKE '%bob%'
     * </blockquote></pre>
     */
    public Expression likeIgnoreCase(String theValue) {
        return toLowerCase().like(theValue.toLowerCase());
    }
Comment 1 Jörg Schömer CLA 2012-07-04 03:57:21 EDT
oracle stands for "Oracle RDBMS 11g"
Comment 2 Jörg Schömer CLA 2012-07-04 04:28:07 EDT
the class Expression is located in org.eclipse.persistence.expressions
Comment 3 Jörg Schömer CLA 2012-07-04 04:35:52 EDT
the version 2.5.0 shows the same behavior
Comment 4 Jörg Schömer CLA 2012-07-31 03:57:42 EDT
Created attachment 219348 [details]
Patch-File for 2.2.0

replaced all toUpperCase by toLowerCase in methods with ignoreCase
Comment 5 Jörg Schömer CLA 2012-07-31 04:29:01 EDT
Created attachment 219349 [details]
Patch-File for 2.5.0-M1
Comment 6 Jörg Schömer CLA 2012-07-31 04:31:49 EDT
Comment on attachment 219349 [details]
Patch-File for 2.5.0-M1

Index: foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/expressions/Expression.java
===================================================================
--- foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/expressions/Expression.java	(revision 11856)
+++ foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/expressions/Expression.java	(working copy)
@@ -1519,7 +1519,7 @@
      * </blockquote></pre>
      */
     public Expression equalsIgnoreCase(String theValue) {
-        return toUpperCase().equal(theValue.toUpperCase());
+        return toLowerCase().equal(theValue.toLowerCase());
     }
 
     /**
@@ -1534,7 +1534,7 @@
      * </blockquote></pre>
      */
     public Expression equalsIgnoreCase(Expression theValue) {
-        return toUpperCase().equal(theValue.toUpperCase());
+        return toLowerCase().equal(theValue.toLowerCase());
     }
 
     /**
@@ -3009,7 +3009,7 @@
      * </blockquote></pre>
      */
     public Expression likeIgnoreCase(String theValue) {
-        return toUpperCase().like(theValue.toUpperCase());
+        return toLowerCase().like(theValue.toLowerCase());
     }
 
     /**
@@ -3018,7 +3018,7 @@
      * This is a case in-sensitive like.
      */
     public Expression likeIgnoreCase(Expression theValue) {
-        return toUpperCase().like(theValue.toUpperCase());
+        return toLowerCase().like(theValue.toLowerCase());
     }
 
     /**
Comment 7 Jörg Schömer CLA 2012-07-31 04:33:54 EDT
Created attachment 219350 [details]
Patch for 2.5.0-M1

based on root folder
Comment 8 Jörg Schömer CLA 2012-07-31 04:48:41 EDT
(In reply to comment #6)
> Comment on attachment 219349 [details]
> Patch-File for 2.5.0-M1
> 
> Index:
> foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/
> expressions/Expression.java
> ===================================================================
> ---
> foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/
> expressions/Expression.java	(revision 11856)
> +++
> foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/
> expressions/Expression.java	(working copy)
> @@ -1519,7 +1519,7 @@
>       * </blockquote></pre>
>       */
>      public Expression equalsIgnoreCase(String theValue) {
> -        return toUpperCase().equal(theValue.toUpperCase());
> +        return toLowerCase().equal(theValue.toLowerCase());
>      }
>  
>      /**
> @@ -1534,7 +1534,7 @@
>       * </blockquote></pre>
>       */
>      public Expression equalsIgnoreCase(Expression theValue) {
> -        return toUpperCase().equal(theValue.toUpperCase());
> +        return toLowerCase().equal(theValue.toLowerCase());
>      }
>  
>      /**
> @@ -3009,7 +3009,7 @@
>       * </blockquote></pre>
>       */
>      public Expression likeIgnoreCase(String theValue) {
> -        return toUpperCase().like(theValue.toUpperCase());
> +        return toLowerCase().like(theValue.toLowerCase());
>      }
>  
>      /**
> @@ -3018,7 +3018,7 @@
>       * This is a case in-sensitive like.
>       */
>      public Expression likeIgnoreCase(Expression theValue) {
> -        return toUpperCase().like(theValue.toUpperCase());
> +        return toLowerCase().like(theValue.toLowerCase());
>      }
>  
>      /**

oops, can be ignored
Comment 9 Tom Ware CLA 2012-07-31 08:11:32 EDT
We have discussed the option above.  The concern we have is that in other languages, toLowerCase will have the same issue as toUpperCase has for german.
Comment 10 Jörg Schömer CLA 2012-07-31 09:15:26 EDT
Can you please give an example of a language ​​in which there is a problem with toLowerCase. Just out of curiosity.
Comment 11 Tom Ware CLA 2012-07-31 09:40:00 EDT
I cannot give an example, I am simply pointing that possibility out as a risk and a reason we need to consider other possibilities for fixing this issue.
Comment 12 Jörg Schömer CLA 2012-07-31 10:46:57 EDT
Your message sounded so definite that I assumed you already had an example.
Comment 13 Jörg Schömer CLA 2012-07-31 11:56:12 EDT
Created attachment 219389 [details]
Test Case for Java String.toUpperCase()

a small Java test case to check which characters are converted to multi character strings
Comment 14 Jörg Schömer CLA 2012-07-31 13:51:44 EDT
Created attachment 219394 [details]
Java Test Case with all available locales

test each locale
Comment 15 Jörg Schömer CLA 2012-08-07 13:13:55 EDT
Hi Tom,

I've created two test cases in order to compare the shortcomings between toLowerCase and toUpperCase. 

The test case "with all available locales" print out a statistic sorted by the total number of mismatches (lowerCase + upperCase).
Most of the mismatches are observed in LT and TR.
Only these two locales have problems with toLowerCase, however, the UTF-8 byte sequence in LT is equal, strange ;-)

The toUpperCase method has a minimum of 75 problems.

Kind regards,
Jörg
Comment 16 Jörg Schömer CLA 2012-08-07 13:38:58 EDT
(In reply to comment #15)
> Hi Tom,
> 
> I've created two test cases in order to compare the shortcomings between
> toLowerCase and toUpperCase. 
> 
> The test case "with all available locales" print out a statistic sorted by
> the total number of mismatches (lowerCase + upperCase).
> Most of the mismatches are observed in LT and TR.
> Only these two locales have problems with toLowerCase, however, the UTF-8
> byte sequence in LT is equal, strange ;-)
> 
> The toUpperCase method has a minimum of 75 problems.
> 
> Kind regards,
> Jörg

I made ​​a mistake at the output, because I did not take into account the locale.
The utf-8 byte sequence differ in LT.
Comment 17 Jörg Schömer CLA 2012-08-07 13:40:29 EDT
Created attachment 219632 [details]
Java Test Case with all available locales

takes into account the locale
Comment 18 David Minsky CLA 2012-08-13 18:53:25 EDT
Created attachment 219834 [details]
Proposed / Potential fix

Fix uses a constant expression for String parameters in case-insensitive Expression methods. Constant expression is then passed to the corresponding method that takes an expression as a parameter. The database is left to perform case insensitive comparisons using UPPER().
Comment 19 David Minsky CLA 2012-08-17 17:51:26 EDT
Created attachment 220024 [details]
Proposed / Potential fix & testcase

The attached patch provides a way for the Expression methods to use the lower() SQL function instead of the upper() function, which is currently used. The current default case insensitive behavior remains unchanged, as the upper() function is still the default.

equalsIgnoreCase
likeIgnoreCase
containsSubstringIgnoringCase

The following static methods were added to Expression to control this setting:

void setUpperCaseForIgnoreCase(boolean)
boolean isUpperCaseForIgnoreCase()

Programmatically invoking org.eclipse.persistence.expressions.Expression.setUpperCaseForIgnoreCase(false) once will set this parameter globally for all expressions
Comment 20 David Minsky CLA 2012-08-20 15:49:22 EDT
Created attachment 220077 [details]
Proposed fix & regression testcase

Updated patch & testcase, taking into account some feedback.

Programmatically configure the use of lower() for Expression case insensitive operations on Expression using the following public static flag:

org.eclipse.persistence.expressions.Expression.shouldUseUpperCaseForIgnoreCase = false;

The default value is true (use upper() for case insensitive expression operations).
Comment 21 David Minsky CLA 2012-08-20 17:22:37 EDT
Checked into trunk (2.5)
SHA-1: e3433691240a250fdffbfbf3d6ca81f2d3da6872
Comment 22 David Minsky CLA 2012-08-31 15:27:26 EDT
Checked into 2.4 with hash: 2ccc0b110a142164ee221e1511f89b6d619477bd

http://git.eclipse.org/c/eclipselink/eclipselink.runtime.git/commit/?h=2.4&id=2ccc0b110a142164ee221e1511f89b6d619477bd
Comment 23 Eclipse Webmaster CLA 2022-06-09 10:07:49 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink