openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1076370 - in /openjpa/trunk: 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/jdbc/update/
Date Wed, 02 Mar 2011 20:57:03 GMT
Author: curtisr7
Date: Wed Mar  2 20:57:03 2011
New Revision: 1076370

URL: http://svn.apache.org/viewvc?rev=1076370&view=rev
Log:
OPENJPA-1954: Fix ArrayIndexOutOfBoundsException when querying on a version field that is
in a MappedSuperclass.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java
  (with props)
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TestTimestampVersion.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TimestampedEntity.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java?rev=1076370&r1=1076369&r2=1076370&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
Wed Mar  2 20:57:03 2011
@@ -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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1076370&r1=1076369&r2=1076370&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Wed Mar  2 20:57:03 2011
@@ -2140,7 +2140,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();

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java?rev=1076370&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java
Wed Mar  2 20:57:03 2011
@@ -0,0 +1,37 @@
+package org.apache.openjpa.persistence.jdbc.update;
+
+import java.sql.Timestamp;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+import javax.persistence.Version;
+
+@MappedSuperclass
+public abstract class BaseTimestampedEntity {
+    @Id
+    @GeneratedValue
+    private long id;
+    
+    private String name;
+    
+    @Version
+    private Timestamp version;
+    
+
+    public long getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+    public Timestamp getVersion() {
+        return version;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/BaseTimestampedEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TestTimestampVersion.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TestTimestampVersion.java?rev=1076370&r1=1076369&r2=1076370&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TestTimestampVersion.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TestTimestampVersion.java
Wed Mar  2 20:57:03 2011
@@ -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/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TimestampedEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TimestampedEntity.java?rev=1076370&r1=1076369&r2=1076370&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TimestampedEntity.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/update/TimestampedEntity.java
Wed Mar  2 20:57:03 2011
@@ -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