mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Refactor Dbmeta classes; Rename methods of list and hash classes
This commit is contained in:
@@ -13,7 +13,7 @@ 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.core.stores; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.stores; import gplx.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; /*Db_conn_info*/
|
||||
public class DbMaprMgr_tst {
|
||||
@@ -95,7 +95,7 @@ public class DbMaprMgr_tst {
|
||||
|
||||
Tfds.Eq(1, disc.Id());
|
||||
Tfds.Eq("name", disc.Name());
|
||||
Tfds.Eq(0, disc.Titles().Count());
|
||||
Tfds.Eq(0, disc.Titles().Len());
|
||||
}
|
||||
@Test public void Load_subs() {
|
||||
rdr = rdr_();
|
||||
@@ -106,7 +106,7 @@ public class DbMaprMgr_tst {
|
||||
|
||||
Tfds.Eq(1, disc.Id());
|
||||
Tfds.Eq("name", disc.Name());
|
||||
Tfds.Eq(2, disc.Titles().Count());
|
||||
Tfds.Eq(2, disc.Titles().Len());
|
||||
Tfds.Eq("title1", ((MockTitle)disc.Titles().Get_at(0)).Name());
|
||||
Tfds.Eq("title2", ((MockTitle)disc.Titles().Get_at(1)).Name());
|
||||
}
|
||||
@@ -121,12 +121,12 @@ public class DbMaprMgr_tst {
|
||||
|
||||
Tfds.Eq(1, disc.Id());
|
||||
Tfds.Eq("name", disc.Name());
|
||||
Tfds.Eq(1, disc.Titles().Count());
|
||||
Tfds.Eq(1, disc.Titles().Len());
|
||||
MockTitle t = ((MockTitle)disc.Titles().Get_at(0));
|
||||
Tfds.Eq("title1", t.Name());
|
||||
Tfds.Eq("chapter1", ((MockChapter)t.Chapters().Get_at(0)).Name());
|
||||
Tfds.Eq(1, t.Audios().Count());
|
||||
Tfds.Eq(1, t.Subtitles().Count());
|
||||
Tfds.Eq(1, t.Audios().Len());
|
||||
Tfds.Eq(1, t.Subtitles().Len());
|
||||
Tfds.Eq("audio1", ((MockStream)t.Audios().Get_at(0)).Name());
|
||||
Tfds.Eq("subtitle1", ((MockStream)t.Subtitles().Get_at(0)).Name());
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Db_conn_fxt implements Rls_able {
|
||||
public void tst_ExecDml(int expd, Db_qry qry) {
|
||||
int actl = conn.Exec_qry(qry);
|
||||
if (dmlAffectedAvailable)
|
||||
Tfds.Eq(expd, actl, "Exec_qry failed: sql={0}", qry.To_sql__exec(conn.Engine().Sql_wtr()));
|
||||
Tfds.Eq(expd, actl, "Exec_qry failed: sql={0}", qry.ToSqlExec(conn.Engine().Sql_wtr()));
|
||||
}
|
||||
public void tst_ExecRdrTbl(int expd, String tblName) {tst_ExecRdr(expd, Db_qry_.select_tbl_(tblName));}
|
||||
public void tst_ExecRdr(int expd, Db_qry qry) {
|
||||
@@ -33,7 +33,7 @@ public class Db_conn_fxt implements Rls_able {
|
||||
tbl = GfoNde_.rdr_(rdr);
|
||||
}
|
||||
catch (Exception e) {Err_.Noop(e); rdr.Rls();}
|
||||
Tfds.Eq(expd, tbl.Subs().Count(), "Exec_qry_as_rdr failed: sql={0}", qry.To_sql__exec(conn.Engine().Sql_wtr()));
|
||||
Tfds.Eq(expd, tbl.Subs().Count(), "Exec_qry_as_rdr failed: sql={0}", qry.ToSqlExec(conn.Engine().Sql_wtr()));
|
||||
} GfoNde tbl;
|
||||
public GfoNde tst_RowAry(int index, Object... expdValAry) {
|
||||
GfoNde record = tbl.Subs().FetchAt_asGfoNde(index);
|
||||
|
||||
@@ -13,19 +13,19 @@ 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; import gplx.*;
|
||||
import gplx.core.gfo_ndes.*;
|
||||
public class GfoNdeTstr {
|
||||
public static void tst_ValsByCol(GfoNde nde, String fld, Object... expdAry) {
|
||||
List_adp expd = List_adp_.New();
|
||||
for (int i = 0; i < expdAry.length; i++) {
|
||||
expd.Add(Object_.Xto_str_strict_or_empty(expdAry[i]));
|
||||
}
|
||||
List_adp actl = List_adp_.New();
|
||||
for (int i = 0; i < nde.Subs().Count(); i++) {
|
||||
GfoNde sub = nde.Subs().FetchAt_asGfoNde(i);
|
||||
actl.Add(Object_.Xto_str_strict_or_empty(sub.Read(fld)));
|
||||
}
|
||||
Tfds.Eq_ary(expd.To_str_ary(), actl.To_str_ary());
|
||||
}
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.core.gfo_ndes.*;
|
||||
public class GfoNdeTstr {
|
||||
public static void tst_ValsByCol(GfoNde nde, String fld, Object... expdAry) {
|
||||
List_adp expd = List_adp_.New();
|
||||
for (int i = 0; i < expdAry.length; i++) {
|
||||
expd.Add(Object_.Xto_str_strict_or_empty(expdAry[i]));
|
||||
}
|
||||
List_adp actl = List_adp_.New();
|
||||
for (int i = 0; i < nde.Subs().Count(); i++) {
|
||||
GfoNde sub = nde.Subs().FetchAt_asGfoNde(i);
|
||||
actl.Add(Object_.Xto_str_strict_or_empty(sub.Read(fld)));
|
||||
}
|
||||
Tfds.Eq_ary(expd.ToStrAry(), actl.ToStrAry());
|
||||
}
|
||||
}
|
||||
@@ -23,18 +23,18 @@ public class Sql_schema_wtr_tst {
|
||||
);
|
||||
}
|
||||
@Test public void Tbl_basic() {
|
||||
Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
flds.Add_int_pkey("fld_int_pkey");
|
||||
flds.Add_bool("fld_bool");
|
||||
flds.Add_short("fld_short");
|
||||
flds.Add_int("fld_int");
|
||||
flds.Add_long("fld_long");
|
||||
flds.Add_float("fld_float");
|
||||
flds.Add_double("fld_double");
|
||||
flds.Add_str("fld_str", 123);
|
||||
flds.Add_text("fld_text");
|
||||
flds.Add_bry("fld_bry");
|
||||
fxt.Test_create_tbl(Dbmeta_tbl_itm.New("tbl_name", flds.To_fld_ary())
|
||||
DbmetaFldList flds = new DbmetaFldList();
|
||||
flds.AddIntPkey("fld_int_pkey");
|
||||
flds.AddBool("fld_bool");
|
||||
flds.AddShort("fld_short");
|
||||
flds.AddInt("fld_int");
|
||||
flds.AddLong("fld_long");
|
||||
flds.AddFloat("fld_float");
|
||||
flds.AddDouble("fld_double");
|
||||
flds.AddStr("fld_str", 123);
|
||||
flds.AddText("fld_text");
|
||||
flds.AddBry("fld_bry");
|
||||
fxt.Test_create_tbl(Dbmeta_tbl_itm.New("tbl_name", flds.ToFldAry())
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "CREATE TABLE IF NOT EXISTS tbl_name"
|
||||
, "( fld_int_pkey integer NOT NULL PRIMARY KEY"
|
||||
@@ -51,16 +51,16 @@ public class Sql_schema_wtr_tst {
|
||||
));
|
||||
}
|
||||
@Test public void Tbl_alter_tbl_add() {
|
||||
Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
flds.Add_int_dflt("fld_int", -1);
|
||||
flds.Add_str_dflt("fld_str", 255, "a");
|
||||
fxt.Test_alter_tbl_add("tbl_name", flds.Get_by("fld_int"), "ALTER TABLE tbl_name ADD fld_int integer NOT NULL DEFAULT -1;");
|
||||
fxt.Test_alter_tbl_add("tbl_name", flds.Get_by("fld_str"), "ALTER TABLE tbl_name ADD fld_str varchar(255) NOT NULL DEFAULT 'a';");
|
||||
DbmetaFldList flds = new DbmetaFldList();
|
||||
flds.AddIntDflt("fld_int", -1);
|
||||
flds.AddStrDflt("fld_str", 255, "a");
|
||||
fxt.Test_alter_tbl_add("tbl_name", flds.GetByOrNull("fld_int"), "ALTER TABLE tbl_name ADD fld_int integer NOT NULL DEFAULT -1;");
|
||||
fxt.Test_alter_tbl_add("tbl_name", flds.GetByOrNull("fld_str"), "ALTER TABLE tbl_name ADD fld_str varchar(255) NOT NULL DEFAULT 'a';");
|
||||
}
|
||||
}
|
||||
class Sql_schema_wtr_fxt {
|
||||
private Sql_schema_wtr sqlbldr = SqlQryWtrUtl.NewSqlite().Schema_wtr();
|
||||
public void Test_create_idx(Dbmeta_idx_itm idx, String expd) {Tfds.Eq(expd, sqlbldr.Bld_create_idx(idx));}
|
||||
public void Test_create_tbl(Dbmeta_tbl_itm tbl, String expd) {Tfds.Eq_str_lines(expd, sqlbldr.Bld_create_tbl(tbl));}
|
||||
public void Test_alter_tbl_add(String tbl, Dbmeta_fld_itm fld, String expd) {Tfds.Eq_str_lines(expd, sqlbldr.Bld_alter_tbl_add(tbl, fld));}
|
||||
public void Test_alter_tbl_add(String tbl, DbmetaFldItm fld, String expd) {Tfds.Eq_str_lines(expd, sqlbldr.Bld_alter_tbl_add(tbl, fld));}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user