GroupBys_base_tst.java 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. XOWA: the XOWA Offline Wiki Application
  3. Copyright (C) 2012 gnosygnu@gmail.com
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as
  6. published by the Free Software Foundation, either version 3 of the
  7. License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package gplx.dbs.groupBys; import gplx.*; import gplx.dbs.*;
  16. import org.junit.*; import gplx.dbs.qrys.*; import gplx.core.gfo_ndes.*; import gplx.core.stores.*;
  17. public abstract class GroupBys_base_tst {
  18. protected abstract Db_conn provider_();
  19. protected Db_conn conn;
  20. @Before public void setup() {
  21. conn = provider_();
  22. Db_qry_.delete_tbl_("dbs_group_bys").Exec_qry(conn);
  23. }
  24. @After public void teardown() {
  25. conn.Rls_conn();
  26. }
  27. protected void GroupBy_1fld_hook() {
  28. conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 1));
  29. conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 2));
  30. DataRdr rdr = conn.Exec_qry_as_old_rdr
  31. (Db_qry_.select_().From_("dbs_group_bys")
  32. .Cols_("key1")
  33. .GroupBy_("key1"));
  34. GfoNde nde = GfoNde_.rdr_(rdr);
  35. GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
  36. }
  37. protected void GroupBy_2fld_hook() {
  38. conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_str("key2", "b").Val_int("val_int", 1));
  39. conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_str("key2", "b").Val_int("val_int", 2));
  40. DataRdr rdr = conn.Exec_qry_as_old_rdr
  41. (Db_qry_.select_().From_("dbs_group_bys")
  42. .Cols_("key1", "key2")
  43. .GroupBy_("key1", "key2"));
  44. GfoNde nde = GfoNde_.rdr_(rdr);
  45. GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
  46. GfoNdeTstr.tst_ValsByCol(nde, "key2", "b");
  47. }
  48. protected void MinMax_hook(boolean min) {
  49. conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 1));
  50. conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 2));
  51. Db_qry__select_cmd qry = Db_qry_.select_().From_("dbs_group_bys")
  52. .Cols_("key1")
  53. .GroupBy_("key1");
  54. int expd = min ? 1 : 2;
  55. if (min)
  56. qry.Cols_groupBy_min("val_int", "val_int_func");
  57. else
  58. qry.Cols_groupBy_max("val_int", "val_int_func");
  59. DataRdr rdr = conn.Exec_qry_as_old_rdr(qry);
  60. GfoNde nde = GfoNde_.rdr_(rdr);
  61. GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
  62. GfoNdeTstr.tst_ValsByCol(nde, "val_int_func", expd);
  63. }
  64. protected void Count_hook() {
  65. conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 10));
  66. conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 20));
  67. DataRdr rdr = conn.Exec_qry_as_old_rdr
  68. (Db_qry_.select_().From_("dbs_group_bys")
  69. .Cols_("key1").Cols_groupBy_count("val_int", "val_int_func")
  70. .GroupBy_("key1"));
  71. GfoNde nde = GfoNde_.rdr_(rdr);
  72. GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
  73. GfoNdeTstr.tst_ValsByCol(nde, "val_int_func", 2);
  74. }
  75. protected void Sum_hook() {
  76. conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 10));
  77. conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 20));
  78. DataRdr rdr = conn.Exec_qry_as_old_rdr
  79. (Db_qry_.select_().From_("dbs_group_bys")
  80. .Cols_("key1").Cols_groupBy_sum("val_int", "val_int_func")
  81. .GroupBy_("key1"));
  82. GfoNde nde = GfoNde_.rdr_(rdr);
  83. GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
  84. GfoNdeTstr.tst_ValsByCol(nde, "val_int_func", 30);
  85. }
  86. }