You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by fa...@apache.org on 2009/12/16 21:33:32 UTC
svn commit: r891417 - in /openjpa/trunk:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/
Author: faywang
Date: Wed Dec 16 20:33:31 2009
New Revision: 891417
URL: http://svn.apache.org/viewvc?rev=891417&view=rev
Log:
OPENJPA-1435: remove null element from the coll
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestOneToManyWithEagerLazyFetch.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/Util1xmLf.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/Util1xmRt.java (with props)
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java?rev=891417&r1=891416&r2=891417&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java Wed Dec 16 20:33:31 2009
@@ -437,7 +437,9 @@
if (field.getOrderColumn() != null)
seq = res.getInt(field.getOrderColumn(), refJoins) + 1;
res.setBaseMapping(null);
- add(store, coll, loadElement(sm, store, fetch, res, dataJoins));
+ Object obj = loadElement(sm, store, fetch, res, dataJoins);
+ if (obj != null)
+ add(store, coll, obj);
if (!res.next() || res.indexOf() != typeIdx) {
res.pushBack();
break;
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestOneToManyWithEagerLazyFetch.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestOneToManyWithEagerLazyFetch.java?rev=891417&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestOneToManyWithEagerLazyFetch.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestOneToManyWithEagerLazyFetch.java Wed Dec 16 20:33:31 2009
@@ -0,0 +1,104 @@
+/*
+ * 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.relations;
+
+import java.util.Collection;
+
+import javax.persistence.EntityManager;
+
+import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * Test Multi-OneToMany relationship with different fetch types.
+ */
+public class TestOneToManyWithEagerLazyFetch extends SingleEMFTestCase {
+
+ final int TestUtil1xm_TestRow_Id = 100;
+
+ public void setUp() {
+ setUp(Util1xmLf.class, Util1xmRt.class);
+
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+
+ // Initialize Util1xmLf entity
+ Util1xmLf lf1xm = new Util1xmLf();
+ lf1xm.setId(TestUtil1xm_TestRow_Id);
+ lf1xm.setFirstName("loaded firstName");
+
+ Util1xmRt rt1xm1 = new Util1xmRt();
+ rt1xm1.setId(TestUtil1xm_TestRow_Id + 11);
+ rt1xm1.setLastName("loaded lastName1");
+ lf1xm.addUniRightLzy(rt1xm1);
+
+ Util1xmRt rt1xm2 = new Util1xmRt();
+ rt1xm2.setId(TestUtil1xm_TestRow_Id + 12);
+ rt1xm2.setLastName("loaded lastName2");
+ lf1xm.addUniRightLzy(rt1xm2);
+
+ Util1xmRt rt1xm3 = new Util1xmRt();
+ rt1xm3.setId(TestUtil1xm_TestRow_Id + 21);
+ rt1xm3.setLastName("loaded eager lastName3");
+ lf1xm.addUniRightEgr(rt1xm3);
+
+ Util1xmRt rt1xm4 = new Util1xmRt();
+ rt1xm4.setId(TestUtil1xm_TestRow_Id + 22);
+ rt1xm4.setLastName("loaded eager lastName4");
+ lf1xm.addUniRightEgr(rt1xm4);
+
+ em.persist(rt1xm1);
+ em.persist(rt1xm2);
+ em.persist(rt1xm3);
+ em.persist(rt1xm4);
+ em.persist(lf1xm);
+
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testLoadedOneToManyCount() {
+ EntityManager em = emf.createEntityManager();
+ Util1xmLf e1 = em.find(Util1xmLf.class, TestUtil1xm_TestRow_Id);
+ // SELECT t0.firstName, t1.UTIL1XMLF_ID, t2.id, t2.lastName FROM Util1xmLf t0
+ // LEFT OUTER JOIN Util1xmLf_Util1xmRt t1 ON t0.id = t1.UTIL1XMLF_ID
+ // LEFT OUTER JOIN Util1xmRt t2 ON t1.UNIRIGHTEGR_ID = t2.id WHERE t0.id = ?
+ // [params=(int) 100]
+
+ assertNotNull("Found Util1xmLf(id=" + TestUtil1xm_TestRow_Id + ")", e1);
+
+ Collection<Util1xmRt> eRs = e1.getUniRightLzy();
+ // SELECT t1.id, t1.lastName FROM Util1xmLf_Util1xmRt t0
+ // INNER JOIN Util1xmRt t1 ON t0.UNIRIGHTLZY_ID = t1.id WHERE t0.UTIL1XMLF_ID = ?
+ // [params=(int) 100]
+ assertNotNull("Util1xmRt uniRightLzy != null", eRs);
+ assertEquals("Util1xmRt uniRightLzy.size == 2", eRs.size(), 2);
+
+ Collection<Util1xmRt> eEs = e1.getUniRightEgr();
+ assertNotNull("Util1xmRt uniRightEgr != null", eEs);
+ // Failing test: Getting 3 in eager collection, one null entry
+ assertEquals("Util1xmRt uniRightEgr.size == 2", eEs.size(), 2);
+
+ em.close();
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(TestOneToManyWithEagerLazyFetch.class);
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestOneToManyWithEagerLazyFetch.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/Util1xmLf.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/Util1xmLf.java?rev=891417&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/Util1xmLf.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/Util1xmLf.java Wed Dec 16 20:33:31 2009
@@ -0,0 +1,90 @@
+/*
+ * 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.relations;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Version;
+
+@Entity
+public class Util1xmLf {
+
+ private int id;
+
+ private int version;
+
+ private String firstName;
+
+ public Collection<Util1xmRt> uniRightLzy = new HashSet<Util1xmRt>();
+
+ public Collection<Util1xmRt> uniRightEgr = new HashSet<Util1xmRt>();
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ @Version
+ public int getVersion() {
+ return version;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ @OneToMany// (fetch = FetchType.LAZY)
+ public Collection<Util1xmRt> getUniRightLzy() {
+ return uniRightLzy;
+ }
+
+ public void setUniRightLzy(Collection<Util1xmRt> uniRightLzy) {
+ this.uniRightLzy = uniRightLzy;
+ }
+
+ public void addUniRightLzy(Util1xmRt uniRightLzy) {
+ getUniRightLzy().add(uniRightLzy);
+ }
+
+ @OneToMany(fetch = FetchType.EAGER)
+ public Collection<Util1xmRt> getUniRightEgr() {
+ return uniRightEgr;
+ }
+
+ public void setUniRightEgr(Collection<Util1xmRt> uniRightEgr) {
+ this.uniRightEgr = uniRightEgr;
+ }
+
+ public void addUniRightEgr(Util1xmRt uniRightEgr) {
+ getUniRightEgr().add(uniRightEgr);
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/Util1xmLf.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/Util1xmRt.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/Util1xmRt.java?rev=891417&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/Util1xmRt.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/Util1xmRt.java Wed Dec 16 20:33:31 2009
@@ -0,0 +1,55 @@
+/*
+ * 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.relations;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+@Entity
+public class Util1xmRt {
+
+ private int id;
+
+ private int version;
+
+ private String lastName;
+
+ @Id
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ @Version
+ public int getVersion() {
+ return version;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/Util1xmRt.java
------------------------------------------------------------------------------
svn:eol-style = native