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

@@ -1,146 +0,0 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.core.lists.*; /*ComparerAble*/ import gplx.xowa.bldrs.cmds.ctgs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.guis.views.*;
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.*; import gplx.xowa.langs.msgs.*;
import gplx.xowa.parsers.utils.*;
import gplx.xowa.wikis.data.tbls.*;
public class Xow_data_mgr implements GfoInvkAble {
private Xop_redirect_mgr redirect_mgr;
private Xoa_url tmp_url = Xoa_url.blank();
public Xow_data_mgr(Xowe_wiki wiki) {this.wiki = wiki; this.redirect_mgr = wiki.Redirect_mgr();}
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public boolean Version_is_1() {return Bool_.Y;}
public Xoae_page Get_page(Xoa_ttl ttl, boolean called_from_tmpl) {tmp_url = wiki.Utl__url_parser().Parse(ttl.Raw()); return Get_page(tmp_url, ttl, called_from_tmpl, false);}
public Xoae_page Get_page_from_msg(Xoa_ttl ttl) {tmp_url = wiki.Utl__url_parser().Parse(ttl.Raw()); return Get_page(tmp_url, ttl, false, true);}
public Xoae_page Get_page(Xoa_url url, Xoa_ttl ttl, boolean called_from_tmpl, boolean called_from_msg) {
Xoae_page rv = Xoae_page.New(wiki, ttl);
return Get_page(rv, url, ttl, called_from_tmpl, called_from_msg);
}
public Xoae_page Get_page(Xoae_page rv, Xoa_url url, Xoa_ttl ttl, boolean called_from_tmpl, boolean called_from_msg) {
rv.Url_(url); // NOTE: must update page.Url(); should combine with Xoae_page.New()
Xow_ns ns = ttl.Ns();
switch (ns.Id()) {
case Xow_ns_.Tid__special:
wiki.Special_mgr().Special__gen(wiki.App(), wiki, rv, url, ttl);
return rv;
case Xow_ns_.Tid__mediawiki:
if ( !called_from_msg // if called from msg, fall through to actual data retrieval below, else infinite loop; DATE:2014-05-09
&& Xow_page_tid.Identify_by_ttl(ttl.Page_db()) == Xow_page_tid.Tid_wikitext // skip ".js" and ".css" pages in MediaWiki; DATE:2014-06-13
) {
Xol_lang_itm lang = wiki.Lang();
byte[] msg_key = ttl.Page_db();
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
msg_key = lang.Case_mgr().Case_build_1st_lower(tmp_bfr, msg_key, 0, msg_key.length);
byte[] msg_val = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, wiki.Lang(), msg_key).Val(); // NOTE: do not change to Get_msg_val; Get_msg_val, also replaces $1 with values, and $1 needs to be preserved for callers;
rv.Data_raw_(msg_val);
tmp_bfr.Mkr_rls();
return rv;
}
break;
}
return Get_page(rv, ns, ttl, called_from_tmpl, url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no));
}
public Xoae_page Get_page(Xoae_page rv, Xow_ns ns, Xoa_ttl ttl, boolean called_from_tmpl, boolean redirect_force) {
int redirects = 0;
Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
while (true) {
boolean exists = wiki.Db_mgr().Load_mgr().Load_by_ttl(db_page, ns, ttl.Page_db());
if (!exists) return rv.Missing_();
if (wiki.App().Mode().Tid_is_gui()) // NOTE: must check if gui, else will write during mass build; DATE:2014-05-03
wiki.Appe().Usr_dlg().Prog_many(GRP_KEY, "file_load", "loading page for ~{0}", String_.new_u8(ttl.Raw()));
wiki.Db_mgr().Load_mgr().Load_page(db_page, ns, !called_from_tmpl);
byte[] bry = db_page.Text();
rv.Data_raw_(bry).Revision_data().Modified_on_(db_page.Modified_on()).Id_(db_page.Id()).Html_db_id_(db_page.Html_db_id());
if (redirect_force) return rv;
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(bry);
if ( redirect_ttl == null // not a redirect
|| redirects++ > 4) // too many redirects; something went wrong
break;
rv.Redirected_ttls().Add(ttl.Full_url()); // NOTE: must be url_encoded; EX: "en.wikipedia.org/?!" should generate link of "en.wikipedia.org/%3F!?redirect=no"
if (rv.Redirected_src() == null) rv.Redirected_src_(bry); // only add src for first redirect; DATE:2014-07-11
rv.Ttl_(redirect_ttl);
ns = redirect_ttl.Ns();
ttl = redirect_ttl;
}
return rv;
}
public Xoae_page Load_page_by_ttl(Xoa_url url, Xoa_ttl ttl) {return Load_page_by_ttl(url, ttl, wiki.Lang(), wiki.Appe().Gui_mgr().Browser_win().Active_tab(), true);}
public Xoae_page Load_page_by_ttl(Xoa_url url, Xoa_ttl ttl, Xog_tab_itm tab) {return Load_page_by_ttl(url, ttl, wiki.Lang(), tab, true);}
public Xoae_page Load_page_by_ttl(Xoa_url url, Xoa_ttl ttl, Xol_lang_itm lang, Xog_tab_itm tab, boolean parse_page) {
wiki.Init_assert();
Xoae_page page = Xoae_page.New(wiki, ttl); page.Tab_data().Tab_(tab);
this.Get_page(page, url, ttl, false, false); // get page from data_mgr
if (page.Missing()) { // page doesn't exist
boolean vnt_missing = true;
Xol_vnt_mgr vnt_mgr = lang.Vnt_mgr();
if (vnt_mgr.Enabled()) { // if vnt enabled, then try to load by vnt form; DATE:2015-09-15
gplx.xowa.wikis.data.tbls.Xowd_page_itm page_itm = vnt_mgr.Convert_mgr().Convert_ttl(wiki, ttl);
if (page_itm != null && page_itm.Exists()) {
Xoa_ttl vnt_ttl = Xoa_ttl.parse(wiki, ttl.Ns().Id(), page_itm.Ttl_page_db());
page = this.Get_page(vnt_ttl, false);
vnt_missing = page.Missing();
}
}
if (vnt_missing) {
if (ttl.Ns().Id_is_file()) {
Xowe_wiki commons_wiki = (Xowe_wiki)wiki.Appe().Wiki_mgr().Get_by_or_null(wiki.Commons_wiki_key());
if (commons_wiki != null) { // commons exists
if (!Bry_.Eq(wiki.Domain_bry(), commons_wiki.Domain_bry())) { // !Bry_.Eq is recursion guard
Xoae_page rv = commons_wiki.Data_mgr().Load_page_by_ttl(url, ttl, wiki.Lang(), tab, true);
if (rv.Exists()) {
rv.Commons_mgr().Source_wiki_(wiki);
return rv;
}
else {
page.Missing_(false);
page.Commons_mgr().Xowa_mockup_(true);
return page;
}
}
}
}
else
return page.Missing_();
}
}
if (page.Missing()) return page; // NOTE: commons can return null page
page.Tab_data().Tab_(tab);
page.Lang_(lang);
if (parse_page)
wiki.Parser_mgr().Parse(page, false); // NOTE: do not clear page b/c reused for search
return page;
}
public Xoae_page Redirect(Xoae_page page, byte[] page_bry) {
Xoa_ttl trg_ttl = Xoa_ttl.parse(wiki, page_bry);
Xoa_url trg_url = Xoa_url.new_(wiki.Domain_bry(), page_bry);
page.Ttl_(trg_ttl).Url_(trg_url).Redirected_(true);
return wiki.Data_mgr().Get_page(page, trg_ttl.Ns(), trg_ttl, false, trg_url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no));
}
public static final int File_idx_unknown = -1;
static final String GRP_KEY = "xowa.wiki.data";
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_create_enabled_)) wiki.Db_mgr().Save_mgr().Create_enabled_(m.ReadYn("v"));
else if (ctx.Match(k, Invk_update_modified_on_enabled_)) wiki.Db_mgr().Save_mgr().Update_modified_on_enabled_(m.ReadYn("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_create_enabled_ = "create_enabled_", Invk_update_modified_on_enabled_ = "update_modified_on_enabled_";
}

View File

@@ -62,7 +62,7 @@ public class Xow_data_mgr_tst {
;
}
@Test public void Update_zip() {
// fxt.Wiki().Fsys_mgr().Dir_regy()[Xow_ns_.Tid__main].Ext_tid_(gplx.core.ios.Io_stream_.Tid_zip);
// fxt.Wiki().Fsys_mgr().Dir_regy()[Xow_ns_.Tid__main].Ext_tid_(gplx.core.ios.streams.Io_stream_.Tid_zip);
// fxt.Wiki().Data_mgr().Zip_mgr_(new Io_zip_mgr_mok());
// fxt .Create("A1", "A1 data")
// .Create("B12", "B12 data")

View File

@@ -18,10 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.bldrs.infos.*;
import gplx.xowa.wikis.data.site_stats.*;
import gplx.xowa.htmls.core.dbs.*; import gplx.xowa.addons.apps.searchs.dbs.*;
public class Xowd_db_file {
Xowd_db_file(Db_cfg_tbl cfg_tbl, Xob_info_session info_session, Xob_info_file info_file, Xowd_core_db_props props, Xowd_db_file_schema_props schema_props, int id, byte tid, Io_url url, String ns_ids, int part_id, Guid_adp guid, Db_conn conn, byte cmd_mode) {
this.id = id; this.tid = tid; this.url = url; this.ns_ids = ns_ids; this.part_id = part_id; this.guid = guid; this.db_props = props; this.schema_props = schema_props;
import gplx.xowa.htmls.core.dbs.*; import gplx.xowa.addons.wikis.searchs.dbs.*;
import gplx.xowa.addons.wikis.htmls.css.dbs.*;
public class Xow_db_file {
protected Xow_db_file(Db_cfg_tbl cfg_tbl, Xowd_core_db_props props, Xob_info_session info_session, Xob_info_file info_file, Xow_db_file_schema_props schema_props, int id, byte tid, Io_url url, String ns_ids, int part_id, Guid_adp guid, Db_conn conn, byte cmd_mode) {
this.id = id; this.tid = tid; this.url = url; this.ns_ids = ns_ids; this.part_id = part_id; this.guid = guid; this.db_props = props;
this.conn = conn; this.cmd_mode = cmd_mode;
this.url_rel = url.NameAndExt();
boolean schema_is_1 = props.Schema_is_1();
@@ -36,10 +37,11 @@ public class Xowd_db_file {
this.tbl__css_file = new Xowd_css_file_tbl(conn);
this.tbl__cat_core = new Xowd_cat_core_tbl(conn, schema_is_1);
this.tbl__cat_link = new Xowd_cat_link_tbl(conn, schema_is_1);
this.tbl__wbase_qid = new Xowd_wbase_qid_tbl(conn, schema_is_1, schema_props.Wbase__qid__src_ttl_has_spaces());
this.tbl__wbase_qid = new Xowd_wbase_qid_tbl(conn, schema_is_1, schema_props == null ? Bool_.N : schema_props.Wbase__qid__src_ttl_has_spaces());
this.tbl__wbase_pid = new Xowd_wbase_pid_tbl(conn, schema_is_1);
this.info_session = info_session;
this.info_file = info_file;
this.schema_props = schema_props;
}
public int Id() {return id;} private final int id; // unique id in xowa_db
public byte Tid() {return tid;} private final byte tid;
@@ -47,15 +49,13 @@ public class Xowd_db_file {
public Io_url Url() {return url;} private final Io_url url;
public String Url_rel() {return url_rel;} private final String url_rel;
public Xowd_core_db_props Db_props() {return db_props;} private final Xowd_core_db_props db_props;
public Xowd_db_file_schema_props Schema_props() {return schema_props;} private final Xowd_db_file_schema_props schema_props;
public String Ns_ids() {return ns_ids;} private final String ns_ids;
public int Ns_id_or_fail() {return Int_.parse(ns_ids);}
public int Part_id() {return part_id;} private final int part_id;
public Guid_adp Guid() {return guid;} private final Guid_adp guid;
public byte Cmd_mode() {return cmd_mode;} public Xowd_db_file Cmd_mode_(byte v) {cmd_mode = v; return this;} private byte cmd_mode;
public long File_len() {return file_len;} public Xowd_db_file File_len_add(int v) {file_len += v; return this;} private long file_len;
public long File_max() {return file_max;} public Xowd_db_file File_max_(long v) {file_max = v; return this;} private long file_max;
public Xob_info_session Info_session() {return info_session;} private final Xob_info_session info_session;
public Xob_info_file Info_file() {return info_file;} private final Xob_info_file info_file;
public byte Cmd_mode() {return cmd_mode;} public Xow_db_file Cmd_mode_(byte v) {cmd_mode = v; return this;} private byte cmd_mode;
public long File_len() {return file_len;} public Xow_db_file File_len_add(int v) {file_len += v; return this;} private long file_len;
public long File_max() {return file_max;} public Xow_db_file File_max_(long v) {file_max = v; return this;} private long file_max;
public Db_cfg_tbl Tbl__cfg() {return tbl__cfg;} private final Db_cfg_tbl tbl__cfg;
public Xowd_xowa_db_tbl Tbl__db() {return tbl__db;} private final Xowd_xowa_db_tbl tbl__db;
public Xowd_site_ns_tbl Tbl__ns() {return tbl__ns;} private final Xowd_site_ns_tbl tbl__ns;
@@ -69,27 +69,44 @@ public class Xowd_db_file {
public Xow_site_stats_tbl Tbl__site_stats() {return tbl__site_stats;} private final Xow_site_stats_tbl tbl__site_stats;
public Xowd_wbase_qid_tbl Tbl__wbase_qid() {return tbl__wbase_qid;} private final Xowd_wbase_qid_tbl tbl__wbase_qid;
public Xowd_wbase_pid_tbl Tbl__wbase_pid() {return tbl__wbase_pid;} private final Xowd_wbase_pid_tbl tbl__wbase_pid;
public void Rls() {conn.Rls_conn();}
public Xowd_page_tbl Tbl__page__rebind() {this.tbl__page = new Xowd_page_tbl(tbl__page.conn, tbl__page.schema_is_1); return tbl__page;}
public Xob_info_session Info_session() {
if (info_session == null) // NOTE: null when load; !null when make
info_session = Xob_info_session.Load(tbl__cfg);
return info_session;
} private Xob_info_session info_session;
public Xob_info_file Info_file() {
if (info_file == null) // NOTE: null when load; !null when make
info_file = Xob_info_file.Load(tbl__cfg);
return info_file;
} private Xob_info_file info_file;
public Xow_db_file_schema_props Schema_props() {
if (schema_props == null)
schema_props = Xow_db_file_schema_props.load_(tbl__cfg, tid, this.Info_session().Version()); // NOTE: must call .Info_session
return schema_props;
} private Xow_db_file_schema_props schema_props;
public static final Xowd_db_file Null = null;
public static Xowd_db_file make_(Xob_info_session info_session, Xowd_core_db_props props, int id, byte tid, Io_url url, String ns_ids, int part_id, String core_file_name, Db_conn conn) {
Guid_adp guid = Guid_adp_.new_();
Xob_info_file info_file = new Xob_info_file(id, Xowd_db_file_.To_key(tid), ns_ids, part_id, guid, props.Schema(), core_file_name, url.NameAndExt());
public void Rls() {conn.Rls_conn();}
public Xowd_page_tbl Tbl__page__rebind() {
this.tbl__page = new Xowd_page_tbl(tbl__page.Conn(), tbl__page.schema_is_1);
return tbl__page;
}
public static final Xow_db_file Null = null;
public static Xow_db_file make_(Xob_info_session info_session, Xowd_core_db_props props, int id, byte tid, Io_url url, String ns_ids, int part_id, String core_file_name, Db_conn conn) {
Guid_adp guid = Guid_adp_.New();
Xob_info_file info_file = new Xob_info_file(id, Xow_db_file_.To_key(tid), ns_ids, part_id, guid, props.Schema(), core_file_name, url.NameAndExt());
Db_cfg_tbl cfg_tbl = gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn);
Xowd_db_file rv = new Xowd_db_file(cfg_tbl, info_session, info_file, props, Xowd_db_file_schema_props.make_(), id, tid, url, ns_ids, part_id, guid, conn, Db_cmd_mode.Tid_create);
Xow_db_file rv = new Xow_db_file(cfg_tbl, props, info_session, info_file, Xow_db_file_schema_props.make_(), id, tid, url, ns_ids, part_id, guid, conn, Db_cmd_mode.Tid_create);
cfg_tbl.Create_tbl(); // always create cfg in each db
return rv;
}
public static Xowd_db_file load_(Xowd_core_db_props props, int id, byte tid, Io_url url, String ns_ids, int part_id, Guid_adp guid) {
public static Xow_db_file load_(Xowd_core_db_props props, int id, byte tid, Io_url url, String ns_ids, int part_id, Guid_adp guid) {
Db_conn conn = Db_conn_bldr.Instance.Get(url);
if (conn == null) {
Xoa_app_.Usr_dlg().Warn_many("", "", "wiki.db:missing db; tid=~{0} url=~{1}", Xowd_db_file_.To_key(tid), url.Raw());
Xoa_app_.Usr_dlg().Warn_many("", "", "wiki.db:missing db; tid=~{0} url=~{1}", Xow_db_file_.To_key(tid), url.Raw());
conn = Db_conn_.Noop;
}
Db_cfg_tbl cfg_tbl = gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn); // NOTE: this loads the cfg tbl for the current db, not the core db
Xob_info_session info_session = Xob_info_session.Load(cfg_tbl);
Xob_info_file info_file = Xob_info_file.Load(cfg_tbl);
return new Xowd_db_file(cfg_tbl, info_session, info_file, props, Xowd_db_file_schema_props.load_(cfg_tbl, tid, info_session.Version()), id, tid, url, ns_ids, part_id, guid, conn, Db_cmd_mode.Tid_ignore);
return new Xow_db_file(cfg_tbl, props, null, null, null, id, tid, url, ns_ids, part_id, guid, conn, Db_cmd_mode.Tid_ignore);
}
}

View File

@@ -0,0 +1,60 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_db_file_ {
public static final int Uid__core = 0;
public static final byte
Tid__core = 1, Tid__text = 2, Tid__cat = 3, Tid__search_core = 4, Tid__wbase = 5 // SERIALIZED:v1
, Tid__cat_core = 6, Tid__cat_link = 7 // SERIALIZED:v2
, Tid__wiki_solo = 8, Tid__text_solo = 9
, Tid__html_solo = 10, Tid__html_data = 11
, Tid__file_solo = 12, Tid__file_core = 13, Tid__file_data = 14, Tid__file_user = 15
, Tid__search_link = 16, Tid__random = 17, Tid__css = 18
;
private static final String
Key__core = "core", Key__text = "text", Key__cat = "xtn.category", Key__search_core = "xtn.search.core", Key__wbase = "core.wbase"
, Key__cat_core = "xtn.category.core", Key__cat_link = "xtn.category.link"
, Key__text_solo = "text.solo", Key__wiki_solo = "wiki.solo"
, Key__html_solo = "html.solo", Key__html_data = "html"
, Key__file_solo = "file.solo", Key__file_core = "file.core", Key__file_data = "file.data", Key__file_user = "file.user"
, Key__search_link = "xtn.search.link", Key__random = "xtn.random", Key__css = "xtn.css"
;
public static String To_key(byte v) {
switch (v) {
case Tid__core: return Key__core;
case Tid__text: return Key__text;
case Tid__cat: return Key__cat;
case Tid__search_core: return Key__search_core;
case Tid__wbase: return Key__wbase;
case Tid__cat_core: return Key__cat_core;
case Tid__cat_link: return Key__cat_link;
case Tid__wiki_solo: return Key__wiki_solo;
case Tid__text_solo: return Key__text_solo;
case Tid__html_solo: return Key__html_solo;
case Tid__html_data: return Key__html_data;
case Tid__file_solo: return Key__file_solo;
case Tid__file_core: return Key__file_core;
case Tid__file_data: return Key__file_data;
case Tid__file_user: return Key__file_user;
case Tid__search_link: return Key__search_link;
case Tid__random: return Key__random;
case Tid__css: return Key__css;
default: throw Err_.new_unhandled(v);
}
}
}

View File

@@ -0,0 +1,117 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.dbs.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.bldrs.infos.*;
public class Xow_db_file__core_ {
public static Io_url Find_core_fil(Xow_wiki wiki) {
Io_url wiki_root_dir = wiki.Fsys_mgr().Root_dir();
String domain_str = wiki.Domain_str();
Io_url[] ary = Io_mgr.Instance.QueryDir_fils(wiki_root_dir);
int ary_len = ary.length; if (ary.length == 0) return null;
Io_url rv = Find_core_fil__xowa(ary, ary_len, domain_str);
return rv == null ? Find_core_fil__sqlite3(wiki_root_dir, ary, ary_len, domain_str) : rv;
}
private static Io_url Find_core_fil__xowa(Io_url[] ary, int ary_len, String domain_str) {
for (int i = 0; i < ary_len; i++) {
Io_url itm = ary[i];
if (!String_.Eq(itm.Ext(), ".xowa")) continue;
if ( String_.Eq(itm.NameOnly(), domain_str) // EX: "en.wikipedia.org"
|| String_.Eq(itm.NameOnly(), domain_str + "-core") // EX: "en.wikipedia.org-core"
) {
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.v2: url=~{0}", itm.Raw());
return itm;
}
}
for (int i = 0; i < ary_len; i++) { // DB.FEW: DATE:2016-06-07
Io_url itm = ary[i];
if (!String_.Eq(itm.Ext(), ".xowa")) continue;
if ( String_.Eq(itm.NameOnly(), domain_str + "-text") // EX: "en.wikipedia.org-text"
) {
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.v2: url=~{0}", itm.Raw());
return itm;
}
}
return null;
}
private static Io_url Find_core_fil__sqlite3(Io_url wiki_root_dir, Io_url[] ary, int ary_len, String domain_str) {
Io_url rv = null;
String v0_str = domain_str + ".000";
for (int i = 0; i < ary_len; i++) {
Io_url itm = ary[i];
if (!String_.Eq(itm.Ext(), ".sqlite3")) continue;
if (String_.Eq(itm.NameOnly(), v0_str)) { // EX: "en.wikipedia.org.000"
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.v1: url=~{0}", itm.Raw());
return itm;
}
if (ary_len == 1) {
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.custom: url=~{0}", itm.Raw());
return rv; // 1 folder and 1 sqlite file; return it; custom wikis?
}
}
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.none: dir=~{0}", wiki_root_dir.Raw());
return rv;
}
public static boolean Is_core_fil_name(String domain_name, String fil_name) {
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(Bry_.new_u8(domain_name));
if (domain_itm.Domain_type_id() == Xow_domain_tid_.Int__other) {
return String_.Has_at_end(fil_name, ".xowa");
}
String domain_str = domain_itm.Domain_str();
return ( String_.Eq(fil_name, domain_str + "-text.xowa")
|| String_.Eq(fil_name, domain_str + "-core.xowa")
|| String_.Eq(fil_name, domain_str + ".xowa")
);
}
public static Xow_db_file Make_core_db(Xowd_core_db_props props, Xob_info_session info_session, Io_url wiki_root_dir, String domain_str) {
String core_file_name = Xow_db_file__core_.Core_file_name(props.Layout_text(), domain_str);
byte core_db_tid = Xow_db_file__core_.Core_db_tid(props.Layout_text());
Io_url core_db_url = wiki_root_dir.GenSubFil(core_file_name);
Db_conn core_conn = Db_conn_bldr.Instance.New(core_db_url);
// make tbls
Xow_db_file rv = Xow_db_file.make_(info_session, props, Xow_db_file_.Uid__core, core_db_tid, core_db_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, core_file_name, core_conn);
rv.Tbl__db().Create_tbl();
rv.Tbl__ns().Create_tbl();
rv.Tbl__site_stats().Create_tbl();
rv.Tbl__page().Create_tbl();
if (props.Layout_text().Tid_is_all_or_few()) { // create in advance else will fail for v2; import wiki -> wiki loads and tries to load categories; v2 category processes and builds tbl; DATE:2015-03-22
rv.Tbl__cat_core().Create_tbl();
rv.Tbl__cat_link().Create_tbl();
}
return rv;
}
private static String Core_file_name(Xow_db_layout layout, String domain_name) {
switch (layout.Tid()) {
case Xow_db_layout.Tid__all: return domain_name + ".xowa"; // EX: en.wikipedia.org.xowa
case Xow_db_layout.Tid__few: //return domain_name + "-text.xowa"; // EX: en.wikipedia.org-text.xowa // DB.FEW: DATE:2016-06-07
case Xow_db_layout.Tid__lot: return domain_name + "-core.xowa"; // EX: en.wikipedia.org-core.xowa
default: throw Err_.new_unimplemented();
}
}
public static byte Core_db_tid(Xow_db_layout layout) {
switch (layout.Tid()) {
case Xow_db_layout.Tid__all: return Xow_db_file_.Tid__wiki_solo;
case Xow_db_layout.Tid__few: // return Xow_db_file_.Tid__core; // DB.FEW: DATE:2016-06-07
case Xow_db_layout.Tid__lot: return Xow_db_file_.Tid__core;
default: throw Err_.new_unimplemented();
}
}
}

View File

@@ -16,19 +16,12 @@ 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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
class Xowd_db_file_hash {
private final Ordered_hash hash = Ordered_hash_.New();
class Xow_db_file_hash {
private final Ordered_hash hash = Ordered_hash_.New();
public int Count_total() {return count_total;} private int count_total;
public void Clear() {hash.Clear(); count_total = 0;}
public void Del(Xowd_db_file file) {
Ordered_hash tids = (Ordered_hash)hash.Get_by(file.Tid());
if (tids == null) throw Err_.new_wo_type("unknown file.tid", "url", file.Url());
if (!tids.Has(file.Id())) throw Err_.new_wo_type("unknown file.id", "url", file.Url());
tids.Del(file.Id());
--count_total;
}
public Ordered_hash Get_by_tid_or_null(byte tid) {return (Ordered_hash)hash.Get_by(tid);}
public void Add_or_new(Xowd_db_file file) {
public void Add_or_new(Xow_db_file file) {
byte tid = file.Tid();
Ordered_hash tids = (Ordered_hash)hash.Get_by(tid);
if (tids == null) {
@@ -38,6 +31,13 @@ class Xowd_db_file_hash {
tids.Add(file.Id(), file);
++count_total;
}
public void Del(Xow_db_file file) {
Ordered_hash tids = (Ordered_hash)hash.Get_by(file.Tid());
if (tids == null) throw Err_.new_wo_type("unknown file.tid", "url", file.Url());
if (!tids.Has(file.Id())) throw Err_.new_wo_type("unknown file.id", "url", file.Url());
tids.Del(file.Id());
--count_total;
}
public int Count_of_tid(byte tid) {
Ordered_hash tids = (Ordered_hash)hash.Get_by(tid);
return tids == null ? 0 : tids.Count();

View File

@@ -17,18 +17,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.dbs.cfgs.*; import gplx.xowa.bldrs.infos.*;
public class Xowd_db_file_schema_props {
Xowd_db_file_schema_props(boolean search__word__page_count_exists, boolean wbase__qid__src_ttl_has_spaces) {
public class Xow_db_file_schema_props {
Xow_db_file_schema_props(boolean search__word__page_count_exists, boolean wbase__qid__src_ttl_has_spaces) {
this.search__word__page_count_exists = search__word__page_count_exists;
this.wbase__qid__src_ttl_has_spaces = wbase__qid__src_ttl_has_spaces;
}
public boolean Search__word__page_count_exists() {return search__word__page_count_exists;} private final boolean search__word__page_count_exists;
public boolean Wbase__qid__src_ttl_has_spaces() {return wbase__qid__src_ttl_has_spaces;} private final boolean wbase__qid__src_ttl_has_spaces;
public static Xowd_db_file_schema_props make_() {return new Xowd_db_file_schema_props(Bool_.Y, Bool_.N);}
public static Xowd_db_file_schema_props load_(Db_cfg_tbl tbl, int tid, String version) {
public boolean Search__word__page_count_exists() {return search__word__page_count_exists;} private final boolean search__word__page_count_exists;
public boolean Wbase__qid__src_ttl_has_spaces() {return wbase__qid__src_ttl_has_spaces;} private final boolean wbase__qid__src_ttl_has_spaces;
public static Xow_db_file_schema_props make_() {return new Xow_db_file_schema_props(Bool_.Y, Bool_.N);}
public static Xow_db_file_schema_props load_(Db_cfg_tbl tbl, int tid, String version) {
boolean search__word__page_count_exists = tbl.Select_yn_or(Grp, Key__col_search_word_page_count, Bool_.N);
boolean wbase__qid__src_ttl_has_spaces = String_.In(version, "2.4.2.1", "2.4.3.1", "2.4.3.2");
return new Xowd_db_file_schema_props(search__word__page_count_exists, wbase__qid__src_ttl_has_spaces);
return new Xow_db_file_schema_props(search__word__page_count_exists, wbase__qid__src_ttl_has_spaces);
}
public static final String Grp = Xow_cfg_consts.Grp__wiki_schema;
public static final String

View File

@@ -0,0 +1,47 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_db_layout {
public Xow_db_layout(int tid) {this.tid = tid;}
public int Tid() {return tid;} private final int tid;
public boolean Tid_is_all() {return tid == Tid__all;}
public boolean Tid_is_all_or_few() {return tid != Tid__lot;}
public boolean Tid_is_lot() {return tid == Tid__lot;}
public String Key() {
switch (tid) {
case Xow_db_layout.Tid__all: return Key__all;
case Xow_db_layout.Tid__few: return Key__few;
case Xow_db_layout.Tid__lot: return Key__lot;
default: throw Err_.new_unimplemented();
}
}
public static final int Tid__all = 1, Tid__few = 2, Tid__lot = 3;
public static final String Key__all = "all", Key__few = "few", Key__lot = "lot";
public static final Xow_db_layout
Itm_all = new Xow_db_layout(Tid__all)
, Itm_few = new Xow_db_layout(Tid__few)
, Itm_lot = new Xow_db_layout(Tid__lot)
;
public static Xow_db_layout Get_by_name(String v) {
if (String_.Eq(v, Key__all)) return Itm_all;
else if (String_.Eq(v, Key__few)) return Itm_few;
else if (String_.Eq(v, Key__lot)) return Itm_lot;
else throw Err_.new_unimplemented();
}
}

View File

@@ -0,0 +1,166 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.core.lists.hashs.*;
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.bldrs.infos.*;
public class Xow_db_mgr {
private final Ordered_hash hash_by_id = Ordered_hash_.New(); private final Xow_db_file_hash hash_by_tids = new Xow_db_file_hash();
private int db_id_next = 0;
private final Xow_wiki wiki; private final Io_url wiki_root_dir; private final String domain_str; // needed for generating new files; EX: en.wikipedia.org-text.ns.001.xowa
public Xow_db_mgr(Xow_wiki wiki, Io_url wiki_root_dir) {
this.wiki = wiki;
this.wiki_root_dir = wiki_root_dir;
this.domain_str = wiki.Domain_str();
}
public Xowd_core_db_props Props() {return props;} private Xowd_core_db_props props = Xowd_core_db_props.Test;
public Db_cfg_tbl Tbl__cfg() {return db__core.Tbl__cfg();}
public Xowd_page_tbl Tbl__page() {return db__core.Tbl__page();}
public Xow_db_file Db__core() {return db__core;} private Xow_db_file db__core;
public Xow_db_file Db__text() {return db__text;} private Xow_db_file db__text;
public Xow_db_file Db__html() {return db__html;} private Xow_db_file db__html;
public Xow_db_file Db__cat_core() {return db__cat_core;} private Xow_db_file db__cat_core;
public Xow_db_file Db__wbase() {return db__wbase;} private Xow_db_file db__wbase; public void Db__wbase_(Xow_db_file v) {db__wbase = v;}
public void Init_by_load(Io_url core_url) {
// clear lists
hash_by_id.Clear();
hash_by_tids.Clear();
// create core_conn / core_db
Db_conn core_conn = Db_conn_bldr.Instance.Get(core_url);
props = Xowd_core_db_props.Cfg_load(core_conn); // load props to get layout_text
Dbs__set_by_tid(Xow_db_file.load_(props, Xow_db_file_.Uid__core, Xow_db_file__core_.Core_db_tid(props.Layout_text()), core_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, Guid_adp_.Empty));
wiki.Props().Init_by_load(wiki.App(), Tbl__cfg()); // load Main_page
// load dbs from "xowa_db" tbl
Xow_db_file[] ary = db__core.Tbl__db().Select_all(props, core_url.OwnerDir());
int len = ary.length;
for (int i = 0; i < len; i++) {
Xow_db_file db = ary[i];
Dbs__set_by_tid(db);
Dbs__add(db);
}
}
public void Init_by_make(Xowd_core_db_props props, Xob_info_session info_session) {
this.props = props;
// save data
Xow_db_file core_db = Xow_db_file__core_.Make_core_db(props, info_session, wiki_root_dir, domain_str);
Dbs__set_by_tid(core_db);
Dbs__add_and_save(core_db);
props.Cfg_save(db__core.Tbl__cfg()); // NOTE: must save cfg now, especially zip_tid; latter will be reloaded after import is done;
}
public void Rls() {
int len = hash_by_id.Len();
for (int i = 0; i < len; i++) {
Xow_db_file db_file = (Xow_db_file)hash_by_id.Get_at(i);
db_file.Rls();
}
}
public int Dbs__len() {return hash_by_id.Len();}
public Xow_db_file Dbs__get_at(int i) {return (Xow_db_file)hash_by_id.Get_at(i);}
public Xow_db_file Dbs__get_by_id_or_fail(int id) {return (Xow_db_file)hash_by_id.Get_by_or_fail(id);}
public Xow_db_file Dbs__get_by_id_or_null(int id) {return (Xow_db_file)hash_by_id.Get_by(id);}
public Xow_db_file Dbs__get_by_tid_or_core(byte... tids_ary) {Xow_db_file rv = Dbs__get_by_tid_or_null(tids_ary); return rv == null ? db__core : rv;}
public Xow_db_file Dbs__get_by_tid_or_null(byte... tids_ary) {
int tids_len = tids_ary.length;
for (int i = 0; i < tids_len; ++i) {
byte tid = tids_ary[i];
Ordered_hash tid_dbs = hash_by_tids.Get_by_tid_or_null(tid); if (tid_dbs == null) continue;
int tid_dbs_len = tid_dbs.Len();
if (tid_dbs_len != 1) { // NOTE: occurs when multiple search imports fail; DATE:2016-04-04
Xoa_app_.Usr_dlg().Warn_many("", "", "expecting only 1 db for tid; tid=~{0} len=~{1} db_api=~{2}", tid, tid_dbs.Len(), db__core.Conn().Conn_info().Db_api());
}
return (Xow_db_file)tid_dbs.Get_at(tid_dbs_len - 1); // get last idx;
}
return null;
}
public Ordered_hash Dbs__get_hash_by_tid(int tid) {return hash_by_tids.Get_by_tid_or_null((byte)tid);}
public Xow_db_file Dbs__make_by_tid(byte tid) {
int tid_idx = Get_tid_idx(hash_by_tids, tid);
return Dbs__make_by_tid(tid, Xob_info_file.Ns_ids_empty, tid_idx, Get_tid_name(tid_idx, tid));
}
public Xow_db_file Dbs__make_by_tid(byte tid, String ns_ids, int part_id, String file_name_suffix) {
return Dbs__make_by_id(db_id_next++, tid, ns_ids, part_id, file_name_suffix);
}
public Xow_db_file Dbs__make_by_id(int id, byte tid, String ns_ids, int part_id, String file_name_suffix) {
Io_url url = wiki_root_dir.GenSubFil(domain_str + file_name_suffix);
Xow_db_file rv = Xow_db_file.make_(db__core.Info_session(), props, id, tid, url, ns_ids, part_id, db__core.Url().NameAndExt(), Db_conn_bldr.Instance.New(url));
Dbs__add_and_save(rv);
Dbs__set_by_tid(rv);
return rv;
}
public Xow_db_file Dbs__remake_by_tid(byte tid) {
Dbs__delete_by_tid(tid);
return Dbs__make_by_tid(tid);
}
public void Dbs__delete_by_tid(byte... tids) {
int len = hash_by_id.Len();
for (int i = 0; i < len; ++i) {
Xow_db_file db = (Xow_db_file)hash_by_id.Get_at(i);
if (!Byte_.In(db.Tid(), tids)) continue;
db.Rls();
Io_mgr.Instance.DeleteFil_args(db.Url()).MissingFails_off().Exec();
db.Cmd_mode_(Db_cmd_mode.Tid_delete);
}
db__core.Tbl__db().Commit_all(this);
this.Init_by_load(db__core.Url());
}
public void Create_page(Xowd_page_tbl core_tbl, Xowd_text_tbl text_tbl, int page_id, int ns_id, byte[] ttl_wo_ns, boolean redirect, DateAdp modified_on, byte[] text_zip_data, int text_raw_len, int random_int, int text_db_id, int html_db_id) {
core_tbl.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, redirect, modified_on, text_raw_len, random_int, text_db_id, html_db_id);
text_tbl.Insert_cmd_by_batch(page_id, text_zip_data);
}
private void Dbs__set_by_tid(Xow_db_file db) {
switch (db.Tid()) {
case Xow_db_file_.Tid__wiki_solo:
case Xow_db_file_.Tid__text_solo:
case Xow_db_file_.Tid__core : {db__core = db; if (props.Layout_text().Tid_is_all_or_few()) db__cat_core = db__text = db; break;}
case Xow_db_file_.Tid__text : {db__text = db; break;}
case Xow_db_file_.Tid__html_data : {db__html = db; break;}
case Xow_db_file_.Tid__wbase : {if (db__wbase == null) db__wbase = db; break;}
case Xow_db_file_.Tid__cat_core :
case Xow_db_file_.Tid__cat : {if (db__cat_core == null) db__cat_core = db; break;}
}
}
private void Dbs__add(Xow_db_file db_file) {
int db_id = db_file.Id();
hash_by_id.Add(db_id, db_file);
hash_by_tids.Add_or_new(db_file);
if (db_id >= db_id_next) // always set db_id_next to largest value in given set of dbs; EX: dbs=[0,1,10]; db_id_next should be 11
db_id_next = db_id + 1;
}
private void Dbs__add_and_save(Xow_db_file db_file) {
Dbs__add(db_file);
db__core.Tbl__db().Commit_all(this);
db_file.Info_file().Save(db_file.Tbl__cfg());
db_file.Info_session().Save(db_file.Tbl__cfg());
}
private int Get_tid_idx(Xow_db_file_hash hash, byte tid) {return hash.Count_of_tid(tid) + Int_.Base1;}
private static String Get_tid_name(int tid_idx, byte tid) {
String tid_name = Xow_db_file_.To_key(tid);
String tid_idx_str = "";
switch (tid) {
case Xow_db_file_.Tid__cat_core : break;
case Xow_db_file_.Tid__cat_link : tid_idx_str = "-db." + Int_.To_str_pad_bgn_zero(tid_idx, 3); break;
default : tid_idx_str = tid_idx == 1 ? "" : "-db." + Int_.To_str_pad_bgn_zero(tid_idx, 3); break;
}
return String_.Format("-{0}{1}.xowa", tid_name, tid_idx_str); // EX: en.wikipedia.org-text-001.sqlite3
}
}

View File

@@ -19,9 +19,8 @@ package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xow
import gplx.dbs.*; import gplx.dbs.cfgs.*;
public class Xowd_cfg_tbl_ {
public static final String Tbl_name = "xowa_cfg";
public static Db_cfg_tbl New(gplx.dbs.Db_conn conn) {
return new Db_cfg_tbl(conn, Tbl_name);
}
public static Db_cfg_tbl New(gplx.dbs.Db_conn conn) {return New(conn, Tbl_name);}
public static Db_cfg_tbl New(gplx.dbs.Db_conn conn, String tbl_name) {return new Db_cfg_tbl(conn, tbl_name);}
public static Db_cfg_tbl Get_or_null(gplx.dbs.Db_conn conn) {
return conn.Meta_tbl_exists(Tbl_name) ? new Db_cfg_tbl(conn, Tbl_name) : null;
}

View File

@@ -16,10 +16,10 @@ 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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.core.ios.*; import gplx.dbs.*; import gplx.dbs.cfgs.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.dbs.*; import gplx.dbs.cfgs.*;
import gplx.dbs.metas.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.wikis.dbs.*;
public class Xowd_core_db_props {
public Xowd_core_db_props(int schema, Xowd_db_layout layout_text, Xowd_db_layout layout_html, Xowd_db_layout layout_file
public Xowd_core_db_props(int schema, Xow_db_layout layout_text, Xow_db_layout layout_html, Xow_db_layout layout_file
, byte zip_tid_text, byte zip_tid_html, boolean hzip_enabled, boolean hzip_mode_is_b256) {
this.schema = schema;
this.layout_text = layout_text; this.layout_html = layout_html; this.layout_file = layout_file;
@@ -28,9 +28,9 @@ public class Xowd_core_db_props {
}
public int Schema() {return schema;} private final int schema;
public boolean Schema_is_1() {return schema == 1;}
public Xowd_db_layout Layout_text() {return layout_text;} private final Xowd_db_layout layout_text;
public Xowd_db_layout Layout_html() {return layout_html;} private final Xowd_db_layout layout_html;
public Xowd_db_layout Layout_file() {return layout_file;} private final Xowd_db_layout layout_file;
public Xow_db_layout Layout_text() {return layout_text;} private final Xow_db_layout layout_text;
public Xow_db_layout Layout_html() {return layout_html;} private final Xow_db_layout layout_html;
public Xow_db_layout Layout_file() {return layout_file;} private final Xow_db_layout layout_file;
public byte Zip_tid_text() {return zip_tid_text;} private final byte zip_tid_text;
public byte Zip_tid_html() {return zip_tid_html;} private final byte zip_tid_html;
public boolean Hzip_enabled() {return hzip_enabled;} private final boolean hzip_enabled;
@@ -38,20 +38,20 @@ public class Xowd_core_db_props {
public void Cfg_save(Db_cfg_tbl tbl) {
tbl.Conn().Txn_bgn("make__core__cfg__save");
tbl.Insert_int (Cfg_grp, Cfg_key__schema_version , schema);
tbl.Insert_str (Cfg_grp, Cfg_key__layout_text , layout_text.Name());
tbl.Insert_str (Cfg_grp, Cfg_key__layout_html , layout_html.Name());
tbl.Insert_str (Cfg_grp, Cfg_key__layout_file , layout_file.Name());
tbl.Insert_str (Cfg_grp, Cfg_key__layout_text , layout_text.Key());
tbl.Insert_str (Cfg_grp, Cfg_key__layout_html , layout_html.Key());
tbl.Insert_str (Cfg_grp, Cfg_key__layout_file , layout_file.Key());
tbl.Insert_byte (Cfg_grp, Cfg_key__zip_tid_text , zip_tid_text);
tbl.Insert_byte (Cfg_grp, Cfg_key__zip_tid_html , zip_tid_html);
tbl.Insert_yn (Cfg_grp, Cfg_key__hzip_enabled , hzip_enabled);
tbl.Insert_yn (Cfg_grp, Cfg_key__hzip_mode_is_b256 , hzip_mode_is_b256);
tbl.Conn().Txn_end();
}
public static Xowd_core_db_props Cfg_load(Io_url url, Db_conn conn) {
Db_cfg_tbl cfg_tbl = gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn);
public static Xowd_core_db_props Cfg_load(Db_conn conn) {return Cfg_load(conn, gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn));}
public static Xowd_core_db_props Cfg_load(Db_conn conn, Db_cfg_tbl cfg_tbl) {
return cfg_tbl.Select_int_or(Cfg_grp, Cfg_key__schema_version, 1) == 1
? new Xowd_core_db_props
( 1, Xowd_db_layout.Itm_lot, Xowd_db_layout.Itm_lot, Xowd_db_layout.Itm_lot, cfg_tbl.Select_byte_or(Xowe_wiki.Invk_db_mgr, Xodb_mgr_sql.Invk_data_storage_format
( 1, Xow_db_layout.Itm_lot, Xow_db_layout.Itm_lot, Xow_db_layout.Itm_lot, cfg_tbl.Select_byte_or(Xowe_wiki.Invk_db_mgr, Xodb_mgr_sql.Invk_data_storage_format
, Io_stream_.Tid_gzip), Io_stream_.Tid_gzip, Bool_.Y, Bool_.N)
: Cfg_load(cfg_tbl);
}
@@ -59,9 +59,9 @@ public class Xowd_core_db_props {
Db_cfg_hash cfg_hash = tbl.Select_as_hash(Cfg_grp);
return new Xowd_core_db_props
( cfg_hash.Get_by(Cfg_key__schema_version).To_int()
, Xowd_db_layout.get_(cfg_hash.Get_by(Cfg_key__layout_text).To_str())
, Xowd_db_layout.get_(cfg_hash.Get_by(Cfg_key__layout_html).To_str())
, Xowd_db_layout.get_(cfg_hash.Get_by(Cfg_key__layout_file).To_str())
, Xow_db_layout.Get_by_name(cfg_hash.Get_by(Cfg_key__layout_text).To_str())
, Xow_db_layout.Get_by_name(cfg_hash.Get_by(Cfg_key__layout_html).To_str())
, Xow_db_layout.Get_by_name(cfg_hash.Get_by(Cfg_key__layout_file).To_str())
, cfg_hash.Get_by(Cfg_key__zip_tid_text).To_byte()
, cfg_hash.Get_by(Cfg_key__zip_tid_html).To_byte()
, cfg_hash.Get_by(Cfg_key__hzip_enabled).To_yn_or(Bool_.N)
@@ -78,5 +78,5 @@ public class Xowd_core_db_props {
, Cfg_key__hzip_enabled = "hzip_enabled"
, Cfg_key__hzip_mode_is_b256 = "hzip_mode_is_b256"
;
public static final Xowd_core_db_props Test = new Xowd_core_db_props(2, Xowd_db_layout.Itm_few, Xowd_db_layout.Itm_few, Xowd_db_layout.Itm_few, Io_stream_.Tid_raw, Io_stream_.Tid_raw, Bool_.Y, Bool_.Y);
public static final Xowd_core_db_props Test = new Xowd_core_db_props(2, Xow_db_layout.Itm_few, Xow_db_layout.Itm_few, Xow_db_layout.Itm_few, Io_stream_.Tid_raw, Io_stream_.Tid_raw, Bool_.Y, Bool_.Y);
}

View File

@@ -1,59 +0,0 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xowd_db_file_ {
public static final int Id_core = 0;
public static final byte
Tid_core = 1, Tid_text = 2, Tid_cat = 3, Tid_search_core = 4, Tid_wbase = 5 // SERIALIZED:v1
, Tid_cat_core = 6, Tid_cat_link = 7 // SERIALIZED:v2
, Tid_wiki_solo = 8, Tid_text_solo = 9
, Tid_html_solo = 10, Tid_html_data = 11
, Tid_file_solo = 12, Tid_file_core = 13, Tid_file_data = 14, Tid_file_user = 15
, Tid_search_link = 16, Tid_random = 17
;
private static final String
Key_core = "core", Key_text = "text", Key_cat = "xtn.category", Key_search_core = "xtn.search.core", Key_wbase = "core.wbase"
, Key_cat_core = "xtn.category.core", Key_cat_link = "xtn.category.link"
, Key_text_solo = "text.solo", Key_wiki_solo = "wiki.solo"
, Key_html_solo = "html.solo", Key_html_data = "html"
, Key_file_solo = "file.solo", Key_file_core = "file.core", Key_file_data = "file.data", Key_file_user = "file.user"
, Key_search_link = "xtn.search.link", Key_random = "xtn.random"
;
public static String To_key(byte v) {
switch (v) {
case Tid_core: return Key_core;
case Tid_text: return Key_text;
case Tid_cat: return Key_cat;
case Tid_search_core: return Key_search_core;
case Tid_wbase: return Key_wbase;
case Tid_cat_core: return Key_cat_core;
case Tid_cat_link: return Key_cat_link;
case Tid_wiki_solo: return Key_wiki_solo;
case Tid_text_solo: return Key_text_solo;
case Tid_html_solo: return Key_html_solo;
case Tid_html_data: return Key_html_data;
case Tid_file_solo: return Key_file_solo;
case Tid_file_core: return Key_file_core;
case Tid_file_data: return Key_file_data;
case Tid_file_user: return Key_file_user;
case Tid_search_link: return Key_search_link;
case Tid_random: return Key_random;
default: throw Err_.new_unhandled(v);
}
}
}

View File

@@ -1,46 +0,0 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xowd_db_layout {
public Xowd_db_layout(int tid) {this.tid = tid;}
public int Tid() {return tid;} private final int tid;
public boolean Tid_is_all() {return tid == Const_all;}
public boolean Tid_is_all_or_few() {return tid != Const_lot;}
public boolean Tid_is_lot() {return tid == Const_lot;}
public String Name() {
switch (tid) {
case Const_all: return Name_all;
case Const_few: return Name_few;
case Const_lot: return Name_lot;
default: throw Err_.new_unimplemented();
}
}
public static final String Name_all = "all", Name_few = "few", Name_lot = "lot";
public static final int Const_all = 1, Const_few = 2, Const_lot = 3;
public static final Xowd_db_layout
Itm_all = new Xowd_db_layout(Const_all)
, Itm_few = new Xowd_db_layout(Const_few)
, Itm_lot = new Xowd_db_layout(Const_lot)
;
public static Xowd_db_layout get_(String v) {
if (String_.Eq(v, Name_all)) return Itm_all;
else if (String_.Eq(v, Name_few)) return Itm_few;
else if (String_.Eq(v, Name_lot)) return Itm_lot;
else throw Err_.new_unimplemented();
}
}

View File

@@ -1,185 +0,0 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*;
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.bldrs.infos.*;
public class Xowd_db_mgr {
private Xowd_db_file[] dbs__ary = new Xowd_db_file[0]; private int dbs__ary_len = 0; private final Xowd_db_file_hash db_file_hash = new Xowd_db_file_hash();
private final Hash_adp id_hash = Hash_adp_.new_(); private final gplx.core.primitives.Int_obj_ref id_hash_ref = gplx.core.primitives.Int_obj_ref.neg1_();
private final Xow_wiki wiki; private final Io_url wiki_root_dir; private final Xow_domain_itm domain_itm;
public Xowd_db_mgr(Xow_wiki wiki, Io_url wiki_root_dir, Xow_domain_itm domain_itm) {this.wiki = wiki; this.wiki_root_dir = wiki_root_dir; this.domain_itm = domain_itm;}
public Xowd_core_db_props Props() {return props;} private Xowd_core_db_props props = Xowd_core_db_props.Test;
public Db_cfg_tbl Tbl__cfg() {return db__core.Tbl__cfg();}
public Xowd_page_tbl Tbl__page() {return db__core.Tbl__page();}
public Xowd_db_file Db__core() {return db__core;} private Xowd_db_file db__core;
public Xowd_db_file Db__text() {return db__text;} private Xowd_db_file db__text;
public Xowd_db_file Db__html() {return db__html;} private Xowd_db_file db__html;
public Xowd_db_file Db__cat_core() {return db__cat_core;} private Xowd_db_file db__cat_core;
public Xowd_db_file Db__wbase() {return db__wbase;} private Xowd_db_file db__wbase;
public int Dbs__len() {return dbs__ary.length;}
public void Db__wbase_(Xowd_db_file v) {db__wbase = v;}
public Ordered_hash Dbs__get_hash_by_tid(int tid) {return db_file_hash.Get_by_tid_or_null((byte)tid);}
public Xowd_db_file Dbs__get_at(int i) {return dbs__ary[i];}
public Xowd_db_file Dbs__get_by_id(int id) {return (Xowd_db_file)id_hash.Get_by_or_fail(id_hash_ref.Val_(id));}
public Xowd_db_file Dbs__get_by_tid_or_core(byte... tids_ary) {Xowd_db_file rv = Dbs__get_by_tid_or_null(tids_ary); return rv == null ? db__core : rv;}
public Xowd_db_file Dbs__get_by_tid_or_null(byte... tids_ary) {
int tids_len = tids_ary.length;
for (int i = 0; i < tids_len; ++i) {
byte tid = tids_ary[i];
Ordered_hash tid_dbs = db_file_hash.Get_by_tid_or_null(tid); if (tid_dbs == null) continue;
int tid_dbs_len = tid_dbs.Len();
if (tid_dbs_len != 1) { // NOTE: occurs when multiple search imports fail; DATE:2016-04-04
Xoa_app_.Usr_dlg().Warn_many("", "", "expecting only 1 db for tid; tid=~{0} len=~{1} db_api=~{2}", tid, tid_dbs.Len(), db__core.Conn().Conn_info().Db_api());
}
return (Xowd_db_file)tid_dbs.Get_at(tid_dbs_len - 1); // get last idx;
}
return null;
}
public Xowd_db_file Dbs__make_by_tid(byte tid) {
int tid_idx = Get_tid_idx(db_file_hash, tid);
return Dbs__make_by_tid(tid, Xob_info_file.Ns_ids_empty, tid_idx, Get_tid_name(db_file_hash, tid_idx, tid));
}
public Xowd_db_file Dbs__make_by_tid(byte tid, String ns_ids, int part_id, String file_name_suffix) {
Io_url url = wiki_root_dir.GenSubFil(domain_itm.Domain_str() + file_name_suffix);
int next_id = Dbs__get_at(dbs__ary_len - 1).Id() + 1;
Xowd_db_file rv = Xowd_db_file.make_(db__core.Info_session(), props, next_id, tid, url, ns_ids, part_id, db__core.Url().NameAndExt(), Db_conn_bldr.Instance.New(url));
Dbs__add_and_save(rv);
Dbs__set_by_tid(rv);
return rv;
}
public Xowd_db_file Dbs__remake_by_tid(byte tid) {
Dbs__delete_by_tid(tid);
return Dbs__make_by_tid(tid);
}
public void Dbs__delete_by_tid(byte... tids) {
int len = dbs__ary_len;
for (int i = 0; i < len; ++i) {
Xowd_db_file db = dbs__ary[i];
if (!Byte_.In(db.Tid(), tids)) continue;
db.Rls();
Io_mgr.Instance.DeleteFil_args(db.Url()).MissingFails_off().Exec();
db.Cmd_mode_(Db_cmd_mode.Tid_delete);
}
db__core.Tbl__db().Commit_all(this);
this.Init_by_load(db__core.Url());
}
public void Init_by_load(Io_url core_url) {
db_file_hash.Clear();
id_hash.Clear();
Db_conn core_conn = Db_conn_bldr.Instance.Get(core_url);
props = Xowd_core_db_props.Cfg_load(core_url, core_conn);
Dbs__set_by_tid(Xowd_db_file.load_(props, Xowd_db_file_.Id_core, Core_db_tid(props.Layout_text()), core_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, Guid_adp_.Empty));
dbs__ary = db__core.Tbl__db().Select_all(props, core_url.OwnerDir());
dbs__ary_len = dbs__ary.length;
for (int i = 0; i < dbs__ary_len; i++) {
Xowd_db_file db = dbs__ary[i];
Dbs__set_by_tid(db);
db_file_hash.Add_or_new(db);
id_hash.Add(gplx.core.primitives.Int_obj_ref.new_(db.Id()), db);
}
wiki.Props().Init_by_load(wiki.App(), Tbl__cfg());
}
public void Init_by_make(Xowd_core_db_props props, Xob_info_session info_session) {
this.props = props;
String core_file_name = Core_file_name(props.Layout_text(), domain_itm.Domain_str());
byte core_db_tid = Core_db_tid(props.Layout_text());
Io_url core_db_url = wiki_root_dir.GenSubFil(core_file_name);
Db_conn conn = Db_conn_bldr.Instance.New(core_db_url);
conn.Txn_bgn("make__core__tbls");
Dbs__set_by_tid(Xowd_db_file.make_(info_session, props, Xowd_db_file_.Id_core, core_db_tid, core_db_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, core_file_name, conn));
db__core.Tbl__db().Create_tbl();
db__core.Tbl__ns().Create_tbl();
db__core.Tbl__site_stats().Create_tbl();
db__core.Tbl__page().Create_tbl();
if (props.Layout_text().Tid_is_all_or_few()) { // create in advance else will fail for v2; import wiki -> wiki loads and tries to load categories; v2 category processes and builds tbl; DATE:2015-03-22
db__core.Tbl__cat_core().Create_tbl();
db__core.Tbl__cat_link().Create_tbl();
}
Dbs__add_and_save(db__core);
props.Cfg_save(db__core.Tbl__cfg()); // NOTE: must save cfg now, especially zip_tid; latter will be reloaded after import is done;
conn.Txn_end();
}
public void Create_page(Xowd_page_tbl core_tbl, Xowd_text_tbl text_tbl, int page_id, int ns_id, byte[] ttl_wo_ns, boolean redirect, DateAdp modified_on, byte[] text_zip_data, int text_raw_len, int random_int, int text_db_id, int html_db_id) {
core_tbl.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, redirect, modified_on, text_raw_len, random_int, text_db_id, html_db_id);
text_tbl.Insert_cmd_by_batch(page_id, text_zip_data);
}
private void Dbs__set_by_tid(Xowd_db_file db) {
switch (db.Tid()) {
case Xowd_db_file_.Tid_wiki_solo:
case Xowd_db_file_.Tid_text_solo:
case Xowd_db_file_.Tid_core : {db__core = db; if (props.Layout_text().Tid_is_all_or_few()) db__cat_core = db__text = db; break;}
case Xowd_db_file_.Tid_text : {db__text = db; break;}
case Xowd_db_file_.Tid_html_data : {db__html = db; break;}
case Xowd_db_file_.Tid_wbase : {if (db__wbase == null) db__wbase = db; break;}
case Xowd_db_file_.Tid_cat_core :
case Xowd_db_file_.Tid_cat : {if (db__cat_core == null) db__cat_core = db; break;}
}
}
private void Dbs__add_and_save(Xowd_db_file rv) {
dbs__ary = (Xowd_db_file[])Array_.Resize(dbs__ary, dbs__ary_len + 1);
dbs__ary[dbs__ary_len++] = rv;
db__core.Tbl__db().Commit_all(this);
rv.Info_file().Save(rv.Tbl__cfg());
rv.Info_session().Save(rv.Tbl__cfg());
db_file_hash.Add_or_new(rv);
id_hash.Add(gplx.core.primitives.Int_obj_ref.new_(rv.Id()), rv);
}
public void Rls() {
for (int i = 0; i < dbs__ary_len; i++)
dbs__ary[i].Rls();
}
private int Get_tid_idx(Xowd_db_file_hash hash, byte tid) {return hash.Count_of_tid(tid) + Int_.Base1;}
private String Get_tid_name(Xowd_db_file_hash hash, int tid_idx, byte tid) {
String tid_name = Xowd_db_file_.To_key(tid);
String tid_idx_str = "";
switch (tid) {
case Xowd_db_file_.Tid_cat_core : break;
case Xowd_db_file_.Tid_cat_link : tid_idx_str = "-db." + Int_.To_str_pad_bgn_zero(tid_idx, 3); break;
default : tid_idx_str = tid_idx == 1 ? "" : "-db." + Int_.To_str_pad_bgn_zero(tid_idx, 3); break;
}
return String_.Format("-{0}{1}.xowa", tid_name, tid_idx_str); // EX: en.wikipedia.org-text-001.sqlite3
}
private static String Core_file_name(Xowd_db_layout layout, String domain_name) {
switch (layout.Tid()) {
case Xowd_db_layout.Const_all: return domain_name + ".xowa"; // EX: en.wikipedia.org.xowa
case Xowd_db_layout.Const_few: return domain_name + "-text.xowa"; // EX: en.wikipedia.org-text.xowa
case Xowd_db_layout.Const_lot: return domain_name + "-core.xowa"; // EX: en.wikipedia.org-core.xowa
default: throw Err_.new_unimplemented();
}
}
public static boolean Maybe_core(String domain_name, String fil_name) {
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(Bry_.new_u8(domain_name));
if (domain_itm.Domain_type_id() == Xow_domain_tid_.Int__other) {
return String_.Has_at_end(fil_name, ".xowa");
}
String domain_str = domain_itm.Domain_str();
return ( String_.Eq(fil_name, domain_str + "-text.xowa")
|| String_.Eq(fil_name, domain_str + "-core.xowa")
|| String_.Eq(fil_name, domain_str + ".xowa")
);
}
private static byte Core_db_tid(Xowd_db_layout layout) {
switch (layout.Tid()) {
case Xowd_db_layout.Const_all: return Xowd_db_file_.Tid_wiki_solo;
case Xowd_db_layout.Const_few: return Xowd_db_file_.Tid_text_solo;
case Xowd_db_layout.Const_lot: return Xowd_db_file_.Tid_core;
default: throw Err_.new_unimplemented();
}
}
}

View File

@@ -15,7 +15,7 @@ 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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
package gplx.xowa.wikis.data.fetchers; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.xowa.wikis.data.tbls.*;
public interface Xow_page_fetcher {
Xow_page_fetcher Wiki_(Xowe_wiki v);

View File

@@ -15,11 +15,11 @@ 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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
package gplx.xowa.wikis.data.fetchers; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.xowa.wikis.data.tbls.*;
public class Xow_page_fetcher_test implements Xow_page_fetcher {
public Xow_page_fetcher Wiki_(Xowe_wiki v) {return this;}
public void Clear() {pages.Clear();} private Hash_adp pages = Hash_adp_.new_();
public void Clear() {pages.Clear();} private Hash_adp pages = Hash_adp_.New();
public void Add(int ns_id, byte[] ttl, byte[] text) {
Xowd_page_itm page = new Xowd_page_itm().Ns_id_(ns_id).Ttl_page_db_(ttl).Text_(text);
pages.Add(Make_key(ns_id, ttl), page);

View File

@@ -15,13 +15,13 @@ 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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
package gplx.xowa.wikis.data.fetchers; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
public class Xow_page_fetcher_wiki implements Xow_page_fetcher {
public Xow_page_fetcher Wiki_(Xowe_wiki v) {this.wiki = v; return this;} private Xowe_wiki wiki;
public void Clear() {}
public byte[] Get_by(int ns_id, byte[] ttl_bry) {
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ns_id, ttl_bry);
Xoae_page page = wiki.Data_mgr().Get_page(ttl, false); // go through data_mgr in case of redirects
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(ttl); // go through data_mgr in case of redirects
return page.Missing() ? null : page.Data_raw();
}
}

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data.site_stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.xowa.wikis.nss.*;
public class Xow_site_stats_mgr implements GfoInvkAble { // REF.MW:https://www.mediawiki.org/wiki/Manual:Site_stats_table
private final Xow_wiki wiki;
public class Xow_site_stats_mgr implements Gfo_invk { // REF.MW:https://www.mediawiki.org/wiki/Manual:Site_stats_table
private final Xow_wiki wiki;
public Xow_site_stats_mgr(Xow_wiki wiki) {this.wiki = wiki;}
public long Num_pages() {return num_pages;} private long num_pages; // ss_total_pages; pages in entire wiki: 16,299,475
public long Num_articles() {return num_articles;} private long num_articles; // ss_good_articles; pages in main ns w/o redirect: 5,072,469
@@ -50,7 +50,7 @@ public class Xow_site_stats_mgr implements GfoInvkAble { // REF.MW:https://www.m
else if (ctx.Match(k, Invk_number_of_articles_)) num_articles = m.ReadInt("v");
else if (ctx.Match(k, Invk_number_of_files_)) num_files = m.ReadInt("v");
else if (ctx.Match(k, Invk_number_of_articles_in_ns_)) return Number_of_articles_in_ns_(m);
else return GfoInvkAble_.Rv_unhandled;
else return Gfo_invk_.Rv_unhandled;
return this;
} public static final String Invk_number_of_pages_ = "number_of_pages_", Invk_number_of_articles_ = "number_of_articles_", Invk_number_of_files_ = "number_of_files_", Invk_number_of_articles_in_ns_ = "number_of_articles_in_ns_";
}

View File

@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.wikis.data.site_stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*; import gplx.xowa.wikis.data.site_stats.*;
public class Xow_site_stats_tbl {
private final String tbl_name = "site_stats";
private final String fld_row_id, fld_good_articles, fld_total_pages, fld_images;
private final Db_conn conn; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String tbl_name = "site_stats";
private final String fld_row_id, fld_good_articles, fld_total_pages, fld_images;
private final Db_conn conn; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public Xow_site_stats_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
fld_row_id = flds.Add_int_pkey("ss_row_id");

View File

@@ -18,10 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*;
public class Xowd_cat_core_tbl implements Rls_able {
private final String tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_id, fld_pages, fld_subcats, fld_files, fld_hidden, fld_link_db_id;
private final Db_conn conn; private Db_stmt stmt_insert, stmt_update, stmt_select;
private final Xowd_cat_core_tbl__in_wkr in_wkr = new Xowd_cat_core_tbl__in_wkr();
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_id, fld_pages, fld_subcats, fld_files, fld_hidden, fld_link_db_id;
private final Db_conn conn; private Db_stmt stmt_insert, stmt_update, stmt_select;
private final Xowd_cat_core_tbl__in_wkr in_wkr = new Xowd_cat_core_tbl__in_wkr();
public Db_conn Conn() {return conn;}
public Xowd_cat_core_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;

View File

@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.wikis.ctgs.*;
public class Xowd_cat_link_tbl implements Rls_able {
private final String tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_from, fld_to_id, fld_sortkey, fld_timestamp, fld_type_id;
private final Db_conn conn; private Db_stmt stmt_insert, stmt_select_in;
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_from, fld_to_id, fld_sortkey, fld_timestamp, fld_type_id;
private final Db_conn conn; private Db_stmt stmt_insert, stmt_select_in;
public Db_conn Conn() {return conn;}
public Xowd_cat_link_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;

View File

@@ -1,26 +0,0 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
public class Xowd_css_core_itm {
public Xowd_css_core_itm(int id, String key, DateAdp updated_on) {
this.id = id; this.key = key; this.updated_on = updated_on;
}
public int Id() {return id;} private final int id;
public String Key() {return key;} private final String key;
public DateAdp Updated_on() {return updated_on;} private final DateAdp updated_on;
}

View File

@@ -1,73 +0,0 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*;
public class Xowd_css_core_tbl implements Rls_able {
private final String tbl_name = "css_core"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_id, fld_key, fld_updated_on;
public Xowd_css_core_tbl(Db_conn conn) {
this.conn = conn;
this.fld_id = flds.Add_int_pkey_autonum("css_id");
this.fld_key = flds.Add_str("css_key", 255);
this.fld_updated_on = flds.Add_str("css_updated_on", 20);
conn.Rls_reg(this);
}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public String Tbl_name() {return tbl_name;}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_key)));}
public void Rls() {}
public int Insert(String key, DateAdp updated_on) {
Db_stmt stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Val_str(fld_key, key).Val_str(fld_updated_on, updated_on.XtoStr_fmt_yyyyMMdd_HHmmss()).Exec_insert();
return Select_id_by_key(key);
}
public void Update(int id, String key, DateAdp updated_on) {
Db_stmt stmt_update = conn.Stmt_update_exclude(tbl_name, flds, fld_id);
stmt_update.Val_str(fld_key, key).Val_str(fld_updated_on, updated_on.XtoStr_fmt_yyyyMMdd_HHmmss()).Crt_int(fld_id, id).Exec_update();
}
public Xowd_css_core_itm Select_by_key(String key) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_key).Crt_str(fld_key, key).Exec_select__rls_auto();
try {return rdr.Move_next() ? new_itm(rdr) : null;}
finally {rdr.Rls();}
}
public int Select_id_by_key(String key) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_key).Crt_str(fld_key, key).Exec_select__rls_auto();
try {return rdr.Move_next() ? rdr.Read_int(fld_id) : Id_null;}
finally {rdr.Rls();}
}
public Xowd_css_core_itm[] Select_all() { // TEST:
Db_stmt stmt = conn.Stmt_select(tbl_name, flds);
return Select_by_stmt(stmt);
}
private Xowd_css_core_itm[] Select_by_stmt(Db_stmt stmt) {
List_adp rv = List_adp_.new_();
Db_rdr rdr = stmt.Exec_select__rls_auto();
try {
while (rdr.Move_next())
rv.Add(new_itm(rdr));
} finally {rdr.Rls();}
return (Xowd_css_core_itm[])rv.To_ary_and_clear(Xowd_css_core_itm.class);
}
public void Delete_all() {
conn.Stmt_delete(tbl_name).Exec_delete();
}
private Xowd_css_core_itm new_itm(Db_rdr rdr) {
return new Xowd_css_core_itm(rdr.Read_int(fld_id), rdr.Read_str(fld_key), rdr.Read_date_by_str(fld_updated_on));
}
public static final int Id_null = -1;
}

View File

@@ -1,24 +0,0 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
public class Xowd_css_file_itm {
public Xowd_css_file_itm(int css_id, String path, byte[] data) {this.css_id = css_id; this.path = path; this.data = data;}
public int Css_id() {return css_id;} private final int css_id;
public String Path() {return path;} private final String path;
public byte[] Data() {return data;} private final byte[] data;
}

View File

@@ -1,63 +0,0 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*;
public class Xowd_css_file_tbl implements Rls_able {
private final String tbl_name = "css_file"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_css_id, fld_path, fld_data;
private final Db_conn conn; private Db_stmt stmt_insert;
public Xowd_css_file_tbl(Db_conn conn) {
this.conn = conn;
fld_css_id = flds.Add_int("css_id");
fld_path = flds.Add_str("file_path", 255);
fld_data = flds.Add_bry("file_data");
conn.Rls_reg(this);
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Insert(int css_id, String path, byte[] data) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear().Val_int(fld_css_id, css_id).Val_str(fld_path, path).Val_bry(fld_data, data).Exec_insert();
}
public void Delete(int css_id) {
conn.Stmt_delete(tbl_name, fld_css_id).Crt_int(fld_css_id, css_id).Exec_delete();
}
public Xowd_css_file_itm[] Select_by_owner(int css_id) {
Db_stmt stmt = conn.Stmt_select(tbl_name, flds, fld_css_id).Crt_int(fld_css_id, css_id);
return Select_by_stmt(stmt);
}
public Xowd_css_file_itm[] Select_all() { // TEST:
Db_stmt stmt = conn.Stmt_select(tbl_name, flds);
return Select_by_stmt(stmt);
}
private Xowd_css_file_itm[] Select_by_stmt(Db_stmt stmt) {
List_adp rv = List_adp_.new_();
Db_rdr rdr = stmt.Exec_select__rls_auto();
try {
while (rdr.Move_next())
rv.Add(new_itm(rdr));
} finally {rdr.Rls();}
return (Xowd_css_file_itm[])rv.To_ary_and_clear(Xowd_css_file_itm.class);
}
public void Delete_all() {
conn.Stmt_delete(tbl_name).Exec_delete();
}
private Xowd_css_file_itm new_itm(Db_rdr rdr) {return new Xowd_css_file_itm(rdr.Read_int(fld_css_id), rdr.Read_str(fld_path), rdr.Read_bry(fld_data));}
}

View File

@@ -29,11 +29,12 @@ public class Xowd_page_itm {
public int Text_len() {return text_len;} public Xowd_page_itm Text_len_(int v) {text_len = v; return this;} private int text_len;
public int Text_db_id() {return text_db_id;} public Xowd_page_itm Text_db_id_(int v) {text_db_id = v; return this;} private int text_db_id;
public byte[] Text() {return text;} public Xowd_page_itm Text_(byte[] v) {text = v; if (v != null) text_len = v.length; return this;} private byte[] text;
public int Random_int() {return random_int;} private int random_int;
public int Html_db_id() {return html_db_id;} private int html_db_id;
public int Redirect_id() {return redirect_id;} private int redirect_id;
public DateAdp Modified_on() {return modified_on;} public Xowd_page_itm Modified_on_(DateAdp v) {modified_on = v; return this;} private DateAdp modified_on;
public boolean Exists() {return exists;} public Xowd_page_itm Exists_(boolean v) {exists = v; return this;} private boolean exists;
public int Page_score;
public int Score() {return score;} private int score;
public Xow_ns Ns() {return ns;} private Xow_ns ns;
public Object Xtn() {return xtn;} public Xowd_page_itm Xtn_(Object v) {this.xtn = v; return this;} private Object xtn;
public int Tdb_row_idx() {return tdb_row_idx;} public void Tdb_row_idx_(int v) {tdb_row_idx = v;} private int tdb_row_idx;
@@ -44,17 +45,18 @@ public class Xowd_page_itm {
id_val = null;
return this;
}
public void Init_by_sql(int id, int ns_id, byte[] ttl_page_db, DateAdp modified_on, boolean redirected, int text_len, int text_db_id, int html_db_id, int redirect_id, int page_score) {
public void Init_by_sql(int id, int ns_id, byte[] ttl_page_db, DateAdp modified_on, boolean redirected, int text_len, int random_int, int text_db_id, int html_db_id, int redirect_id, int score) {
this.id = id;
this.ns_id = ns_id;
this.ttl_page_db = ttl_page_db;
this.modified_on = modified_on;
this.redirected = redirected;
this.text_len = text_len;
this.random_int = random_int;
this.text_db_id = text_db_id;
this.html_db_id = html_db_id;
this.redirect_id = redirect_id;
this.Page_score = page_score;
this.score = score;
}
public void Init_by_tdb(int id, int text_db_id, int tdb_row_idx, boolean redirected, int text_len, int ns_id, byte[] ttl_page_db) {
this.id = id;
@@ -128,4 +130,9 @@ public class Xowd_page_itm {
public static final Xowd_page_itm Null = null;
public static Xowd_page_itm new_tmp() {return new Xowd_page_itm();}
public static Xowd_page_itm new_srch(int id, int text_len) {return new Xowd_page_itm().Id_(id).Text_len_(text_len);}
public static final int Db_row_size_fixed =
(8 * 4) // page_id, page_namespace, page_random_int, page_text_db_id, page_html_db_id, page_redirect_id, page_score, page_is_redirect (assume byte saved as int in SQLITE)
+ 14 // page_touched
;
}

View File

@@ -21,28 +21,11 @@ import gplx.dbs.*; import gplx.xowa.*; import gplx.xowa.wikis.dbs.*; import gplx
import gplx.xowa.wikis.nss.*;
public class Xowd_page_tbl implements Rls_able {
private final String tbl_name = "page";
public final Db_conn conn; public final boolean schema_is_1;
public final boolean schema_is_1;
private String fld_id, fld_ns, fld_title, fld_is_redirect, fld_touched, fld_len, fld_random_int, fld_score, fld_text_db_id, fld_html_db_id, fld_redirect_id;
private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private Db_stmt stmt_select_all_by_ttl, stmt_select_all_by_id, stmt_select_id_by_ttl, stmt_insert;
private final String[] flds_select_all, flds_select_idx;
public String Tbl_name() {return tbl_name;}
public Dbmeta_fld_list Flds__all() {return flds;}
public String Fld_page_id() {return fld_id;}
public String Fld_page_ns() {return fld_ns;}
public String Fld_page_title() {return fld_title;}
public String Fld_page_len() {return fld_len;}
public String Fld_page_score() {return fld_score;} public static final String Fld__page_score__key = "page_score";
public String Fld_html_db_id() {return fld_html_db_id;}
public String Fld_is_redirect() {return fld_is_redirect;}
public String Fld_redirect_id() {return fld_redirect_id;}
public String[] Flds_select_idx() {return flds_select_idx;}
public String[] Flds_select_all() {return flds_select_all;}
public void Flds__assert() {
conn.Meta_fld_assert(tbl_name, this.Fld_html_db_id() , Dbmeta_fld_tid.Itm__int, -1);
conn.Meta_fld_assert(tbl_name, this.Fld_redirect_id() , Dbmeta_fld_tid.Itm__int, -1);
conn.Meta_fld_assert(tbl_name, Fld__page_score__key , Dbmeta_fld_tid.Itm__int, -1);
}
public Xowd_page_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn; this.schema_is_1 = schema_is_1;
String fld_text_db_id_name = "";
@@ -59,10 +42,31 @@ public class Xowd_page_tbl implements Rls_able {
fld_html_db_id = flds.Add_int_dflt("page_html_db_id", -1); // MW:XOWA
fld_redirect_id = flds.Add_int_dflt("page_redirect_id", -1); // MW:XOWA
fld_score = flds.Add_int_dflt(Fld__page_score__key, -1); // MW:XOWA
flds_select_all = String_.Ary_wo_null(fld_id, fld_ns, fld_title, fld_touched, fld_is_redirect, fld_len, fld_text_db_id, fld_html_db_id, fld_redirect_id, fld_score);
flds_select_all = String_.Ary_wo_null(fld_id, fld_ns, fld_title, fld_touched, fld_is_redirect, fld_len, fld_random_int, fld_text_db_id, fld_html_db_id, fld_redirect_id, fld_score);
flds_select_idx = String_.Ary_wo_null(fld_ns, fld_title, fld_id, fld_len, fld_score);
conn.Rls_reg(this);
}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public String Tbl_name() {return tbl_name;}
public Dbmeta_fld_list Flds__all() {return flds;}
public String Fld_page_id() {return fld_id;}
public String Fld_page_ns() {return fld_ns;}
public String Fld_page_title() {return fld_title;}
public String Fld_page_len() {return fld_len;}
public String Fld_page_score() {return fld_score;} public static final String Fld__page_score__key = "page_score";
public String Fld_text_db_id() {return fld_text_db_id;}
public String Fld_html_db_id() {return fld_html_db_id;}
public String Fld_is_redirect() {return fld_is_redirect;}
public String Fld_random_int() {return fld_random_int;}
public String Fld_modified_on() {return fld_touched;}
public String Fld_redirect_id() {return fld_redirect_id;}
public String[] Flds_select_idx() {return flds_select_idx;}
public String[] Flds_select_all() {return flds_select_all;}
public void Flds__assert() {
conn.Meta_fld_assert(tbl_name, this.Fld_html_db_id() , Dbmeta_fld_tid.Itm__int, -1);
conn.Meta_fld_assert(tbl_name, this.Fld_redirect_id() , Dbmeta_fld_tid.Itm__int, -1);
conn.Meta_fld_assert(tbl_name, Fld__page_score__key , Dbmeta_fld_tid.Itm__int, -1);
}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds.To_fld_ary()));}
public void Insert(int page_id, int ns_id, byte[] ttl_wo_ns, boolean page_is_redirect, DateAdp modified_on, int page_len, int random_int, int text_db_id, int html_db_id) {
this.Insert_bgn();
@@ -86,6 +90,21 @@ public class Xowd_page_tbl implements Rls_able {
.Val_int(fld_score, -1)
.Exec_insert();
}
public void Insert_by_itm(Db_stmt stmt, Xowd_page_itm itm, int html_db_id) {
stmt.Clear()
.Val_int (fld_id , itm.Id())
.Val_int (fld_ns , itm.Ns_id())
.Val_bry_as_str (fld_title , itm.Ttl_page_db())
.Val_bool_as_byte (fld_is_redirect , itm.Redirected())
.Val_str (fld_touched , itm.Modified_on().XtoStr_fmt(Xowd_page_tbl.Page_touched_fmt))
.Val_int (fld_len , itm.Text_len())
.Val_int (fld_random_int , itm.Random_int())
.Val_int (fld_text_db_id , itm.Text_db_id())
.Val_int (fld_html_db_id , html_db_id)
.Val_int (fld_redirect_id , itm.Redirect_id())
.Val_int (fld_score , itm.Score())
.Exec_insert();
}
public boolean Select_by_ttl(Xowd_page_itm rv, Xow_ns ns, byte[] ttl) {
if (stmt_select_all_by_ttl == null) stmt_select_all_by_ttl = conn.Stmt_select(tbl_name, flds, String_.Ary(fld_ns, fld_title));
Db_rdr rdr = stmt_select_all_by_ttl.Clear().Crt_int(fld_ns, ns.Id()).Crt_bry_as_str(fld_title, ttl).Exec_select__rls_manual();
@@ -281,6 +300,7 @@ public class Xowd_page_tbl implements Rls_able {
, DateAdp_.parse_fmt(rdr.Read_str(fld_touched), Page_touched_fmt)
, rdr.Read_bool_by_byte(fld_is_redirect)
, page_len
, rdr.Read_int(fld_random_int)
, rdr.Read_int(fld_text_db_id)
, html_db_id
, redirected_id
@@ -314,7 +334,7 @@ public class Xowd_page_tbl implements Rls_able {
.Exec_update()
;
}
public void Create_index() {
public void Create_idx() {
conn.Meta_idx_create(Xoa_app_.Usr_dlg()
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "title" , fld_title, fld_ns)
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "random" , fld_random_int)

View File

@@ -19,9 +19,9 @@ package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gpl
import gplx.dbs.*; import gplx.dbs.qrys.*;
import gplx.xowa.wikis.nss.*;
public class Xowd_site_ns_tbl {
private final String tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_id, fld_name, fld_case, fld_count, fld_is_alias;
private final Db_conn conn;
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_id, fld_name, fld_case, fld_count, fld_is_alias;
private final Db_conn conn;
public Xowd_site_ns_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
this.tbl_name = schema_is_1 ? "xowa_ns" : "site_ns";

View File

@@ -18,10 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.core.ios.*; import gplx.dbs.*; import gplx.dbs.utls.*;
public class Xowd_text_tbl implements Rls_able {
private final String tbl_name = "text"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_page_id, fld_text_data;
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
private final Io_stream_zip_mgr zip_mgr = Xoa_app_.Utl__zip_mgr(); private final byte zip_tid;
private final String tbl_name = "text"; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_page_id, fld_text_data;
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
private final Io_stream_zip_mgr zip_mgr = Xoa_app_.Utl__zip_mgr(); private final byte zip_tid;
public String Fld_text_data() {return fld_text_data;}
public Xowd_text_tbl(Db_conn conn, boolean schema_is_1, byte zip_tid) {
this.conn = conn; this.zip_tid = zip_tid;
@@ -46,9 +46,12 @@ public class Xowd_text_tbl implements Rls_able {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_page_id);
Db_rdr rdr = stmt_select.Clear().Val_int(fld_page_id, page_id).Exec_select__rls_manual();
try {
byte[] rv = (byte[])rdr.Read_bry(fld_text_data);
if (rv == null) rv = Bry_.Empty; // NOTE: defect wherein blank page inserts null not ""; for now always convert nul to empty String; DATE:2015-11-08
rv = zip_mgr.Unzip(zip_tid, rv);
byte[] rv = Bry_.Empty;
if (rdr.Move_next()) {
rv = rdr.Read_bry(fld_text_data);
if (rv == null) rv = Bry_.Empty; // NOTE: defect wherein blank page inserts null not ""; for now always convert null to empty String; DATE:2015-11-08
rv = zip_mgr.Unzip(zip_tid, rv);
}
return rv;
} finally {rdr.Rls();}
}

View File

@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*; import gplx.xowa.xtns.wdatas.*;
public class Xowd_wbase_pid_tbl implements Rls_able {
private final String tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_src_lang, fld_src_ttl, fld_trg_ttl;
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_src_lang, fld_src_ttl, fld_trg_ttl;
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
public Xowd_wbase_pid_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
String fld_prefix = "";

View File

@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*;
public class Xowd_wbase_qid_tbl implements Rls_able {
private final String tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_src_wiki, fld_src_ns, fld_src_ttl, fld_trg_ttl;
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_src_wiki, fld_src_ns, fld_src_ttl, fld_trg_ttl;
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
private boolean src_ttl_has_spaces;
public Xowd_wbase_qid_tbl(Db_conn conn, boolean schema_is_1, boolean src_ttl_has_spaces) {
this.conn = conn; this.src_ttl_has_spaces = src_ttl_has_spaces;

View File

@@ -19,15 +19,16 @@ package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gpl
import gplx.dbs.*; import gplx.dbs.qrys.*;
import gplx.xowa.wikis.data.*;
public class Xowd_xowa_db_tbl {
private final String tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_id, fld_type, fld_url, fld_ns_ids, fld_part_id, fld_guid; private boolean schema_is_1;
private final Db_conn conn; private final Db_stmt_bldr stmt_bldr = new Db_stmt_bldr();
public static final String Tbl_name = "xowa_db", Fld_id = "db_id", Fld_type = "db_type", Fld_url = "db_url";
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_id, fld_type, fld_url, fld_ns_ids, fld_part_id, fld_guid; private boolean schema_is_1;
private final Db_conn conn; private final Db_stmt_bldr stmt_bldr = new Db_stmt_bldr();
public Xowd_xowa_db_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn; this.schema_is_1 = schema_is_1;
this.tbl_name = "xowa_db";
fld_id = flds.Add_int_pkey ("db_id");
fld_type = flds.Add_byte ("db_type");
fld_url = flds.Add_str ("db_url", 512);
this.tbl_name = Tbl_name;
fld_id = flds.Add_int_pkey (Fld_id);
fld_type = flds.Add_byte (Fld_type);
fld_url = flds.Add_str (Fld_url, 512);
if (schema_is_1) {
fld_ns_ids = fld_part_id = fld_guid = Dbmeta_fld_itm.Key_null;
}
@@ -39,8 +40,8 @@ public class Xowd_xowa_db_tbl {
stmt_bldr.Conn_(conn, tbl_name, flds, fld_id);
}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public Xowd_db_file[] Select_all(Xowd_core_db_props props, Io_url wiki_root_dir) {
List_adp list = List_adp_.new_();
public Xow_db_file[] Select_all(Xowd_core_db_props props, Io_url wiki_root_dir) {
List_adp list = List_adp_.New();
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
@@ -48,15 +49,17 @@ public class Xowd_xowa_db_tbl {
if (!schema_is_1) {
ns_ids = rdr.Read_str(fld_ns_ids);
part_id = rdr.Read_int(fld_part_id);
guid = Guid_adp_.parse(rdr.Read_str(fld_guid));
guid = Guid_adp_.Parse(rdr.Read_str(fld_guid));
}
list.Add(Xowd_db_file.load_(props, rdr.Read_int(fld_id), rdr.Read_byte(fld_type), wiki_root_dir.GenSubFil(rdr.Read_str(fld_url)), ns_ids, part_id, guid));
int db_id = rdr.Read_int(fld_id);
Xow_db_file db_file = Xow_db_file.load_(props, db_id, rdr.Read_byte(fld_type), wiki_root_dir.GenSubFil(rdr.Read_str(fld_url)), ns_ids, part_id, guid);
list.Add(db_file);
}
} finally {rdr.Rls();}
list.Sort_by(Xowd_db_file_sorter__id.Instance);
return (Xowd_db_file[])list.To_ary(Xowd_db_file.class);
list.Sort_by(Xow_db_file_sorter__id.Instance);
return (Xow_db_file[])list.To_ary_and_clear(Xow_db_file.class);
}
public void Commit_all(Xowd_db_mgr core_data_mgr) {
public void Commit_all(Xow_db_mgr core_data_mgr) {
stmt_bldr.Batch_bgn();
try {
int len = core_data_mgr.Dbs__len();
@@ -64,7 +67,7 @@ public class Xowd_xowa_db_tbl {
Commit_itm(core_data_mgr.Dbs__get_at(i));
} finally {stmt_bldr.Batch_end();}
}
private void Commit_itm(Xowd_db_file itm) {
private void Commit_itm(Xow_db_file itm) {
Db_stmt stmt = stmt_bldr.Get(itm.Cmd_mode());
switch (itm.Cmd_mode()) {
case Db_cmd_mode.Tid_create: stmt.Clear().Val_int(fld_id, itm.Id()); Commit_itm_vals(stmt, itm); stmt.Exec_insert(); break;
@@ -75,15 +78,15 @@ public class Xowd_xowa_db_tbl {
}
itm.Cmd_mode_(Db_cmd_mode.Tid_ignore);
}
private void Commit_itm_vals(Db_stmt stmt, Xowd_db_file itm) {
private void Commit_itm_vals(Db_stmt stmt, Xow_db_file itm) {
stmt.Val_byte(fld_type, itm.Tid()).Val_str(fld_url, itm.Url_rel()).Val_str(fld_ns_ids, itm.Ns_ids()).Val_int(fld_part_id, itm.Part_id()).Val_str(fld_guid, itm.Guid().To_str());
}
}
class Xowd_db_file_sorter__id implements gplx.core.lists.ComparerAble {
class Xow_db_file_sorter__id implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Xowd_db_file lhs = (Xowd_db_file)lhsObj;
Xowd_db_file rhs = (Xowd_db_file)rhsObj;
Xow_db_file lhs = (Xow_db_file)lhsObj;
Xow_db_file rhs = (Xow_db_file)rhsObj;
return Int_.Compare(lhs.Id(), rhs.Id());
}
public static final Xowd_db_file_sorter__id Instance = new Xowd_db_file_sorter__id(); Xowd_db_file_sorter__id() {}
public static final Xow_db_file_sorter__id Instance = new Xow_db_file_sorter__id(); Xow_db_file_sorter__id() {}
}