openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1342097 - in /openjpa/branches/2.2.x: 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...
Date Thu, 24 May 2012 00:03:47 GMT
Author: hthomann
Date: Thu May 24 00:03:46 2012
New Revision: 1342097

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

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

Modified: openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MappedQueryResultObjectProvider.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MappedQueryResultObjectProvider.java?rev=1342097&r1=1342096&r2=1342097&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MappedQueryResultObjectProvider.java
(original)
+++ openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MappedQueryResultObjectProvider.java
Thu May 24 00:03:46 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/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java?rev=1342097&r1=1342096&r2=1342097&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java
(original)
+++ openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java
Thu May 24 00:03:46 2012
@@ -508,7 +508,8 @@ public class ResultSetResult
           DBIdentifier sName = DBIdentifier.newColumn(obj.toString());
           return getResultSet().findColumn(_dict.convertSchemaCase(sName));
         } catch (SQLException se) {
-            return 0;
+            _dict.log.trace(se.getMessage());
+        	return 0;
         }
     }
   

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/ShipRate.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/ShipRate.java?rev=1342097&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/ShipRate.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/ShipRate.java
Thu May 24 00:03:46 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/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/ShipRate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/results/TestResultSetMapping.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/results/TestResultSetMapping.java?rev=1342097&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/results/TestResultSetMapping.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/results/TestResultSetMapping.java
Thu May 24 00:03:46 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/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/results/TestResultSetMapping.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message