openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1533233 - in /openjpa/branches/2.1.x: ./ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/joi...
Date Thu, 17 Oct 2013 19:56:08 GMT
Author: hthomann
Date: Thu Oct 17 19:56:08 2013
New Revision: 1533233

URL: http://svn.apache.org/r1533233
Log:
OPENJPA-1954: ArrayIndexOutOfBoundsException when querying on a version field that is in a
MappedSuperclass - back ported to 2.1.x Rick Curtis's commit to trunk.

Added:
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java
      - copied, changed from r1076370, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java
Modified:
    openjpa/branches/2.1.x/   (props changed)
    openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
    openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/
  (props changed)
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TestTimestampVersion.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TimestampedEntity.java

Propchange: openjpa/branches/2.1.x/
------------------------------------------------------------------------------
  Merged /openjpa/trunk:r1076370,1076388

Modified: openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java?rev=1533233&r1=1533232&r2=1533233&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
(original)
+++ openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
Thu Oct 17 19:56:08 2013
@@ -1075,9 +1075,14 @@ public class FieldMapping
         // version, it will have a NoneFieldMapping (since the version strategy
         // for the class takes care of it's mapping), and NoneFieldStrategies
         // do not have columns.
-        if (isVersion())
-            return getDeclaringMapping().getVersion().getColumns();
-        else
+        //
+        // rgc : 2 March 2011 : Still hacky. If the version field is in a mapped super class
we need to look
+        // at the defining metadata to find the correct Version. Not sure why the version
for the declaring metadata
+        // is different than the defining metadata.
+        if (isVersion()){
+            ClassMapping cm = (ClassMapping)((FieldMetaData)this).getDefiningMetaData();
+            return cm.getVersion().getColumns();
+        }else
             return _val.getColumns();
     }
 

Modified: openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1533233&r1=1533232&r2=1533233&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Thu Oct 17 19:56:08 2013
@@ -2189,7 +2189,8 @@ public class DBDictionary
         if (augmentUpdates) {
             Path path = (Path) updateParams.keySet().iterator().next();
             FieldMapping fm = (FieldMapping) path.last();
-            ClassMapping meta = fm.getDeclaringMapping();
+            
+            ClassMapping meta = fm.getDefiningMapping();
             Map<Column,?> updates = meta.getVersion().getBulkUpdateValues();
             for (Map.Entry e : updates.entrySet()) {
                 Column col = (Column) e.getKey();

Propchange: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/
------------------------------------------------------------------------------
  Merged /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany:r1076370,1076388

Copied: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java
(from r1076370, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java)
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java?p2=openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java&p1=openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java&r1=1076370&r2=1533233&rev=1533233&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java
Thu Oct 17 19:56:08 2013
@@ -1,3 +1,21 @@
+/*
+ * 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.jdbc.update;
 
 import java.sql.Timestamp;

Modified: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TestTimestampVersion.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TestTimestampVersion.java?rev=1533233&r1=1533232&r2=1533233&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TestTimestampVersion.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TestTimestampVersion.java
Thu Oct 17 19:56:08 2013
@@ -19,9 +19,15 @@
 package org.apache.openjpa.persistence.jdbc.update;
 
 import java.sql.Timestamp;
+import java.util.Date;
+import java.util.List;
 
 import javax.persistence.EntityManager;
+import javax.persistence.Query;
 
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.Version;
+import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
@@ -34,7 +40,15 @@ import org.apache.openjpa.persistence.te
  */
 public class TestTimestampVersion extends SingleEMFTestCase {
 	public void setUp() {
-		super.setUp(CLEAR_TABLES, TimestampedEntity.class, NumericVersionedEntity.class);
+        super.setUp(CLEAR_TABLES, TimestampedEntity.class, NumericVersionedEntity.class,
BaseTimestampedEntity.class);
+    }
+	public void testQueryOnVersion() {
+	    EntityManager em = emf.createEntityManager();
+	    String pql = "SELECT s FROM TimestampedEntity s WHERE s.version < :endDate";
+        Query queryObj = em.createQuery(pql);
+        Timestamp t1 = new Timestamp((new Date()).getTime());
+        queryObj.setParameter("endDate", t1);
+        List<TimestampedEntity> scenarioList = queryObj.getResultList();
 	}
 
     public void testBulkUpdateOnTimestampedVersion() {
@@ -47,7 +61,7 @@ public class TestTimestampVersion extend
         
         try {
             // delay to ensure the new timestamp exceeds the timer's resolution.
-            Thread.sleep(1000);
+            Thread.sleep(1500);
         } catch (InterruptedException e) {
         }
 

Modified: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TimestampedEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TimestampedEntity.java?rev=1533233&r1=1533232&r2=1533233&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TimestampedEntity.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TimestampedEntity.java
Thu Oct 17 19:56:08 2013
@@ -18,13 +18,8 @@
  */
 package org.apache.openjpa.persistence.jdbc.update;
 
-import java.sql.Timestamp;
-
 import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
 import javax.persistence.Table;
-import javax.persistence.Version;
 
 /**
  * An entity using a Timestamp as Version field.
@@ -35,31 +30,7 @@ import javax.persistence.Version;
  */
 @Entity
 @Table(name="TSENTITY1")
-public class TimestampedEntity {
-	@Id
-	@GeneratedValue
-	private long id;
-	
-	private String name;
-	
-	@Version
-	private Timestamp version;
-	
-
-	public long getId() {
-		return id;
-	}
-
-	public String getName() {
-		return name;
-	}
+public class TimestampedEntity extends BaseTimestampedEntity{
 
-	public void setName(String name) {
-		this.name = name;
-	}
-	
-	public Timestamp getVersion() {
-	    return version;
-	}
 
 }



Mime
View raw message