1035 JPA2 Query allow embeddable as orderby item

add more test strings for IS NULL and IS EMPTY predicates with path navigation thru key path or embeddable

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@767084 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Catalina Wei 2009-04-21 09:21:02 +00:00
parent 282b8770cd
commit f3b437ab76
5 changed files with 131 additions and 14 deletions

View File

@ -292,15 +292,13 @@ public class PCPath
case JavaTypes.ARRAY:
case JavaTypes.COLLECTION:
ValueMapping elem = pstate.field.getElementMapping();
if (pstate.field.isElementCollection() &&
pstate.field.getElement().isEmbedded())
return ((HandlerCollectionTableFieldStrategy)
pstate.field.getStrategy()).getElementColumns(
elem.getTypeMapping());
if (pstate.joinedRel && elem.getTypeCode() == JavaTypes.PC)
{
if (pstate.field.isElementCollection() &&
pstate.field.getElement().isEmbedded())
return ((HandlerCollectionTableFieldStrategy)
pstate.field.getStrategy()).getElementColumns(
elem.getTypeMapping());
return elem.getTypeMapping().getPrimaryKeyColumns();
}
if (elem.getColumns().length > 0)
return elem.getColumns();
return pstate.field.getColumns();

View File

@ -1277,7 +1277,9 @@ void orderby_clause() #ORDERBY : { }
void orderby_item() #ORDERBYITEM : { }
{
(LOOKAHEAD(path()) path() | qualified_path() | orderby_extension() | identification_variable()
(LOOKAHEAD(path()) path() | LOOKAHEAD(qualified_path()) qualified_path()
| LOOKAHEAD(general_identification_variable()) general_identification_variable()
| orderby_extension() | identification_variable()
)
[ <ASC> #ASCENDING | <DESC> #DESCENDING ]
}

View File

@ -1037,13 +1037,26 @@ public class TestEmbeddable extends SingleEMFTestCase {
"select e from " +
" EntityA_Coll_String a " +
" , in (a.nickNames) e order by a.id",
"select e from " +
" EntityA_Coll_String a " +
" , in (a.nickNames) e order by e",
"select a from " +
" EntityA_Coll_String a " +
" WHERE a.nickNames IS EMPTY order by a",
};
List rs = null;
for (int i = 0; i < query.length; i++) {
rs = em.createQuery(query[i]).getResultList();
assertTrue(rs.size() > 0);
Object obj = rs.get(0);
assertTrue(obj instanceof String);
switch (i) {
case 0:
case 1:
assertTrue(rs.size() > 0);
Object obj = rs.get(0);
assertTrue(obj instanceof String);
break;
case 2:
assertTrue(rs.size() == 0);
}
em.clear();
}
EntityTransaction tran = em.getTransaction();
@ -1068,6 +1081,11 @@ public class TestEmbeddable extends SingleEMFTestCase {
" EntityA_Embed_ToOne a ",
"select e from EntityA_Embed_ToOne a " +
" join a.embed e join e.b b where e.b.id > 0 order by a.id",
"select a.embed from " +
" EntityA_Embed_ToOne a ORDER BY a.embed",
"select a.embed from " +
" EntityA_Embed_ToOne a WHERE a.embed.b IS NOT NULL " +
" ORDER BY a.embed",
};
for (int i = 0; i < query.length; i++) {
List<Object[]> rs = null;
@ -1100,6 +1118,12 @@ public class TestEmbeddable extends SingleEMFTestCase {
" EntityA_Embed_MappedToOne a ",
"select e from EntityA_Embed_MappedToOne a " +
" join a.embed e join e.bm bm where e.bm.id > 0 order by a.id",
"select a.embed as e from " +
" EntityA_Embed_MappedToOne a ORDER BY e",
"select a.embed from " +
" EntityA_Embed_MappedToOne a WHERE a.embed IS NOT NULL",
"select a.embed from " +
" EntityA_Embed_MappedToOne a WHERE a.embed.bm IS NOT NULL",
};
for (int i = 0; i < query.length; i++) {
List<Object[]> rs = null;
@ -1137,6 +1161,16 @@ public class TestEmbeddable extends SingleEMFTestCase {
" EntityA_Coll_Embed_ToOne a " +
" , in (a.embed1s) e where e.name1 like '%1'" +
" order by e.name3",
"select e, e.b.id from " +
" EntityA_Coll_Embed_ToOne a " +
" , in (a.embed1s) e where e.name1 like '%1'" +
" order by e",
"select e, e.b.id from " +
" EntityA_Coll_Embed_ToOne a " +
" , in (a.embed1s) e where e.name1 like '%1' and" +
" a.embed1s IS NOT EMPTY and " +
" e.b IS NOT NULL " +
" order by e",
};
List<Object[]> rs = null;
for (int i = 0; i < query.length; i++) {
@ -1179,7 +1213,13 @@ public class TestEmbeddable extends SingleEMFTestCase {
" b",
"select e from EntityA_Embed_ToMany a join a.embed e " +
" where e.name1 like '%1'",
};
"select a.embed from EntityA_Embed_ToMany a ORDER BY a.embed",
"select e from EntityA_Embed_ToMany a join a.embed e ORDER BY e",
"select b from EntityA_Embed_ToMany a join a.embed.bs" +
" b ORDER BY b",
"select e from EntityA_Embed_ToMany a join a.embed e " +
" WHERE e.bs IS NOT EMPTY ORDER BY e",
};
List rs = null;
for (int i = 0; i < query.length; i++) {
rs = em.createQuery(query[i]).getResultList();
@ -1188,10 +1228,14 @@ public class TestEmbeddable extends SingleEMFTestCase {
switch (i) {
case 0:
case 1:
case 4:
case 5:
case 7:
assertTrue(obj instanceof Embed_ToMany);
assertTrue(((Embed_ToMany) obj).getEntityBs().size() > 0);
break;
case 2:
case 6:
assertTrue(obj instanceof EntityB1);
break;
}
@ -1227,6 +1271,11 @@ public class TestEmbeddable extends SingleEMFTestCase {
" left join a.embed e1 left join e1.embed e2",
"select e2 from EntityA_Embed_Embed_ToMany a " +
" join a.embed e1 join e1.embed e2",
"select a.embed as e from EntityA_Embed_Embed_ToMany a ORDER BY e",
"select a.embed.embed as e from EntityA_Embed_Embed_ToMany a " +
" where a.embed.embed.name1 like '%1' ORDER BY e",
"select a.embed from EntityA_Embed_Embed_ToMany a " +
" where a.embed.embed.bs IS NOT EMPTY",
};
List rs = null;
for (int i = 0; i < query.length; i++) {
@ -1236,6 +1285,8 @@ public class TestEmbeddable extends SingleEMFTestCase {
switch (i) {
case 0:
case 1:
case 7:
case 9:
assertTrue(obj instanceof Embed_Embed_ToMany);
assertTrue(((Embed_Embed_ToMany) obj).getEmbed().getEntityBs().
size() > 0);
@ -1244,6 +1295,7 @@ public class TestEmbeddable extends SingleEMFTestCase {
case 4:
case 5:
case 6:
case 8:
assertTrue(obj instanceof Embed_ToMany);
assertTrue(((Embed_ToMany) obj).getEntityBs().size() > 0);
break;
@ -1271,6 +1323,9 @@ public class TestEmbeddable extends SingleEMFTestCase {
EntityManager em = emf.createEntityManager();
// test select embed object from element collection in embeddable object
String[] query = {
"select e, a.id from " +
" EntityA_Embed_Coll_Integer a " +
" , in (a.embed.otherIntVals) e order by e",
"select e, a.id from " +
" EntityA_Embed_Coll_Integer a " +
" , in (a.embed.otherIntVals) e order by a.id",
@ -1279,6 +1334,10 @@ public class TestEmbeddable extends SingleEMFTestCase {
"select e, a.embed.intVal2 from " +
" EntityA_Embed_Coll_Integer a " +
" , in (a.embed.otherIntVals) e order by e",
"select e, a.embed.intVal2 from " +
" EntityA_Embed_Coll_Integer a " +
" , in (a.embed.otherIntVals) e " +
" WHERE a.embed.otherIntVals IS NOT EMPTY order by e",
};
List<Object[]> rs = null;
for (int i = 0; i < query.length; i++) {
@ -1308,7 +1367,10 @@ public class TestEmbeddable extends SingleEMFTestCase {
// test select embeddable
String query[] = {
"select a.embed from EntityA_Embed_Embed a",
"select a.embed.embed from EntityA_Embed_Embed a"
"select a.embed.embed from EntityA_Embed_Embed a",
"select a.embed as e from EntityA_Embed_Embed a ORDER BY e",
"select a.embed from EntityA_Embed_Embed a WHERE a.embed.embed " +
" IS NOT NULL",
};
List rs = null;
for (int i = 0; i < query.length; i++) {
@ -1316,10 +1378,13 @@ public class TestEmbeddable extends SingleEMFTestCase {
assertTrue(rs.size() > 0);
switch (i) {
case 0:
case 2:
case 3:
assertTrue(rs.get(0) instanceof Embed_Embed);
break;
case 1:
assertTrue(rs.get(0) instanceof Embed);
break;
}
em.clear();
}
@ -1346,6 +1411,12 @@ public class TestEmbeddable extends SingleEMFTestCase {
" , in (a.embeds) e order by e.intVal3",
"select e, a.id from EntityA_Coll_Embed_Embed a " +
" , in (a.embeds) e order by a.id",
"select e, a.id from EntityA_Coll_Embed_Embed a " +
" , in (a.embeds) e order by e desc",
"select e, e.intVal1, e.embed.intVal2 from " +
" EntityA_Coll_Embed_Embed a " +
" , in (a.embeds) e WHERE a.embeds IS NOT EMPTY " +
" order by e.intVal3",
};
List rs = null;
for (int i = 0; i < query.length; i++) {
@ -1374,6 +1445,9 @@ public class TestEmbeddable extends SingleEMFTestCase {
EntityManager em = emf.createEntityManager();
// test select embed object from element collection in embeddable object
String[] query = {
"select e, e.intVal1, e.intVal2 from " +
" EntityA_Embed_Coll_Embed a " +
" , in (a.embed.embeds) e order by e",
"select e, e.intVal1 from " +
" EntityA_Embed_Coll_Embed a " +
" , in (a.embed.embeds) e order by e.intVal3",
@ -1382,6 +1456,10 @@ public class TestEmbeddable extends SingleEMFTestCase {
"select e, e.intVal1, e.intVal2 from " +
" EntityA_Embed_Coll_Embed a " +
" , in (a.embed.embeds) e order by e.intVal3",
"select e, e.intVal1, e.intVal2 from " +
" EntityA_Embed_Coll_Embed a " +
" , in (a.embed.embeds) e where a.embed.embeds IS NOT EMPTY" +
" order by e",
};
List<Object[]> rs = null;
for (int i = 0; i < query.length; i++) {

View File

@ -89,7 +89,7 @@ public class TestMany2ManyMapEx2 extends SQLListenerTestCase {
setCandidate(q, PhoneNumber.class);
List rs = q.getResultList();
String d = (String) rs.get(0);
query = "select KEY(p) from Employee e, " +
" in (e.phones) p";
q = em.createQuery(query);
@ -126,6 +126,15 @@ public class TestMany2ManyMapEx2 extends SQLListenerTestCase {
rs = q.getResultList();
assertEquals((String) rs.get(0), "String1");
query = "select KEY(e) from PhoneNumber p, " +
" in (p.emps) e WHERE KEY(e) = ?1";
q = em.createQuery(query);
q.setParameter(1, "String1");
if (inMemory)
setCandidate(q, PhoneNumber.class);
rs = q.getResultList();
assertEquals((String) rs.get(0), "String1");
em.close();
}

View File

@ -135,6 +135,7 @@ public class TestMany2ManyMapEx3 extends SQLListenerTestCase {
rs = q.getResultList();
d2 = (Department) ((Object[]) rs.get(0))[0];
String dname = (String) ((Object[]) rs.get(0))[1];
assertEquals(d2.getName(), dname);
// test GROUP BY qualified path
sql.clear();
@ -147,6 +148,35 @@ public class TestMany2ManyMapEx3 extends SQLListenerTestCase {
if (!inMemory)
assertTrue(sql.get(0).toUpperCase().indexOf(" GROUP BY ") != -1);
query = "select KEY(p) as k, KEY(p).name from Employee e, " +
" in (e.phones) p ORDER BY k";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Employee.class);
rs = q.getResultList();
d2 = (Department) ((Object[]) rs.get(0))[0];
dname = (String) ((Object[]) rs.get(0))[1];
assertEquals(d2.getName(), dname);
query = "select KEY(p), KEY(p).name from Employee e, " +
" in (e.phones) p ORDER BY KEY(p)";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Employee.class);
rs = q.getResultList();
d2 = (Department) ((Object[]) rs.get(0))[0];
dname = (String) ((Object[]) rs.get(0))[1];
assertEquals(d2.getName(), dname);
query = "select VALUE(p), KEY(p).name from Employee e, " +
" in (e.phones) p ORDER BY VALUE(p)";
q = em.createQuery(query);
if (inMemory)
setCandidate(q, Employee.class);
rs = q.getResultList();
PhoneNumber ph = (PhoneNumber) ((Object[]) rs.get(0))[0];
assertEquals(ph.getNumber(), 1);
em.close();
}