@@ -190,4 +190,72 @@ public void test_SelectQueryWithOptimisticLocking() throws SQLException {
190190 assertEquals (str +"A" , result .get (0 ).getCryptoString ());
191191 }
192192
193+ @ Test
194+ public void test_ScalarColumnQuery () throws SQLException {
195+ // make sure compression is on...
196+ byte [] cryptoBytes1 = CryptoUnitUtils .bytesOfSize (GZIP_THRESHOLD + 101 );
197+ byte [] cryptoBytes2 = CryptoUnitUtils .bytesOfSize (GZIP_THRESHOLD + 102 );
198+
199+ ObjectContext context = runtime .newContext ();
200+
201+ Table2 t1 = context .newObject (Table2 .class );
202+ t1 .setPlainBytes ("a" .getBytes ());
203+ t1 .setCryptoBytes (cryptoBytes1 );
204+
205+ Table2 t2 = context .newObject (Table2 .class );
206+ t2 .setPlainBytes ("b" .getBytes ());
207+ t2 .setCryptoBytes (cryptoBytes2 );
208+
209+ Table2 t3 = context .newObject (Table2 .class );
210+ t3 .setPlainBytes ("c" .getBytes ());
211+ t3 .setCryptoBytes (null );
212+
213+ context .commitChanges ();
214+
215+ List <byte []> result = ObjectSelect .query (Table2 .class )
216+ .column (Table2 .CRYPTO_BYTES )
217+ .orderBy (Table2 .PLAIN_BYTES .asc ())
218+ .select (runtime .newContext ());
219+
220+ assertEquals (3 , result .size ());
221+ assertArrayEquals (cryptoBytes1 , result .get (0 ));
222+ assertArrayEquals (cryptoBytes2 , result .get (1 ));
223+ assertArrayEquals (null , result .get (2 ));
224+ }
225+
226+ @ Test
227+ public void test_MultipleColumnsQuery () throws SQLException {
228+ // make sure compression is on...
229+ byte [] cryptoBytes1 = CryptoUnitUtils .bytesOfSize (GZIP_THRESHOLD + 101 );
230+ byte [] cryptoBytes2 = CryptoUnitUtils .bytesOfSize (GZIP_THRESHOLD + 102 );
231+
232+ ObjectContext context = runtime .newContext ();
233+
234+ Table2 t1 = context .newObject (Table2 .class );
235+ t1 .setPlainBytes ("a" .getBytes ());
236+ t1 .setCryptoBytes (cryptoBytes1 );
237+
238+ Table2 t2 = context .newObject (Table2 .class );
239+ t2 .setPlainBytes ("b" .getBytes ());
240+ t2 .setCryptoBytes (cryptoBytes2 );
241+
242+ Table2 t3 = context .newObject (Table2 .class );
243+ t3 .setPlainBytes ("c" .getBytes ());
244+ t3 .setCryptoBytes (null );
245+
246+ context .commitChanges ();
247+
248+ List <Object []> result = ObjectSelect .query (Table2 .class )
249+ .columns (Table2 .CRYPTO_BYTES , Table2 .PLAIN_BYTES )
250+ .orderBy (Table2 .PLAIN_BYTES .asc ())
251+ .select (runtime .newContext ());
252+
253+ assertEquals (3 , result .size ());
254+ assertArrayEquals (cryptoBytes1 , (byte [])result .get (0 )[0 ]);
255+ assertArrayEquals ("a" .getBytes (), (byte [])result .get (0 )[1 ]);
256+ assertArrayEquals (cryptoBytes2 , (byte [])result .get (1 )[0 ]);
257+ assertArrayEquals ("b" .getBytes (), (byte [])result .get (1 )[1 ]);
258+ assertArrayEquals (null , (byte [])result .get (2 )[0 ]);
259+ }
260+
193261}
0 commit comments