db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Eade <se...@backstagetech.com.au>
Subject Re: Torque: Criteria and NOT_LIKE
Date Sat, 19 Jun 2004 04:32:31 GMT
Thanks for the patch Clemens.  Including test cases makes things much 
easier for everyone.

Scott

-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au


Clemens Fuchslocher wrote:

>Scott Eade wrote:
>
>[...]
>  
>
>>One think you could do that would be of a great help would be to add to
>>the Torque runtime test suite some tests that illustrate this problem -
>>if you don't do it then I will have to and that will slow me down
>>further.  I really welcome your help and contribution and I hope to be
>>able to get to it very soon.
>>    
>>
>
>I have added two new test cases to org.apache.torque.util.CriteriaTest:
>
>testLikeWithoutWildcards()
>    This test case verifies if the Criteria.LIKE comparison type will get
>    replaced through Criteria.EQUAL if there are no SQL wildcards in the
>    given string. This is already working properly. No work is needed. :-)
>
>testNotLikeWithoutWildcards()
>    This test case verifies if the Criteria.NOT_LIKE comparison type will
>    get replaced through Criteria.NOT_EQUAL if there are no SQL wildcards
>    in the given string. This test case fails because the NOT_LIKE operator
>    is also replaced through EQUAL in the buildLike() method instead of
>    NOT_LIKE.
>
>See the attached CriteriaTest.java.patch file.
>
>Finally the attached SqlExpression.java.patch file contains a patch which
>will correct the behavior of the buildLike() method. Now the method will
>also doing the correct thing when handling with NOT_LIKE instead of LIKE.
>
>Have a nice weekend!
>  
>
>------------------------------------------------------------------------
>
>Index: SqlExpression.java
>===================================================================
>RCS file: /home/cvspublic/db-torque/src/java/org/apache/torque/util/SqlExpression.java,v
>retrieving revision 1.26
>diff -u -r1.26 SqlExpression.java
>--- SqlExpression.java	22 Feb 2004 06:16:35 -0000	1.26
>+++ SqlExpression.java	21 May 2004 11:49:37 -0000
>@@ -381,6 +381,11 @@
>         // use = (equals).  Wildcards can be escaped by prepending
>         // them with \ (backslash).
>         String equalsOrLike = " = ";
>+        if (comparison.equals (Criteria.NOT_LIKE))
>+        {
>+            equalsOrLike = " " + Criteria.NOT_EQUAL + " ";
>+        }
>+
>         int position = 0;
>         StringBuffer sb = new StringBuffer();
>         while (position < criteria.length())
>  
>
>------------------------------------------------------------------------
>
>Index: CriteriaTest.java
>===================================================================
>RCS file: /home/cvspublic/db-torque/src/test/org/apache/torque/util/CriteriaTest.java,v
>retrieving revision 1.21
>diff -u -r1.21 CriteriaTest.java
>--- CriteriaTest.java	22 Feb 2004 06:22:27 -0000	1.21
>+++ CriteriaTest.java	21 May 2004 11:47:20 -0000
>@@ -431,6 +431,59 @@
>     }
> 
>     /**
>+     * This test case verifies if the Criteria.LIKE comparison type will
>+     * get replaced through Criteria.EQUAL if there are no SQL wildcards
>+     * in the given value.
>+     */
>+    public void testLikeWithoutWildcards()
>+    {
>+        Criteria c = new Criteria()
>+                .add("TABLE.COLUMN", (Object) "no wildcards", Criteria.LIKE);
>+
>+        String expect = "SELECT  FROM TABLE WHERE TABLE.COLUMN = 'no wildcards'";
>+
>+        String result = null;
>+        try
>+        {
>+            result = BasePeer.createQueryString(c);
>+        }
>+        catch (TorqueException e)
>+        {
>+            e.printStackTrace();
>+            fail("TorqueException thrown in BasePeer.createQueryString()");
>+        }
>+
>+        assertEquals(expect, result);
>+    }
>+
>+    /**
>+     * This test case verifies if the Criteria.NOT_LIKE comparison type will
>+     * get replaced through Criteria.NOT_EQUAL if there are no SQL wildcards
>+     * in the given value.
>+     */
>+    public void testNotLikeWithoutWildcards()
>+    {
>+        Criteria c = new Criteria()
>+                .add("TABLE.COLUMN", (Object) "no wildcards", Criteria.NOT_LIKE);
>+
>+        String firstExpect = "SELECT  FROM TABLE WHERE TABLE.COLUMN != 'no wildcards'";
>+        String secondExpect = "SELECT  FROM TABLE WHERE TABLE.COLUMN <> 'no wildcards'";
>+
>+        String result = null;
>+        try
>+        {
>+            result = BasePeer.createQueryString(c);
>+        }
>+        catch (TorqueException e)
>+        {
>+            e.printStackTrace();
>+            fail("TorqueException thrown in BasePeer.createQueryString()");
>+        }
>+
>+        assertTrue(result.equals(firstExpect) || result.equals(secondExpect));
>+    }
>+
>+    /**
>      * test for TRQS25
>      */
> /*
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message