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

v2.10.3.1

This commit is contained in:
gnosygnu
2015-10-18 22:17:57 -04:00
parent 8e18af05b6
commit 4f43f51b18
1935 changed files with 12500 additions and 12889 deletions

View File

@@ -0,0 +1,42 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.core.primitives.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.bldrs.cmds.ctgs.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.specials.search.*; import gplx.xowa.wikis.data.tbls.*;
public interface Xodb_load_mgr {
void Load_init (Xowe_wiki wiki);
void Load_page (Xowd_page_itm rv, Xow_ns ns, boolean timestamp_enabled);
boolean Load_by_id (Xowd_page_itm rv, int id);
void Load_by_ids (Cancelable cancelable, List_adp rv, int bgn, int end);
boolean Load_by_ttl (Xowd_page_itm rv, Xow_ns ns, byte[] ttl);
void Load_by_ttls (Cancelable cancelable, Ordered_hash rv, boolean fill_idx_fields_only, int bgn, int end);
int Load_ctg_count (byte[] ttl);
boolean Load_ctg_v1 (Xoctg_view_ctg rv, byte[] ttl);
boolean Load_ctg_v2 (Xoctg_data_ctg rv, byte[] ttl);
void Load_ctg_v2a (Xoctg_view_ctg rv, Xoctg_url url_ctg, byte[] ttl_bry, int limit);
Xowd_page_itm[] Load_ctg_list (byte[][] ctg_ttls);
void Load_search (Cancelable cancelable, List_adp rv, byte[] search, int results_max);
void Load_ttls_for_all_pages (Cancelable cancelable, List_adp rslt_list, Xowd_page_itm rslt_nxt, Xowd_page_itm rslt_prv, Int_obj_ref rslt_count, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item);
void Load_ttls_for_search_suggest(Cancelable cancelable, List_adp rslt_list, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item);
byte[] Find_random_ttl (Xow_ns ns);
void Clear(); // TEST:helper function
byte[] Load_qid (byte[] wiki_alias, byte[] ns_num, byte[] ttl);
int Load_pid (byte[] lang_key, byte[] pid_name);
Xodb_page_rdr Get_page_rdr (Xowe_wiki wiki);
}

View File

@@ -0,0 +1,205 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.core.primitives.*; import gplx.dbs.*; import gplx.dbs.cfgs.*;
import gplx.xowa.apps.gfs.*; import gplx.xowa.bldrs.cmds.ctgs.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.specials.search.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.data.*;
public class Xodb_load_mgr_sql implements Xodb_load_mgr {
public Xodb_load_mgr_sql(Xodb_mgr_sql db_mgr, Xowd_db_mgr fsys_mgr) {this.db_mgr = db_mgr; this.fsys_mgr = fsys_mgr;} private Xodb_mgr_sql db_mgr; Xowd_db_mgr fsys_mgr;
public byte Search_version() {
if (search_version_init_needed) Search_version_init();
return search_version;
} private byte search_version = gplx.xowa.specials.search.Xows_page__search.Version_null;
public void Search_version_refresh() {
search_version_init_needed = true;
Search_version_init();
}
public void Load_init(Xowe_wiki wiki) {
Load_init_cfg(wiki);
Xowd_db_file db_core = wiki.Data__core_mgr().Db__core();
db_core.Tbl__site_stats().Select(wiki.Stats());
db_core.Tbl__ns().Select_all(wiki.Ns_mgr());
}
private void Load_init_cfg(Xowe_wiki wiki) {
String version_key = Xoa_gfs_wtr_.Write_func_chain(Xowe_wiki.Invk_props, Xow_wiki_props.Invk_bldr_version);
Db_cfg_hash cfg_hash = db_mgr.Core_data_mgr().Tbl__cfg().Select_as_hash(Xow_cfg_consts.Grp__wiki_init);
String version_val = cfg_hash.Get_by(version_key).To_str_or("");
Xodb_upgrade_mgr.Upgrade(db_mgr, cfg_hash, version_key, version_val);
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
Xoa_gfs_mgr gfs_mgr = wiki.Appe().Gfs_mgr();
try {
int len = cfg_hash.Len();
for (int i = 0; i < len; ++i) {
Db_cfg_itm cfg_itm = cfg_hash.Get_at(i);
Xoa_gfs_wtr_.Write_prop(bfr, Bry_.new_u8(cfg_itm.Key()), Bry_.new_u8(cfg_itm.To_str_or("")));
}
gfs_mgr.Run_str_for(wiki, bfr.To_str_and_clear());
} finally {bfr.Mkr_rls();}
}
public boolean Load_by_ttl(Xowd_page_itm rv, Xow_ns ns, byte[] ttl) {return db_mgr.Core_data_mgr().Tbl__page().Select_by_ttl(rv, ns, ttl);}
public void Load_by_ttls(Cancelable cancelable, Ordered_hash rv, boolean fill_idx_fields_only, int bgn, int end) {
db_mgr.Core_data_mgr().Tbl__page().Select_in__ns_ttl(cancelable, rv, db_mgr.Wiki().Ns_mgr(), fill_idx_fields_only, bgn, end);
}
public void Load_page(Xowd_page_itm rv, Xow_ns ns, boolean timestamp_enabled) {
Xowd_text_tbl text_tbl = db_mgr.Core_data_mgr().Dbs__get_at(rv.Text_db_id()).Tbl__text();
byte[] text_bry = text_tbl.Select(rv.Id());
rv.Text_(text_bry);
}
public boolean Load_by_id (Xowd_page_itm rv, int id) {return db_mgr.Core_data_mgr().Tbl__page().Select_by_id(rv, id);}
public void Load_by_ids(Cancelable cancelable, List_adp rv, int bgn, int end) {db_mgr.Core_data_mgr().Tbl__page().Select_in__id(cancelable, false, rv, bgn, end);}
public boolean Load_ctg_v1(Xoctg_view_ctg rv, byte[] ctg_bry) {
int cat_page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Id_category, ctg_bry); if (cat_page_id == Xowd_page_itm.Id_null) return false;
Xowd_category_itm ctg = fsys_mgr.Db__cat_core().Tbl__cat_core().Select(cat_page_id); if (ctg == Xowd_category_itm.Null) return false;
return Ctg_select_v1(db_mgr.Wiki(), db_mgr.Core_data_mgr(), rv, ctg.File_idx(), ctg);
}
public boolean Load_ctg_v2(Xoctg_data_ctg rv, byte[] ctg_bry) {throw Err_.new_unimplemented();}
public void Load_ctg_v2a(Xoctg_view_ctg rv, Xoctg_url ctg_url, byte[] ctg_ttl, int load_max) {
int cat_page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Id_category, ctg_ttl); if (cat_page_id == Xowd_page_itm.Id_null) return;
Xowd_category_itm ctg = fsys_mgr.Db__cat_core().Tbl__cat_core().Select(cat_page_id); if (ctg == Xowd_category_itm.Null) return;
List_adp list = List_adp_.new_();
Load_ctg_v2a_db_retrieve(rv, ctg_url, cat_page_id, load_max, ctg.File_idx(), list);
Load_ctg_v2a_ui_sift(rv, ctg, list);
}
private void Load_ctg_v2a_db_retrieve(Xoctg_view_ctg rv, Xoctg_url ctg_url, int cat_page_id, int load_max, int cat_link_db_idx, List_adp list) {
int len = Xoa_ctg_mgr.Tid__max;
for (byte i = Xoa_ctg_mgr.Tid_subc; i < len; i++) {
boolean arg_is_from = ctg_url.Grp_fwds()[i] == Bool_.N_byte;
byte[] arg_sortkey = ctg_url.Grp_idxs()[i];
Xowd_cat_link_tbl cat_link_tbl = db_mgr.Core_data_mgr().Dbs__get_at(cat_link_db_idx).Tbl__cat_link();
int found = cat_link_tbl.Select_by_type(list, cat_page_id, i, arg_sortkey, arg_is_from, load_max);
if (found > 0 && found == load_max + 1) {
Xowd_page_itm last_page = (Xowd_page_itm)List_adp_.Pop(list);
Xoctg_page_xtn last_ctg = (Xoctg_page_xtn)last_page.Xtn();
rv.Grp_by_tid(i).Itms_last_sortkey_(last_ctg.Sortkey());
}
}
db_mgr.Core_data_mgr().Tbl__page().Select_in__id(Cancelable_.Never, list);
}
private void Load_ctg_v2a_ui_sift(Xoctg_view_ctg rv, Xowd_category_itm ctg, List_adp list) {
int len = list.Count();
Xowe_wiki wiki = this.db_mgr.Wiki();
byte prv_tid = Byte_.Max_value_127;
Xoctg_view_grp view_grp = null;
for (int i = 0; i < len; i++) {
Xowd_page_itm db_page = (Xowd_page_itm)list.Get_at(i);
if (db_page.Ns_id() == Int_.Min_value) continue; // HACK: page not found; ignore
Xoctg_page_xtn db_ctg = (Xoctg_page_xtn)db_page.Xtn();
byte cur_tid = db_ctg.Tid();
if (prv_tid != cur_tid) {
view_grp = rv.Grp_by_tid(cur_tid);
prv_tid = cur_tid;
}
Xoa_ttl ttl = Xoa_ttl.parse(wiki, db_page.Ns_id(), db_page.Ttl_page_db());
Xoctg_view_itm view_itm = new Xoctg_view_itm().Sortkey_(db_ctg.Sortkey()).Ttl_(ttl);
view_itm.Load_by_ttl_data(cur_tid, db_page.Id(), Xowd_page_itm.Modified_on_null_int, db_page.Text_len());
view_grp.Itms_add(view_itm);
}
len = Xoa_ctg_mgr.Tid__max;
for (byte i = Xoa_ctg_mgr.Tid_subc; i < len; i++) {
view_grp = rv.Grp_by_tid(i);
view_grp.Itms_make();
view_grp.Total_(ctg.Count_by_tid(i));
}
}
private boolean search_version_init_needed = true;
private void Search_version_init() {
if (search_version_init_needed) {
search_version_init_needed = false;
Xowd_db_file search_db = db_mgr.Core_data_mgr().Db__search();
search_version = search_db == Xowd_db_file.Null ? Xows_page__search.Version_1 : Xows_page__search.Version_2;
}
}
public void Load_search(Cancelable cancelable, List_adp rv, byte[] search, int results_max) {
if (search_version_init_needed) Search_version_init();
if (search_version == gplx.xowa.specials.search.Xows_page__search.Version_1)
db_mgr.Core_data_mgr().Tbl__page().Select_by_search(cancelable, rv, search, results_max);
else {
Xowd_db_mgr core_data_mgr = db_mgr.Core_data_mgr();
core_data_mgr.Db__search().Tbl__search_word().Select_by_word(cancelable, core_data_mgr.Db__search().Tbl__search_link(), rv, search, results_max);
core_data_mgr.Tbl__page().Select_in__id(cancelable, true, rv);
}
}
public void Load_ttls_for_all_pages(Cancelable cancelable, List_adp rslt_list, Xowd_page_itm rslt_nxt, Xowd_page_itm rslt_prv, Int_obj_ref rslt_count, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item) {
db_mgr.Core_data_mgr().Tbl__page().Select_for_special_all_pages(cancelable, rslt_list, rslt_nxt, rslt_prv, rslt_count, ns, key, max_results, min_page_len, browse_len, include_redirects, fetch_prv_item);
}
public void Load_ttls_for_search_suggest(Cancelable cancelable, List_adp rslt_list, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item) {
db_mgr.Core_data_mgr().Tbl__page().Select_for_search_suggest(cancelable, rslt_list, ns, key, max_results, min_page_len, browse_len, include_redirects, fetch_prv_item);
}
public int Load_ctg_count(byte[] ttl) {
if (db_mgr.Core_data_mgr().Db__cat_core() == null) return 0;
int page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Id_category, ttl);
if (page_id == Xowd_page_itm.Id_null) return 0; // title not found; return 0;
return db_mgr.Core_data_mgr().Db__cat_core().Tbl__cat_core().Select(page_id).Count_all();
}
public byte[] Load_qid(byte[] wiki_alias, byte[] ns_num, byte[] ttl) {return db_mgr.Core_data_mgr().Db__wbase().Tbl__wbase_qid().Select_qid(wiki_alias, ns_num, ttl);}
public int Load_pid(byte[] lang_key, byte[] pid_name) {return db_mgr.Core_data_mgr().Db__wbase().Tbl__wbase_pid().Select_pid(lang_key, pid_name);}
public byte[] Find_random_ttl(Xow_ns ns) {return db_mgr.Core_data_mgr().Tbl__page().Select_random(ns);}
public Xodb_page_rdr Get_page_rdr(Xowe_wiki wiki) {return new Xodb_page_rdr__sql(wiki);}
public void Clear() {}
public Xowd_page_itm[] Load_ctg_list(byte[][] ctg_ttls) {
if (db_mgr.Core_data_mgr().Db__cat_core() == null) return Xowd_page_itm.Ary_empty;
int len = ctg_ttls.length;
Ordered_hash hash = Ordered_hash_.New_bry();
for (int i = 0; i < len; i++) {
Xowd_page_itm page = new Xowd_page_itm();
byte[] ttl = Xoa_ttl.Replace_spaces(ctg_ttls[i]); // NOTE: ctg_ttls has spaces since v1 rendered it literally;
page.Ttl_page_db_(ttl);
if (!hash.Has(ttl))
hash.Add(ttl, page);
}
len = hash.Count(); // must update len (!hash.Has() may have skipped titles)
db_mgr.Core_data_mgr().Tbl__page().Select_in__ttl(Cancelable_.Never, hash, Xow_ns_.Id_category, 0, len);
Ordered_hash hash2 = Ordered_hash_.New();
for (int i = 0; i < len; i++) {
Xowd_page_itm page = (Xowd_page_itm)hash.Get_at(i);
if (!hash2.Has(page.Id_val()))
hash2.Add(page.Id_val(), page);
}
len = hash2.Count(); // must update len (!hash2.Has() may have skipped titles)
db_mgr.Core_data_mgr().Db__cat_core().Tbl__cat_core().Select_by_cat_id_in(Cancelable_.Never, hash2, 0, len);
return (Xowd_page_itm[])hash.To_ary(Xowd_page_itm.class);
}
private static boolean Ctg_select_v1(Xowe_wiki wiki, Xowd_db_mgr core_data_mgr, Xoctg_view_ctg view_ctg, int link_db_id, Xowd_category_itm ctg) {
List_adp link_list = List_adp_.new_();
core_data_mgr.Dbs__get_at(link_db_id).Tbl__cat_link().Select_in(link_list, ctg.Id());
int link_list_len = link_list.Count();
link_list.Sort_by(Xowd_page_itm_sorter.IdAsc);
core_data_mgr.Tbl__page().Select_in__id(Cancelable_.Never, false, link_list, 0, link_list_len);
link_list.Sort_by(Xowd_page_itm_sorter.Ns_id_TtlAsc);
boolean rv = false;
for (int i = 0; i < link_list.Count(); i++) {
Xowd_page_itm page = (Xowd_page_itm)link_list.Get_at(i);
if (page.Ns_id() == Int_.Min_value) continue; // HACK: page not found; ignore
byte ctg_tid = Xodb_load_mgr_txt.Load_ctg_v1_tid(page.Ns_id());
Xoctg_view_grp ctg_grp = view_ctg.Grp_by_tid(ctg_tid);
Xoctg_view_itm ctg_itm = new Xoctg_view_itm();
ctg_itm.Load_by_ttl_data(ctg_tid, page.Id(), 0, page.Text_len());
ctg_itm.Ttl_(Xoa_ttl.parse(wiki, page.Ns_id(), page.Ttl_page_db()));
ctg_itm.Sortkey_(page.Ttl_page_db());
ctg_grp.Itms_add(ctg_itm);
rv = true;
}
for (byte i = 0; i < Xoa_ctg_mgr.Tid__max; i++) {
Xoctg_view_grp ctg_grp = view_ctg.Grp_by_tid(i);
ctg_grp.Itms_make();
ctg_grp.Total_(ctg_grp.Itms().length);
}
return rv;
}
}

View File

@@ -0,0 +1,173 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.bldrs.*; import gplx.xowa.wikis.ctgs.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.nss.*;
public class Xodb_load_mgr_sql_tst {
@Before public void init() {if (Xoa_test_.Db_skip()) return; fxt.Clear();} private Xodb_load_mgr_sql_fxt fxt = new Xodb_load_mgr_sql_fxt();
@After public void term() {if (Xoa_test_.Db_skip()) return; fxt.Rls();}
@Test public void Load_ctg_ttls() {
if (Xoa_test_.Db_skip()) return;
Xowd_page_itm[] ctgs = fxt.pages_
( fxt.ctg_(1, "Ctg_1", Bool_.Y, 10, 11, 12)
, fxt.ctg_(2, "Ctg_2", Bool_.N, 20, 21, 22)
, fxt.ctg_(3, "Ctg_3", Bool_.Y, 30, 31, 32)
);
fxt.Init_save_ctgs(ctgs);
fxt.Test_load_ctg_list(ctgs);
}
}
class Xoctg_url_mok extends Xoctg_url { public Xoctg_url_mok Page_bgn_(String v) {return Grp(Xoa_ctg_mgr.Tid_page, Bool_.Y, v);}
public Xoctg_url_mok Page_end_(String v) {return Grp(Xoa_ctg_mgr.Tid_page, Bool_.N, v);}
Xoctg_url_mok Grp(byte tid, boolean v, String bmk) {
this.Grp_fwds()[tid] = v ? Bool_.Y_byte : Bool_.N_byte;
this.Grp_idxs()[tid] = Bry_.new_a7(bmk);
return this;
}
}
class Xodb_load_mgr_sql_fxt {
Db_mgr_fxt fxt; Int_obj_ref next_id = Int_obj_ref.new_(1); Xoae_app app; Xowe_wiki wiki;
public void Clear() {
if (fxt == null) {
fxt = new Db_mgr_fxt();
fxt.Ctor_fsys();
fxt.Init_db_sqlite();
wiki = fxt.Wiki();
app = wiki.Appe();
}
}
public void Rls() {fxt.Rls();}
public Xowd_page_itm[] pages_(Xowd_page_itm... ary) {return ary;}
public Xowd_page_itm ctg_(int id, String ttl, boolean hidden, int count_subcs, int count_files, int count_pages) {
Xowd_page_itm rv = new Xowd_page_itm().Ns_id_(Xow_ns_.Id_category).Id_(id).Ttl_page_db_(Bry_.new_a7(ttl));
Xowd_category_itm ctg = Xowd_category_itm.load_(id, 0, hidden, count_subcs, count_files, count_pages);
rv.Xtn_(ctg);
return rv;
}
public void Init_save_ctgs(Xowd_page_itm[] ary) {
int len = ary.length;
Xodb_mgr_sql db_mgr = wiki.Db_mgr_as_sql();
Xowd_cat_core_tbl cat_core_tbl = db_mgr.Core_data_mgr().Db__cat_core().Tbl__cat_core().Create_tbl();
DateAdp modified = DateAdp_.Now();
Xowd_page_tbl tbl_page = wiki.Db_mgr_as_sql().Core_data_mgr().Tbl__page();
tbl_page.Insert_bgn();
cat_core_tbl.Insert_bgn();
for (int i = 0; i < len; i++) {
Xowd_page_itm page = ary[i];
tbl_page.Insert_cmd_by_batch(page.Id(), page.Ns_id(), page.Ttl_page_db(), false, modified, 10, page.Id(), 0, 0);
Xowd_category_itm ctg_itm = (Xowd_category_itm)page.Xtn();
cat_core_tbl.Insert_cmd_by_batch(ctg_itm.Id(), ctg_itm.Count_pages(), ctg_itm.Count_subcs(), ctg_itm.Count_files(), Bool_.To_byte(ctg_itm.Hidden()), 0);
}
cat_core_tbl.Insert_end();
tbl_page.Insert_end();
}
public void Test_load_ctg_list(Xowd_page_itm[] ary) {
int len = ary.length;
byte[][] ttls = new byte[len][];
for (int i = 0; i < len; i++) {
ttls[i] = ary[i].Ttl_page_db();
}
Xowd_page_itm[] actl = wiki.Db_mgr_as_sql().Load_mgr().Load_ctg_list(ttls);
Tfds.Eq_str_lines(Xto_str(ary), Xto_str(actl));
}
private static String Xto_str(Xowd_page_itm[] ary) {
Bry_bfr bfr = Bry_bfr.new_();
int len = ary.length;
for (int i = 0; i < len; i++) {
Xowd_page_itm page = ary[i];
Xowd_category_itm ctg_itm = (Xowd_category_itm)page.Xtn();
bfr.Add_int_variable(page.Id()).Add_byte_pipe();
bfr.Add(page.Ttl_page_db()).Add_byte_pipe();
bfr.Add_byte(Bool_.To_byte(ctg_itm.Hidden())).Add_byte_nl();
}
return bfr.To_str_and_clear();
}
public Xoctg_url_mok ctg_url_() {return new Xoctg_url_mok();}
public Xodb_load_mgr_sql_fxt Init_limit_(int v) {limit = v; return this;} private int limit = 3;
public void Test_select(Xoctg_url ctg_url, Xoctg_mok_ctg expd) {
Xoctg_view_ctg view_ctg = new Xoctg_view_ctg();
wiki.Db_mgr_as_sql().Load_mgr().Load_ctg_v2a(view_ctg, ctg_url, expd.Ttl(), limit);
for (byte i = 0; i < Xoa_ctg_mgr.Tid__max; i++) {
Xoctg_view_grp view_grp = view_ctg.Grp_by_tid(i);
Xoctg_mok_grp mok_grp = expd.Grps_get_or_new(i);
Tfds.Eq_ary_str(Xto_str(mok_grp), Xto_str(view_grp));
Tfds.Eq(String_.new_a7(mok_grp.Last_plus_one_sortkey()), String_.new_a7(view_grp.Itms_last_sortkey()));
}
}
String[] Xto_str(Xoctg_view_grp grp) {
Xoctg_view_itm[] ary = grp.Itms();
int len = ary.length;
String[] rv = new String[len];
for (int i = 0; i< len; i++) {
Xoctg_view_itm itm = ary[i];
rv[i] = itm.Ttl().Page_db_as_str();
}
return rv;
}
String[] Xto_str(Xoctg_mok_grp grp) {
List_adp list = grp.Itms();
int len = list.Count();
String[] rv = new String[len];
for (int i = 0; i< len; i++) {
Xowd_page_itm itm = (Xowd_page_itm)list.Get_at(i);
rv[i] = String_.new_a7(itm.Ttl_page_db());
}
return rv;
}
public Xoctg_mok_ctg ctg_() {
Xoctg_mok_ctg rv = new Xoctg_mok_ctg(next_id);
return rv;
}
}
class Xoctg_mok_grp {
public byte Tid() {return tid;} public Xoctg_mok_grp Tid_(byte v) {this.tid = v; return this;} private byte tid;
public byte[] Last_plus_one_sortkey() {return last_plus_one_sortkey;} public Xoctg_mok_grp Last_plus_one_sortkey_(byte[] v) {this.last_plus_one_sortkey = v; return this;} private byte[] last_plus_one_sortkey;
public List_adp Itms() {return itms;} List_adp itms = List_adp_.new_();
}
class Xoctg_mok_ctg {
public Xoctg_mok_ctg(Int_obj_ref next_id) {this.next_id = next_id;} Int_obj_ref next_id;
public byte[] Ttl() {return ttl;}
public Xoctg_mok_ctg Ttl_(String v) {return Ttl_(Bry_.new_a7(v));}
public Xoctg_mok_ctg Ttl_(byte[] v) {this.ttl = v; return this;} private byte[] ttl;
public Xoctg_mok_grp[] Grps() {return grps;} private Xoctg_mok_grp[] grps = new Xoctg_mok_grp[3];
public Xoctg_mok_grp Grps_get_or_new(byte tid) {
Xoctg_mok_grp rv = grps[tid];
if (rv == null) {
rv = new Xoctg_mok_grp().Tid_(tid);
grps[tid] = rv;
}
return rv;
}
public Xoctg_mok_ctg Grp_pages_(int count) {return Grp_pages_(0, count, null);}
public Xoctg_mok_ctg Grp_pages_(int bgn, int end, String last_itm_plus_one_sortkey) {
Xoctg_mok_grp grp = Grps_get_or_new(Xoa_ctg_mgr.Tid_page);
byte[] ttl_prefix = Bry_.new_a7("Page_");
int ns_id = Xow_ns_.Id_main;
byte ctg_tid = Xoa_ctg_mgr.Tid_page;
for (int i = bgn; i < end; i++) {
byte[] ttl = Bry_.Add(ttl_prefix, Bry_.new_a7(Int_.To_str_pad_bgn_zero(i, 3)));
Xoctg_page_xtn db_ctg = new Xoctg_page_xtn(ctg_tid, ttl);
Xowd_page_itm page = new Xowd_page_itm();
int page_id = next_id.Val_add_post();
page.Id_(page_id).Ns_id_(ns_id).Ttl_page_db_(ttl).Xtn_(db_ctg);
grp.Itms().Add(page);
}
grp.Last_plus_one_sortkey_(Bry_.new_a7(last_itm_plus_one_sortkey));
return this;
}
}

View File

@@ -0,0 +1,571 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.flds.*; import gplx.xowa.bldrs.cmds.ctgs.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.specials.search.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.tdbs.hives.*; import gplx.xowa.wikis.tdbs.xdats.*;
import gplx.xowa.guis.views.*;
public class Xodb_load_mgr_txt implements Xodb_load_mgr {
private final Xob_xdat_file tmp_xdat_file = new Xob_xdat_file(); private final Xob_xdat_itm tmp_xdat_itm = new Xob_xdat_itm();
private final Xowd_page_itm tmp_page = new Xowd_page_itm();
private final Object thread_lock = new Object();
private Xowe_wiki wiki; private Xotdb_fsys_mgr fsys_mgr;
public Xodb_load_mgr_txt(Xowe_wiki wiki) {
this.wiki = wiki;
this.fsys_mgr = wiki.Tdb_fsys_mgr();
}
public void Load_init (Xowe_wiki wiki) {}
public void Load_page(Xowd_page_itm rv, Xow_ns ns, boolean timestamp_enabled) {Load_page(rv, rv.Text_db_id(), rv.Tdb_row_idx(), ns, timestamp_enabled, tmp_xdat_file, tmp_xdat_itm);}
public void Load_page(Xowd_page_itm rv, int txt_fil_idx, int txt_row_idx, Xow_ns ns, boolean timestamp_enabled, Xob_xdat_file xdat_file, Xob_xdat_itm xdat_itm) {
Io_url file = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_page, ns.Id(), txt_fil_idx);
byte[] bry = gplx.ios.Io_stream_rdr_.Load_all(file); int bry_len = bry.length;
xdat_file.Clear().Parse(bry, bry_len, file).GetAt(xdat_itm, txt_row_idx);
Load_page_parse(rv, bry, bry_len, xdat_itm.Itm_bgn(), xdat_itm.Itm_end(), timestamp_enabled);
}
public boolean Load_by_ttl(Xowd_page_itm rv, Xow_ns ns, byte[] ttl) { // NOTE: ttl must be correct case; EX: "Example title"
if (!Env_.Mode_testing() && wiki.Init_needed()) wiki.Init_assert(); // NOTE: need to call assert as wiki_finder (and possibly elsewhere) may call load on commons_wiki without ever asserting; DATE:2013-03-19
if (!Load_xdat_itm(tmp_xdat_itm, ns, Xotdb_dir_info_.Tid_ttl, ttl, Xotdb_page_itm_.Txt_ttl_pos, Byte_ascii.Tab, true)) return false;
Xotdb_page_itm_.Txt_ttl_load(rv, tmp_xdat_itm.Itm_bry());
rv.Exists_(true);
return Bry_.Eq(rv.Ttl_page_db(), ttl);
}
public void Load_by_ttls(Cancelable cancelable, Ordered_hash rv, boolean fill_idx_fields_only, int bgn, int end) {// NOTE: Load_by_ttls just a wrapper around Load_by_ttl; for xdat, Load_by_ttl is fast enough
for (int i = bgn; i < end; i++) {
if (cancelable.Canceled()) return;
Xowd_page_itm page = (Xowd_page_itm)rv.Get_at(i);
Load_by_ttl(page, page.Ns(), page.Ttl_page_db());
}
}
public void Load_by_ids(Cancelable cancelable, List_adp list, int bgn, int end) {
int prv_fil_idx = -1;
byte[] id_bry = new byte[5];
int len = end - bgn;
Gfo_usr_dlg_fmt msg_wtr = Gfo_usr_dlg_fmt.fmt_(GRP_KEY, "search2_ids", "resolving ids: ~{0} of ~{1} (~{2})", len, 10f);
for (int i = 0; i < len; i++) {
if (cancelable.Canceled()) return;
Xowd_page_itm itm = (Xowd_page_itm)list.Get_at(i + bgn);
Base85_utl.XtoStrByAry(itm.Id(), id_bry, 0, 5);
int cur_fil_idx = this.Find_file_idx_by_site(Xotdb_dir_info_.Tid_id, id_bry);
if (cur_fil_idx != prv_fil_idx) {
if (!this.Load_xdat_file(cancelable, tmp_xdat_file, Xotdb_dir_info_.Tid_id, cur_fil_idx)) continue; // file not found; ignore
prv_fil_idx = cur_fil_idx;
}
if (!this.Load_by_id(tmp_page, tmp_xdat_file, id_bry)) continue; // id not found in file; ignore
itm.Ns_id_(tmp_page.Ns_id()).Ttl_page_db_(tmp_page.Ttl_page_db());
msg_wtr.Write_prog_cur(i, wiki.Appe().Usr_dlg());
}
}
public void Load_search(Cancelable cancelable, List_adp rv, byte[] search, int results_max) {
Xow_ns ns = wiki.Ns_mgr().Ns_main();
int search_len = search.length;
byte match_tid = Xows_page__search.Match_tid_all;
if (search_len > 0 && search[search_len - 1] == Byte_ascii.Star) {
search = Bry_.Mid(search, 0, search_len - 1);
match_tid = Xows_page__search.Match_tid_bgn;
}
int bgn_idx = this.Find_file_idx_by_ns(Xotdb_dir_info_.Tid_search_ttl, ns, search);
if (bgn_idx == Xow_data_mgr.File_idx_unknown) return;
if (match_tid == Xows_page__search.Match_tid_all) {
if (!this.Load_xdat_file(cancelable, tmp_xdat_file, Xotdb_dir_info_.Tid_search_ttl, ns, bgn_idx)) return;
tmp_xdat_file.Find(tmp_xdat_itm, search, 0, Byte_ascii.Pipe, true);
if (tmp_xdat_itm.Missing()) return;
Find_ttls__add_itms(rv, tmp_xdat_file, tmp_xdat_itm);
}
else {
byte[] end_ttl = Bry_.Increment_last(Bry_.Copy(search));
int end_idx = this.Find_file_idx_by_ns(Xotdb_dir_info_.Tid_search_ttl, ns, end_ttl);
for (int i = bgn_idx; i <= end_idx; i++) {
if (cancelable.Canceled()) return;
this.Load_xdat_file(cancelable, tmp_xdat_file, Xotdb_dir_info_.Tid_search_ttl, ns, i);
if (cancelable.Canceled()) return;
int itm_bgn_idx = 0;
if (i == bgn_idx) {
tmp_xdat_file.Find(tmp_xdat_itm, search, 0, Byte_ascii.Pipe, false);
itm_bgn_idx = tmp_xdat_itm.Itm_idx();
}
int itm_end_idx = tmp_xdat_file.Count();
if (i == end_idx) {
tmp_xdat_file.Find(tmp_xdat_itm, end_ttl, 0, Byte_ascii.Pipe, false);
itm_end_idx = tmp_xdat_itm.Itm_idx();
}
for (int j = itm_bgn_idx; j < itm_end_idx; j++) {
tmp_xdat_file.GetAt(tmp_xdat_itm, j);
Find_ttls__add_itms(rv, tmp_xdat_file, tmp_xdat_itm);
}
}
}
}
private void Find_ttls__add_itms(List_adp rv, Xob_xdat_file rdr, Xob_xdat_itm xdat_itm) {
byte[] raw = rdr.Src();
int itm_bgn = xdat_itm.Itm_bgn(), itm_end = xdat_itm.Itm_end();
int pos = Bry_find_.Find_fwd(raw, Byte_ascii.Pipe, itm_bgn, raw.length);
if (pos == Bry_.NotFound) throw wiki.Appe().Usr_dlg().Fail_many(GRP_KEY, "invalid_search_file", "search file is invalid");
pos += Int_.Const_dlm_len; // pipe
while (pos < itm_end) {
int page_id = Base85_utl.XtoIntByAry(raw, pos, pos + 4);
pos += 6; // 5 + 1 for semic;
int page_len = Base85_utl.XtoIntByAry(raw, pos, pos + 4);
rv.Add(Xowd_page_itm.new_srch(page_id, page_len));
pos += 6; // 5 + 1 for pipe
// if (match.Itms_len() == max_results) break;
}
}
public boolean Load_ctg_v2(Xoctg_data_ctg ctg, byte[] name) {
boolean rv = Load_xdat_itm(tmp_xdat_itm, Xotdb_dir_info_.Tid_category2_link, name, true); if (!rv) return false;
byte[] src = tmp_xdat_itm.Itm_bry();
Load_ctg_v2_data(wiki.Appe().Usr_dlg(), wiki.Appe().Utl_fld_rdr(), ctg, name, src, tmp_ctg_grp_lens);
Load_ctg_v2_main(ctg, name);
return true;
} int[] tmp_ctg_grp_lens = new int[3];
private void Load_ctg_v2_data(Gfo_usr_dlg usr_dlg, Gfo_fld_rdr fld_rdr, Xoctg_data_ctg ctg, byte[] ctg_name, byte[] src, int[] tmp_grp_lens) { // Name|subc_len|file_len|page_len|subc_bfr|file_bfr|page_bfr
fld_rdr.Data_(src); fld_rdr.Read_bry_escape(); // 1st field is name; skip;
Load_ctg_v2_data_lens(fld_rdr, tmp_grp_lens);
Load_ctg_v2_data_mgrs(usr_dlg, ctg_name, src, fld_rdr.Pos(), tmp_grp_lens, ctg.Grp_mgrs());
}
private void Load_ctg_v2_data_lens(Gfo_fld_rdr fld_rdr, int[] grp_lens) {
for (int i = 0; i < 3; i++)
grp_lens[i] = fld_rdr.Read_int_base85_len5();
}
private void Load_ctg_v2_data_mgrs(Gfo_usr_dlg usr_dlg, byte[] ctg_name, byte[] src, int bgn, int[] grp_lens, Xoctg_idx_mgr[] grp_mgrs) {
for (int i = 0; i < 3; i++) {
int grp_len = grp_lens[i]; if (grp_len == 0) continue;
int end = bgn + grp_len;
Xoctg_idx_mgr grp_mgr = new Xoctg_idx_mgr();
byte[] grp_src = Bry_.Mid(src, bgn, end);
grp_mgr.Src_(grp_src);
grp_mgr.Index(usr_dlg, ctg_name, grp_src);
grp_mgrs[i] = grp_mgr;
bgn = end;
}
}
private void Load_ctg_v2_main(Xoctg_data_ctg rv, byte[] name) {
if (!Load_xdat_itm(tmp_xdat_itm, Xotdb_dir_info_.Tid_category2_main, name, true)) return;
if (tmp_xdat_itm.Missing()) return;
byte[] bry = tmp_xdat_itm.Itm_bry();
int bgn = name.length + 1;
boolean hidden = bry[bgn] == Byte_ascii.Ltr_y;
int count_subcs = Base85_utl.XtoIntByAry(bry, bgn + 2, bgn + 6);
int count_files = Base85_utl.XtoIntByAry(bry, bgn + 8, bgn + 12);
int count_pages = Base85_utl.XtoIntByAry(bry, bgn + 14, bgn + 18);
rv.Hidden_(hidden);
for (byte i = 0; i < Xoa_ctg_mgr.Tid__max; i++) {
Xoctg_idx_mgr idx_mgr = rv.Grp_by_tid(i);
if (idx_mgr == null) continue;
int count = 0;
switch (i) {
case Xoa_ctg_mgr.Tid_subc: count = count_subcs; break;
case Xoa_ctg_mgr.Tid_file: count = count_files; break;
case Xoa_ctg_mgr.Tid_page: count = count_pages; break;
default: throw Err_.new_unhandled(i);
}
idx_mgr.Total_(count);
}
}
public boolean Load_by_id(Xowd_page_itm page, int id) {Base85_utl.XtoStrByAry(id, tmp_id_bry, 0, 5); return Load_by_id(page, tmp_id_bry);} private byte[] tmp_id_bry = new byte[5];
boolean Load_by_id(Xowd_page_itm page, byte[] id_bry) {
if (!Load_xdat_itm(tmp_xdat_itm, Xotdb_dir_info_.Tid_id, id_bry, true)) return false;;
Xotdb_page_itm_.Txt_id_load(page, tmp_xdat_itm.Itm_bry());
return true;
}
boolean Load_by_id(Xowd_page_itm page, Xob_xdat_file xdat_file, byte[] id_bry) {
xdat_file.Find(tmp_xdat_itm, id_bry, 0, Byte_ascii.Pipe, true);
if (tmp_xdat_itm.Missing()) return false;
Xotdb_page_itm_.Txt_id_load(page, tmp_xdat_itm.Itm_bry());
return true;
}
private boolean Load_xdat_itm(Xob_xdat_itm xdat_itm, byte regy_tid, byte[] key, boolean exact) {return Load_xdat_itm(xdat_itm, null, regy_tid, key, 0, Byte_ascii.Pipe, exact);}
private boolean Load_xdat_itm(Xob_xdat_itm xdat_itm, Xow_ns ns, byte regy_tid, byte[] key, int parse_bgn, byte parse_dlm, boolean exact) {
// get regy
Xowd_regy_mgr regy = null;
if (ns == null)
regy = Get_regy_by_site(regy_tid);
else {
regy = Get_regy_by_ns(ns);
if (regy == null) return false;
}
// find file
int fil_idx = regy.Files_find(key);
if (fil_idx == Xowd_regy_mgr.Regy_null) return false; // NOTE: must check for -1, not 0; else defect in which entries in file 0 are ignored; DATE:2013-04-11
// load file
Io_url fil = ns == null ? fsys_mgr.Url_site_fil(regy_tid, fil_idx) : fsys_mgr.Url_ns_fil(regy_tid, ns.Id(), fil_idx);
Load_xdat_file(Cancelable_.Never, tmp_xdat_file, fil);
// find itm by key
tmp_xdat_file.Find(xdat_itm, key, parse_bgn, parse_dlm, exact);
return !xdat_itm.Missing();
} private final Int_obj_ref tmp_len = Int_obj_ref.zero_();
public boolean Load_xdat_file(Cancelable cancelable, Xob_xdat_file xdat_file, byte regy_tid, int fil_idx) {return Load_xdat_file(cancelable, xdat_file, regy_tid, null, fil_idx);}
boolean Load_xdat_file(Cancelable cancelable, Xob_xdat_file xdat_file, byte regy_tid, Xow_ns ns, int fil_idx) {
Io_url fil = ns == null ? fsys_mgr.Url_site_fil(regy_tid, fil_idx) : fsys_mgr.Url_ns_fil(regy_tid, ns.Id(), fil_idx);
return Load_xdat_file(cancelable, xdat_file, fil);
}
public boolean Load_xdat_file(Cancelable cancelable, Xob_xdat_file xdat_file, Io_url url) {
boolean rv = false;
synchronized (thread_lock) {
if (cancelable.Canceled()) return false;
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
byte[] tmp_bry = tmp_bfr.Bfr();
if (cancelable.Canceled()) return false;
tmp_bry = Io_mgr.Instance.LoadFilBry_reuse(url, tmp_bry, tmp_len);
if (cancelable.Canceled()) return false;
if (tmp_bry.length == 0)
wiki.Appe().Usr_dlg().Warn_many("", "file.empty", "hive file is empty: ~{0}", url.Raw());
else {
int src_len = tmp_len.Val();
xdat_file.Clear().Parse(tmp_bry, src_len, url);
xdat_file.Src_len_(src_len);
rv = true;
}
if (cancelable.Canceled()) return false;
tmp_bfr.Clear_and_rls();
}
return rv;
}
int Find_file_idx_by_ns(byte regy_tid, Xow_ns ns, byte[] key) {
Xowd_regy_mgr regy = new Xowd_regy_mgr(fsys_mgr.Url_ns_reg(ns.Num_str(), regy_tid));
return regy.Files_find(key);
}
public int Find_file_idx_by_site(byte regy_tid, byte[] key) {
Xowd_regy_mgr regy = site_regys[regy_tid];
if (regy == null) {
regy = new Xowd_regy_mgr(fsys_mgr.Url_site_reg(regy_tid));
site_regys[regy_tid] = regy;
}
return regy.Files_find(key);
}
public void Clear() {
int len = ns_regys.length;
for (int i = 0; i < len; i++)
ns_regys[i] = null;
len = site_regys.length;
for (int i = 0; i < len; i++)
site_regys[i] = null;
}
public byte[] Find_random_ttl(Xow_ns ns) {
Xowd_regy_mgr regy_mgr = this.Get_regy_by_ns(ns);
Int_obj_ref count = Int_obj_ref.zero_();
Xob_random_itm[] files = Build_random_itms(regy_mgr, count);
int random_idx = RandomAdp_.new_().Next(count.Val() - 1); // get a random idx; -1 since count is super 1 (EX: count of 1 mil; random_idx of 0 - 999,999)
int file_idx = CompareAble_.FindSlot(Xob_random_itm_comparer.Instance, files, new Xob_random_itm(-1, random_idx, -1));
Io_url file_url = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_ttl, ns.Id(), file_idx);
Load_xdat_file(Cancelable_.Never, tmp_xdat_file, file_url);
Xob_random_itm file = files[file_idx];
tmp_xdat_file.GetAt(tmp_xdat_itm, random_idx - file.Bgn()); // get nth row; EX: random_idx=120; .Bgn=103 -> get 17th
Xowd_page_itm page = Xotdb_page_itm_.Txt_ttl_load(tmp_xdat_itm.Itm_bry());
return page.Ttl_page_db();
}
private static Xob_random_itm[] Build_random_itms(Xowd_regy_mgr mgr, Int_obj_ref count) {
// convert regy to list of random_itms (similar to regy_itms, but has integer bgn / end; EX: [0]:0,50; [1]:51-102; [2]:103-130)
Xowd_hive_regy_itm[] files_ary = mgr.Files_ary();
int len = files_ary.length;
Xob_random_itm[] rv = new Xob_random_itm[len];
int tmp_count = 0;
for (int i = 0; i < len; i++) {
Xowd_hive_regy_itm file = files_ary[i];
rv[i] = new Xob_random_itm(i, tmp_count, file.Count());
tmp_count += file.Count();
}
count.Val_(tmp_count);
return rv;
}
public boolean Load_ctg_v1(Xoctg_view_ctg view_ctg, byte[] ctg_ttl) {return Load_ctg_v1_wkr(view_ctg, ctg_ttl, null);}
private boolean Load_ctg_v1_wkr(Xoctg_view_ctg view_ctg, byte[] ctg_ttl, Int_obj_ref count_only) {
Xowd_regy_mgr ctg_regy = Get_regy_by_site(Xotdb_dir_info_.Tid_category);
int fil_idx = ctg_regy.Files_find(ctg_ttl);
if (fil_idx == Xowd_regy_mgr.Regy_null) return false; // NOTE: must check for -1, not 0; else defect in which entries in file 0 are ignored; DATE:2013-04-11
Io_url fil = fsys_mgr.Url_site_fil(Xotdb_dir_info_.Tid_category, fil_idx);
Load_xdat_file(Cancelable_.Never, tmp_xdat_file, fil);
tmp_xdat_file.Find(tmp_xdat_itm, ctg_ttl, 0, Byte_ascii.Pipe, true);
if (tmp_xdat_itm.Missing()) return false;
List_adp ctgs = List_adp_.new_();
Load_ctg_v1_parse(ctgs, wiki.Appe().Usr_dlg(), tmp_xdat_itm.Itm_bry());
ctgs.Sort_by(Xowd_page_itm_sorter.IdAsc);
this.Load_by_ids(Cancelable_.Never, ctgs, 0, ctgs.Count());
ctgs.Sort_by(Xowd_page_itm_sorter.Ns_id_TtlAsc);
int ctgs_len = ctgs.Count(); if (ctgs_len == 0) return false;
if (count_only != null) { // Ctg_count specificed
count_only.Val_(ctgs_len);
return true;
}
for (int i = 0; i < ctgs_len; i++) {
Xowd_page_itm itm = (Xowd_page_itm)ctgs.Get_at(i);
byte itm_tid = Load_ctg_v1_tid(itm.Ns_id());
Xoctg_view_itm sub = Load_ctg_v1_sub(itm_tid, itm);
sub.Ttl_(Xoa_ttl.parse(wiki, itm.Ns_id(), itm.Ttl_page_db())).Sortkey_(itm.Ttl_page_db());
view_ctg.Grp_by_tid(itm_tid).Itms_add(sub);
}
for (byte i = 0; i < Xoa_ctg_mgr.Tid__max; i++) {
Xoctg_view_grp grp = view_ctg.Grp_by_tid(i);
grp.Itms_make();
grp.Total_(grp.Itms().length);
}
return true;
}
private static void Load_ctg_v1_parse(List_adp rv, Gfo_usr_dlg usr_dlg, byte[] ary) {
int aryLen = ary.length;
int pos = Bry_find_.Find_fwd(ary, Byte_ascii.Pipe, 0, aryLen);
int rowCount = (aryLen - pos + 1) / (Base85_utl.Len_int + gplx.xowa.apps.progs.Xoa_prog_mgr.Len_dlm_fld);
rv.Clear();
boolean garbage = false;
for (int i = 0; i < rowCount; i++) {
Xowd_page_itm row = new Xowd_page_itm();
rv.Add(row);
if (garbage) continue;
int bgn = pos + 1 + (i * (Base85_utl.Len_int + gplx.xowa.apps.progs.Xoa_prog_mgr.Len_dlm_fld));
try {
int id = Base85_utl.XtoIntByAry(ary, bgn, bgn + Base85_utl.Len_int - 1);
if (id < 0) throw Err_.new_wo_type("invalid id", "id", id);
row.Id_(id);
}
catch (Exception e) {
row.Id_(0);
usr_dlg.Warn_many("xowa.ttl_request", "parse", "failed to parse row: row=~{0} err=~{1}", String_.new_u8(ary), Err_.Message_lang(e));
garbage = true;
continue; // NOTE: must break b/c rest of ids are garbage
}
}
}
public static byte Load_ctg_v1_tid(int ns_id) {
switch (ns_id) {
case Xow_ns_.Id_category: return Xoa_ctg_mgr.Tid_subc;
case Xow_ns_.Id_file: return Xoa_ctg_mgr.Tid_file;
default: return Xoa_ctg_mgr.Tid_page;
}
}
private static Xoctg_view_itm Load_ctg_v1_sub(byte tid, Xowd_page_itm data) {
Xoctg_view_itm rv = new Xoctg_view_itm();
rv.Load_by_ttl_data(tid, data.Id(), 0, data.Text_len());
return rv;
}
public static boolean Load_page_or_false(Xowd_page_itm page, Xob_xdat_itm xdat, int ns_id) {
byte[] src = xdat.Src(); int itm_end = xdat.Itm_end();
int bgn = xdat.Itm_bgn();
int timestamp = Base85_utl.XtoIntByAry(src, bgn + 6 , bgn + 10);
int ttl_end = Bry_find_.Find_fwd(src, Xotdb_page_itm_.Txt_page_dlm, bgn + 12, itm_end);
if (ttl_end == -1) return false;
byte[] ttl = Bry_.Mid (src, bgn + 12 , ttl_end);
byte[] text = Bry_.Mid (src, ttl_end + 1 , itm_end - 1);
page.Init_by_tdb(-1, -1, xdat.Itm_idx(), Bool_.N, text.length, ns_id, ttl);
page.Modified_on_(Bit_.Xto_date_short(timestamp));
page.Text_(text);
return true;
}
private void Load_page_parse(Xowd_page_itm page, byte[] src, int src_len, int row_bgn, int row_end, boolean timestamp_enabled) { // \n\tdate5\tpage_title\tpage_text
int timestamp_bgn = row_bgn + 5 + 1;
int timestamp_end = timestamp_bgn + 5;
if (timestamp_enabled) {
int timestamp = Base85_utl.XtoIntByAry(src, timestamp_bgn, timestamp_end - 1);
page.Modified_on_(Bit_.Xto_date_short(timestamp));
}
int name_bgn = timestamp_end + 1;
int name_end = Bry_find_.Find_fwd(src, Xotdb_page_itm_.Txt_page_dlm, name_bgn, src_len);
page.Text_(Bry_.Mid(src, name_end + 1, row_end - 1)); // +1 to skip dlm
}
Xowd_regy_mgr Get_regy_by_site(byte regy_tid) {
Xowd_regy_mgr rv = site_regys[regy_tid];
if (rv == null) {
rv = new Xowd_regy_mgr(fsys_mgr.Url_site_reg(regy_tid));
site_regys[regy_tid] = rv;
}
return rv;
} private Xowd_regy_mgr[] site_regys = new Xowd_regy_mgr[Xotdb_dir_info_.Regy_tid_max];
Xowd_regy_mgr Get_regy_by_ns(Xow_ns ns) {
int ns_ord = ns.Ord();
Xowd_regy_mgr rv = ns_regys[ns_ord];
if (rv == null) {
Io_url file = fsys_mgr.Url_ns_reg(ns.Num_str(), Xotdb_dir_info_.Tid_ttl);
if (!Io_mgr.Instance.ExistsFil(file)) return null;
rv = new Xowd_regy_mgr(file);
ns_regys[ns_ord] = rv;
}
return rv;
} private Xowd_regy_mgr[] ns_regys = new Xowd_regy_mgr[Xow_ns_mgr_.Ordinal_max];
private Xowd_page_itm tmp_rslt_nxt = new Xowd_page_itm(), tmp_rslt_prv = new Xowd_page_itm(); private Int_obj_ref tmp_rslt_count = Int_obj_ref.zero_();
public void Load_ttls_for_search_suggest(Cancelable cancelable, List_adp rslt_list, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item) {
this.Load_ttls_for_all_pages(cancelable, rslt_list, tmp_rslt_nxt, tmp_rslt_prv, tmp_rslt_count, ns, key, max_results, min_page_len, browse_len, include_redirects, fetch_prv_item);
}
public void Load_ttls_for_all_pages(Cancelable cancelable, List_adp rslt_list, Xowd_page_itm rslt_nxt, Xowd_page_itm rslt_prv, Int_obj_ref rslt_count, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item) {
byte dir_tid = Xotdb_dir_info_.Tid_ttl;
Xob_xdat_file cur_xdat_file = new Xob_xdat_file();
Xob_xdat_itm cur_xdat_itm = new Xob_xdat_itm();
Xowd_regy_mgr regy = new Xowd_regy_mgr(fsys_mgr.Url_ns_reg(ns.Num_str(), dir_tid));
int fil_idx = regy.Files_find(key); if (fil_idx == Xowd_regy_mgr.Regy_null) return;
if (!this.Load_xdat_file(Cancelable_.Never, cur_xdat_file, dir_tid, ns, fil_idx)) return;
cur_xdat_file.Find(cur_xdat_itm, key, Xotdb_page_itm_.Txt_ttl_pos, Byte_ascii.Tab, false);
int itm_idx = cur_xdat_itm.Itm_idx();
if (itm_idx == -1) itm_idx = 0; // nothing found; return;
Special_allpages_query_fwd(rslt_list, rslt_nxt, rslt_count , dir_tid, ns, include_redirects, browse_len, fil_idx, itm_idx , cur_xdat_file, cur_xdat_itm, regy);
Special_allpages_query_bwd(rslt_list, rslt_prv , dir_tid, ns, include_redirects, browse_len, fil_idx, itm_idx - 1, cur_xdat_file, cur_xdat_itm);
}
private void Special_allpages_query_fwd(List_adp rslt_list, Xowd_page_itm rslt_nxt, Int_obj_ref rslt_count, byte dir_tid, Xow_ns ns, boolean include_redirects, int total, int fil_idx, int row_idx, Xob_xdat_file xdat_file, Xob_xdat_itm xdat_itm, Xowd_regy_mgr regy) {
int count = 0; ++total;
boolean loop = true;
int regy_len = regy.Files_ary().length;
int rslt_list_len = rslt_count.Val();
Xowd_page_itm nxt_itm = null;
while (loop) {
if (fil_idx == regy_len) break;
if (xdat_file == null) {
xdat_file = new Xob_xdat_file();
this.Load_xdat_file(Cancelable_.Never, xdat_file, dir_tid, ns, fil_idx);
row_idx = 0;
}
int rows_len = xdat_file.Count();
for (; row_idx < rows_len; row_idx++) {
xdat_file.GetAt(xdat_itm, row_idx);
Xowd_page_itm ttl_itm = Xotdb_page_itm_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
if (!include_redirects && ttl_itm.Redirected()) continue;
++count;
nxt_itm = ttl_itm;
if (count == total) {
loop = false;
break;
}
else {
rslt_list.Add(ttl_itm);
++rslt_list_len;
}
}
xdat_file = null;
++fil_idx;
}
rslt_count.Val_(rslt_list_len);
if (rslt_nxt != null)
rslt_nxt.Copy(nxt_itm);
}
private void Special_allpages_query_bwd(List_adp rslt_list, Xowd_page_itm rslt_prv, byte dir_tid, Xow_ns ns, boolean include_redirects, int total, int fil_idx, int row_idx, Xob_xdat_file xdat_file, Xob_xdat_itm xdat_itm) {
if (row_idx < 0) {
--fil_idx;
row_idx = -1;
}
int count = 0;
boolean loop = true;
Xowd_page_itm prv_itm = null;
while (loop) {
if (fil_idx == -1) break;
if (xdat_file == null) {
xdat_file = new Xob_xdat_file();
this.Load_xdat_file(Cancelable_.Never, xdat_file, dir_tid, ns, fil_idx);
row_idx = -1;
}
if (row_idx == -1)
row_idx = xdat_file.Count() - 1;
for (; row_idx > -1; row_idx--) {
xdat_file.GetAt(xdat_itm, row_idx);
Xowd_page_itm ttl_itm = Xotdb_page_itm_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
if (!include_redirects && ttl_itm.Redirected()) continue;
// list.Add(ttl_itm);
++count;
prv_itm = ttl_itm;
if (count == total) {
loop = false;
break;
}
else {
// rslt_list_ttls[rslt_list_len++] = ttl_itm;
}
}
xdat_file = null;
--fil_idx;
}
if (prv_itm == null && rslt_list.Count() > 0) {
prv_itm = (Xowd_page_itm)rslt_list.Get_at(0);
}
if (rslt_prv != null)
rslt_prv.Copy(prv_itm);
}
public byte[] Load_qid(byte[] wiki_alias, byte[] ns_num, byte[] ttl) {
String xwiki_key = String_.new_a7(wiki_alias);
if (qids_root == null)
qids_root = wiki.Appe().Wiki_mgr().Wdata_mgr().Wdata_wiki().Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "qid");
Xob_xdat_itm qid_itm = Load_xdat_itm_by_dir(qids_root.GenSubDir_nest(xwiki_key, String_.new_a7(ns_num)), ttl); if (qid_itm == null) return null;
return Bry_.Mid(qid_itm.Src(), qid_itm.Itm_bgn() + ttl.length + 1, qid_itm.Itm_end()); // extract qid; note that all itms have format of "ttl|qid"
} Io_url qids_root;
public int Load_pid(byte[] lang_key, byte[] pid_name) {
if (pids_root == null)
pids_root = wiki.Appe().Wiki_mgr().Wdata_mgr().Wdata_wiki().Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "pid");
Xob_xdat_itm pid_itm = Load_xdat_itm_by_dir(pids_root.GenSubDir(String_.new_u8(lang_key)), pid_name); if (pid_itm == null) return gplx.xowa.xtns.wdatas.Wdata_wiki_mgr.Pid_null;
return Bry_.To_int_or(pid_itm.Src(), pid_itm.Itm_bgn() + pid_name.length + 1 + 1, pid_itm.Itm_end(), gplx.xowa.xtns.wdatas.Wdata_wiki_mgr.Pid_null); // extract pid; note that all itms have format of "ttl|pid"; +1=skip pipe; +1 skip p
} Io_url pids_root;
public int Load_ctg_count(byte[] ttl) {return wiki.Db_mgr().Category_version() == Xoa_ctg_mgr.Version_1 ? Load_ctg_count_v1(ttl) : Load_ctg_count_v2(ttl);}
int Load_ctg_count_v1(byte[] ttl) {
Xoctg_view_ctg view_ctg = new Xoctg_view_ctg();
Int_obj_ref count = Int_obj_ref.zero_();
Load_ctg_v1_wkr(view_ctg, ttl, count);
return count.Val();
}
int Load_ctg_count_v2(byte[] ttl) {
Xoctg_data_ctg data_ctg = new Xoctg_data_ctg(ttl);
Load_ctg_v2(data_ctg, ttl);
return data_ctg.Total_count();
}
Xob_xdat_itm Load_xdat_itm_by_dir(Io_url dir, byte[] ttl) {
Xoa_hive_mgr hive_mgr = wiki.Appe().Hive_mgr();
int fil_idx = hive_mgr.Find_fil(dir, ttl); if (fil_idx == Xowd_regy_mgr.Regy_null) return null; // sub_dir not found; EX: commonswiki if qid; fr if pid;
Xob_xdat_file rdr = hive_mgr.Get_rdr(dir, Xotdb_dir_info_.Bry_xdat, fil_idx);
rdr.Find(tmp_xdat_itm, ttl, 0, Byte_ascii.Pipe, true);
return tmp_xdat_itm.Found_exact() ? tmp_xdat_itm : null;
}
public void Load_ctg_v2a(Xoctg_view_ctg rv, Xoctg_url url_ctg, byte[] ttl_bry, int limit) {
Xoctg_html_mgr ctg_mgr = wiki.Html_mgr().Ns_ctg();
Xoctg_data_cache data_cache = ctg_mgr.Data_cache();
Xoctg_data_ctg data_ctg = data_cache.Get_or_null(ttl_bry);
if (data_ctg == null) {
data_ctg = data_cache.Load_or_null(wiki, ttl_bry);
if (data_ctg == null) return;
}
rv.Fill(url_ctg, data_ctg);
ctg_mgr.Get_titles(wiki.Appe().Usr_dlg(), wiki, rv);
rv.Num_(data_ctg);
}
public Xowd_page_itm[] Load_ctg_list(byte[][] ttls) {
int len = ttls.length;
Xowd_page_itm[] rv = new Xowd_page_itm[len];
Xow_ns ns = wiki.Ns_mgr().Ns_category();
Xoctg_data_ctg ctg_temp = new Xoctg_data_ctg(Bry_.Empty);
for (int i = 0; i < len; i++) {
byte[] ttl = Xoa_ttl.Replace_spaces(ttls[i]); // NOTE: ctg_ttls has spaces since v1 rendered it literally;
Xowd_page_itm page = new Xowd_page_itm();
this.Load_by_ttl(page, ns, ttl);
Load_ctg_v2_main(ctg_temp, page.Ttl_page_db());
Xowd_category_itm ctg_itm = Xowd_category_itm.load_(page.Id(), page.Text_db_id(), ctg_temp.Hidden(), ctg_temp.Total_by_tid(Xoa_ctg_mgr.Tid_subc), ctg_temp.Total_by_tid(Xoa_ctg_mgr.Tid_file), ctg_temp.Total_by_tid(Xoa_ctg_mgr.Tid_page));
page.Xtn_(ctg_itm);
rv[i] = page;
}
return rv;
}
public Xodb_page_rdr Get_page_rdr(Xowe_wiki wiki) {return new Xodb_page_rdr__tdb(wiki);}
static final String GRP_KEY = "xowa.wiki.db.load";
}
class Xob_random_itm {
public int Idx() {return idx;} private int idx;
public int Bgn() {return bgn;} private int bgn;
public int End() {return bgn + len;}
public int Len() {return len;} private int len;
public Xob_random_itm(int idx, int bgn, int len) {this.idx = idx; this.bgn = bgn; this.len = len;}
}
class Xob_random_itm_comparer implements gplx.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
return Int_.Compare(((Xob_random_itm)lhsObj).End(), ((Xob_random_itm)rhsObj).End());
}
public static final Xob_random_itm_comparer Instance = new Xob_random_itm_comparer(); Xob_random_itm_comparer() {}
}

View File

@@ -0,0 +1,28 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.htmls.hdumps.*;
public interface Xodb_mgr extends GfoInvkAble {
byte Tid();
String Tid_name();
byte Category_version();
byte Search_version(); void Search_version_refresh();
Xodb_load_mgr Load_mgr();
Xodb_save_mgr Save_mgr();
DateAdp Dump_date_query(); // used by maint_mgr
}

View File

@@ -0,0 +1,63 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.ios.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.engines.sqlite.*;
import gplx.xowa.apps.gfs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.htmls.hdumps.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
public Xodb_mgr_sql(Xowe_wiki wiki) {
this.wiki = wiki;
this.core_data_mgr = new Xowd_db_mgr(wiki, wiki.Fsys_mgr().Root_dir(), wiki.Domain_itm());
this.load_mgr = new Xodb_load_mgr_sql(this, core_data_mgr);
this.save_mgr = new Xodb_save_mgr_sql(this);
}
public byte Tid() {return Tid_sql;} public String Tid_name() {return "sqlite3";} public static final byte Tid_sql = 1;
public Xowd_db_mgr Core_data_mgr() {return core_data_mgr;} private final Xowd_db_mgr core_data_mgr;
public Xowe_wiki Wiki() {return wiki;} private final Xowe_wiki wiki;
public Xodb_load_mgr Load_mgr() {return load_mgr;} private final Xodb_load_mgr_sql load_mgr;
public Xodb_save_mgr Save_mgr() {return save_mgr;} private final Xodb_save_mgr_sql save_mgr;
public byte Category_version() {return category_version;} private byte category_version = Xoa_ctg_mgr.Version_null;
public byte Search_version() {return load_mgr.Search_version();} public void Search_version_refresh() {load_mgr.Search_version_refresh();}
public DateAdp Dump_date_query() {
DateAdp rv = wiki.Props().Modified_latest(); if (rv != null) return rv;
Io_url url = core_data_mgr.Db__core().Url();
return Io_mgr.Instance.QueryFil(url).ModifiedTime();
}
public void Category_version_update(boolean version_is_1) {
String grp = Xow_cfg_consts.Grp__wiki_init;
String key = Xoa_gfs_wtr_.Write_func_chain(Xowe_wiki.Invk_db_mgr, Xodb_mgr_sql.Invk_category_version);
core_data_mgr.Tbl__cfg().Delete_val(grp, key);// always delete ctg version
category_version = version_is_1 ? Xoa_ctg_mgr.Version_1 : Xoa_ctg_mgr.Version_2;
core_data_mgr.Tbl__cfg().Insert_byte(grp, key, category_version);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_data_storage_format)) return Io_stream_.Obsolete_to_str(core_data_mgr.Props().Zip_tid_text());
else if (ctx.Match(k, Invk_data_storage_format_)) {} // SERIALIZED:000.sqlite3|xowa_cfg; ignore; read from Xow_db_props
else if (ctx.Match(k, Invk_category_version)) return category_version;
else if (ctx.Match(k, Invk_category_version_)) category_version = m.ReadByte("v");
else if (ctx.Match(k, Invk_search_version)) return this.Search_version();
else if (ctx.Match(k, Invk_tid_name)) return this.Tid_name();
return this;
}
public static final String
Invk_data_storage_format = "data_storage_format", Invk_data_storage_format_ = "data_storage_format_" // SERIALIZED:000.sqlite3|xowa_cfg
, Invk_category_version = "category_version", Invk_category_version_ = "category_version_" // SERIALIZED:000.sqlite3|xowa_cfg
, Invk_search_version = "search_version"
, Invk_tid_name = "tid_name"
;
}

View File

@@ -0,0 +1,61 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.nss.*;
public class Xodb_mgr_txt implements Xodb_mgr {
public Xodb_mgr_txt(Xowe_wiki wiki, Xow_data_mgr data_mgr) {
this.wiki = wiki;
load_mgr = new Xodb_load_mgr_txt(wiki);
save_mgr = new Xodb_save_mgr_txt(wiki, load_mgr);
} private Xowe_wiki wiki;
public byte Tid() {return Tid_txt;} public static final byte Tid_txt = 0;
public String Tid_name() {return "xdat";}
public byte Data_storage_format() {return data_storage_format;} public void Data_storage_format_(byte v) {data_storage_format = v;} private byte data_storage_format = gplx.ios.Io_stream_.Tid_raw;
public Xodb_load_mgr Load_mgr() {return load_mgr;} private Xodb_load_mgr_txt load_mgr;
public Xodb_save_mgr Save_mgr() {return save_mgr;} private Xodb_save_mgr_txt save_mgr;
public DateAdp Dump_date_query() {
Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Id_main, 0);
return Io_mgr.Instance.QueryFil(url).ModifiedTime();
}
public byte Category_version() {
if (category_version == Xoa_ctg_mgr.Version_null) {
if (Io_mgr.Instance.ExistsDir(wiki.Tdb_fsys_mgr().Url_site_dir(Xotdb_dir_info_.Tid_category2_link)))
category_version = Xoa_ctg_mgr.Version_2;
else
category_version = Xoa_ctg_mgr.Version_1;
}
return category_version;
} byte category_version = Xoa_ctg_mgr.Version_null;
public byte Search_version() {return gplx.xowa.specials.search.Xows_page__search.Version_2;}
public void Search_version_refresh() {throw Err_.new_unimplemented();}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_data_storage_format)) return Io_stream_.Obsolete_to_str(data_storage_format);
else if (ctx.Match(k, Invk_data_storage_format_)) data_storage_format = Io_stream_.Obsolete_to_tid(m.ReadStr("v"));
else if (ctx.Match(k, Invk_category_version)) return this.Category_version();
else if (ctx.Match(k, Invk_category_version_)) category_version = m.ReadByte("v");
else if (ctx.Match(k, Invk_search_version)) return this.Search_version();
else if (ctx.Match(k, Invk_tid_name)) return Tid_name();
return this;
}
public static final String
Invk_data_storage_format = "data_storage_format", Invk_data_storage_format_ = "data_storage_format_"
, Invk_category_version = "category_version", Invk_category_version_ = "category_version_"
, Invk_search_version = "search_version"
, Invk_tid_name = "tid_name"
;
}

View File

@@ -0,0 +1,24 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.wikis.data.tbls.*;
public interface Xodb_page_rdr {
boolean Move_next();
boolean Read(Xowd_page_itm page);
void Rls();
}

View File

@@ -0,0 +1,40 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.dbs.*;
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
class Xodb_page_rdr__sql implements Xodb_page_rdr {
private final Xowd_db_mgr db_mgr;
private final Xowd_page_tbl page_tbl; private final Db_rdr rdr;
public Xodb_page_rdr__sql(Xowe_wiki wiki) {
this.db_mgr = wiki.Data__core_mgr();
this.page_tbl = db_mgr.Tbl__page();
this.rdr = page_tbl.Select_all();
}
public boolean Move_next() {return rdr.Move_next();}
public boolean Read(Xowd_page_itm page) {
page_tbl.Read_page__all(page, rdr);
Xowd_text_tbl text_tbl = db_mgr.Dbs__get_at(page.Text_db_id()).Tbl__text();
page.Text_(text_tbl.Select(page.Id()));
return true;
}
public void Rls() {
rdr.Rls();
}
}

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.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.ios.*;
import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.tdbs.hives.*; import gplx.xowa.wikis.tdbs.xdats.*;
public class Xodb_page_rdr__tdb implements Xodb_page_rdr {
private final Xow_ns_mgr ns_mgr; private final Xotdb_fsys_mgr fsys_mgr;
private int cur_ns_ord = -1; private Xow_ns cur_ns; private Io_url[] cur_file_ary; private Io_url cur_file; private int cur_file_idx = -1;
private final Xob_xdat_file cur_xdat_file = new Xob_xdat_file(); private int cur_xdat_len, cur_xdat_idx; private final Xob_xdat_itm cur_xdat_itm = new Xob_xdat_itm();
private int page_id = 0;
public Xodb_page_rdr__tdb(Xowe_wiki wiki) {
this.ns_mgr = wiki.Ns_mgr(); this.fsys_mgr = wiki.Tdb_fsys_mgr();
}
public boolean Move_next() {
while (true) {
if (cur_ns == null) {
++this.cur_ns_ord;
if (cur_ns_ord >= ns_mgr.Ords_len()) return false; // no more ns; return false;
this.cur_ns = ns_mgr.Ords_get_at(cur_ns_ord);
this.cur_file_ary = Get_page_url_ary(cur_ns);
if (cur_file_ary == null) { // ns doesn't have files; try next ns;
cur_ns = null;
continue;
}
this.cur_file_idx = -1;
this.cur_file = null;
}
if (cur_file == null) {
++this.cur_file_idx;
if (cur_file_idx == cur_file_ary.length) { // no more files in ns; try next ns;
cur_ns = null;
continue;
}
this.cur_file = cur_file_ary[cur_file_idx];
byte[] bry = Io_stream_rdr_.Load_all(cur_file);
cur_xdat_file.Clear().Parse(bry, bry.length, cur_file);
this.cur_xdat_len = cur_xdat_file.Count();
this.cur_xdat_idx = -1;
}
++this.cur_xdat_idx;
if (cur_xdat_idx == cur_xdat_len) { // no more rows in file; try next file
cur_file = null;
continue;
}
cur_xdat_file.GetAt(cur_xdat_itm, cur_xdat_idx);
return true;
}
}
public boolean Read(Xowd_page_itm page) {
boolean rv = Xodb_load_mgr_txt.Load_page_or_false(page, cur_xdat_itm, cur_ns.Id());
if (!rv)
Xoa_app_.Usr_dlg().Warn_many("", "", "page_rdr.tdb; unable to read page; ns=~{0}, file=~{1} itm_idx=~{2}", cur_ns.Id(), cur_file.Raw(), cur_xdat_idx);
// wiki.Db_mgr().Load_mgr().Load_by_ttl(page, cur_ns, page.Ttl_page_db());
page.Id_(++page_id);
return rv;
}
public void Rls() {}
private Io_url[] Get_page_url_ary(Xow_ns ns) {
Io_url reg_url = fsys_mgr.Url_ns_reg(ns.Num_str(), Xotdb_dir_info_.Tid_ttl);
if (!Io_mgr.Instance.ExistsFil(reg_url)) return null;
Xowd_regy_mgr reg_mgr = new Xowd_regy_mgr(reg_url);
Xowd_hive_regy_itm[] file_ary = reg_mgr.Files_ary();
int len = file_ary.length;
Io_url[] rv = new Io_url[len];
for (int i = 0; i < len; ++i) {
int fil_idx = file_ary[i].Idx();
rv[i] = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_page, ns.Id(), fil_idx);
}
return rv;
}
}

View File

@@ -0,0 +1,27 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public interface Xodb_save_mgr {
boolean Create_enabled(); void Create_enabled_(boolean v);
boolean Update_modified_on_enabled(); void Update_modified_on_enabled_(boolean v);
int Page_id_next(); void Page_id_next_(int v);
void Data_create(Xoa_ttl ttl, byte[] text);
void Data_update(Xoae_page page, byte[] text);
void Data_rename(Xoae_page page, int trg_ns, byte[] trg_ttl);
void Clear();
}

View File

@@ -0,0 +1,80 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.dbs.qrys.*;
import gplx.xowa.wikis.*;
public class Xodb_save_mgr_sql implements Xodb_save_mgr {
private final Xodb_mgr_sql db_mgr;
public Xodb_save_mgr_sql(Xodb_mgr_sql db_mgr) {this.db_mgr = db_mgr;}
public boolean Create_enabled() {return create_enabled;} public void Create_enabled_(boolean v) {create_enabled = v;} private boolean create_enabled;
public boolean Update_modified_on_enabled() {return update_modified_on_enabled;} public void Update_modified_on_enabled_(boolean v) {update_modified_on_enabled = v;} private boolean update_modified_on_enabled;
public int Page_id_next() {return page_id_next;} public void Page_id_next_(int v) {page_id_next = v;} private int page_id_next;
public void Data_create(Xoa_ttl ttl, byte[] text_raw) {
int ns_id = ttl.Ns().Id();
Xowd_db_file db_file = db_mgr.Core_data_mgr().Db__core();
int ns_count = db_file.Tbl__ns().Select_ns_count(ns_id) + 1;
int page_id = db_file.Tbl__cfg().Select_int_or("db", "page.id_next", -1);
if (page_id == -1) { // HACK: changed for tests; was dbs.qrys.Db_qry_sql.rdr_("SELECT (Max(page_id) + 1) AS max_page_id FROM page;")
// Db_rdr rdr = db_mgr.Core_data_mgr().Tbl__page().Conn().Stmt_new(Db_qry_sql.rdr_("SELECT (Max(page_id) + 1) AS max_page_id FROM page;")).Exec_select__rls_manual();
Db_rdr rdr = db_mgr.Core_data_mgr().Tbl__page().Conn().Stmt_select(db_file.Tbl__page().Tbl_name(), String_.Ary(db_file.Tbl__page().Fld_page_id()), Db_meta_fld.Ary_empty).Exec_select__rls_auto();
try {
int max_page_id = -1;
while (rdr.Move_next()) {
int cur_page_id = rdr.Read_int("page_id");
if (cur_page_id > max_page_id) max_page_id = cur_page_id;
}
page_id = max_page_id + 1;
db_mgr.Core_data_mgr().Tbl__cfg().Upsert_int("db", "page.id_next", page_id + 1);
} finally {rdr.Rls();}
}
Xowd_db_mgr fsys_mgr = db_mgr.Core_data_mgr();
Xowd_db_file page_text_db = fsys_mgr.Db__text();
Xowd_text_tbl page_text_tbl = page_text_db.Tbl__text();
byte[] text_zip = page_text_tbl.Zip(text_raw);
boolean redirect = db_mgr.Wiki().Redirect_mgr().Is_redirect(text_raw, text_raw.length);
Xowd_page_tbl page_core_tbl = db_mgr.Core_data_mgr().Tbl__page();
page_core_tbl.Insert_bgn();
page_text_tbl.Insert_bgn();
try {
db_mgr.Core_data_mgr().Create_page(page_core_tbl, page_text_tbl, page_id, ns_id, ttl.Page_db(), redirect, DateAdp_.Now(), text_zip, text_raw.length, ns_count, page_text_db.Id(), -1);
db_file.Tbl__ns().Update_ns_count(ns_id, ns_count);
db_file.Tbl__cfg().Update_int("db", "page.id_next", page_id + 1);
} finally {
page_core_tbl.Insert_end();
page_text_tbl.Insert_end();
}
}
public void Data_update(Xoae_page page, byte[] text_raw) {
boolean redirect = db_mgr.Wiki().Redirect_mgr().Is_redirect(text_raw, text_raw.length);
DateAdp modified = update_modified_on_enabled ? DateAdp_.Now() : page.Revision_data().Modified_on();
int page_id = page.Revision_data().Id();
db_mgr.Core_data_mgr().Tbl__page().Update__redirect__modified(page_id, redirect, modified);
Xowd_page_itm db_page = new Xowd_page_itm();
db_mgr.Load_mgr().Load_by_id(db_page, page.Revision_data().Id());
Xowd_text_tbl text_tbl = db_mgr.Core_data_mgr().Dbs__get_at(db_page.Text_db_id()).Tbl__text();
text_tbl.Update(page.Revision_data().Id(), text_raw);
// int html_db_id = db_page.Html_db_id();
// if (html_db_id != -1)
// db_mgr.Core_data_mgr().Tbl__page().Update__html_db_id(page_id, -1); // zap html_db_id so that next load will repopulate it
}
public void Data_rename(Xoae_page page, int trg_ns, byte[] trg_ttl) {
db_mgr.Core_data_mgr().Tbl__page().Update__ns__ttl(page.Revision_data().Id(), trg_ns, trg_ttl);
}
public void Clear() {}
}

View File

@@ -0,0 +1,122 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.parsers.utils.*;
import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.tdbs.hives.*; import gplx.xowa.wikis.tdbs.xdats.*;
public class Xodb_save_mgr_txt implements Xodb_save_mgr {
public Xodb_save_mgr_txt(Xowe_wiki wiki, Xodb_load_mgr_txt load_mgr) {
this.wiki = wiki;
this.load_mgr = load_mgr;
this.fsys_mgr = wiki.Tdb_fsys_mgr();
this.redirect_mgr = wiki.Redirect_mgr();
} private Xowe_wiki wiki; private Xotdb_fsys_mgr fsys_mgr; private Xodb_load_mgr_txt load_mgr; private Xop_redirect_mgr redirect_mgr;
public boolean Create_enabled() {return create_enabled;} public void Create_enabled_(boolean v) {create_enabled = v;} private boolean create_enabled;
public boolean Update_modified_on_enabled() {return update_modified_on_enabled;} public void Update_modified_on_enabled_(boolean v) {update_modified_on_enabled = v;} private boolean update_modified_on_enabled;
public int Page_id_next() {return page_id_next;} public void Page_id_next_(int v) {page_id_next = v;} private int page_id_next = 0;
public void Clear() {page_id_next = 0;} // TEST: needed for ctg_test
public void Data_create(Xoa_ttl ttl, byte[] text) {
Xow_ns ns_itm = ttl.Ns(); byte[] ttl_bry = ttl.Page_db();
Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
boolean found = load_mgr.Load_by_ttl(db_page, ns_itm, ttl_bry);
if (found) throw Err_.new_wo_type("create requested but title already exists", "ttl", String_.new_u8(ttl_bry));
int text_len = text.length;
Bry_bfr tmp = wiki.Utl__bfr_mkr().Get_m001();
int page_id = page_id_next++;
int fil_idx = 0;
int ns_id = ttl.Ns().Id();
Xotdb_page_itm_.Txt_page_save(tmp, page_id, DateAdp_.Now(), ttl_bry, text, true);
Io_url page_rdr_url = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_page, ns_id, fil_idx);
byte[] page_rdr_bry = gplx.ios.Io_stream_rdr_.Load_all(page_rdr_url);
Xob_xdat_file page_rdr = new Xob_xdat_file();
if (Bry_.Len_gt_0(page_rdr_bry)) page_rdr.Parse(page_rdr_bry, page_rdr_bry.length, page_rdr_url);
int row_idx = page_rdr.Count();
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
page_rdr.Insert(tmp_bfr, tmp.To_bry_and_clear());
this.Data_save(Xotdb_dir_info_.Tid_page, page_rdr, page_rdr_url, tmp_bfr);
tmp_bfr.Mkr_rls();
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(text, text_len);
db_page.Init(page_id, ttl.Page_db(), redirect_ttl != null, text_len, fil_idx, row_idx);
Xotdb_page_itm_.Txt_ttl_save(tmp, db_page);
byte[] ttl_row_bry = tmp.To_bry_and_rls();
Xowd_hive_mgr ttl_hive = new Xowd_hive_mgr(wiki, Xotdb_dir_info_.Tid_ttl);
ttl_hive.Create(ttl.Ns(), ttl.Page_db(), ttl_row_bry, Bry_comparer_fld_last.Instance);
wiki.Db_mgr().Load_mgr().Clear(); // NOTE: need to clear cached regy_ary in load_mgr
}
public void Data_update(Xoae_page page, byte[] text) {Data_update_under(page, text, null);}
public void Data_rename(Xoae_page page, int trg_ns, byte[] trg_ttl) {
if (wiki.Domain_tid() != Xow_domain_tid_.Int__home) {
wiki.Appe().Usr_dlg().Warn_many("", "", "Only pages in the home wiki can be renamed");
return;
}
Data_update_under(page, null, trg_ttl);
}
private void Data_update_under(Xoae_page page, byte[] text, byte[] new_ttl) {
Xoa_ttl ttl = page.Ttl();
Xow_ns ns = ttl.Ns(); byte[] ttl_bry = ttl.Page_db();
Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
if (!load_mgr.Load_by_ttl(db_page, ns, ttl_bry)) throw Err_.new_wo_type("update requested but title does not exist", "ttl", String_.new_u8(ttl_bry));
byte[] old_ttl = ttl_bry;
if (new_ttl != null) {
ttl_bry = new_ttl;
db_page.Ttl_page_db_(new_ttl);
}
// update page
Xob_xdat_file page_rdr = new Xob_xdat_file(); Xob_xdat_itm page_itm = new Xob_xdat_itm();
load_mgr.Load_page(tmp_page, db_page.Text_db_id(), db_page.Tdb_row_idx(), ns, true, page_rdr, page_itm);
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
if (text == null) text = tmp_page.Text();
int text_len = text.length;
DateAdp modified_on = tmp_page.Modified_on();
if (update_modified_on_enabled) {
modified_on = DateAdp_.Now();
page.Revision_data().Modified_on_(modified_on);
}
Xotdb_page_itm_.Txt_page_save(tmp_bfr, db_page.Id(), modified_on, ttl_bry, text, true);
page_rdr.Update(tmp_bfr, page_itm, tmp_bfr.To_bry_and_clear());
Io_url page_rdr_url = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_page, ttl.Ns().Id(), db_page.Text_db_id());
this.Data_save(Xotdb_dir_info_.Tid_page, page_rdr, page_rdr_url, tmp_bfr);
tmp_bfr.Mkr_rls();
// update ttl
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(text, text_len);
db_page.Text_len_(text_len);
db_page.Redirected_(redirect_ttl != null);
Bry_bfr tmp = wiki.Utl__bfr_mkr().Get_b512();
Xotdb_page_itm_.Txt_ttl_save(tmp, db_page);
byte[] ttl_row_bry = tmp.To_bry_and_clear();
tmp.Mkr_rls();
Xowd_hive_mgr ttl_hive = new Xowd_hive_mgr(wiki, Xotdb_dir_info_.Tid_ttl);
ttl_hive.Update(ns, old_ttl, new_ttl, ttl_row_bry, Xotdb_page_itm_.Txt_ttl_pos, Byte_ascii.Pipe, true, true);
}
private void Data_save(byte dir_tid, Xob_xdat_file xdat_file, Io_url url, Bry_bfr tmp_bfr) {
xdat_file.Save(url);
}
private Xowd_page_itm tmp_page = new Xowd_page_itm();
public static final int File_idx_unknown = -1;
}
class Bry_comparer_fld_last implements gplx.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
byte[] lhs = (byte[])lhsObj, rhs = (byte[])rhsObj;
int lhs_bgn = Bry_find_.Find_bwd(lhs, Byte_ascii.Pipe); if (lhs_bgn == Bry_.NotFound) lhs_bgn = -1;
int rhs_bgn = Bry_find_.Find_bwd(rhs, Byte_ascii.Pipe); if (rhs_bgn == Bry_.NotFound) rhs_bgn = -1;
return Bry_.Compare(lhs, lhs_bgn + 1, lhs.length, rhs, rhs_bgn + 1, rhs.length);
}
public static final Bry_comparer_fld_last Instance = new Bry_comparer_fld_last();
}

View File

@@ -0,0 +1,68 @@
/*
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.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.wikis.data.tbls.*;
class Xodb_upgrade_mgr {
public static void Upgrade(Xodb_mgr_sql db_mgr, Db_cfg_hash cfg_hash, String version_key, String version_val) {
// String version_new = null;
// if (String_.Eq(version_val, "0.6.2.0")) {
// Xodb_upgrade_mgr_v0_6_2_0.Upgrade(db_mgr, kv_ary);
// version_new = "0.6.2.1";
// }
// if (version_new != null) {
// db_mgr.Tbl_xowa_cfg().Update(Xodb_mgr_sql.Grp__wiki_init, version_key, version_new);
// }
}
}
// class Xodb_upgrade_mgr_v0_6_2_0 {
// public static void Upgrade(Xodb_mgr_sql db_mgr, KeyVal[] kv_ary) {
// Db_conn p = db_mgr.Fsys_mgr().Core_provider();
// Fix_storage_format(p, db_mgr, kv_ary);
// Fix_category_version(p, db_mgr);
// }
// private static void Fix_storage_format(Db_conn p, Xodb_mgr_sql db_mgr, KeyVal[] kv_ary) { // storage_format saved incorrectly as int
// int len = kv_ary.length;
// String gfs_data_storage_format = Xoa_gfs_mgr.Build_code(Xowe_wiki.Invk_db_mgr, Xodb_mgr_sql.Invk_data_storage_format);
// for (int i = 0; i < len; i++) {
// KeyVal kv = kv_ary[i];
// String kv_key = kv.Key();
// if (String_.Eq(kv_key, gfs_data_storage_format)) {
// byte data_storage_format_byte = Byte_.parse(kv.Val_to_str_or_empty());
// String data_storage_format_name = Xoi_dump_mgr.Wtr_tid_to_str(data_storage_format_byte);
// kv.Val_(data_storage_format_name); // update memory
// db_mgr.Tbl_xowa_cfg().Update(Xodb_mgr_sql.Grp__wiki_init, gfs_data_storage_format, data_storage_format_name); // update_database
// break;
// }
// }
// }
// private static void Fix_category_version(Db_conn p, Xodb_mgr_sql db_mgr) {
// Db_qry qry = Db_qry_.select_().From_(Xodb_categorylinks_tbl.Tbl_name).Cols_(Xodb_categorylinks_tbl.Fld_cl_type_id).Where_(Db_crt_.eq_(Xodb_categorylinks_tbl.Fld_cl_type_id, ));
// Db_stmt stmt = Db_stmt_.Null;
// DataRdr rdr = DataRdr_.Null;
// int types = 0;
// try {
// stmt = db_mgr.Fsys_mgr().Category_provider().Prepare(qry);
// rdr = stmt.Exec_select();
// while (rdr.MoveNextPeer()) {
// ++types;
// }
// } finally {rdr.Rls(); stmt.Rls();}
// boolean schema_is_1 = types <= 1; // if 0 or 1 types assume version_1 (1=page only; 0=not set up)
// db_mgr.Category_version_update(true); // assume version_1; will be wrong if user actually did version_2, but currently version_1 vs version_2 has no
// }
// }