mirror of https://github.com/apache/openjpa.git
1035 JPA2 Query map key path in predicates
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@765469 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
60988f8be8
commit
5239148763
|
@ -62,18 +62,25 @@ public class MapKey
|
|||
|
||||
public void appendTo(Select sel, ExpContext ctx, ExpState state,
|
||||
SQLBuffer sql, int index) {
|
||||
KeyExpState estate = (KeyExpState) state;
|
||||
_key.appendTo(sel, ctx, estate.key, sql, index);
|
||||
}
|
||||
|
||||
public void calculateValue(Select sel, ExpContext ctx, ExpState state,
|
||||
Val other, ExpState otherState) {
|
||||
_key.calculateValue(sel, ctx, state, other, otherState);
|
||||
KeyExpState estate = (KeyExpState) state;
|
||||
_key.calculateValue(sel, ctx, estate.key, other, otherState);
|
||||
}
|
||||
|
||||
public void groupBy(Select sel, ExpContext ctx, ExpState state) {
|
||||
KeyExpState estate = (KeyExpState) state;
|
||||
_key.groupBy(sel, ctx, estate.key);
|
||||
}
|
||||
|
||||
public void orderBy(Select sel, ExpContext ctx, ExpState state,
|
||||
boolean asc) {
|
||||
KeyExpState estate = (KeyExpState) state;
|
||||
_key.orderBy(sel, ctx, estate.key, asc);
|
||||
}
|
||||
|
||||
public ExpState initialize(Select sel, ExpContext ctx, int flags) {
|
||||
|
|
|
@ -82,6 +82,7 @@ public class PCPath
|
|||
private Class _cast = null;
|
||||
private boolean _cid = false;
|
||||
private FieldMetaData _xmlfield = null;
|
||||
private boolean _keyPath = false;
|
||||
|
||||
/**
|
||||
* Return a path starting with the 'this' ptr.
|
||||
|
@ -274,7 +275,9 @@ public class PCPath
|
|||
* The columns used by this path.
|
||||
*/
|
||||
private Column[] calculateColumns(PathExpState pstate) {
|
||||
if (_key) {
|
||||
if (_key ||
|
||||
(_keyPath && pstate.field.getKey() != null &&
|
||||
!pstate.field.getKey().isEmbedded())) {
|
||||
if (!pstate.joinedRel
|
||||
&& pstate.field.getKey().getValueMappedBy() != null)
|
||||
joinRelation(pstate, _key, false, false);
|
||||
|
@ -500,6 +503,9 @@ public class PCPath
|
|||
key = action.op == Action.GET_KEY;
|
||||
forceOuter |= action.op == Action.GET_OUTER;
|
||||
|
||||
if (key && itr.hasNext())
|
||||
_keyPath = true;
|
||||
|
||||
// get mapping for the current field
|
||||
pstate.field = field;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import javax.persistence.*;
|
|||
import java.util.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="MEx10Emp")
|
||||
@Table(name="M10Emp")
|
||||
public class Employee {
|
||||
@EmbeddedId
|
||||
EmployeePK empPK;
|
||||
|
|
|
@ -23,7 +23,7 @@ import javax.persistence.*;
|
|||
import java.util.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="MEx10Phone")
|
||||
@Table(name="M10Phone")
|
||||
public class PhoneNumber {
|
||||
@EmbeddedId
|
||||
PhonePK phonePK;
|
||||
|
|
|
@ -109,6 +109,14 @@ public class TestMany2ManyMapEx2 extends SQLListenerTestCase {
|
|||
|
||||
assertTrue(d.equals(me.getKey()));
|
||||
|
||||
query = "select KEY(e) from PhoneNumber p, " +
|
||||
" in (p.emps) e WHERE value(e).empId = 1 and KEY(e) = 'String1'";
|
||||
q = em.createQuery(query);
|
||||
if (inMemory)
|
||||
setCandidate(q, PhoneNumber.class);
|
||||
rs = q.getResultList();
|
||||
assertEquals((String) rs.get(0), "String1");
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S26Dept1")
|
||||
@Table(name="T6D1")
|
||||
//@Access(AccessType.PROPERTY)
|
||||
public class Department1 {
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S26Dept2")
|
||||
@Table(name="T6D2")
|
||||
public class Department2 {
|
||||
|
||||
int deptId;
|
||||
|
|
|
@ -29,7 +29,7 @@ import javax.persistence.OneToMany;
|
|||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="S26Dept3")
|
||||
@Table(name="T6D3")
|
||||
public class Department3 {
|
||||
|
||||
@Id
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.apache.openjpa.persistence.jdbc.maps.spec_10_1_26_ex0;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S26Emp1")
|
||||
@Table(name="T6E1")
|
||||
public class Employee1 {
|
||||
@Id
|
||||
int empId;
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.util.Date;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S26Emp2")
|
||||
@Table(name="T6E2")
|
||||
public class Employee2 {
|
||||
EmployeePK2 empPK;
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.apache.openjpa.persistence.jdbc.maps.spec_10_1_26_ex0;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S26Emp3")
|
||||
@Table(name="T6E3")
|
||||
public class Employee3 {
|
||||
@Id
|
||||
int empId;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S26Ex1Dept")
|
||||
@Table(name="S26x1Dept")
|
||||
public class Department {
|
||||
|
||||
@Id
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.apache.openjpa.persistence.jdbc.maps.spec_10_1_26_ex1;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S26Ex1Emp")
|
||||
@Table(name="S26x1Emp")
|
||||
public class Employee {
|
||||
@Id
|
||||
int empId;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S26Ex2Dept")
|
||||
@Table(name="S6Dept")
|
||||
public class Department {
|
||||
|
||||
int deptId;
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.util.Date;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S26Ex2Emp")
|
||||
@Table(name="S6E2Emp")
|
||||
public class Employee {
|
||||
EmployeePK empPK;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import javax.persistence.OneToMany;
|
|||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="S26Ex3Dept")
|
||||
@Table(name="A63Dept")
|
||||
public class Department {
|
||||
|
||||
@Id
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.apache.openjpa.persistence.jdbc.maps.spec_10_1_26_ex3;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S26Ex3Emp")
|
||||
@Table(name="A63Emp")
|
||||
public class Employee {
|
||||
@Id
|
||||
int empId;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S27x3Comp")
|
||||
@Table(name="S273Comp")
|
||||
public class Company {
|
||||
@Id
|
||||
int id;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S27x4Comp")
|
||||
@Table(name="S274Comp")
|
||||
public class Company {
|
||||
@Id
|
||||
int id;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S27x5Comp")
|
||||
@Table(name="S275Comp")
|
||||
public class Company {
|
||||
@Id
|
||||
int id;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S27x6Comp")
|
||||
@Table(name="S276Comp")
|
||||
public class Company {
|
||||
@Id
|
||||
int id;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S27x7Comp")
|
||||
@Table(name="S277Comp")
|
||||
public class Company {
|
||||
@Id
|
||||
int id;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="S27x8Comp")
|
||||
@Table(name="S278Comp")
|
||||
public class Company {
|
||||
@Id
|
||||
int id;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="T29x1Comp")
|
||||
@Table(name="T291Comp")
|
||||
public class Company {
|
||||
@Id
|
||||
int id;
|
||||
|
|
|
@ -119,6 +119,14 @@ public class TestSpec10_1_29_Ex3 extends SQLListenerTestCase {
|
|||
assertTrue(c.equals(me.getKey()));
|
||||
assertEquals(s.getId(), ((Semester) me.getValue()).getId());
|
||||
|
||||
query = "select KEY(e) from Student s " +
|
||||
" join s.enrollment e WHERE KEY(e).id = 1 order by s.id";
|
||||
q = em.createQuery(query);
|
||||
if (inMemory)
|
||||
setCandidate(q, Student.class);
|
||||
rs = q.getResultList();
|
||||
assertEquals(((Course) rs.get(0)).getId(), 1);
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue