openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r577066 - in /openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql: DB2Dictionary.java DBDictionary.java LogicalUnion.java Select.java SelectImpl.java
Date Tue, 18 Sep 2007 21:05:01 GMT
Author: mikedd
Date: Tue Sep 18 14:05:00 2007
New Revision: 577066

URL: http://svn.apache.org/viewvc?rev=577066&view=rev
Log:
OPENJPA-356 in 1.0.x committing Patrick's changes originally done in rev 573676

Modified:
    openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
    openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
    openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java
    openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java

Modified: openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java?rev=577066&r1=577065&r2=577066&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
(original)
+++ openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Tue Sep 18 14:05:00 2007
@@ -155,6 +155,33 @@
             append(" ROWS ONLY");
     }
 
+    protected void appendSelect(SQLBuffer selectSQL, Object alias, Select sel,
+        int idx) {
+        // if this is a literal value, add a cast...
+        Object val = sel.getSelects().get(idx);
+        if (val instanceof Lit)
+            selectSQL.append("CAST(");
+
+        // ... and add the select per super's behavior...
+        super.appendSelect(selectSQL, alias, sel, idx);
+
+        // ... and finish the cast
+        if (val instanceof Lit) {
+            Class c = ((Lit) val).getType();
+            int javaTypeCode = JavaTypes.getTypeCode(c);
+            int jdbcTypeCode = getJDBCType(javaTypeCode, false);
+            String typeName = getTypeName(jdbcTypeCode);
+            selectSQL.append(" AS " + typeName);
+
+            // if the literal is a string, use the default char col size
+            // in the cast statement.
+            if (String.class.equals(c))
+                selectSQL.append("(" + characterColumnSize + ")");
+
+            selectSQL.append(")");
+        }
+    }
+
     public String[] getCreateSequenceSQL(Sequence seq) {
         String[] sql = super.getCreateSequenceSQL(seq);
         if (seq.getAllocate() > 1)
@@ -645,7 +672,9 @@
     public String addCastAsType(String func, Val val) {
         String fstring = null;
         String type = getTypeName(getJDBCType(JavaTypes.getTypeCode(val
-                .getType()), false));
+            .getType()), false));
+        if (String.class.equals(val.getType()))
+            type = type + "(" + characterColumnSize + ")";
         fstring = "CAST(? AS " + type + ")";
         return fstring;
     }
@@ -730,7 +759,10 @@
             String sqlString = buf.getSQL(false);
             if (sqlString.endsWith("?")) {
                 // case "(?" - convert to "CAST(? AS type"
-                String str = "CAST(? AS " + getTypeName(type) + ")";
+                String typeName = getTypeName(type);
+                if (String.class.equals(val.getType()))
+                    typeName = typeName + "(" + characterColumnSize + ")";
+                String str = "CAST(? AS " + typeName + ")";
                 buf.replaceSqlString(sqlString.length() - 1,
                         sqlString.length(), str);
             }

Modified: openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=577066&r1=577065&r2=577066&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Tue Sep 18 14:05:00 2007
@@ -2281,16 +2281,28 @@
             aliases = sel.getSelectAliases();
 
         Object alias;
-        for (Iterator itr = aliases.iterator(); itr.hasNext();) {
-            alias = itr.next();
-            if (alias instanceof SQLBuffer)
-                selectSQL.append((SQLBuffer) alias);
-            else
-                selectSQL.append(alias.toString());
-            if (itr.hasNext())
+        for (int i = 0; i < aliases.size(); i++) {
+            alias = aliases.get(i);
+            appendSelect(selectSQL, alias, sel, i);
+            if (i < aliases.size() - 1)
                 selectSQL.append(", ");
         }
         return selectSQL;
+    }
+
+    /**
+     * Append <code>elem</code> to <code>selectSQL</code>.
+     * @param selectSQL The SQLBuffer to append to.
+     * @param alias A {@link SQLBuffer} or a {@link String} to append.
+     *
+     * @since 1.1.0
+     */
+    protected void appendSelect(SQLBuffer selectSQL, Object elem, Select sel,
+        int idx) {
+        if (elem instanceof SQLBuffer)
+            selectSQL.append((SQLBuffer) elem);
+        else
+            selectSQL.append(elem.toString());
     }
 
     /**

Modified: openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java?rev=577066&r1=577065&r2=577066&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
(original)
+++ openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
Tue Sep 18 14:05:00 2007
@@ -447,6 +447,10 @@
             return sel.getTableAliases();
         }
 
+        public List getSelects() {
+            return sel.getSelects();
+        }
+
         public List getSelectAliases() {
             return sel.getSelectAliases();
         }

Modified: openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java?rev=577066&r1=577065&r2=577066&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java
(original)
+++ openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java
Tue Sep 18 14:05:00 2007
@@ -150,6 +150,14 @@
     public Collection getTableAliases();
 
     /**
+     * Return the actual {@link Val}s and {@link Column}s that were
+     * selected, in the order that they were selected.
+     *
+     * @since 1.1.0
+     */
+    public List getSelects();
+
+    /**
      * Return the aliases of all selected columns and all selected buffers,
      * in the order they were selected. Each alias may be either a string
      * or a {@link SQLBuffer}.

Modified: openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=577066&r1=577065&r2=577066&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
(original)
+++ openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
Tue Sep 18 14:05:00 2007
@@ -505,6 +505,10 @@
         return (_tables == null) ? Collections.EMPTY_SET : _tables.values();
     }
 
+    public List getSelects() {
+        return Collections.unmodifiableList(_selects);
+    }
+
     public List getSelectAliases() {
         return _selects.getAliases(false, _outer != null);
     }



Mime
View raw message