You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by cu...@apache.org on 2011/04/05 18:35:57 UTC
svn commit: r1089124 - in /openjpa/trunk:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/
Author: curtisr7
Date: Tue Apr 5 16:35:56 2011
New Revision: 1089124
URL: http://svn.apache.org/viewvc?rev=1089124&view=rev
Log:
OPENJPA-1974: Fix StackOverflow in SelectImpl.
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/TestOneToManySubQuery.java (with props)
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/EagerEntity.java
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=1089124&r1=1089123&r2=1089124&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java Tue Apr 5 16:35:56 2011
@@ -155,7 +155,7 @@ public class SelectImpl
private Set _eagerKeys = null;
// subselect support
- private List _subsels = null;
+ private List<SelectImpl> _subsels = null;
private SelectImpl _parent = null;
private String _subPath = null;
private boolean _hasSub = false;
@@ -2050,7 +2050,7 @@ public class SelectImpl
return -1;
// not found; create alias
- i = aliasSize(null);
+ i = aliasSize(false, null);
// System.out.println("GetTableIndex\t"+
// ((_parent != null) ? "Sub" :"") +
// " created alias: "+
@@ -2153,19 +2153,19 @@ public class SelectImpl
_tables.put(alias, tableString);
}
+
/**
* Calculate total number of aliases.
+ *
+ * From 1.2.x
*/
- private int aliasSize(SelectImpl fromSub) {
- int aliases = (_parent == null) ? 0
- : _parent.aliasSize(this);
+ private int aliasSize(boolean fromParent, SelectImpl fromSub) {
+ int aliases = (fromParent || _parent == null) ? 0 : _parent.aliasSize(false, this);
aliases += (_aliases == null) ? 0 : _aliases.size();
if (_subsels != null) {
- SelectImpl sub;
- for (int i = 0; i < _subsels.size(); i++) {
- sub = (SelectImpl) _subsels.get(i);
+ for (SelectImpl sub : _subsels) {
if (sub != fromSub)
- aliases += sub.aliasSize(null);
+ aliases += sub.aliasSize(true, null);
}
}
return aliases;
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/TestOneToManySubQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/TestOneToManySubQuery.java?rev=1089124&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/TestOneToManySubQuery.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/TestOneToManySubQuery.java Tue Apr 5 16:35:56 2011
@@ -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.jpql;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.persistence.util.EagerEmbed;
+import org.apache.openjpa.persistence.util.EagerEmbedRel;
+import org.apache.openjpa.persistence.util.EagerEntity;
+
+public class TestOneToManySubQuery extends SingleEMFTestCase {
+
+ public void setUp() throws Exception {
+ super.setUp(CLEAR_TABLES, EagerEntity.class, EagerEmbed.class, EagerEmbedRel.class);
+ }
+
+ public void test() {
+ EntityManager em = emf.createEntityManager();
+ try {
+ assertEquals(0, em.createQuery(
+ "SELECT e FROM EagerEntity e WHERE EXISTS (SELECT e1 FROM e.eagerSelf e1 WHERE e1.id = 0)"
+ + " OR EXISTS (SELECT e1 FROM e.eagerSelf e1 WHERE e1.id = 1)", EagerEntity.class).getResultList()
+ .size());
+
+ } finally {
+ em.close();
+
+ }
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/TestOneToManySubQuery.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/EagerEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/EagerEntity.java?rev=1089124&r1=1089123&r2=1089124&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/EagerEntity.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/EagerEntity.java Tue Apr 5 16:35:56 2011
@@ -26,6 +26,7 @@ import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
+import javax.persistence.OneToMany;
import javax.persistence.Transient;
@Entity
@@ -45,6 +46,9 @@ public class EagerEntity {
@ElementCollection(fetch=FetchType.EAGER)
private List<EagerEmbed> eagerEmbedColl;
+
+ @OneToMany(fetch=FetchType.EAGER)
+ private List<EagerEntity> eagerSelf;
@Transient
private String transField;