You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by dw...@apache.org on 2010/10/26 22:14:15 UTC
svn commit: r1027722 - in /openjpa/trunk:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/
Author: dwoods
Date: Tue Oct 26 20:14:15 2010
New Revision: 1027722
URL: http://svn.apache.org/viewvc?rev=1027722&view=rev
Log:
OPENJPA-1793 @EmbeddedId class having only one field java.sql.Data. Contributed by Heath Thomann.
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_Single_Coll.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_Single_Coll.java (with props)
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java?rev=1027722&r1=1027721&r2=1027722&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java Tue Oct 26 20:14:15 2010
@@ -316,10 +316,17 @@ public class HandlerFieldStrategy
Object val = null;
if (cols.length == 1) {
col = cols[0];
- if (fk != null)
+ if (fk != null){
col = fk.getColumn(col);
- val = res.getObject(col, field.getHandler().
- getResultArgument(field), joins);
+ }
+
+ //OJ-1793: Get the args from the handler and first check to see if the
+ //args are null. If they aren't null then use the first element in the args
+ //array rather than passing into 'getObject' the entire args array. This is
+ //akin to what is done in the 'else if' leg below.
+ Object[] args = (Object[]) field.getHandler().getResultArgument(field);
+ val = res.getObject(col, (args == null) ? null : args[0],
+ joins);
} else if (cols.length > 1) {
Object[] vals = new Object[cols.length];
Object[] args = (Object[]) field.getHandler().
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_Single_Coll.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_Single_Coll.java?rev=1027722&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_Single_Coll.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_Single_Coll.java Tue Oct 26 20:14:15 2010
@@ -0,0 +1,70 @@
+/*
+ * 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.embed;
+
+import java.sql.Date;
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.Embeddable;
+import javax.persistence.ElementCollection;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+/* This test was created to test OJ-1793 */
+
+@Embeddable
+public class Embed_Single_Coll {
+
+ @Temporal(TemporalType.DATE)
+ private Date date;
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((date == null) ? 0 : date.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Embed_Single_Coll other = (Embed_Single_Coll) obj;
+ if (date == null) {
+ if (other.date != null)
+ return false;
+ } else if (!date.equals(other.date))
+ return false;
+ return true;
+ }
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_Single_Coll.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_Single_Coll.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_Single_Coll.java?rev=1027722&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_Single_Coll.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_Single_Coll.java Tue Oct 26 20:14:15 2010
@@ -0,0 +1,51 @@
+/*
+ * 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.embed;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+
+@Entity
+public class EntityA_Embed_Single_Coll implements Serializable {
+
+ @EmbeddedId
+ protected Embed_Single_Coll embed;
+
+ @Column(length = 30)
+ String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Embed_Single_Coll getEmbed() {
+ return embed;
+ }
+
+ public void setEmbed(Embed_Single_Coll embed) {
+ this.embed = embed;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_Single_Coll.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java?rev=1027722&r1=1027721&r2=1027722&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java Tue Oct 26 20:14:15 2010
@@ -103,7 +103,8 @@ public class TestEmbeddable extends SQLL
Embed_MappedToOne.class, Embed_MappedToOneCascadeDelete.class,
EntityA_Embed_MappedToOneCascadeDelete.class, EntityB2.class,
Book.class, Listing.class, Seller.class,
- EntityA_Embed_Coll_Map.class, Embed_Coll_Map.class, EntityA_Embed.class,
+ EntityA_Embed_Coll_Map.class, Embed_Coll_Map.class,
+ EntityA_Embed_Single_Coll.class, Embed_Single_Coll.class, EntityA_Embed.class,
EntityA_Embed_Complex.class, A.class, CLEAR_TABLES);
sql.clear();
DBDictionary dict = ((JDBCConfiguration)emf.getConfiguration()).getDBDictionaryInstance();
@@ -164,6 +165,35 @@ public class TestEmbeddable extends SQLL
queryEntityA_Embed_Coll_Map();
}
+ /**
+ * Test for OJ-1793.
+ */
+ public void testEntityA_Embed_Single_Coll() {
+ EntityManager em = emf.createEntityManager();
+
+ //create an EntityA_Embed_Single_Coll and persist it.
+ EntityA_Embed_Single_Coll eesc = new EntityA_Embed_Single_Coll();
+ Embed_Single_Coll esc = new Embed_Single_Coll();
+ java.sql.Date date = java.sql.Date.valueOf("2010-10-13");
+ esc.setDate(date);
+ eesc.setEmbed(esc);
+ em.getTransaction().begin();
+ em.persist(eesc);
+ em.flush();
+ em.getTransaction().commit();
+ em.close();
+
+ //Now query the recently created EntityA_Embed_Single_Coll. Without OJ-1793, when you query
+ //the EntityA_Embed_Single_Coll object, the issue of OJ-1793 will occur, regardless of the query
+ //string (even the simplest string will do).
+ em = emf.createEntityManager();
+ Query query1 = em.createQuery("SELECT e FROM EntityA_Embed_Single_Coll e "
+ + "where e.embed.date = '" + date + "'");
+ eesc = (EntityA_Embed_Single_Coll) query1.getSingleResult();
+ assertEquals(eesc.getEmbed().getDate().toString(), date.toString());
+ em.close();
+ }
+
public void queryEntityA_Embed_Coll_Map() {
EntityManager em = emf.createEntityManager();
String query[] = {