Joins_base_tst.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.joins; import gplx.*; import gplx.dbs.*;
  16. import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.*; import gplx.core.stores.*;
  17. public abstract class Joins_base_tst {
  18. protected Db_conn conn;
  19. @Before public void setup() {
  20. conn = provider_();
  21. Db_qry_delete.new_("dbs_crud_ops").Exec_qry(conn);
  22. Db_qry_delete.new_("dbs_join1").Exec_qry(conn);
  23. }
  24. @After public void teardown() {
  25. conn.Rls_conn();
  26. }
  27. protected void InnerJoin_hook() {
  28. conn.Exec_qry(new Db_qry_insert("dbs_crud_ops").Val_int("id", 0).Val_str("name", "me"));
  29. conn.Exec_qry(new Db_qry_insert("dbs_crud_ops").Val_int("id", 1).Val_str("name", "you"));
  30. conn.Exec_qry(new Db_qry_insert("dbs_join1").Val_int("join_id", 0).Val_str("join_data", "data0"));
  31. conn.Exec_qry(new Db_qry_insert("dbs_join1").Val_int("join_id", 1).Val_str("join_data", "data1"));
  32. Db_qry__select_cmd select = new Db_qry__select_cmd().From_("dbs_crud_ops").Join_("dbs_join1", "j1", Db_qry_.New_join__join("join_id", "dbs_crud_ops", "id")).Cols_("id", "name", "join_data");
  33. DataRdr rdr = conn.Exec_qry_as_old_rdr(select);
  34. GfoNde table = GfoNde_.rdr_(rdr);
  35. Tfds.Eq(table.Subs().Count(), 2);
  36. Tfds.Eq(table.Subs().FetchAt_asGfoNde(0).Read("join_data"), "data0");
  37. Tfds.Eq(table.Subs().FetchAt_asGfoNde(1).Read("join_data"), "data1");
  38. }
  39. protected abstract Db_conn provider_();
  40. }