mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Html: Move get_elem_val to xo.elem
This commit is contained in:
72
140_dbs/src/gplx/dbs/engines/mems/Mem_db_fxt.java
Normal file
72
140_dbs/src/gplx/dbs/engines/mems/Mem_db_fxt.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
class Mem_db_fxt {
|
||||
public Mem_db_fxt() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
}
|
||||
public Db_conn Make_conn(String url) {return Db_conn_bldr.Instance.Get_or_autocreate(Bool_.Y, Io_url_.mem_fil_(url));}
|
||||
public Dbmeta_tbl_itm Exec__create_tbl(Db_conn conn, String tbl, String... fld_names) {
|
||||
Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
int len = fld_names.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
flds.Add_str(fld_names[i], 255);
|
||||
Dbmeta_tbl_itm rv = Dbmeta_tbl_itm.New(tbl, flds);
|
||||
conn.Meta_tbl_create(rv);
|
||||
return rv;
|
||||
}
|
||||
public void Exec__insert(Db_conn conn, String tbl_name, String[]... rows) {
|
||||
Mem_engine engine = (Mem_engine)conn.Engine();
|
||||
int rows_len = rows.length;
|
||||
Mem_tbl tbl = engine.Tbls__get(tbl_name);
|
||||
Dbmeta_fld_list flds_list = tbl.Meta().Flds().To_fld_list();
|
||||
int flds_len = flds_list.Len();
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds_list);
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
stmt.Clear();
|
||||
String[] row = rows[i];
|
||||
for (int j = 0; j < flds_len; ++j)
|
||||
stmt.Val_str(flds_list.Get_at(j).Name(), row[j]);
|
||||
stmt.Exec_insert();
|
||||
}
|
||||
}
|
||||
public void Test__select(Db_conn conn, Db_qry qry, String[]... expd) {
|
||||
Db_stmt stmt = conn.Stmt_new(qry);
|
||||
Db_rdr rdr = new Mem_exec_select((Mem_engine)conn.Engine()).Select((Mem_stmt)stmt);
|
||||
List_adp actl_list = List_adp_.New();
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
int expd_len = expd.length;
|
||||
String[] expd_rows = new String[expd_len];
|
||||
for (int i = 0; i < expd_len; ++i) {
|
||||
String[] expd_row = expd[i];
|
||||
for (int j = 0; j < expd_row.length; ++j) {
|
||||
if (j != 0) tmp_bfr.Add_byte_pipe();
|
||||
tmp_bfr.Add_str_u8(expd_row[j]);
|
||||
}
|
||||
expd_rows[i] = tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
while (rdr.Move_next()) {
|
||||
int fld_len = rdr.Fld_len();
|
||||
for (int i = 0; i < fld_len; ++i) {
|
||||
if (i != 0) tmp_bfr.Add_byte_pipe();
|
||||
tmp_bfr.Add_obj_strict(rdr.Read_at(i));
|
||||
}
|
||||
actl_list.Add(tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
Tfds.Eq_ary(expd_rows, (String[])actl_list.To_ary_and_clear(String.class));
|
||||
}
|
||||
}
|
||||
128
140_dbs/src/gplx/dbs/engines/mems/Mem_exec_select_tst.java
Normal file
128
140_dbs/src/gplx/dbs/engines/mems/Mem_exec_select_tst.java
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import org.junit.*; import gplx.dbs.sqls.itms.*;
|
||||
public class Mem_exec_select_tst {
|
||||
private final Mem_db_fxt__single fxt = new Mem_db_fxt__single();
|
||||
@Test public void Basic() {
|
||||
fxt.Exec__create_tbl("tbl_1", "fld_1");
|
||||
fxt.Exec__insert("tbl_1"
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_0")
|
||||
);
|
||||
|
||||
// select all
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_()
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_0")
|
||||
);
|
||||
|
||||
// order by
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Order_("fld_1", Bool_.N)
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_0")
|
||||
);
|
||||
|
||||
// offset
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Offset_(1)
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_0")
|
||||
);
|
||||
|
||||
// limit
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Limit_(2)
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_2")
|
||||
);
|
||||
}
|
||||
@Test public void Join__single() {
|
||||
fxt.Exec__create_tbl("tbl_1", "fld_a", "fld_1a");
|
||||
fxt.Exec__create_tbl("tbl_2", "fld_a", "fld_2a");
|
||||
fxt.Exec__insert("tbl_1"
|
||||
, String_.Ary("a_0", "1a_0")
|
||||
, String_.Ary("a_1", "1a_1")
|
||||
, String_.Ary("a_2", "1a_2")
|
||||
);
|
||||
fxt.Exec__insert("tbl_2"
|
||||
, String_.Ary("a_0", "2a_0")
|
||||
, String_.Ary("a_2", "2a_2")
|
||||
);
|
||||
|
||||
// inner join
|
||||
fxt.Test__select(Db_qry_.select_()
|
||||
.Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a")
|
||||
.From_("tbl_1", "t1")
|
||||
. Join_("tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a"))
|
||||
, String_.Ary("a_0", "1a_0", "2a_0")
|
||||
, String_.Ary("a_2", "1a_2", "2a_2")
|
||||
);
|
||||
|
||||
// left join
|
||||
fxt.Test__select(Db_qry_.select_()
|
||||
.Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a")
|
||||
.From_("tbl_1", "t1")
|
||||
. Join_(Sql_tbl_itm.Tid__left, Sql_tbl_itm.Db__null, "tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a"))
|
||||
, String_.Ary("a_0", "1a_0", "2a_0")
|
||||
, String_.Ary("a_1", "1a_1", Db_null.Null_str)
|
||||
, String_.Ary("a_2", "1a_2", "2a_2")
|
||||
);
|
||||
}
|
||||
@Test public void Join__many() {
|
||||
fxt.Exec__create_tbl("tbl_1", "fld_a", "fld_1a");
|
||||
fxt.Exec__create_tbl("tbl_2", "fld_a", "fld_2a");
|
||||
fxt.Exec__insert("tbl_1"
|
||||
, String_.Ary("a_0", "1a_0")
|
||||
, String_.Ary("a_1", "1a_1")
|
||||
);
|
||||
fxt.Exec__insert("tbl_2"
|
||||
, String_.Ary("a_0", "2a_0")
|
||||
, String_.Ary("a_0", "2a_1")
|
||||
);
|
||||
|
||||
// inner join
|
||||
fxt.Test__select(Db_qry_.select_()
|
||||
.Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a")
|
||||
.From_("tbl_1", "t1")
|
||||
. Join_("tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a"))
|
||||
, String_.Ary("a_0", "1a_0", "2a_0")
|
||||
, String_.Ary("a_0", "1a_0", "2a_1")
|
||||
);
|
||||
|
||||
// left join
|
||||
fxt.Test__select(Db_qry_.select_()
|
||||
.Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a")
|
||||
.From_("tbl_1", "t1")
|
||||
. Join_(Sql_tbl_itm.Tid__left, Sql_tbl_itm.Db__null, "tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a"))
|
||||
, String_.Ary("a_0", "1a_0", "2a_0")
|
||||
, String_.Ary("a_0", "1a_0", "2a_1")
|
||||
, String_.Ary("a_1", "1a_1", Db_null.Null_str)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Mem_db_fxt__single {
|
||||
private final Mem_db_fxt mem_fxt;
|
||||
private final Db_conn conn;
|
||||
public Mem_db_fxt__single() {
|
||||
this.mem_fxt = new Mem_db_fxt();
|
||||
this.conn = mem_fxt.Make_conn("mem/test.db");
|
||||
}
|
||||
public void Exec__create_tbl (String tbl, String... fld_names) {mem_fxt.Exec__create_tbl(conn, tbl, fld_names);}
|
||||
public void Exec__insert (String tbl, String[]... rows) {mem_fxt.Exec__insert(conn, tbl, rows);}
|
||||
public void Test__select (Db_qry qry, String[]... expd) {mem_fxt.Test__select(conn, qry, expd);}
|
||||
}
|
||||
30
140_dbs/src/gplx/dbs/engines/tdbs/TdbConnectInfo_tst.java
Normal file
30
140_dbs/src/gplx/dbs/engines/tdbs/TdbConnectInfo_tst.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import org.junit.*;
|
||||
public class TdbConnectInfo_tst {
|
||||
@Test public void Full() {
|
||||
Db_conn_info connectInfo = Db_conn_info_.parse("gplx_key=tdb;url=C:\\dir\\xmpl.tdb;format=dsv;");
|
||||
tst_Parse(connectInfo, Io_url_.new_any_("C:\\dir\\xmpl.tdb"), "dsv");
|
||||
}
|
||||
@Test public void DefaultFormat() {
|
||||
Db_conn_info connectInfo = Db_conn_info_.parse("gplx_key=tdb;url=C:\\dir\\xmpl.tdb"); // dsv Format inferred
|
||||
tst_Parse(connectInfo, Io_url_.new_any_("C:\\dir\\xmpl.tdb"), "dsv");
|
||||
}
|
||||
void tst_Parse(Db_conn_info connectInfo, Io_url url, String format) {
|
||||
Tfds.Eq(((Tdb_conn_info)connectInfo).Url(), url);
|
||||
}
|
||||
}
|
||||
99
140_dbs/src/gplx/dbs/engines/tdbs/TdbDbLoadMgr_tst.java
Normal file
99
140_dbs/src/gplx/dbs/engines/tdbs/TdbDbLoadMgr_tst.java
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
import gplx.core.stores.*; /*DsvDataRdr*/ import gplx.langs.dsvs.*; /*DsvDataWtr*/
|
||||
public class TdbDbLoadMgr_tst {
|
||||
@Before public void setup() {
|
||||
Io_url dbInfo = Io_url_.mem_fil_("mem/dir/db0.dsv");
|
||||
db = TdbDatabase.new_(dbInfo);
|
||||
wtr = DsvDataWtr_.new_();
|
||||
}
|
||||
TdbDatabase db; TdbDbLoadMgr loadMgr = TdbDbLoadMgr.new_(); TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_();
|
||||
DataRdr rdr; DataWtr wtr;
|
||||
@Test public void ReadDbFiles() {
|
||||
String raw = String_.Concat_lines_crlf
|
||||
( "=======DIF======================, ,\" \",//"
|
||||
, "_files, ,\" \",#"
|
||||
, "==DEF==DIF======================, ,\" \",//"
|
||||
, "int," + StringClassXtn.Key_const + "," + StringClassXtn.Key_const + ", ,\" \",$"
|
||||
, "id,url,format, ,\" \",@"
|
||||
, "==DATA=DIF======================, ,\" \",//"
|
||||
, "1,mem/dir/db0.dsv,dsv"
|
||||
, "2,C:\\file.dsv,dsv"
|
||||
);
|
||||
rdr = rdr_(raw);
|
||||
|
||||
db.Files().DataObj_Rdr(rdr);
|
||||
Tfds.Eq(db.Files().Count(), 2);
|
||||
TdbFile file2 = db.Files().Get_by_or_fail(2);
|
||||
Tfds.Eq(file2.Path().Raw(), "C:\\file.dsv");
|
||||
|
||||
db.Files().DataObj_Wtr(wtr);
|
||||
Tfds.Eq(wtr.To_str(), raw);
|
||||
}
|
||||
@Test public void ReadDbTbls() {
|
||||
String raw = String_.Concat_lines_crlf
|
||||
( "=======DIF======================, ,\" \",//"
|
||||
, "_tables, ,\" \",#"
|
||||
, "==DEF==DIF======================, ,\" \",//"
|
||||
, "int," + StringClassXtn.Key_const + ",int, ,\" \",$"
|
||||
, "id,name,file_id, ,\" \",@"
|
||||
, "==DATA=DIF======================, ,\" \",//"
|
||||
, "1,tbl1,1"
|
||||
);
|
||||
rdr = rdr_(raw);
|
||||
|
||||
db.Tables().DataObj_Rdr(rdr, db.Files());
|
||||
Tfds.Eq(db.Tables().Count(), 1);
|
||||
TdbTable table = db.Tables().Get_by_or_fail("tbl1");
|
||||
Tfds.Eq(table.Name(), "tbl1");
|
||||
Tfds.Eq(table.File().Id(), 1);
|
||||
|
||||
db.Tables().DataObj_Wtr(wtr);
|
||||
Tfds.Eq(wtr.To_str(), raw);
|
||||
}
|
||||
@Test public void ReadTbl() {
|
||||
String raw = String_.Concat_lines_crlf
|
||||
( "=======DIF======================, ,\" \",//"
|
||||
, "tbl0, ,\" \",#"
|
||||
, "==DEF==DIF======================, ,\" \",//"
|
||||
, "int," + StringClassXtn.Key_const + ", ,\" \",$"
|
||||
, "id,name, ,\" \",@"
|
||||
, "==DATA=DIF======================, ,\" \",//"
|
||||
, "0,me"
|
||||
);
|
||||
rdr = rdr_(raw);
|
||||
|
||||
db.MakeTbl("tbl0", TdbFile.MainFileId);
|
||||
db.Tables().Get_by_or_fail(rdr.NameOfNode()).DataObj_Rdr(rdr);
|
||||
Tfds.Eq(db.Tables().Count(), 1);
|
||||
TdbTable tbl = db.Tables().Get_by_or_fail("tbl0");
|
||||
Tfds.Eq(tbl.Rows().Count(), 1);
|
||||
|
||||
GfoNde row = tbl.Rows().FetchAt_asGfoNde(0);
|
||||
Tfds.Eq(row.Read("id"), 0);
|
||||
Tfds.Eq(row.Read("name"), "me");
|
||||
|
||||
tbl.DataObj_Wtr(wtr);
|
||||
Tfds.Eq(wtr.To_str(), raw);
|
||||
}
|
||||
DataRdr rdr_(String raw) {
|
||||
DataRdr rdr = DsvDataRdr_.dsv_(raw);
|
||||
rdr.MoveNextPeer(); // must move next as cur is not set and ReadProcs assume cur is set
|
||||
return rdr;
|
||||
}
|
||||
}
|
||||
75
140_dbs/src/gplx/dbs/engines/tdbs/TdbDbSaveMgr_tst.java
Normal file
75
140_dbs/src/gplx/dbs/engines/tdbs/TdbDbSaveMgr_tst.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import org.junit.*; import gplx.core.stores.*;
|
||||
import gplx.langs.dsvs.*; import gplx.core.type_xtns.*;
|
||||
public class TdbDbSaveMgr_tst {
|
||||
@Before public void setup() {
|
||||
Io_url dbInfo = Io_url_.mem_fil_("mem/dir/db0.dsv");
|
||||
db = TdbDatabase.new_(dbInfo);
|
||||
wtr.Clear();
|
||||
} TdbDatabase db; TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_(); DataWtr wtr = DsvDataWtr_.new_();
|
||||
@Test public void WriteDbFils() {
|
||||
String expd = String_.Concat_lines_crlf
|
||||
( ""
|
||||
, ""
|
||||
, "================================, ,\" \",//"
|
||||
, "_files, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int," + StringClassXtn.Key_const + "," + StringClassXtn.Key_const + ", ,\" \",$"
|
||||
, "id,url,format, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
, "1,mem/dir/db0.dsv,dsv"
|
||||
);
|
||||
db.Files().DataObj_Wtr(wtr);
|
||||
String actl = wtr.To_str();
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
@Test public void WriteDbTbls() {
|
||||
String expd = String_.Concat_lines_crlf
|
||||
( ""
|
||||
, ""
|
||||
, "================================, ,\" \",//"
|
||||
, "_tables, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int," + StringClassXtn.Key_const + ",int, ,\" \",$"
|
||||
, "id,name,file_id, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
);
|
||||
db.Tables().DataObj_Wtr(wtr);
|
||||
String actl = wtr.To_str();
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
@Test public void WriteTbl() {
|
||||
String expd = String_.Concat_lines_crlf
|
||||
( ""
|
||||
, ""
|
||||
, "================================, ,\" \",//"
|
||||
, "tbl, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int," + StringClassXtn.Key_const + ", ,\" \",$"
|
||||
, "id,name, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
);
|
||||
TdbTable tbl = db.MakeTbl("tbl", TdbFile.MainFileId);
|
||||
tbl.Flds().Add("id", IntClassXtn.Instance);
|
||||
tbl.Flds().Add("name", StringClassXtn.Instance);
|
||||
|
||||
tbl.DataObj_Wtr(wtr);
|
||||
String actl = wtr.To_str();
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
}
|
||||
117
140_dbs/src/gplx/dbs/engines/tdbs/TdbFlush_tst.java
Normal file
117
140_dbs/src/gplx/dbs/engines/tdbs/TdbFlush_tst.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.ios.*; /*IoMgrFxt*/ import gplx.dbs.qrys.*; import gplx.core.type_xtns.*;
|
||||
public class TdbFlush_tst {
|
||||
@Before public void setup() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
engine = fx_engine.run_MakeEngine(dbPath);
|
||||
}
|
||||
TdbEngine engine; Io_url dbPath = Io_url_.mem_fil_("mem/dir/db0.dsv"); DateAdp time = DateAdp_.parse_gplx("2001-01-01");
|
||||
TdbEngineFxt fx_engine = TdbEngineFxt.new_(); IoMgrFxt fx_io = IoMgrFxt.new_();
|
||||
@Test public void FlushNewDb() {
|
||||
fx_engine.tst_FilesCount(engine, 1);
|
||||
fx_engine.tst_File(engine, 0, TdbFile.MainFileId, Io_url_.mem_fil_("mem/dir/db0.dsv"), "dsv");
|
||||
fx_io.tst_Exists(false, dbPath);
|
||||
|
||||
engine.FlushAll();
|
||||
fx_io.tst_Exists(true, dbPath);
|
||||
}
|
||||
@Test public void IgnoreFlushedDb() {
|
||||
engine.FlushAll();
|
||||
fx_io.tst_Exists(true, dbPath);
|
||||
fx_io.run_UpdateFilModifiedTime(dbPath, time);
|
||||
|
||||
engine.FlushAll();
|
||||
fx_io.tst_QueryFilModified(true, dbPath, time);
|
||||
}
|
||||
@Test public void FlushNewTbl() {
|
||||
engine.FlushAll();
|
||||
fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId);
|
||||
fx_io.run_UpdateFilModifiedTime(dbPath, time);
|
||||
|
||||
engine.FlushAll();
|
||||
fx_io.tst_QueryFilModified(false, dbPath, time);
|
||||
}
|
||||
@Test public void IgnoreFlushedTbl() {
|
||||
fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId);
|
||||
engine.FlushAll();
|
||||
fx_io.run_UpdateFilModifiedTime(dbPath, time);
|
||||
|
||||
engine.FlushAll();
|
||||
fx_io.tst_QueryFilModified(true, dbPath, time);
|
||||
}
|
||||
@Test public void FlushDirtyTbl() {
|
||||
fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId);
|
||||
engine.FlushAll();
|
||||
fx_io.run_UpdateFilModifiedTime(dbPath, time);
|
||||
|
||||
fx_engine.run_InsertRow(engine, "tbl0", 1);
|
||||
engine.FlushAll();
|
||||
fx_io.tst_QueryFilModified(false, dbPath, time);
|
||||
}
|
||||
@Test public void FlushDirtyFilOnly() {
|
||||
Io_url dbPathOther = Io_url_.mem_fil_("mem/dir/db1.dsv");
|
||||
TdbFile filOther = fx_engine.run_MakeFile(engine, dbPathOther); Tfds.Eq(false, Object_.Eq(filOther.Id(), TdbFile.MainFileId));
|
||||
fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId); fx_engine.run_MakeTbl(engine, "tbl1", filOther.Id());
|
||||
engine.FlushAll();
|
||||
fx_io.run_UpdateFilModifiedTime(dbPath, time); fx_io.run_UpdateFilModifiedTime(dbPathOther, time);
|
||||
|
||||
fx_engine.run_InsertRow(engine, "tbl1", 1);
|
||||
engine.FlushAll();
|
||||
fx_io.tst_QueryFilModified(true, dbPath, time);
|
||||
fx_io.tst_QueryFilModified(false, dbPathOther, time);
|
||||
}
|
||||
}
|
||||
class TdbEngineFxt {
|
||||
public TdbEngine run_MakeEngine(Io_url url) {
|
||||
Db_conn_info connectInfo = Db_conn_info_.tdb_(url);
|
||||
TdbEngine engine = (TdbEngine)TdbEngine.Instance.New_clone(connectInfo);
|
||||
engine.Conn_open();
|
||||
return engine;
|
||||
}
|
||||
public TdbFile run_MakeFile(TdbEngine engine, Io_url url) {return engine.Db().MakeFile(url);}
|
||||
public TdbTable run_MakeTbl(TdbEngine engine, String tblName, int srcId) {
|
||||
TdbTable rv = engine.Db().MakeTbl(tblName, srcId);
|
||||
rv.Flds().Add("id", IntClassXtn.Instance);
|
||||
return rv;
|
||||
}
|
||||
public void run_InsertRow(TdbEngine engine, String tblName, int idVal) {
|
||||
Db_qry_insert cmd = new Db_qry_insert(tblName);
|
||||
cmd.Val_int("id", idVal);
|
||||
engine.Exec_as_obj(cmd);
|
||||
}
|
||||
|
||||
public void tst_FilesCount(TdbEngine engine, int count) {Tfds.Eq(engine.Db().Files().Count(), count);}
|
||||
public void tst_File(TdbEngine engine, int index, int id, Io_url url, String format) {
|
||||
TdbFile src = engine.Db().Files().Get_by_or_fail(id);
|
||||
Tfds.Eq(src.Path().Raw(), url.Raw());
|
||||
}
|
||||
public static TdbEngineFxt new_() {return new TdbEngineFxt();} TdbEngineFxt() {}
|
||||
}
|
||||
class IoMgrFxt {
|
||||
public void run_UpdateFilModifiedTime(Io_url url, DateAdp val) {Io_mgr.Instance.UpdateFilModifiedTime(url, val);}
|
||||
public void tst_QueryFilModified(boolean expdMatch, Io_url url, DateAdp expt) {
|
||||
IoItmFil filItem = Io_mgr.Instance.QueryFil(url);
|
||||
DateAdp actl = filItem.ModifiedTime();
|
||||
boolean actlMatch = String_.Eq(expt.XtoStr_gplx(), actl.XtoStr_gplx());
|
||||
Tfds.Eq(expdMatch, actlMatch, expt.XtoStr_gplx() + (expdMatch ? "!=" : "==") + actl.XtoStr_gplx());
|
||||
}
|
||||
public void tst_Exists(boolean expd, Io_url url) {Tfds.Eq(expd, Io_mgr.Instance.ExistsFil(url));}
|
||||
|
||||
public static IoMgrFxt new_() {return new IoMgrFxt();} IoMgrFxt() {}
|
||||
}
|
||||
Reference in New Issue
Block a user