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 .CapsStrategy ;
28
29
import org .apache .cayenne .query .ObjectSelect ;
29
30
import org .apache .cayenne .query .SQLTemplate ;
30
31
import org .apache .cayenne .query .SelectQuery ;
32
+ import org .apache .cayenne .query .EJBQLQuery ;
31
33
import org .apache .cayenne .test .jdbc .DBHelper ;
32
34
import org .apache .cayenne .test .jdbc .TableHelper ;
33
35
import org .apache .cayenne .testdo .lob .ClobTestEntity ;
@@ -96,28 +98,6 @@ public void testColumnSelect_DistinctResultIterator() throws Exception {
96
98
@ Test
97
99
public void testAddingDistinctToQuery () throws Exception {
98
100
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
101
122
102
TableHelper tDistEntity = new TableHelper (dbHelper , "DIST_ENTITY" );
123
103
tDistEntity .setColumns ("ID" , "NAME" , "FIELD" );
@@ -141,7 +121,9 @@ public void testAddingDistinctToQuery() throws Exception{
141
121
ObjectContext objectContext = serverRuntime .newContext ();
142
122
143
123
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')" );
124
+ select .setColumnNamesCapitalization (CapsStrategy .UPPER );
144
125
List <DistEntity > list1 = objectContext .performQuery (select );
126
+
145
127
assertEquals (4 , list1 .size ());
146
128
147
129
List <DistEntity > list2 = ObjectSelect .query (DistEntity .class )
@@ -150,6 +132,27 @@ public void testAddingDistinctToQuery() throws Exception{
150
132
.select (objectContext );
151
133
152
134
assertEquals (1 ,list2 .size ());
135
+
136
+ EJBQLQuery query1 = new EJBQLQuery ("select d FROM DistEntity d JOIN d.distRel r where d.name='dist_entity1' and r.num>0" );
137
+ List <DistEntity > list3 = context .performQuery (query1 );
138
+
139
+ assertEquals (4 ,list3 .size ());
140
+
141
+ List <String > list4 = ObjectSelect
142
+ .columnQuery (DistEntity .class , DistEntity .NAME )
143
+ .where (DistEntity .DIST_REL .dot (DistEntityRel .NUM ).gt (0 ))
144
+ .and (DistEntity .NAME .eq ("dist_entity1" ))
145
+ .select (context );
146
+
147
+ assertEquals (1 ,list4 .size ());
148
+
149
+ List <Object []> list5 = ObjectSelect
150
+ .columnQuery (DistEntity .class , DistEntity .NAME , DistEntity .FIELD )
151
+ .where (DistEntity .DIST_REL .dot (DistEntityRel .NUM ).gt (0 ))
152
+ .and (DistEntity .NAME .eq ("dist_entity1" ))
153
+ .select (context );
154
+
155
+ assertEquals (1 ,list5 .size ());
153
156
}
154
157
}
155
158
0 commit comments