You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2009/10/30 16:56:28 UTC

svn commit: r831355 - in /cayenne/main/branches/STABLE-3.0: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/

Author: aadamchik
Date: Fri Oct 30 15:56:28 2009
New Revision: 831355

URL: http://svn.apache.org/viewvc?rev=831355&view=rev
Log:
CAY-1067 likeIgnoreCase is not supported for CLOBs in MS SQL adapter

a test case reproducing the issue and a fix... Looks like the original fix worked,
but adding support for quoted identifiers broke some of the logic
(cherry picked from commit 91a4d7ece8b9534e118cc2f76e4deb13a39c378b)

Modified:
    cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerTrimmingQualifierTranslator.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java

Modified: cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=831355&r1=831354&r2=831355&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt Fri Oct 30 15:56:28 2009
@@ -13,6 +13,7 @@
 ----------------------------------
 Bug Fixes Since B1:
 
+CAY-1067 likeIgnoreCase is not supported for CLOBs in MS SQL adapter
 CAY-1292 Modeler does not allow to unset/change entity inheritance
 
 ----------------------------------

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerTrimmingQualifierTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerTrimmingQualifierTranslator.java?rev=831355&r1=831354&r2=831355&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerTrimmingQualifierTranslator.java (original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerTrimmingQualifierTranslator.java Fri Oct 30 15:56:28 2009
@@ -80,6 +80,35 @@
             }
         }
     }
+    
+    @Override
+    protected void processColumnWithQuoteSqlIdentifiers(DbAttribute dbAttr) throws IOException {
+        Expression node = peek(1);
+
+        boolean likeCI = node != null
+                && dbAttr.getType() == Types.CLOB
+                && (node.getType() == Expression.LIKE_IGNORE_CASE || node.getType() == Expression.NOT_LIKE_IGNORE_CASE);
+
+        if (likeCI) {
+            try {
+                out.append("CAST(");
+            }
+            catch (IOException ioex) {
+                throw new CayenneRuntimeException("Error appending content", ioex);
+            }
+        }
+
+        super.processColumnWithQuoteSqlIdentifiers(dbAttr);
+
+        if (likeCI) {
+            try {
+                out.append(" AS NVARCHAR(MAX))");
+            }
+            catch (IOException ioex) {
+                throw new CayenneRuntimeException("Error appending content", ioex);
+            }
+        }
+    }
 
     @Override
     public void endNode(Expression node, Expression parentNode) {

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java?rev=831355&r1=831354&r2=831355&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java (original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java Fri Oct 30 15:56:28 2009
@@ -23,10 +23,10 @@
 import java.sql.PreparedStatement;
 import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.art.Artist;
 import org.apache.art.ArtistExhibit;
+import org.apache.art.ClobTestEntity;
 import org.apache.art.Exhibit;
 import org.apache.art.Gallery;
 import org.apache.art.Painting;
@@ -41,6 +41,7 @@
 public class SelectQueryTest extends SelectQueryBase {
 
     private static final int _artistCount = 20;
+    private static final int _clobCount = 2;
 
     public void testFetchLimit() throws Exception {
         query.setRoot(Artist.class);
@@ -234,7 +235,7 @@
         assertNotNull(objects);
         assertEquals(_artistCount, objects.size());
     }
-
+    
     /** Test how "like ignore case" works when using lowercase parameter. */
     public void testSelectLikeIgnoreCaseObjects2() throws Exception {
         query.setRoot(Artist.class);
@@ -247,6 +248,22 @@
         assertNotNull(objects);
         assertEquals(_artistCount, objects.size());
     }
+    
+    /** Test how "like ignore case" works when using uppercase parameter. */
+    public void testSelectLikeIgnoreCaseClob() throws Exception {
+        
+        
+        query.setRoot(ClobTestEntity.class);
+        Expression qual = ExpressionFactory.likeIgnoreCaseExp("clobCol", "clob%");
+        query.setQualifier(qual);
+        performQuery();
+
+        // check query results
+        List objects = opObserver.rowsForQuery(query);
+        assertNotNull(objects);
+        assertEquals(_clobCount, objects.size());
+    }
+
 
     public void testSelectIn() throws Exception {
         query.setRoot(Artist.class);
@@ -498,5 +515,28 @@
         finally {
             conn.close();
         }
+        
+        String insertClob = "INSERT INTO CLOB_TEST (CLOB_TEST_ID, CLOB_COL) VALUES (?,?)";
+        Connection connection = getConnection();
+
+        try {
+            connection.setAutoCommit(false);
+
+          
+            PreparedStatement stmt = connection.prepareStatement(insertClob);
+            long dateBase = System.currentTimeMillis();
+
+            for (int i = 1; i <= _clobCount; i++) {
+                stmt.setInt(1, i);
+                stmt.setString(2, "clob" + i);
+                stmt.executeUpdate();
+            }
+
+            stmt.close();
+            connection.commit();
+        }
+        finally {
+            connection.close();
+        }
     }
 }