mirror of https://github.com/gnosygnu/xowa
parent
62c81e6d77
commit
5c3e4287f0
@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.xowa.addons.bldrs.mass_parses.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
|
||||
import gplx.xowa.addons.bldrs.mass_parses.dbs.*;
|
||||
interface Xomp_make_merger {
|
||||
void Merger__init(Xowe_wiki wiki, Xomp_wkr_db[] src_dbs);
|
||||
int Merger__load(Xomp_mgr_db src_mgr_db, Xomp_wkr_db src_wkr_db, int uid_bgn, int uid_end);
|
||||
void Merger__save();
|
||||
void Merger__term();
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
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.xowa.addons.bldrs.mass_parses.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
|
||||
import gplx.dbs.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.addons.bldrs.mass_parses.dbs.*;
|
||||
// merges xomp.wkr_dbs into xowa.file.make.sqlite3
|
||||
// NOTE: can't do INSERT b/c (a) autonum id is same in diff worker dbs; (b): want autonum to match ns_id, page_id order
|
||||
abstract class Xomp_make_merger__base implements Xomp_make_merger, gplx.core.lists.ComparerAble {
|
||||
private Xob_db_file trg_db;
|
||||
protected Db_tbl trg_tbl;
|
||||
private List_adp rows = List_adp_.New();
|
||||
private String src_tbl__name, src_fld__page_id;
|
||||
public void Merger__init(Xowe_wiki wiki, Xomp_wkr_db[] src_dbs) {
|
||||
// get trg.db
|
||||
this.trg_db = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir());
|
||||
|
||||
// make trg.tbl
|
||||
this.trg_tbl = Init__trg_tbl(trg_db);
|
||||
trg_db.Conn().Meta_tbl_remake(trg_tbl);
|
||||
|
||||
// make idxs on src.tbls
|
||||
this.src_tbl__name = this.trg_tbl.Tbl_name();
|
||||
this.src_fld__page_id = this.Init__src_fld__page_id();
|
||||
int len = src_dbs.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
src_dbs[i].Conn().Meta_idx_assert(src_tbl__name, src_fld__page_id, src_fld__page_id);
|
||||
}
|
||||
|
||||
// do any other init, such as init'ing insert stmt
|
||||
this.Init__trg_bgn();
|
||||
this.trg_db.Conn().Txn_bgn("merger__" + src_tbl__name);
|
||||
}
|
||||
protected abstract Db_tbl Init__trg_tbl(Xob_db_file trg_db);
|
||||
protected abstract String Init__src_fld__page_id();
|
||||
@gplx.Virtual protected void Init__trg_bgn() {}
|
||||
|
||||
public int Merger__load(Xomp_mgr_db src_mgr_db, Xomp_wkr_db src_wkr_db, int uid_bgn, int uid_end) {
|
||||
// build sql
|
||||
Db_attach_mgr attach_mgr = new Db_attach_mgr(src_mgr_db.Conn());
|
||||
attach_mgr.Conn_links_(new Db_attach_itm("src_wkr_db", src_wkr_db.Conn()));
|
||||
String sql = Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "SELECT src_mgr.xomp_uid"
|
||||
, ", src_wkr.*"
|
||||
, "FROM <src_wkr_db>{0} src_wkr"
|
||||
, " JOIN xomp_page src_mgr ON src_wkr.{1} = src_mgr.page_id"
|
||||
, "WHERE src_mgr.xomp_uid > {2} AND src_mgr.xomp_uid <= {3}" // NOTE: mgr.xomp_uid will sort pages by ns_id, page_id
|
||||
)
|
||||
, src_tbl__name, src_fld__page_id
|
||||
, uid_bgn, uid_end
|
||||
);
|
||||
sql = attach_mgr.Resolve_sql(sql);
|
||||
|
||||
// load rows
|
||||
attach_mgr.Attach();
|
||||
Db_rdr rdr = src_mgr_db.Conn().Stmt_sql(sql).Exec_select__rls_auto();
|
||||
int rv = -1;
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
rv = rdr.Read_int("xomp_uid");
|
||||
Object row = Load__src_row(rdr);
|
||||
rows.Add(row);
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
attach_mgr.Detach();
|
||||
return rv;
|
||||
}
|
||||
protected abstract Object Load__src_row(Db_rdr rdr);
|
||||
|
||||
public void Merger__save() {
|
||||
rows.Sort_by(this);
|
||||
int len = rows.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Save__trg_row(rows.Get_at(i));
|
||||
}
|
||||
rows.Clear();
|
||||
}
|
||||
protected abstract void Save__trg_row(Object row_obj);
|
||||
public void Merger__term() {
|
||||
this.trg_db.Conn().Txn_end();
|
||||
}
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
return Compare__hook(lhsObj, rhsObj);
|
||||
}
|
||||
protected abstract int Compare__hook(Object lhsObj, Object rhsObj);
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
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.xowa.addons.bldrs.mass_parses.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
|
||||
import gplx.dbs.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.addons.bldrs.files.dbs.*;
|
||||
class Xomp_make_merger__lnki_temp extends Xomp_make_merger__base {
|
||||
private int lnki_id;
|
||||
private Xob_lnki_temp_tbl trg_tbl__lnki_temp;
|
||||
@Override protected Db_tbl Init__trg_tbl(Xob_db_file trg_db) {
|
||||
this.trg_tbl__lnki_temp = new Xob_lnki_temp_tbl(trg_db.Conn());
|
||||
return trg_tbl__lnki_temp;
|
||||
}
|
||||
@Override protected String Init__src_fld__page_id() {return "lnki_page_id";}
|
||||
@Override protected void Init__trg_bgn() {trg_tbl__lnki_temp.Insert_stmt_make();}
|
||||
@Override protected Object Load__src_row(Db_rdr rdr) {
|
||||
Xob_lnki_temp_row rv = new Xob_lnki_temp_row();
|
||||
rv.Load(rdr, ++lnki_id);
|
||||
return rv;
|
||||
}
|
||||
@Override protected void Save__trg_row(Object row_obj) {
|
||||
Xob_lnki_temp_row row = (Xob_lnki_temp_row)row_obj;
|
||||
trg_tbl__lnki_temp.Insert_cmd_by_batch(row.Lnki_tier_id(), row.Lnki_page_id(), row.Lnki_ttl(), row.Lnki_commons_ttl()
|
||||
, row.Lnki_ext(), row.Lnki_type(), row.Lnki_src_tid(), row.Lnki_w(), row.Lnki_h(), row.Lnki_upright()
|
||||
, row.Lnki_time(), row.Lnki_page());
|
||||
}
|
||||
@Override protected int Compare__hook(Object lhsObj, Object rhsObj) {
|
||||
Xob_lnki_temp_row lhs = (Xob_lnki_temp_row)lhsObj;
|
||||
Xob_lnki_temp_row rhs = (Xob_lnki_temp_row)rhsObj;
|
||||
return Int_.Compare(lhs.Lnki_page_id(), rhs.Lnki_page_id());
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
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.xowa.addons.bldrs.mass_parses.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
|
||||
import gplx.dbs.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.addons.bldrs.mass_parses.dbs.*;
|
||||
import gplx.xowa.addons.bldrs.files.dbs.*;
|
||||
import gplx.xowa.parsers.logs.*;
|
||||
class Xomp_make_merger__xnde extends Xomp_make_merger__base {
|
||||
private Xop_log_basic_tbl trg_tbl__log_basic_temp;
|
||||
@Override protected Db_tbl Init__trg_tbl(Xob_db_file trg_db) {
|
||||
this.trg_tbl__log_basic_temp = new Xop_log_basic_tbl(trg_db.Conn());
|
||||
return trg_tbl__log_basic_temp;
|
||||
}
|
||||
@Override protected String Init__src_fld__page_id() {return "page_id";}
|
||||
@Override protected void Init__trg_bgn() {} // NOTE: trg_tbl has implicit insert_stmt creation
|
||||
@Override protected Object Load__src_row(Db_rdr rdr) {
|
||||
Xop_log_basic_row rv = new Xop_log_basic_row();
|
||||
rv.Load(rdr);
|
||||
return rv;
|
||||
}
|
||||
@Override protected void Save__trg_row(Object row_obj) {
|
||||
Xop_log_basic_row row = (Xop_log_basic_row)row_obj;
|
||||
trg_tbl__log_basic_temp.Insert(row.Log_tid, row.Log_msg, row.Log_time, row.Page_id, row.Page_ttl, row.Args_len, row.Args_str, row.Src_len, row.Src_str);
|
||||
}
|
||||
@Override protected int Compare__hook(Object lhsObj, Object rhsObj) {
|
||||
Xop_log_basic_row lhs = (Xop_log_basic_row)lhsObj;
|
||||
Xop_log_basic_row rhs = (Xop_log_basic_row)rhsObj;
|
||||
return Int_.Compare(lhs.Page_id, rhs.Page_id);
|
||||
}
|
||||
}
|
||||
class Xop_log_basic_row {
|
||||
public int Log_tid;
|
||||
public String Log_msg;
|
||||
public int Log_time;
|
||||
public int Page_id;
|
||||
public String Page_ttl;
|
||||
public int Args_len;
|
||||
public String Args_str;
|
||||
public int Src_len;
|
||||
public String Src_str;
|
||||
public void Load(Db_rdr rdr) {
|
||||
this.Log_tid = rdr.Read_int("log_tid");
|
||||
this.Log_msg = rdr.Read_str("log_msg");
|
||||
this.Log_time = rdr.Read_int("log_time");
|
||||
this.Page_id = rdr.Read_int("page_id");
|
||||
this.Page_ttl = rdr.Read_str("page_ttl");
|
||||
this.Args_len = rdr.Read_int("args_len");
|
||||
this.Args_str = rdr.Read_str("args_str");
|
||||
this.Src_len = rdr.Read_int("src_len");
|
||||
this.Src_str = rdr.Read_str("src_str");
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
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.xowa.parsers.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.dbs.*; import gplx.xowa.bldrs.*;
|
||||
public class Xop_log_wkr_factory {
|
||||
private final Db_conn conn; private Xop_log_basic_tbl log_tbl;
|
||||
public Xop_log_wkr_factory(Db_conn conn) {this.conn = conn;}
|
||||
public Xop_log_invoke_wkr Make__invoke() {return new Xop_log_invoke_wkr(conn);}
|
||||
public Xop_log_property_wkr Make__property() {return new Xop_log_property_wkr(conn);}
|
||||
public Xop_log_basic_wkr Make__generic() {
|
||||
if (log_tbl == null) log_tbl = new Xop_log_basic_tbl(conn);
|
||||
return new Xop_log_basic_wkr(log_tbl);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue