mirror of
https://github.com/apache/openjpa.git
synced 2025-03-06 16:39:11 +00:00
OPENJPA-1974: Applied to 2.1.x Rick's changes from trunk (2.2.x)
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1340872 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
47e5d28034
commit
e0793ab046
@ -155,7 +155,7 @@ public class SelectImpl
|
|||||||
private Set _eagerKeys = null;
|
private Set _eagerKeys = null;
|
||||||
|
|
||||||
// subselect support
|
// subselect support
|
||||||
private List _subsels = null;
|
private List<SelectImpl> _subsels = null;
|
||||||
private SelectImpl _parent = null;
|
private SelectImpl _parent = null;
|
||||||
private String _subPath = null;
|
private String _subPath = null;
|
||||||
private boolean _hasSub = false;
|
private boolean _hasSub = false;
|
||||||
@ -2050,7 +2050,7 @@ public class SelectImpl
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// not found; create alias
|
// not found; create alias
|
||||||
i = aliasSize(null);
|
i = aliasSize(false, null);
|
||||||
// System.out.println("GetTableIndex\t"+
|
// System.out.println("GetTableIndex\t"+
|
||||||
// ((_parent != null) ? "Sub" :"") +
|
// ((_parent != null) ? "Sub" :"") +
|
||||||
// " created alias: "+
|
// " created alias: "+
|
||||||
@ -2153,19 +2153,19 @@ public class SelectImpl
|
|||||||
_tables.put(alias, tableString);
|
_tables.put(alias, tableString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate total number of aliases.
|
* Calculate total number of aliases.
|
||||||
|
*
|
||||||
|
* From 1.2.x
|
||||||
*/
|
*/
|
||||||
private int aliasSize(SelectImpl fromSub) {
|
private int aliasSize(boolean fromParent, SelectImpl fromSub) {
|
||||||
int aliases = (_parent == null) ? 0
|
int aliases = (fromParent || _parent == null) ? 0 : _parent.aliasSize(false, this);
|
||||||
: _parent.aliasSize(this);
|
|
||||||
aliases += (_aliases == null) ? 0 : _aliases.size();
|
aliases += (_aliases == null) ? 0 : _aliases.size();
|
||||||
if (_subsels != null) {
|
if (_subsels != null) {
|
||||||
SelectImpl sub;
|
for (SelectImpl sub : _subsels) {
|
||||||
for (int i = 0; i < _subsels.size(); i++) {
|
|
||||||
sub = (SelectImpl) _subsels.get(i);
|
|
||||||
if (sub != fromSub)
|
if (sub != fromSub)
|
||||||
aliases += sub.aliasSize(null);
|
aliases += sub.aliasSize(true, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return aliases;
|
return aliases;
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,7 @@ import javax.persistence.Embedded;
|
|||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import javax.persistence.FetchType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Transient;
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@ -45,6 +46,9 @@ public class EagerEntity {
|
|||||||
|
|
||||||
@ElementCollection(fetch=FetchType.EAGER)
|
@ElementCollection(fetch=FetchType.EAGER)
|
||||||
private List<EagerEmbed> eagerEmbedColl;
|
private List<EagerEmbed> eagerEmbedColl;
|
||||||
|
|
||||||
|
@OneToMany(fetch=FetchType.EAGER)
|
||||||
|
private List<EagerEntity> eagerSelf;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private String transField;
|
private String transField;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user