cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r490286 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/access/jdbc/ main/java/org/apache/cayenne/dba/db2/ test/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/access/jdbc/ test/java/org...
Date Tue, 26 Dec 2006 11:51:05 GMT
Author: aadamchik
Date: Tue Dec 26 03:51:04 2006
New Revision: 490286

URL: http://svn.apache.org/viewvc?view=rev&rev=490286
Log:
CAY-726: SQLTemplate parsing bug when macros appear at the end of line
(fix for trunk)

Removed:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/db2/DB2ActionBuilder.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/dba/db2/
Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java?view=diff&rev=490286&r1=490285&r2=490286
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
Tue Dec 26 03:51:04 2006
@@ -17,7 +17,6 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.access.jdbc;
 
 import java.sql.Connection;
@@ -52,7 +51,6 @@
 public class SQLTemplateAction implements SQLAction {
 
     protected DbAdapter adapter;
-    protected boolean removingLineBreaks;
     protected SQLTemplate query;
 
     public SQLTemplateAction(SQLTemplate query, DbAdapter adapter) {
@@ -237,7 +235,10 @@
      */
     protected String extractTemplateString() {
         String sql = query.getTemplate(getAdapter().getClass().getName());
-        return isRemovingLineBreaks() ? Util.stripLineBreaks(sql, " ") : sql;
+
+        // note that we MUST convert line breaks to spaces. On some databases (DB2)
+        // queries with breaks simply won't run; the rest are affected by CAY-726.
+        return Util.stripLineBreaks(sql, " ");
     }
 
     /**
@@ -260,15 +261,19 @@
     }
 
     /**
-     * Returns whether line breaks are removed when the query is executed. Some databases
-     * (like DB2) can't handle multiline queries.
+     * Always returns true.
+     * 
+     * @deprecated since 3.0
      */
     public boolean isRemovingLineBreaks() {
-        return removingLineBreaks;
+        return true;
     }
 
+    /**
+     * @deprecated since 3.0 - does nothing
+     */
     public void setRemovingLineBreaks(boolean removingLineBreaks) {
-        this.removingLineBreaks = removingLineBreaks;
+
     }
 
     /**

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java?view=diff&rev=490286&r1=490285&r2=490286
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
Tue Dec 26 03:51:04 2006
@@ -17,14 +17,12 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.dba.db2;
 
 import java.sql.PreparedStatement;
 import java.util.Iterator;
 
 import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.trans.QualifierTranslator;
 import org.apache.cayenne.access.trans.QueryAssembler;
 import org.apache.cayenne.access.types.BooleanType;
@@ -37,8 +35,6 @@
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DerivedDbEntity;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.SQLAction;
 
 /**
  * DbAdapter implementation for the <a href="http://www.ibm.com/db2/"> DB2 RDBMS </a>.
@@ -47,13 +43,13 @@
  * use with DB2 are shown below:
  * 
  * <pre>
- * 
- *      test-db2.cayenne.adapter = org.apache.cayenne.dba.db2.DB2Adapter
- *      test-db2.jdbc.username = test
- *      test-db2.jdbc.password = secret
- *      test-db2.jdbc.url = jdbc:db2://servername:50000/databasename
- *      test-db2.jdbc.driver = com.ibm.db2.jcc.DB2Driver
  *  
+ *       test-db2.cayenne.adapter = org.apache.cayenne.dba.db2.DB2Adapter
+ *       test-db2.jdbc.username = test
+ *       test-db2.jdbc.password = secret
+ *       test-db2.jdbc.url = jdbc:db2://servername:50000/databasename
+ *       test-db2.jdbc.driver = com.ibm.db2.jcc.DB2Driver
+ *   
  * </pre>
  * 
  * @author Holger Hoffstaette
@@ -61,15 +57,6 @@
 public class DB2Adapter extends JdbcAdapter {
 
     /**
-     * Uses DB2ActionBuilder to create the right action.
-     * 
-     * @since 1.2
-     */
-    public SQLAction getAction(Query query, DataNode node) {
-        return query.createSQLAction(new DB2ActionBuilder(this, node.getEntityResolver()));
-    }
-
-    /**
      * Creates a DB2 specific PK Generator.
      */
     protected PkGenerator createPkGenerator() {
@@ -84,7 +71,7 @@
 
         // configure boolean type to work with numeric columns
         map.registerType(new DB2BooleanType());
-        
+
         map.registerType(new ByteArrayType(false, false));
     }
 

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java?view=diff&rev=490286&r1=490285&r2=490286
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java
Tue Dec 26 03:51:04 2006
@@ -159,4 +159,21 @@
             it.close();
         }
     }
+
+    public void testQueryWithLineBreakAfterMacroCAY726() throws Exception {
+        getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
+
+        // see CAY-726 for details
+        String template = "SELECT #result('count(*)' 'int' 'X')"
+                + System.getProperty("line.separator")
+                + "FROM ARTIST";
+        SQLTemplate query = getSQLTemplateBuilder().createSQLTemplate(
+                Artist.class,
+                template);
+        query.setFetchingDataRows(true);
+
+        List result = context.performQuery(query);
+
+        assertEquals(new Integer(25), ((Map) result.get(0)).get("X"));
+    }
 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java?view=diff&rev=490286&r1=490285&r2=490286
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java
Tue Dec 26 03:51:04 2006
@@ -329,10 +329,6 @@
                 template,
                 getAccessStackAdapter().getAdapter());
 
-        action.setRemovingLineBreaks(false);
-        assertEquals("A\nBC", action.extractTemplateString());
-
-        action.setRemovingLineBreaks(true);
         assertEquals("A BC", action.extractTemplateString());
     }
 



Mime
View raw message