25
25
import org .apache .cayenne .di .Inject ;
26
26
import org .apache .cayenne .exp .Expression ;
27
27
import org .apache .cayenne .exp .ExpressionFactory ;
28
- import org .apache .cayenne .query .ObjectSelect ;
29
- import org .apache .cayenne .query .SQLTemplate ;
30
- import org .apache .cayenne .query .SelectQuery ;
28
+ import org .apache .cayenne .query .*;
31
29
import org .apache .cayenne .test .jdbc .DBHelper ;
32
30
import org .apache .cayenne .test .jdbc .TableHelper ;
33
31
import org .apache .cayenne .testdo .lob .ClobTestEntity ;
@@ -96,28 +94,6 @@ public void testColumnSelect_DistinctResultIterator() throws Exception {
96
94
@ Test
97
95
public void testAddingDistinctToQuery () throws Exception {
98
96
if (accessStackAdapter .supportsLobs ()){
99
- // DistEntity obj = context.newObject(DistEntity.class);
100
- // obj.setName("ABC");
101
- // obj.setField("test".getBytes());
102
- // DistEntity obj2 = context.newObject(DistEntity.class);
103
- // obj2.setName("ABC1");
104
- // obj2.setField("test".getBytes());
105
- //
106
- // DistEntityRel objRel1 = context.newObject(DistEntityRel.class);
107
- // objRel1.setNum(5);
108
- // DistEntityRel objRel2 = context.newObject(DistEntityRel.class);
109
- // objRel2.setNum(6);
110
- // DistEntityRel objRel3 = context.newObject(DistEntityRel.class);
111
- // objRel3.setNum(7);
112
- // DistEntityRel objRel4 = context.newObject(DistEntityRel.class);
113
- // objRel4.setNum(5);
114
- //
115
- // obj.addToDistRel(objRel1);
116
- // obj.addToDistRel(objRel2);
117
- // obj.addToDistRel(objRel3);
118
- // obj2.addToDistRel(objRel4);
119
-
120
- // context.commitChanges();
121
97
122
98
TableHelper tDistEntity = new TableHelper (dbHelper , "DIST_ENTITY" );
123
99
tDistEntity .setColumns ("ID" , "NAME" , "FIELD" );
@@ -141,7 +117,9 @@ public void testAddingDistinctToQuery() throws Exception{
141
117
ObjectContext objectContext = serverRuntime .newContext ();
142
118
143
119
SQLTemplate select = new SQLTemplate (DistEntity .class , "SELECT t0.FIELD, t0.NAME, t0.ID FROM DIST_ENTITY t0 JOIN DIST_ENTITY_REL t1 ON (t0.ID = t1.DIST_ID) WHERE (t1.NUM > 0) AND (t0.NAME LIKE 'dist_entity1')" );
120
+ select .setColumnNamesCapitalization (CapsStrategy .UPPER );
144
121
List <DistEntity > list1 = objectContext .performQuery (select );
122
+
145
123
assertEquals (4 , list1 .size ());
146
124
147
125
List <DistEntity > list2 = ObjectSelect .query (DistEntity .class )
@@ -150,6 +128,27 @@ public void testAddingDistinctToQuery() throws Exception{
150
128
.select (objectContext );
151
129
152
130
assertEquals (1 ,list2 .size ());
131
+
132
+ EJBQLQuery query1 = new EJBQLQuery ("select d FROM DistEntity d JOIN d.distRel r where d.name='dist_entity1' and r.num>0" );
133
+ List <DistEntity > list3 = context .performQuery (query1 );
134
+
135
+ assertEquals (4 ,list3 .size ());
136
+
137
+ List <String > list4 = ObjectSelect
138
+ .columnQuery (DistEntity .class , DistEntity .NAME )
139
+ .where (DistEntity .DIST_REL .dot (DistEntityRel .NUM ).gt (0 ))
140
+ .and (DistEntity .NAME .eq ("dist_entity1" ))
141
+ .select (context );
142
+
143
+ assertEquals (1 ,list4 .size ());
144
+
145
+ List <Object []> list5 = ObjectSelect
146
+ .columnQuery (DistEntity .class , DistEntity .NAME , DistEntity .FIELD )
147
+ .where (DistEntity .DIST_REL .dot (DistEntityRel .NUM ).gt (0 ))
148
+ .and (DistEntity .NAME .eq ("dist_entity1" ))
149
+ .select (context );
150
+
151
+ assertEquals (1 ,list5 .size ());
153
152
}
154
153
}
155
154
0 commit comments