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

'v3.6.3.1'

This commit is contained in:
gnosygnu
2016-06-19 23:58:10 -04:00
parent 96636f3161
commit d4e8590345
1960 changed files with 20790 additions and 9272 deletions

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.dbs; import gplx.*;
import gplx.dbs.metas.*; import gplx.dbs.sqls.*; import gplx.dbs.sqls.wtrs.*;
class Db_diff_bldr {
private final Bry_bfr bfr = Bry_bfr.new_();
private final Bry_bfr bfr = Bry_bfr_.New();
private final Sql_schema_wtr sql_bldr = new Sql_schema_wtr();
public Db_diff_bldr() {sql_bldr.Bfr_(bfr);}
public String Compare_db(String src_str, String trg_str) {

View File

@@ -0,0 +1,88 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.bulks; import gplx.*; import gplx.dbs.*;
import gplx.dbs.metas.*;
public class Db_bulk_exec_ {
public static void Insert(Db_bulk_prog prog_wkr, String msg, Dbmeta_fld_itm[] flds, Db_rdr src, Db_stmt trg, Db_conn trg_conn) {
// init
int flds_len = flds.length;
String[] fld_names = Db_bulk_exec_utl_.To_fld_names(flds, flds_len);
int[] fld_types = Db_bulk_exec_utl_.To_fld_types(flds, flds_len);
// loop all rows
Gfo_log_.Instance.Prog(msg);
trg_conn.Txn_bgn("bulk_insert");
try {
while (src.Move_next()) {
// fill insert
trg.Clear();
int row_size = 0;
for (int i = 0; i < flds_len; ++i) {
String fld_name = fld_names[i];
switch (fld_types[i]) {
case Dbmeta_fld_tid.Tid__bool : trg.Val_bool_as_byte (fld_name, src.Read_bool_by_byte (fld_name)); row_size += 1; break;
case Dbmeta_fld_tid.Tid__byte : trg.Val_byte (fld_name, src.Read_byte (fld_name)); row_size += 1; break;
case Dbmeta_fld_tid.Tid__int : trg.Val_int (fld_name, src.Read_int (fld_name)); row_size += 4; break;
case Dbmeta_fld_tid.Tid__long : trg.Val_long (fld_name, src.Read_long (fld_name)); row_size += 8; break;
case Dbmeta_fld_tid.Tid__float : trg.Val_float (fld_name, src.Read_float (fld_name)); row_size += 4; break;
case Dbmeta_fld_tid.Tid__double : trg.Val_double (fld_name, src.Read_double (fld_name)); row_size += 8; break;
case Dbmeta_fld_tid.Tid__str : String src_str = src.Read_str(fld_name); trg.Val_str(fld_name, src_str); row_size += src_str == null ? 0 : String_.Len(src_str); break;
case Dbmeta_fld_tid.Tid__bry : byte[] src_bry = src.Read_bry(fld_name); trg.Val_bry(fld_name, src_bry); row_size += src_bry == null ? 0 : src_bry.length; break;
default : throw Err_.new_unhandled_default(fld_types[i]);
}
}
// exec insert
try {trg.Exec_insert();}
catch (Exception e) {throw Db_bulk_exec_utl_.New_err(e, src, flds_len, fld_names, fld_types);}
// commit and notify if applicable
if (prog_wkr.Prog__insert_and_stop_if_suspended(row_size)) break;
}
}
catch (Exception e) {throw Err_.new_wo_type("dbs.bulk:insert failed", "err", e);}
finally {
trg_conn.Txn_end();
}
}
public static final String Invk__bulk_insert_err = "bulk.insert.err", Invk__bulk_insert_prog = "bulk.insert.prog";
}
class Db_bulk_exec_utl_ {
public static String[] To_fld_names(Dbmeta_fld_itm[] flds, int flds_len) {
String[] rv = new String[flds_len];
for (int i = 0; i < flds_len; ++i)
rv[i] = flds[i].Name();
return rv;
}
public static int[] To_fld_types(Dbmeta_fld_itm[] flds, int flds_len) {
int[] rv = new int[flds_len];
for (int i = 0; i < flds_len; ++i)
rv[i] = flds[i].Type().Tid_ansi();
return rv;
}
public static Err New_err(Exception e, Db_rdr rdr, int flds_len, String[] fld_names, int[] fld_types) {
Object[] args = new Object[(flds_len * 2) + 2];
for (int i = 0; i < flds_len; i += 2) {
args[i ] = fld_names[i];
args[i + 1] = rdr.Read_at(i);
}
args[flds_len - 2] = "err";
args[flds_len - 1] = Err_.Message_gplx_log(e);
return Err_.new_wo_type("dbs.bulk:insert row failed", args);
}
}

View File

@@ -0,0 +1,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.bulks; import gplx.*; import gplx.dbs.*;
public interface Db_bulk_prog {
boolean Prog__insert_and_stop_if_suspended(int row_size);
}

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.bulks; import gplx.*; import gplx.dbs.*;
import gplx.dbs.*; import gplx.dbs.metas.*;
public class Db_tbl_copy {
private final Bry_bfr bfr = Bry_bfr_.New();
private final Db_attach_mgr attach_mgr = new Db_attach_mgr();
public void Copy_many(Db_conn src_conn, Db_conn trg_conn, String... tbl_names) {
for (String tbl_name : tbl_names)
Copy_one(src_conn, trg_conn, tbl_name, tbl_name);
}
public void Copy_one(Db_conn src_conn, Db_conn trg_conn, String src_tbl, String trg_tbl) {
Dbmeta_tbl_itm tbl = src_conn.Meta_mgr().Get_by(src_tbl); if (tbl == null) throw Err_.new_wo_type("tbl does not exist", "tbl_name", src_tbl);
trg_conn.Meta_tbl_remake(Dbmeta_tbl_itm.New(trg_tbl, tbl.Flds().To_ary(), tbl.Idxs().To_ary()));
// do copy
attach_mgr.Conn_main_(trg_conn).Conn_others_(new Db_attach_itm("src_db", src_conn));
attach_mgr.Exec_sql(Bld_sql(tbl, src_tbl, trg_tbl));
}
public String Bld_sql(Dbmeta_tbl_itm tbl, String src_tbl, String trg_tbl) {
Dbmeta_fld_mgr flds = tbl.Flds();
int flds_len = flds.Len();
bfr.Add_str_a7("INSERT INTO ").Add_str_a7(trg_tbl).Add_byte_nl();
bfr.Add_byte(Byte_ascii.Paren_bgn);
for (int i = 0; i < flds_len; ++i) {
Dbmeta_fld_itm fld = flds.Get_at(i);
if (i != 0) bfr.Add_str_a7(", ");
bfr.Add_str_a7(fld.Name());
}
bfr.Add_byte(Byte_ascii.Paren_end).Add_byte_nl();
bfr.Add_str_a7("SELECT").Add_byte_nl().Add_byte_space();
for (int i = 0; i < flds_len; ++i) {
Dbmeta_fld_itm fld = flds.Get_at(i);
if (i != 0) bfr.Add_str_a7(", ");
bfr.Add_str_a7(fld.Name());
}
bfr.Add_byte_nl();
bfr.Add_str_a7("FROM <src_db>").Add_str_a7(src_tbl);
return bfr.To_str_and_clear();
}
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.bulks; import gplx.*; import gplx.dbs.*;
import org.junit.*; import gplx.core.tests.*; import gplx.dbs.metas.*;
public class Db_tbl_copy_tst {
private final Db_tbl_copy_fxt fxt = new Db_tbl_copy_fxt();
@Test public void Basic() {
fxt.Test__bld_sql(fxt.Make_tbl("tbl_1", Dbmeta_fld_itm.new_int("fld_1"), Dbmeta_fld_itm.new_int("fld_2")),
String_.Concat_lines_nl_skip_last
( "INSERT INTO trg"
, "(fld_1, fld_2)"
, "SELECT"
, " fld_1, fld_2"
, "FROM <src_db>src"
));
}
}
class Db_tbl_copy_fxt {
private final Db_tbl_copy mgr = new Db_tbl_copy();
public Dbmeta_tbl_itm Make_tbl(String name, Dbmeta_fld_itm... flds) {return Dbmeta_tbl_itm.New(name, flds);}
public void Test__bld_sql(Dbmeta_tbl_itm tbl, String expd) {
Gftest.Eq__ary__lines(expd, mgr.Bld_sql(tbl, "src", "trg"), "sql");
}
}

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.dbs.cfgs; import gplx.*; import gplx.dbs.*;
public class Db_cfg_itm {
public Db_cfg_itm(String grp, String key, String val) {this.grp = grp; this.key = key; this.val = val;}
public String Grp() {return grp;} private final String grp;
public String Key() {return key;} private final String key;
public String Grp() {return grp;} private final String grp;
public String Key() {return key;} private final String key;
public String Val() {return val;} public Db_cfg_itm Val_(String v) {val = v; return this;} private String val;
public String To_str_or(String or) {return val == null ? or : val;}
public byte[] To_bry_or(byte[] or) {try {return val == null ? or : Bry_.new_u8(val) ;} catch (Exception e) {throw err_parse(e, Bry_.Cls_val_name);}}
@@ -29,7 +29,7 @@ public class Db_cfg_itm {
public boolean To_yn_or_n() {return To_yn_or(Bool_.N);}
public boolean To_yn_or(boolean or) {try {return val == null ? or : Yn.parse_by_char_or(val, or);} catch (Exception e) {throw err_parse(e, Bool_.Cls_val_name);}}
public DateAdp To_date_or(DateAdp or) {try {return val == null ? or : DateAdp_.parse_gplx(val) ;} catch (Exception e) {throw err_parse(e, DateAdp_.Cls_ref_name);}}
public Guid_adp To_guid_or(Guid_adp or) {try {return val == null ? or : Guid_adp_.parse(val) ;} catch (Exception e) {throw err_parse(e, Guid_adp_.Cls_ref_name);}}
public Guid_adp To_guid_or(Guid_adp or) {try {return val == null ? or : Guid_adp_.Parse(val) ;} catch (Exception e) {throw err_parse(e, Guid_adp_.Cls_ref_name);}}
public boolean To_bool() {Fail_if_null(); try {return Yn.parse(val) ;} catch (Exception e) {throw err_parse(e, Bool_.Cls_val_name);}}
public byte To_byte() {Fail_if_null(); try {return Byte_.parse(val) ;} catch (Exception e) {throw err_parse(e, Byte_.Cls_val_name);}}
public int To_int() {Fail_if_null(); try {return Int_.parse(val) ;} catch (Exception e) {throw err_parse(e, Int_.Cls_val_name);}}
@@ -53,5 +53,5 @@ public class Db_cfg_itm {
public static Db_cfg_itm new_DateAdp (String grp, String key, DateAdp val) {return new Db_cfg_itm(grp , key, val.XtoStr_fmt_yyyyMMdd_HHmmss());}
public static Db_cfg_itm new_guid (String key, Guid_adp val) {return new Db_cfg_itm(Grp_none , key, val.To_str());}
public static Db_cfg_itm new_guid (String grp, String key, Guid_adp val) {return new Db_cfg_itm(grp , key, val.To_str());}
public static final Db_cfg_itm Empty = new Db_cfg_itm("empty", "empty", null);
public static final Db_cfg_itm Empty = new Db_cfg_itm("empty", "empty", null);
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.dbs.cfgs; import gplx.*; import gplx.dbs.*;
import gplx.core.primitives.*;
public class Db_cfg_tbl implements Rls_able {
private final String tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_grp, fld_key, fld_val;
private Db_stmt stmt_insert, stmt_update, stmt_select;
public Db_conn Conn() {return conn;} private final Db_conn conn;
@@ -72,14 +72,14 @@ public class Db_cfg_tbl implements Rls_able {
if (cur_val == null) this.Insert_str(grp, key, val);
else this.Update_str(grp, key, val);
}
public boolean Select_yn (String grp, String key) {String val = Select_str(grp, key); return Parse_yn (grp, key, val);}
public boolean Select_yn (String grp, String key) {String val = Select_str(grp, key); return Parse_yn (grp, key, val);}
public byte Select_byte (String grp, String key) {String val = Select_str(grp, key); return Parse_byte (grp, key, val);}
public int Select_int (String grp, String key) {String val = Select_str(grp, key); return Parse_int (grp, key, val);}
public long Select_long (String grp, String key) {String val = Select_str(grp, key); return Parse_long (grp, key, val);}
public byte[] Select_bry (String grp, String key) {String val = Select_str(grp, key); return Parse_bry (grp, key, val);}
public DateAdp Select_date (String grp, String key) {String val = Select_str(grp, key); return Parse_date (grp, key, val);}
public Guid_adp Select_guid (String grp, String key) {String val = Select_str(grp, key); return Parse_guid (grp, key, val);}
public boolean Select_yn_or (String grp, String key, boolean or) {String val = Select_str_or(grp, key, null) ; return val == null ? or : Parse_yn (grp, key, val);}
public boolean Select_yn_or (String grp, String key, boolean or) {String val = Select_str_or(grp, key, null) ; return val == null ? or : Parse_yn (grp, key, val);}
public byte Select_byte_or (String grp, String key, byte or) {String val = Select_str_or(grp, key, null) ; return val == null ? or : Parse_byte (grp, key, val);}
public int Select_int_or (String grp, String key, int or) {String val = Select_str_or(grp, key, null) ; return val == null ? or : Parse_int (grp, key, val);}
public long Select_long_or (String grp, String key, long or) {String val = Select_str_or(grp, key, null) ; return val == null ? or : Parse_long (grp, key, val);}
@@ -131,6 +131,6 @@ public class Db_cfg_tbl implements Rls_able {
private long Parse_long (String grp, String key, String val) {try {return Long_.parse(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, Long_.Cls_val_name);}}
private byte[] Parse_bry (String grp, String key, String val) {try {return Bry_.new_u8(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, Bry_.Cls_val_name);}}
private DateAdp Parse_date (String grp, String key, String val) {try {return DateAdp_.parse_gplx(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, DateAdp_.Cls_ref_name);}}
private Guid_adp Parse_guid (String grp, String key, String val) {try {return Guid_adp_.parse(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, Guid_adp_.Cls_ref_name);}}
private Guid_adp Parse_guid (String grp, String key, String val) {try {return Guid_adp_.Parse(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, Guid_adp_.Cls_ref_name);}}
private Err err_parse(Exception e, String grp, String key, String val, String type) {return Err_.new_exc(e, "db", "cfg.val is not parseable", "grp", grp, "key", key, "val", val, "type", type);}
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
public class Schema_update_mgr {
private List_adp cmds = List_adp_.new_();
private List_adp cmds = List_adp_.New();
public void Add(Schema_update_cmd cmd) {cmds.Add(cmd);}
public void Update(Schema_db_mgr schema_mgr, Db_conn conn) {
int cmds_len = cmds.Count();

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.percentiles; import gplx.*; import gplx.dbs.*;
class Log_tbl_fmtr {
private final Bry_bfr bfr = Bry_bfr.new_();
private final List_adp itms = List_adp_.new_();
private final Bry_bfr bfr = Bry_bfr_.New();
private final List_adp itms = List_adp_.New();
private Log_fld_itm[] ary;
public Log_tbl_fmtr Add_str(String key, int len) {ary = null; itms.Add(new Log_fld_itm__bry(Type_adp_.Tid__bry, key, len)); return this;}
public Log_tbl_fmtr Add_int(String key, int bgn, int end) {ary = null; itms.Add(new Log_fld_itm__int(Type_adp_.Tid__int, key, bgn, end)); return this;}
@@ -43,8 +43,8 @@ abstract class Log_fld_itm__base implements Log_fld_itm {
public Log_fld_itm__base(int tid, String key, int len) {
this.tid = tid; this.key = key; this.len = len;
}
public int Tid() {return tid;} private final int tid;
public String Key() {return key;} private final String key;
public int Tid() {return tid;} private final int tid;
public String Key() {return key;} private final String key;
public int Len() {return len;} protected int len;
public abstract void Fmt(Bry_bfr bfr, Object val);
}
@@ -64,8 +64,8 @@ class Log_fld_itm__int extends Log_fld_itm__base {
this.bgn = bgn; this.end = end;
this.len = Int_.DigitCount(end);
}
public int Bgn() {return bgn;} private final int bgn;
public int End() {return end;} private final int end;
public int Bgn() {return bgn;} private final int bgn;
public int End() {return end;} private final int end;
@Override public void Fmt(Bry_bfr bfr, Object val) {
int val_int = Int_.cast(val);
String val_str = String_.PadBgn(Int_.To_str(val_int), this.Len(), " ");