1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Refactor: Remove whitespace after final and remove @gplx.Virtual

This commit is contained in:
gnosygnu
2021-11-28 08:45:40 -05:00
parent b0082fd231
commit 231e10bc19
2362 changed files with 43007 additions and 42938 deletions

View File

@@ -0,0 +1,34 @@
/*
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.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
import gplx.core.criterias.*;
class Sql_core_wtr_fxt {
private final Sql_core_wtr__sqlite wtr = new Sql_core_wtr__sqlite();
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
private final Bry_bfr bfr = Bry_bfr_.New();
public Sql_core_wtr_fxt Sql_wtr_(SqlQryWtr v) {sql_wtr = v; return this;} private SqlQryWtr sql_wtr = SqlQryWtrUtl.NewSqlite();
public void Test__val(Object val, String expd) {
wtr.Val_wtr().Bld_val(bfr, ctx, val);
Tfds.Eq_str(expd, bfr.To_str_and_clear());
}
public void Test__where(Criteria crt, String... expd) {
wtr.Where_wtr().Bld_where_elem(bfr, ctx, crt);
Tfds.Eq_str_lines(String_.Concat_lines_nl_skip_last(expd), bfr.To_str_and_clear());
}
public void Test__qry(Db_qry qry, String expd) {
Tfds.Eq_str_lines(expd, sql_wtr.ToSqlStr(qry, Bool_.N));
}
}

View File

@@ -0,0 +1,31 @@
/*
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.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
import org.junit.*;
public class Sql_from_wtr_tst {
private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt();
@Test public void Abrv() {
fxt.Test__qry(Db_qry_.select_().Cols_all_().From_("tbl", "t"), "SELECT * FROM tbl t");
}
@Test public void Db() {
fxt.Test__qry(Db_qry_.select_().Cols_all_().From_("db", "tbl", "t"), "SELECT * FROM db.tbl t");
}
@Test public void Join() {
fxt.Test__qry
( Db_qry_.select_().Cols_all_().From_("src", "s").Join_("trg", "t", Db_qry_.New_join__join("trg_id", "s", "src_id"))
, "SELECT * FROM src s INNER JOIN trg t ON s.src_id = t.trg_id");
}
}

View File

@@ -0,0 +1,97 @@
/*
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.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
import org.junit.*;
import gplx.core.criterias.*;
public class Sql_qry_wtr__ansi__tst {
SqlQryWtr sqlWtr = SqlQryWtrUtl.NewBasic();
@Test public void Insert() {
tst_XtoSql
( Db_qry_.insert_("people").Val_int("id", 1).Val_str("name", "me")
, "INSERT INTO people (id, name) VALUES (1, 'me')"
);
}
@Test public void Delete() {
Criteria crt = Db_crt_.New_eq("id", 1);
tst_XtoSql
( Db_qry_.delete_("people", crt)
, "DELETE FROM people WHERE id = 1"
);
}
@Test public void Update() {
tst_XtoSql
( Db_qry_.update_("people", Db_crt_.New_eq("id", 1)).Val_str("name", "me")
, "UPDATE people SET name='me' WHERE id = 1"
);
}
@Test public void SelectAll() {
tst_XtoSql
( Db_qry_.select_().From_("people")
, "SELECT * FROM people"
);
}
@Test public void SelectFlds() {
tst_XtoSql
( Db_qry_.select_().Cols_("id", "name").From_("people")
, "SELECT id, name FROM people"
);
}
@Test public void SelectOrderBy() {
tst_XtoSql
( Db_qry_.select_().From_("people").Order_("name", false)
, "SELECT * FROM people ORDER BY name DESC"
);
}
@Test public void SelectWhere() {
tst_XtoSql
( Db_qry_.select_().From_("people").Where_(Db_crt_.New_eq("id", 1))
, "SELECT * FROM people WHERE id = 1"
);
}
@Test public void Select_From_Alias() {
tst_XtoSql
( Db_qry_.select_().From_("people", "p")
, "SELECT * FROM people p"
);
}
@Test public void Select_Join_Alias() {
tst_XtoSql
( Db_qry_.select_().From_("people", "p").Join_("roles", "r", Db_qry_.New_join__same("p", "id"))
, "SELECT * FROM people p INNER JOIN roles r ON p.id = r.id"
);
}
@Test public void Prepare() {
tst_XtoSql
( Db_qry_.insert_("people").Val_int("id", 1).Val_str("name", "me")
, "INSERT INTO people (id, name) VALUES (?, ?)"
, true
);
tst_XtoSql
( Db_qry_.delete_("people", Db_crt_.New_eq("id", 1))
, "DELETE FROM people WHERE id = ?"
, true
);
tst_XtoSql
( Db_qry_.update_("people", Db_crt_.New_eq("id", 1)).Val_str("name", "me")
, "UPDATE people SET name=? WHERE id = ?"
, true
);
}
void tst_XtoSql(Db_qry cmd, String expd) {tst_XtoSql(cmd, expd, false);}
void tst_XtoSql(Db_qry cmd, String expd, boolean prepare) {Tfds.Eq(expd, sqlWtr.ToSqlStr(cmd, prepare));}
}

View File

@@ -0,0 +1,60 @@
/*
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.sqls.wtrs; import gplx.*;
import gplx.dbs.sqls.*;
import org.junit.*;
import gplx.core.criterias.*; /*Criteria_base*/
import gplx.core.ios.*;
public class Sql_qry_wtr__iosql__tst {
@Test public void Type() {
fld = IoItm_base_.Prop_Type;
tst_Write("type = 1", ioCrt_(fld, Criteria_.eq_(IoItmDir.Type_Dir)));
tst_Write("type = 2", ioCrt_(fld, Criteria_.eq_(IoItmFil.Type_Fil)));
}
@Test public void Ext() {
fld = IoItm_base_.Prop_Ext;
tst_Write("ext = '.txt'", ioCrt_(fld, Criteria_.eq_(".txt")));
tst_Write("ext IN ('.txt', '.xml', '.html')", ioCrt_(fld, Criteria_.in_(".txt", ".xml", ".html")));
tst_Write("ext NOT IN ('.dll', '.exe')", ioCrt_(fld, Criteria_.inn_(".dll", ".exe")));
}
@Test public void Title() {
fld = IoItm_base_.Prop_Title;
tst_Write("title = 'bin'", ioCrt_(fld, Criteria_.eq_("bin")));
tst_Write("title NOT IN ('bin', 'obj')", ioCrt_(fld, Criteria_.inn_("bin", "obj")));
}
@Test public void Url() {
fld = IoItm_base_.Prop_Path;
tst_Write("url = 'C:\\fil.txt'", ioCrt_(fld, Criteria_.eq_("C:\\fil.txt")));
tst_Write("url IOMATCH '*.txt'", ioCrt_(fld, Criteria_ioMatch.parse(true, "*.txt", false)));
}
@Test public void Binary() {
// parentheses around lhs and rhs
tst_Write(
"(type = 1 OR type = 2)"
, Criteria_.Or
( ioCrt_(IoItm_base_.Prop_Type, Criteria_.eq_(IoItmDir.Type_Dir)), ioCrt_(IoItm_base_.Prop_Type, Criteria_.eq_(IoItmFil.Type_Fil))
));
}
Criteria ioCrt_(String fld, Criteria crt) {return Criteria_fld.new_(fld, crt);}
String fld;
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
void tst_Write(String expd, Criteria crt) {
Sql_where_wtr where_wtr = ((Sql_core_wtr)SqlQryWtrUtl.NewBasic()).Where_wtr();
Bry_bfr bfr = Bry_bfr_.New();
where_wtr.Bld_where_elem(bfr, ctx, crt);
Tfds.Eq(expd, bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,66 @@
/*
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.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
import org.junit.*;
public class Sql_schema_wtr_tst {
@Before public void setup() {} private final Sql_schema_wtr_fxt fxt = new Sql_schema_wtr_fxt();
@Test public void Idx_unique() {
fxt.Test_create_idx(Dbmeta_idx_itm.new_unique_by_tbl("tbl_name", "idx_name", "fld_1", "fld_2")
, "CREATE UNIQUE INDEX IF NOT EXISTS tbl_name__idx_name ON tbl_name (fld_1, fld_2);"
);
}
@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())
, String_.Concat_lines_nl_skip_last
( "CREATE TABLE IF NOT EXISTS tbl_name"
, "( fld_int_pkey integer NOT NULL PRIMARY KEY"
, ", fld_bool boolean NOT NULL"
, ", fld_short smallint NOT NULL"
, ", fld_int integer NOT NULL"
, ", fld_long bigint NOT NULL"
, ", fld_float float NOT NULL"
, ", fld_double double NOT NULL"
, ", fld_str varchar(123) NOT NULL"
, ", fld_text text NOT NULL"
, ", fld_bry blob NOT NULL"
, ");"
));
}
@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';");
}
}
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));}
}

View File

@@ -0,0 +1,26 @@
/*
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.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
import org.junit.*;
public class Sql_select_wtr_tst {
private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt();
@Test public void Offset__automatically_add_limit() {
fxt.Test__qry(Db_qry_.select_tbl_("tbl").Offset_(1), "SELECT * FROM tbl LIMIT -1 OFFSET 1");
}
@Test public void Offset__do_not_overwrite_limit() {
fxt.Test__qry(Db_qry_.select_tbl_("tbl").Limit_(20).Offset_(1), "SELECT * FROM tbl LIMIT 20 OFFSET 1");
}
}

View File

@@ -0,0 +1,37 @@
/*
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.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
import org.junit.*;
public class Sql_val_wtr_tst {
private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt();
@Test public void Null() {fxt.Test__val(null , "NULL");}
@Test public void Bool__n() {fxt.Test__val(Bool_.N , "0");}
@Test public void Bool__y() {fxt.Test__val(Bool_.Y , "1");}
@Test public void Byte() {fxt.Test__val(Byte_.By_int(2) , "2");}
@Test public void Short() {fxt.Test__val(Short_.By_int(3) , "3");}
@Test public void Int() {fxt.Test__val(4 , "4");}
@Test public void Long() {fxt.Test__val(5 , "5");}
@Test public void Float() {fxt.Test__val(6.1f , "6.1");}
@Test public void Double() {fxt.Test__val(7.1d , "7.1");}
@Test public void Decimal() {fxt.Test__val(Decimal_adp_.float_(8) , "'8'");}
@Test public void Str() {fxt.Test__val("abc" , "'abc'");}
@Test public void Str__apos_mid() {fxt.Test__val("a'b" , "'a''b'");}
@Test public void Str__apos_bgn() {fxt.Test__val("'ab" , "'''ab'");}
@Test public void Str__apos_end() {fxt.Test__val("ab'" , "'ab'''");}
@Test public void Str__apos_many() {fxt.Test__val("a'b'c" , "'a''b''c'");}
@Test public void Str__back() {fxt.Test__val("a\\b" , "'a\\b'");}
@Test public void Date() {fxt.Test__val(DateAdp_.parse_gplx("2016-02-03") , "'2016-02-03 00:00:00.000'");}
}

View File

@@ -0,0 +1,53 @@
/*
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.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
import org.junit.*; import gplx.core.criterias.*;
public class Sql_where_wtr_tst {
private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt();
@Test public void Eq() {fxt.Test__where(Db_crt_.New_eq ("fld", 1) , "fld = 1");}
@Test public void Eq_not() {fxt.Test__where(Db_crt_.New_eq_not ("fld", 1) , "fld != 1");}
@Test public void Eq_pre() {fxt.Test__where(Db_crt_.New_eq ("a", "fld", 1) , "a.fld = 1");}
@Test public void Lt() {fxt.Test__where(Db_crt_.New_lt ("fld", 1) , "fld < 1");}
@Test public void Lte() {fxt.Test__where(Db_crt_.New_lte ("fld", 1) , "fld <= 1");}
@Test public void Mt() {fxt.Test__where(Db_crt_.New_mt ("fld", 1) , "fld > 1");}
@Test public void Mte() {fxt.Test__where(Db_crt_.New_mte ("fld", 1) , "fld >= 1");}
@Test public void Between() {fxt.Test__where(Db_crt_.New_between ("fld", 1, 3) , "fld BETWEEN 1 AND 3");}
@Test public void In() {fxt.Test__where(Db_crt_.New_in ("fld", 1, 2, 3) , "fld IN (1, 2, 3)");}
@Test public void Like() {fxt.Test__where(Db_crt_.New_like ("fld", "A%") , "fld LIKE 'A%' ESCAPE '|'");}
@Test public void And__subs__2() {
fxt.Test__where
( Criteria_.And
( Db_crt_.New_eq("id", 1)
, Db_crt_.New_eq("name", "me")
), "(id = 1 AND name = 'me')");
}
@Test public void Or__subs__2() {
fxt.Test__where
( Criteria_.Or
( Db_crt_.New_eq("id", 1)
, Db_crt_.New_eq("name", "me")
), "(id = 1 OR name = 'me')");
}
@Test public void Nested() {
fxt.Test__where
( Criteria_.Or
( Db_crt_.New_eq("id", 1)
, Criteria_.And
( Db_crt_.New_eq("name", "me")
, Db_crt_.New_eq("id", 2))
), "(id = 1 OR (name = 'me' AND id = 2))");
}
}