Author: ppoddar
Date: Tue Nov 17 20:35:20 2009
New Revision: 881495
URL: http://svn.apache.org/viewvc?rev=881495&view=rev
Log:
OPENJPA-1390: From.join(String attr) checks any attribute not only singular
attributes.
Modified:
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/FromImpl.java
Modified:
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/FromImpl.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/FromImpl.java?rev=881495&r1=881494&r2=881495&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/FromImpl.java
(original)
+++
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/FromImpl.java
Tue Nov 17 20:35:20 2009
@@ -175,53 +175,68 @@
return join(attr, JoinType.INNER);
}
- public <W,Y> Join<W,Y> join(String attr, JoinType jt) {
- assertJoinable();
- return
(Join<W,Y>)join(((ManagedType<X>)type).getSingularAttribute(attr), jt);
+ public <W,Y> Join<W,Y> join(String name, JoinType jt) {
+ assertJoinable(type);
+ ManagedType<X> mType = (ManagedType<X>)type;
+ Attribute<?, ?> attr = mType.getAttribute(name);
+ assertJoinable(attr.getDeclaringType());
+ if (attr instanceof SingularAttribute) {
+ return join((SingularAttribute)attr, jt);
+ } else if (attr instanceof ListAttribute) {
+ return join((ListAttribute)attr, jt);
+ } else if (attr instanceof SetAttribute) {
+ return join((SetAttribute)attr, jt);
+ } else if (attr instanceof CollectionAttribute) {
+ return join((CollectionAttribute)attr, jt);
+ } else if (attr instanceof MapAttribute) {
+ return join((MapAttribute)attr, jt);
+ } else {
+ throw new IllegalArgumentException(name);
+ }
}
public <W,Y> CollectionJoin<W, Y> joinCollection(String attr) {
- assertJoinable();
+ assertJoinable(type);
return
(CollectionJoin<W,Y>)join(((ManagedType<X>)type).getCollection(attr),
JoinType.INNER);
}
public <W,Y> CollectionJoin<W, Y> joinCollection(String attr, JoinType jt)
{
- assertJoinable();
+ assertJoinable(type);
return
(CollectionJoin<W,Y>)join(((ManagedType<X>)type).getCollection(attr), jt);
}
public <W,Y> ListJoin<W, Y> joinList(String attr) {
- assertJoinable();
+ assertJoinable(type);
return (ListJoin<W,Y>)join(((ManagedType<X>)type).getList(attr),
JoinType.INNER);
}
public <W,Y> ListJoin<W,Y> joinList(String attr, JoinType jt) {
- assertJoinable();
+ assertJoinable(type);
return (ListJoin<W,Y>)join(((ManagedType<X>)type).getList(attr), jt);
}
public <W,K,V> MapJoin<W,K,V> joinMap(String attr) {
- assertJoinable();
+ assertJoinable(type);
return (MapJoin<W,K,V>)join(((ManagedType<X>)type).getMap(attr));
}
public <W,K,V> MapJoin<W,K,V> joinMap(String attr, JoinType jt) {
- assertJoinable();
+ assertJoinable(type);
return (MapJoin<W,K,V>)join(((ManagedType<X>)type).getMap(attr));
}
public <W,Y> SetJoin<W, Y> joinSet(String attr) {
- assertJoinable();
+ assertJoinable(type);
return (SetJoin<W, Y>)join(((ManagedType<X>)type).getSet(attr));
}
public <W,Y> SetJoin<W, Y> joinSet(String attr, JoinType jt) {
- assertJoinable();
+ assertJoinable(type);
return (SetJoin<W, Y>)join(((ManagedType<X>)type).getSet(attr), jt);
}
- void assertJoinable() {
+ void assertJoinable(Type<?> type) {
if (type.getPersistenceType() == PersistenceType.BASIC) {
throw new IllegalArgumentException(this + " is a basic path and
can not be navigated to ");
}
@@ -258,7 +273,7 @@
}
public <X,Y> Fetch<X, Y> fetch(String name, JoinType jt) {
- assertJoinable();
+ assertJoinable(type);
Attribute<? super X,?> attr =
((ManagedType<X>)type).getAttribute(name);
if (attr.isCollection()) {
return fetch((PluralAttribute)attr, jt);