cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r737707 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ main/java/org/apache/cayenne/query/ test/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/query/
Date Mon, 26 Jan 2009 15:09:41 GMT
Author: aadamchik
Date: Mon Jan 26 15:09:41 2009
New Revision: 737707

URL: http://svn.apache.org/viewvc?rev=737707&view=rev
Log:
CAY-1047 Aligning query capabilities

procedureQueryTest.txt from Dima Loiko

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/ProcedureQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/ProcedureQueryTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java?rev=737707&r1=737706&r2=737707&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java
Mon Jan 26 15:09:41 2009
@@ -37,6 +37,7 @@
 import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.map.ProcedureParameter;
 import org.apache.cayenne.query.ProcedureQuery;
+import org.apache.cayenne.query.SQLTemplate;
 
 /**
  * A SQLAction that runs a stored procedure. Note that ProcedureAction has internal state
@@ -170,6 +171,16 @@
             ColumnDescriptor[] columns = descriptors.get(setIndex);
             builder.setColumns(columns);
         }
+        if (query.getColumnNamesCapitalization() != null) {
+            if (SQLTemplate.LOWERCASE_COLUMN_NAMES.equals(query
+                    .getColumnNamesCapitalization())) {
+                builder.useLowercaseColumnNames();
+            }
+            else if (SQLTemplate.UPPERCASE_COLUMN_NAMES.equals(query
+                    .getColumnNamesCapitalization())) {
+                builder.useUppercaseColumnNames();
+            }
+        }
         
         return builder.getDescriptor(getAdapter().getExtendedTypes());
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/ProcedureQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/ProcedureQuery.java?rev=737707&r1=737706&r2=737707&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/ProcedureQuery.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/ProcedureQuery.java
Mon Jan 26 15:09:41 2009
@@ -58,6 +58,17 @@
 public class ProcedureQuery extends AbstractQuery implements ParameterizedQuery,
         XMLSerializable {
 
+    static final String COLUMN_NAME_CAPITALIZATION_PROPERTY = "cayenne.ProcedureQuery.columnNameCapitalization";
+
+    /**
+     * @since 3.0
+     */
+    public static final String UPPERCASE_COLUMN_NAMES = "upper";
+
+    /**
+     * @since 3.0
+     */
+    public static final String LOWERCASE_COLUMN_NAMES = "lower";
     /**
      * @since 1.2
      */
@@ -67,6 +78,7 @@
      * @since 1.2
      */
     protected Class<?> resultClass;
+    protected String columnNamesCapitalization;
 
     protected Map<String, Object> parameters = new HashMap<String, Object>();
 
@@ -215,7 +227,12 @@
         if (properties == null) {
             properties = Collections.EMPTY_MAP;
         }
-
+        Object columnNamesCapitalization = properties
+                .get(COLUMN_NAME_CAPITALIZATION_PROPERTY);
+        this.columnNamesCapitalization = (columnNamesCapitalization != null)
+                ? columnNamesCapitalization.toString()
+                : null;
+                
         metaData.initWithProperties(properties);
     }
 
@@ -254,9 +271,14 @@
 
         encoder.println("\">");
         encoder.indent(1);
-
+        
         metaData.encodeAsXML(encoder);
-
+        if (getColumnNamesCapitalization() != null) {
+            encoder.printProperty(
+                    COLUMN_NAME_CAPITALIZATION_PROPERTY,
+                    getColumnNamesCapitalization());
+        }
+        
         encoder.indent(-1);
         encoder.println("</query>");
     }
@@ -502,4 +524,12 @@
     public void setResultEntityName(String resultEntityName) {
         this.resultEntityName = resultEntityName;
     }
+    
+    public String getColumnNamesCapitalization() {
+        return columnNamesCapitalization;
+    }
+    
+    public void setColumnNamesCapitalization(String columnNameCapitalization) {
+        this.columnNamesCapitalization = columnNameCapitalization;
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java?rev=737707&r1=737706&r2=737707&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java
Mon Jan 26 15:09:41 2009
@@ -258,6 +258,32 @@
         assertEquals(1, artists.size());
     }
 
+    public void testColumnNameCapitalization() throws Exception{
+        if (!getAccessStackAdapter().supportsStoredProcedures()) {
+            return;
+        }
+        
+        // create an artist with painting in the database
+        createArtist(1000.0);
+        ProcedureQuery q = new ProcedureQuery(SELECT_STORED_PROCEDURE);
+        
+        q.setColumnNamesCapitalization(ProcedureQuery.LOWERCASE_COLUMN_NAMES);
+        q.addParameter("aName", "An Artist");
+        List<DataRow> artists = runProcedureSelect(q);
+        
+        ProcedureQuery q1 = new ProcedureQuery(SELECT_STORED_PROCEDURE);
+        
+        q1.setColumnNamesCapitalization(ProcedureQuery.UPPERCASE_COLUMN_NAMES);
+        q1.addParameter("aName", "An Artist");
+        List<DataRow> artists1 = runProcedureSelect(q1);
+        
+        assertTrue(artists.get(0).containsKey("date_of_birth"));
+        assertFalse(artists.get(0).containsKey("DATE_OF_BIRTH"));
+        
+        assertFalse(artists1.get(0).containsKey("date_of_birth"));
+        assertTrue(artists1.get(0).containsKey("DATE_OF_BIRTH"));
+        
+    }
 
     public void testOutParams() throws Exception {
         if (!getAccessStackAdapter().supportsStoredProcedures()) {
@@ -310,7 +336,7 @@
     }
 
     public void testSelectWithRowDescriptor() throws Exception {
-        // Don't run this on MySQL
+
         if (!getAccessStackAdapter().supportsStoredProcedures()) {
             return;
         }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/ProcedureQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/ProcedureQueryTest.java?rev=737707&r1=737706&r2=737707&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/ProcedureQueryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/ProcedureQueryTest.java
Mon Jan 26 15:09:41 2009
@@ -38,6 +38,13 @@
         assertNotSame(template, clone);
     }
 
+    public void testColumnNameCapitalization() {
+        ProcedureQuery q1 = new ProcedureQuery();
+        assertNull(q1.getColumnNamesCapitalization());
+        q1.setColumnNamesCapitalization(ProcedureQuery.UPPERCASE_COLUMN_NAMES);
+        assertEquals(ProcedureQuery.UPPERCASE_COLUMN_NAMES, q1.getColumnNamesCapitalization());
+    }
+    
     public void testCreateQueryWithParameters() {
         Map params = new HashMap();
         params.put("a", "1");



Mime
View raw message