You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by ht...@apache.org on 2012/05/31 15:39:53 UTC

svn commit: r1344721 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/ openjpa...

Author: hthomann
Date: Thu May 31 13:39:52 2012
New Revision: 1344721

URL: http://svn.apache.org/viewvc?rev=1344721&view=rev
Log:
OPENJPA-2174: Applied Helen Xu's patch to trunk

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/ShipRate.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/results/TestResultSetMapping.java   (with props)
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MappedQueryResultObjectProvider.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MappedQueryResultObjectProvider.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MappedQueryResultObjectProvider.java?rev=1344721&r1=1344720&r2=1344721&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MappedQueryResultObjectProvider.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MappedQueryResultObjectProvider.java Thu May 31 13:39:52 2012
@@ -35,6 +35,7 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Stack;
 
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.meta.FieldMapping;
 import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
@@ -407,8 +408,16 @@ class MappedQueryResultObjectProvider
         protected Object getObjectInternal(Object obj, int metaTypeCode,
             Object arg, Joins joins)
             throws SQLException {
-            if (obj instanceof Column)
-                return _res.getObject((Column) obj, arg, joins);
+            if (obj instanceof Column){
+                Column col = (Column) obj;
+                Object resultCol = _pc.getMapping(col.toString());
+                if (resultCol != null) {
+                    int javaType = col.getJavaType();
+                    col = new Column(DBIdentifier.newColumn(resultCol.toString()), col.getTable());
+                    col.setJavaType(javaType);                    
+                }
+                return _res.getObject(col, arg, joins);
+            }                
             return _res.getObject(obj, metaTypeCode, arg);
         }
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java?rev=1344721&r1=1344720&r2=1344721&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java Thu May 31 13:39:52 2012
@@ -508,6 +508,7 @@ public class ResultSetResult
           DBIdentifier sName = DBIdentifier.newColumn(obj.toString());
           return getResultSet().findColumn(_dict.convertSchemaCase(sName));
         } catch (SQLException se) {
+            _dict.log.trace(se.getMessage());
             return 0;
         }
     }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/ShipRate.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/ShipRate.java?rev=1344721&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/ShipRate.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/ShipRate.java Thu May 31 13:39:52 2012
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.openjpa.persistence.criteria.results;
+
+import java.math.BigDecimal;
+
+import javax.persistence.*;
+
+@Entity
+@SqlResultSetMapping(name="selectShipRateMapping", 
+    entities=@EntityResult(entityClass=org.apache.openjpa.persistence.criteria.results.ShipRate.class,
+                           fields = {@FieldResult(name="shipRateId", column = "id"),  
+                            @FieldResult(name="billedAsWeight", column = "RBLWGT")}) )
+//Try to create a result set with different column name 
+//than the attribute name defined in the result entity
+@NamedNativeQuery(name = "selectShipRateQuery", 
+query = "SELECT shipRateId as id, billedAsWeight as RBLWGT from ShipRate", 
+resultSetMapping="selectShipRateMapping")
+public class ShipRate {    
+    @Id
+    long shipRateId;
+    
+    public ShipRate(long shipRateId, BigDecimal billedAsWeight) {
+        super();
+        this.shipRateId = shipRateId;
+        this.billedAsWeight = billedAsWeight;
+    }
+
+    private BigDecimal billedAsWeight;
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/ShipRate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/results/TestResultSetMapping.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/results/TestResultSetMapping.java?rev=1344721&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/results/TestResultSetMapping.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/results/TestResultSetMapping.java Thu May 31 13:39:52 2012
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.openjpa.persistence.query.results;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+
+import org.apache.openjpa.persistence.criteria.results.ShipRate;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+public class TestResultSetMapping extends SQLListenerTestCase{
+    
+    public void setUp() {
+        setUp(CLEAR_TABLES, ShipRate.class);        
+    }
+
+    public void testQuery () {
+        EntityManager em = emf.createEntityManager();         
+        try 
+        {
+            EntityTransaction tx = em.getTransaction();
+            tx.begin();
+            ShipRate rate = new ShipRate(1000, new BigDecimal(20.5));
+            em.persist(rate);
+            tx.commit();
+            em.close();
+            
+            em = emf.createEntityManager(); 
+            //Query query = em.createNativeQuery(sqlStatement, "ShipRateMapping");
+            Query query = em.createNamedQuery("selectShipRateQuery");
+            
+            List<ShipRate> results = (List<ShipRate>)query.getResultList();    
+            assertEquals(1, results.size());
+        } 
+        catch(RuntimeException x)
+        {
+            x.printStackTrace();
+            throw x;
+        }
+        finally 
+        {
+            em.close();
+        }
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/results/TestResultSetMapping.java
------------------------------------------------------------------------------
    svn:eol-style = native