mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.2.1
This commit is contained in:
24
400_xowa/src/gplx/xowa/wikis/data/Xow_page_fetcher.java
Normal file
24
400_xowa/src/gplx/xowa/wikis/data/Xow_page_fetcher.java
Normal 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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public interface Xow_page_fetcher {
|
||||
Xow_page_fetcher Wiki_(Xowe_wiki v);
|
||||
byte[] Get_by(int ns_id, byte[] ttl);
|
||||
void Clear();
|
||||
}
|
||||
32
400_xowa/src/gplx/xowa/wikis/data/Xow_page_fetcher_test.java
Normal file
32
400_xowa/src/gplx/xowa/wikis/data/Xow_page_fetcher_test.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.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 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);
|
||||
}
|
||||
public byte[] Get_by(int ns_id, byte[] ttl) {
|
||||
Xowd_page_itm rv = (Xowd_page_itm)pages.Get_by(Make_key(ns_id, ttl));
|
||||
return rv == null ? null : rv.Text();
|
||||
}
|
||||
String Make_key(int ns_id, byte[] ttl) {return Int_.Xto_str(ns_id) + "|" + String_.new_u8(ttl);}
|
||||
}
|
||||
27
400_xowa/src/gplx/xowa/wikis/data/Xow_page_fetcher_wiki.java
Normal file
27
400_xowa/src/gplx/xowa/wikis/data/Xow_page_fetcher_wiki.java
Normal 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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
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
|
||||
return page.Missing() ? null : page.Data_raw();
|
||||
}
|
||||
}
|
||||
70
400_xowa/src/gplx/xowa/wikis/data/Xowd_core_db_props.java
Normal file
70
400_xowa/src/gplx/xowa/wikis/data/Xowd_core_db_props.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
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.ios.*; import gplx.dbs.*; import gplx.dbs.cfgs.*;
|
||||
import gplx.dbs.metas.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.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, byte zip_tid_text, byte zip_tid_html) {
|
||||
this.schema = schema;
|
||||
this.layout_text = layout_text; this.layout_html = layout_html; this.layout_file = layout_file;
|
||||
this.zip_tid_text = zip_tid_text; this.zip_tid_html = zip_tid_html;
|
||||
}
|
||||
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 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 void Cfg_save(Db_cfg_tbl tbl) {
|
||||
tbl.Conn().Txn_bgn();
|
||||
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_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.Conn().Txn_end();
|
||||
}
|
||||
public static Xowd_core_db_props Cfg_load(Io_url url, Db_conn conn) {
|
||||
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, "xowa_cfg");
|
||||
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, Io_stream_.Tid_gzip), Io_stream_.Tid_gzip)
|
||||
: Cfg_load(cfg_tbl);
|
||||
}
|
||||
private static Xowd_core_db_props Cfg_load(Db_cfg_tbl tbl) {
|
||||
Db_cfg_hash cfg_hash = tbl.Select_as_hash(Cfg_grp);
|
||||
return new Xowd_core_db_props
|
||||
( cfg_hash.Get(Cfg_key__schema_version).To_int()
|
||||
, Xowd_db_layout.get_(cfg_hash.Get(Cfg_key__layout_text).To_str())
|
||||
, Xowd_db_layout.get_(cfg_hash.Get(Cfg_key__layout_html).To_str())
|
||||
, Xowd_db_layout.get_(cfg_hash.Get(Cfg_key__layout_file).To_str())
|
||||
, cfg_hash.Get(Cfg_key__zip_tid_text).To_byte()
|
||||
, cfg_hash.Get(Cfg_key__zip_tid_html).To_byte()
|
||||
);
|
||||
}
|
||||
private static final String Cfg_grp = Xow_cfg_consts.Grp__wiki_core
|
||||
, Cfg_key__schema_version = "schema_version"
|
||||
, Cfg_key__layout_text = "layout_text"
|
||||
, Cfg_key__layout_html = "layout_html"
|
||||
, Cfg_key__layout_file = "layout_file"
|
||||
, Cfg_key__zip_tid_text = "zip_tid_text"
|
||||
, Cfg_key__zip_tid_html = "zip_tid_html"
|
||||
;
|
||||
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);
|
||||
}
|
||||
94
400_xowa/src/gplx/xowa/wikis/data/Xowd_db_file.java
Normal file
94
400_xowa/src/gplx/xowa/wikis/data/Xowd_db_file.java
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
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.data.tbls.*; import gplx.xowa.bldrs.infos.*;
|
||||
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.conn = conn; this.cmd_mode = cmd_mode;
|
||||
this.url_rel = url.NameAndExt();
|
||||
boolean schema_is_1 = props.Schema_is_1();
|
||||
this.tbl__cfg = cfg_tbl;
|
||||
this.tbl__db = new Xowd_xowa_db_tbl(conn, schema_is_1);
|
||||
this.tbl__ns = new Xowd_site_ns_tbl(conn, schema_is_1);
|
||||
this.tbl__site_stats = new Xowd_site_stats_tbl(conn, schema_is_1);
|
||||
this.tbl__page = new Xowd_page_tbl(conn, schema_is_1);
|
||||
this.tbl__text = new Xowd_text_tbl(conn, schema_is_1, props.Zip_tid_text());
|
||||
this.tbl__html = new Xowd_html_tbl(conn, props.Zip_tid_html());
|
||||
this.tbl__css_core = new Xowd_css_core_tbl(conn);
|
||||
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_pid = new Xowd_wbase_pid_tbl(conn, schema_is_1);
|
||||
this.tbl__search_word = new Xowd_search_word_tbl(conn, schema_is_1, schema_props.Search__word__page_count_exists());
|
||||
this.tbl__search_link = new Xowd_search_link_tbl(conn, schema_is_1);
|
||||
this.info_session = info_session;
|
||||
this.info_file = info_file;
|
||||
}
|
||||
public int Id() {return id;} private final int id; // unique id in xowa_db
|
||||
public byte Tid() {return tid;} private final byte tid;
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
public String Url_rel() {return url_rel;} private final String url_rel;
|
||||
public String Ns_ids() {return ns_ids;} private final String 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 Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
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 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;
|
||||
public Xowd_page_tbl Tbl__page() {return tbl__page;} private final Xowd_page_tbl tbl__page;
|
||||
public Xowd_text_tbl Tbl__text() {return tbl__text;} private final Xowd_text_tbl tbl__text;
|
||||
public Xowd_html_tbl Tbl__html() {return tbl__html;} private final Xowd_html_tbl tbl__html;
|
||||
public Xowd_css_core_tbl Tbl__css_core() {return tbl__css_core;} private final Xowd_css_core_tbl tbl__css_core;
|
||||
public Xowd_css_file_tbl Tbl__css_file() {return tbl__css_file;} private final Xowd_css_file_tbl tbl__css_file;
|
||||
public Xowd_cat_core_tbl Tbl__cat_core() {return tbl__cat_core;} private final Xowd_cat_core_tbl tbl__cat_core;
|
||||
public Xowd_cat_link_tbl Tbl__cat_link() {return tbl__cat_link;} private final Xowd_cat_link_tbl tbl__cat_link;
|
||||
public Xowd_search_word_tbl Tbl__search_word() {return tbl__search_word;} private final Xowd_search_word_tbl tbl__search_word;
|
||||
public Xowd_search_link_tbl Tbl__search_link() {return tbl__search_link;} private final Xowd_search_link_tbl tbl__search_link;
|
||||
public Xowd_site_stats_tbl Tbl__site_stats() {return tbl__site_stats;} private final Xowd_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 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());
|
||||
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, "xowa_cfg");
|
||||
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);
|
||||
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) {
|
||||
Db_conn conn = Db_conn_bldr.I.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());
|
||||
conn = Db_conn_.Noop;
|
||||
}
|
||||
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, "xowa_cfg"); // 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);
|
||||
}
|
||||
}
|
||||
55
400_xowa/src/gplx/xowa/wikis/data/Xowd_db_file_.java
Normal file
55
400_xowa/src/gplx/xowa/wikis/data/Xowd_db_file_.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
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
|
||||
;
|
||||
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"
|
||||
;
|
||||
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;
|
||||
default: throw Exc_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
44
400_xowa/src/gplx/xowa/wikis/data/Xowd_db_file_hash.java
Normal file
44
400_xowa/src/gplx/xowa/wikis/data/Xowd_db_file_hash.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.*;
|
||||
class Xowd_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 Exc_.new_("unknown file.tid", "url", file.Url());
|
||||
if (!tids.Has(file.Id())) throw Exc_.new_("unknown file.id", "url", file.Url());
|
||||
tids.Del(file.Id());
|
||||
--count_total;
|
||||
}
|
||||
public void Add_or_new(Xowd_db_file file) {
|
||||
byte tid = file.Tid();
|
||||
Ordered_hash tids = (Ordered_hash)hash.Get_by(tid);
|
||||
if (tids == null) {
|
||||
tids = Ordered_hash_.new_();
|
||||
hash.Add(tid, tids);
|
||||
}
|
||||
tids.Add(file.Id(), file);
|
||||
++count_total;
|
||||
}
|
||||
public int Count_of_tid(byte tid) {
|
||||
Ordered_hash tids = (Ordered_hash)hash.Get_by(tid);
|
||||
return tids == null ? 0 : tids.Count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.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) {
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
public static final String Grp = Xow_cfg_consts.Grp__wiki_schema;
|
||||
public static final String
|
||||
Key__tbl_css_core = "tbl.css_core" // VERSION:2.4.1
|
||||
, Key__col_search_word_page_count = "col.search_word.word_page_count" // VERSION:2.4.2
|
||||
;
|
||||
}
|
||||
46
400_xowa/src/gplx/xowa/wikis/data/Xowd_db_layout.java
Normal file
46
400_xowa/src/gplx/xowa/wikis/data/Xowd_db_layout.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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 Exc_.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 Exc_.new_unimplemented();
|
||||
}
|
||||
}
|
||||
147
400_xowa/src/gplx/xowa/wikis/data/Xowd_db_mgr.java
Normal file
147
400_xowa/src/gplx/xowa/wikis/data/Xowd_db_mgr.java
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
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.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.*; 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 Xow_wiki wiki; private final Io_url wiki_root_dir; private final Xow_domain domain_itm;
|
||||
public Xowd_db_mgr(Xow_wiki wiki, Io_url wiki_root_dir, Xow_domain 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__search() {return db__search;} private Xowd_db_file db__search;
|
||||
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 Xowd_db_file Dbs__get_at(int i) {return dbs__ary[i];}
|
||||
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);
|
||||
Xowd_db_file rv = Xowd_db_file.make_(db__core.Info_session(), props, dbs__ary_len, tid, url, ns_ids, part_id, db__core.Url().NameAndExt(), Db_conn_bldr.I.New(url));
|
||||
Dbs__add_and_save(rv);
|
||||
Dbs__set_by_tid(rv);
|
||||
return rv;
|
||||
}
|
||||
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.I.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();
|
||||
Db_conn core_conn = Db_conn_bldr.I.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);
|
||||
}
|
||||
wiki.Props().Init_by_load(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.I.New(core_db_url);
|
||||
conn.Txn_bgn();
|
||||
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();
|
||||
}
|
||||
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__search = 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_search_core : {if (db__search == null) db__search = 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);
|
||||
}
|
||||
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_.Xto_str_pad_bgn_zero(tid_idx, 3); break;
|
||||
default : tid_idx_str = tid_idx == 1 ? "" : "-db." + Int_.Xto_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 Exc_.new_unimplemented();
|
||||
}
|
||||
}
|
||||
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 Exc_.new_unimplemented();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
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_cat_core_tbl implements RlsAble {
|
||||
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_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();
|
||||
public Db_conn Conn() {return conn;}
|
||||
public Xowd_cat_core_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
String fld_link_db_id_name = "";
|
||||
if (schema_is_1) {tbl_name = "category"; fld_link_db_id_name = "cat_file_idx";}
|
||||
else {tbl_name = "cat_core"; fld_link_db_id_name = "cat_link_db_id";}
|
||||
fld_id = flds.Add_int_pkey ("cat_id");
|
||||
fld_pages = flds.Add_int ("cat_pages");
|
||||
fld_subcats = flds.Add_int ("cat_subcats");
|
||||
fld_files = flds.Add_int ("cat_files");
|
||||
fld_hidden = flds.Add_byte ("cat_hidden");
|
||||
fld_link_db_id = flds.Add_int(fld_link_db_id_name);
|
||||
in_wkr.Ctor(this, tbl_name, flds, fld_id);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Xowd_cat_core_tbl Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds)); return this;}
|
||||
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int id, int pages, int subcats, int files, byte hidden, int link_db_id) {
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_id, id).Val_int(fld_pages, pages).Val_int(fld_subcats, subcats).Val_int(fld_files, files)
|
||||
.Val_byte(fld_hidden, hidden).Val_int(fld_link_db_id, link_db_id)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Update_bgn() {conn.Txn_bgn(); stmt_update = conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_hidden);}
|
||||
public void Update_end() {conn.Txn_end(); stmt_update = Db_stmt_.Rls(stmt_update);}
|
||||
public void Update_by_batch(int id, byte hidden) {
|
||||
stmt_update.Clear().Val_byte(fld_hidden, hidden).Crt_int(fld_id, id).Exec_update();
|
||||
}
|
||||
public void Delete_all() {conn.Stmt_delete(tbl_name, Db_meta_fld.Ary_empty).Exec_delete();;}
|
||||
public Xowd_category_itm Select(int id) {
|
||||
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_id);
|
||||
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_id, id).Exec_select__rls_manual();
|
||||
try {return rdr.Move_next() ? new_itm(rdr) : Xowd_category_itm.Null;} finally {rdr.Rls();}
|
||||
}
|
||||
public void Select_by_cat_id_in(Cancelable cancelable, Ordered_hash rv, int bgn, int end) {
|
||||
in_wkr.Init(rv);
|
||||
in_wkr.Select_in(cancelable, conn, bgn, end);
|
||||
}
|
||||
public Xowd_category_itm new_itm(Db_rdr rdr) {
|
||||
return Xowd_category_itm.load_
|
||||
( rdr.Read_int(fld_id)
|
||||
, rdr.Read_int(fld_link_db_id)
|
||||
, rdr.Read_bool_by_byte(fld_hidden)
|
||||
, rdr.Read_int(fld_subcats)
|
||||
, rdr.Read_int(fld_files)
|
||||
, rdr.Read_int(fld_pages)
|
||||
);
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_update = Db_stmt_.Rls(stmt_update);
|
||||
stmt_select = Db_stmt_.Rls(stmt_select);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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.*; import gplx.dbs.utls.*;
|
||||
class Xowd_cat_core_tbl__in_wkr extends Db_in_wkr__base {
|
||||
private Xowd_cat_core_tbl tbl;
|
||||
private String tbl_name, fld_cat_id; private Db_meta_fld_list flds; private Ordered_hash hash;
|
||||
public void Ctor(Xowd_cat_core_tbl tbl, String tbl_name, Db_meta_fld_list flds, String fld_cat_id) {
|
||||
this.tbl = tbl; this.tbl_name = tbl_name; this.flds = flds; this.fld_cat_id = fld_cat_id;
|
||||
}
|
||||
public void Init(Ordered_hash hash) {this.hash = hash;}
|
||||
@Override protected Db_qry Make_qry(int bgn, int end) {
|
||||
Object[] part_ary = In_ary(end - bgn);
|
||||
return Db_qry_.select_cols_(tbl_name, Db_crt_.in_(fld_cat_id, part_ary), flds.To_str_ary());
|
||||
}
|
||||
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xowd_page_itm itm = (Xowd_page_itm)hash.Get_at(i);
|
||||
stmt.Crt_int(fld_cat_id, itm.Id());
|
||||
}
|
||||
}
|
||||
@Override protected void Read_data(Cancelable cancelable, Db_rdr rdr) {
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xowd_category_itm ctg_data = tbl.new_itm(rdr);
|
||||
Xowd_page_itm page = (Xowd_page_itm)hash.Get_by(ctg_data.Id_val());
|
||||
page.Xtn_(ctg_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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.*; import gplx.dbs.qrys.*; import gplx.xowa.ctgs.*;
|
||||
public class Xowd_cat_link_tbl implements RlsAble {
|
||||
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_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;
|
||||
public Db_conn Conn() {return conn;}
|
||||
public Xowd_cat_link_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = schema_is_1 ? "categorylinks" : "cat_link";
|
||||
fld_from = flds.Add_int ("cl_from");
|
||||
fld_to_id = flds.Add_int ("cl_to_id");
|
||||
fld_type_id = flds.Add_byte ("cl_type_id");
|
||||
fld_sortkey = flds.Add_str ("cl_sortkey", 230);
|
||||
fld_timestamp = flds.Add_str ("cl_timestamp", 14);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Xowd_cat_link_tbl Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds)); return this;}
|
||||
public void Create_idx() {
|
||||
conn.Ddl_create_idx(Xoa_app_.Usr_dlg()
|
||||
, Db_meta_idx.new_normal_by_tbl(tbl_name, "main", fld_to_id, fld_type_id, fld_sortkey, fld_from)
|
||||
, Db_meta_idx.new_normal_by_tbl(tbl_name, "from", fld_from)
|
||||
);
|
||||
}
|
||||
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int page_id, int ctg_page_id, byte ctg_tid, byte[] sortkey, int timestamp) {
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_from , page_id)
|
||||
.Val_int(fld_to_id , ctg_page_id)
|
||||
.Val_byte(fld_type_id , ctg_tid)
|
||||
.Val_bry_as_str(fld_sortkey , sortkey)
|
||||
.Val_int(fld_timestamp , timestamp)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Delete_all() {conn.Stmt_delete(tbl_name, Db_meta_fld.Ary_empty).Exec_delete();}
|
||||
public int Select_by_type(List_adp list, int cat_page_id, byte arg_tid, byte[] arg_sortkey, boolean arg_is_from, int limit) {
|
||||
String arg_sortkey_str = arg_sortkey == null ? "" : String_.new_u8(arg_sortkey);
|
||||
gplx.core.criterias.Criteria comp_crt = !arg_is_from
|
||||
? Db_crt_.mte_(fld_sortkey, arg_sortkey_str) // from: sortkey >= 'val'
|
||||
: Db_crt_.lte_(fld_sortkey, arg_sortkey_str); // until: sortkey <= 'val'
|
||||
Db_qry__select_cmd qry = Db_qry_.select_().Cols_(fld_from, fld_sortkey).From_(tbl_name)
|
||||
.Where_(gplx.core.criterias.Criteria_.And_many(Db_crt_.eq_(fld_to_id, -1), Db_crt_.eq_(fld_type_id, arg_tid), comp_crt))
|
||||
.OrderBy_(fld_sortkey, !arg_is_from)
|
||||
.Limit_(limit + 1); // + 1 to get last_plus_one for next page / previous page
|
||||
Db_rdr rdr = conn.Stmt_new(qry).Crt_int(fld_to_id, cat_page_id).Crt_byte(fld_type_id, arg_tid).Crt_str(fld_sortkey, arg_sortkey_str).Exec_select__rls_auto();
|
||||
int count = 0;
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
int itm_page_id = rdr.Read_int(fld_from);
|
||||
byte[] itm_sortkey = rdr.Read_bry_by_str(fld_sortkey);
|
||||
Xowd_page_itm itm = new Xowd_page_itm().Id_(itm_page_id).Xtn_(new Xoctg_page_xtn(arg_tid, itm_sortkey));
|
||||
list.Add(itm);
|
||||
++count;
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
list.Sort_by(Xowd_page_itm_sorter.Ctg_tid_sortkey_asc);
|
||||
return count;
|
||||
}
|
||||
public void Select_in(List_adp rv, int cat_id) {
|
||||
if (stmt_select_in == null) stmt_select_in = conn.Stmt_select(tbl_name, flds, fld_to_id);
|
||||
Db_rdr rdr = stmt_select_in.Clear().Crt_int(fld_to_id, cat_id).Exec_select__rls_manual();
|
||||
try {
|
||||
while (rdr.Move_next())
|
||||
rv.Add(new Xowd_page_itm().Id_(rdr.Read_int(fld_from)));
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_select_in = Db_stmt_.Rls(stmt_select_in);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.core.primitives.*; import gplx.xowa.ctgs.*;
|
||||
public class Xowd_category_itm {
|
||||
public int Id() {return id;} private int id;
|
||||
public Int_obj_val Id_val() {if (id_val == null) id_val = Int_obj_val.new_(id); return id_val;} Int_obj_val id_val;
|
||||
public int File_idx() {return file_idx;} private int file_idx;
|
||||
public boolean Hidden() {return hidden;} private boolean hidden;
|
||||
public int Count_all() {return count_subcs + count_files + count_pages;}
|
||||
public int Count_subcs() {return count_subcs;} private int count_subcs;
|
||||
public int Count_files() {return count_files;} private int count_files;
|
||||
public int Count_pages() {return count_pages;} private int count_pages;
|
||||
public int Count_by_tid(byte tid) {
|
||||
switch (tid) {
|
||||
case Xoa_ctg_mgr.Tid_subc: return count_subcs;
|
||||
case Xoa_ctg_mgr.Tid_page: return count_pages;
|
||||
case Xoa_ctg_mgr.Tid_file: return count_files;
|
||||
default: throw Exc_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static Xowd_category_itm load_(int id, int file_idx, boolean hidden, int count_subcs, int count_files, int count_pages) {
|
||||
Xowd_category_itm rv = new Xowd_category_itm();
|
||||
rv.id = id; rv.file_idx = file_idx; rv.hidden = hidden;
|
||||
rv.count_subcs = count_subcs; rv.count_files = count_files; rv.count_pages = count_pages;
|
||||
return rv;
|
||||
}
|
||||
public static final Xowd_category_itm Null = new Xowd_category_itm(); Xowd_category_itm() {}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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 RlsAble {
|
||||
private final String tbl_name = "css_core"; private final Db_meta_fld_list flds = Db_meta_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.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds, Db_meta_idx.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;
|
||||
}
|
||||
@@ -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.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;
|
||||
}
|
||||
@@ -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.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 RlsAble {
|
||||
private final String tbl_name = "css_file"; private final Db_meta_fld_list flds = Db_meta_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.Ddl_create_tbl(Db_meta_tbl.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));}
|
||||
}
|
||||
29
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_html_row.java
Normal file
29
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_html_row.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
public class Xowd_html_row {
|
||||
public Xowd_html_row(int page_id, int tid, byte[] data) {this.page_id = page_id; this.tid = tid; this.data = data;}
|
||||
public int Page_id() {return page_id;} private final int page_id;
|
||||
public int Tid() {return tid;} private final int tid;
|
||||
public byte[] Data() {return data;} private final byte[] data;
|
||||
public static final int // SERIALIZED
|
||||
Tid_html = 0
|
||||
, Tid_img = 1
|
||||
, Tid_redlink = 2
|
||||
;
|
||||
}
|
||||
71
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_html_tbl.java
Normal file
71
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_html_tbl.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.ios.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.dbs.*; import gplx.dbs.cfgs.*;
|
||||
public class Xowd_html_tbl implements RlsAble {
|
||||
private final String tbl_name = "html"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_page_id, fld_html_tid, fld_html_data;
|
||||
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert, stmt_delete;
|
||||
private final Io_stream_zip_mgr zip_mgr = Xoa_app_.Utl__zip_mgr(); private final byte zip_tid;
|
||||
public Xowd_html_tbl(Db_conn conn, byte zip_tid) {
|
||||
this.conn = conn; this.zip_tid = zip_tid;
|
||||
fld_page_id = flds.Add_int("page_id");
|
||||
fld_html_tid = flds.Add_int("html_tid");
|
||||
fld_html_data = flds.Add_bry("html_data");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Create_idx() {conn.Ddl_create_idx(Gfo_usr_dlg_.I, Db_meta_idx.new_unique_by_tbl(tbl_name, "main", fld_page_id, fld_html_tid));}
|
||||
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public int Insert(int page_id, int tid, byte[] data) {
|
||||
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
|
||||
data = zip_mgr.Zip(zip_tid, data);
|
||||
stmt_insert.Clear().Val_int(fld_page_id, page_id).Val_int(fld_html_tid, tid).Val_bry(fld_html_data, data).Exec_insert();
|
||||
return data.length;
|
||||
}
|
||||
public void Delete(int page_id) {
|
||||
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, String_.Ary(fld_page_id));
|
||||
stmt_delete.Clear().Crt_int(fld_page_id, page_id).Exec_delete();
|
||||
}
|
||||
public void Select_by_page(List_adp rv, int page_id) {
|
||||
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, String_.Ary(fld_page_id));
|
||||
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_page_id, page_id).Exec_select__rls_manual();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
Xowd_html_row row = new Xowd_html_row(rdr.Read_int(fld_page_id), rdr.Read_int(fld_html_tid), zip_mgr.Unzip(zip_tid, rdr.Read_bry(fld_html_data)));
|
||||
rv.Add(row);
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_delete = Db_stmt_.Rls(stmt_delete);
|
||||
stmt_select = Db_stmt_.Rls(stmt_select);
|
||||
}
|
||||
public static void Assert_col__page_html_db_id(Xowd_db_mgr db_mgr) {
|
||||
Xowd_page_tbl page_tbl = db_mgr.Tbl__page(); Db_conn page_conn = page_tbl.Conn();
|
||||
boolean html_flds_exists = page_conn.Meta_fld_exists(page_tbl.Tbl_name(), page_tbl.Fld_html_db_id());
|
||||
if (html_flds_exists) return;
|
||||
page_conn.Ddl_append_fld(page_tbl.Tbl_name(), Db_meta_fld.new_int(page_tbl.Fld_html_db_id()).Default_(-1));
|
||||
page_conn.Ddl_append_fld(page_tbl.Tbl_name(), Db_meta_fld.new_int(page_tbl.Fld_redirect_id()).Default_(-1));
|
||||
page_tbl.Hdump_enabled_(Bool_.Y);
|
||||
}
|
||||
}
|
||||
126
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm.java
Normal file
126
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm.java
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
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.core.primitives.*;
|
||||
public class Xowd_page_itm implements Xobl_data_itm {
|
||||
public Xowd_page_itm() {this.Clear();}
|
||||
public int Id() {return id;} public Xowd_page_itm Id_(int v) {id = v; id_val = null; return this;} private int id;
|
||||
public Int_obj_val Id_val() {if (id_val == null) id_val = Int_obj_val.new_(id); return id_val;} private Int_obj_val id_val;
|
||||
public int Ns_id() {return ns_id;} public Xowd_page_itm Ns_id_(int v) {ns_id = v; return this;} private int ns_id;
|
||||
public byte[] Ttl_page_db() {return ttl_page_db;} public Xowd_page_itm Ttl_page_db_(byte[] v) {ttl_page_db = v; return this;} private byte[] ttl_page_db; // EX: Category1
|
||||
public byte[] Ttl_full_db() {return ttl_full_db;} private byte[] ttl_full_db; // EX: Category:Category1
|
||||
public boolean Redirected() {return redirected;} public Xowd_page_itm Redirected_(boolean v) {redirected = v; return this;} private boolean redirected;
|
||||
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 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 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;
|
||||
public Xowd_page_itm Init(int id, byte[] ttl_page_db, boolean redirected, int text_len, int text_db_id, int tdb_row_idx) {
|
||||
this.id = id; this.ttl_page_db = ttl_page_db; this.redirected = redirected;
|
||||
this.text_len = text_len; this.text_db_id = text_db_id; this.tdb_row_idx = tdb_row_idx;
|
||||
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) {
|
||||
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.text_db_id = text_db_id;
|
||||
this.html_db_id = html_db_id;
|
||||
this.redirect_id = redirect_id;
|
||||
}
|
||||
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;
|
||||
this.text_db_id = text_db_id;
|
||||
this.tdb_row_idx = tdb_row_idx;
|
||||
this.redirected = redirected;
|
||||
this.text_len = text_len;
|
||||
this.ns_id = ns_id;
|
||||
this.ttl_page_db = ttl_page_db;
|
||||
}
|
||||
public Xowd_page_itm Ttl_(Xow_ns ns, byte[] ttl_page_db) {
|
||||
this.ns = ns;
|
||||
ns_id = ns.Id();
|
||||
this.ttl_page_db = ttl_page_db;
|
||||
this.ttl_full_db = ns.Gen_ttl(ttl_page_db);
|
||||
return this;
|
||||
}
|
||||
public Xowd_page_itm Ttl_(Xoa_ttl ttl) {
|
||||
ttl_full_db = ttl.Full_txt();
|
||||
ttl_page_db = ttl.Page_db();
|
||||
ns = ttl.Ns();
|
||||
ns_id = ns.Id();
|
||||
return this;
|
||||
}
|
||||
public Xowd_page_itm Ttl_(byte[] v, Xow_ns_mgr ns_mgr) {
|
||||
ttl_full_db = v;
|
||||
Object o = ns_mgr.Names_get_w_colon(v, 0, v.length);
|
||||
if (o == null) {
|
||||
ns = ns_mgr.Ns_main();
|
||||
ttl_page_db = v;
|
||||
}
|
||||
else {
|
||||
ns = (Xow_ns)o;
|
||||
ttl_page_db = Bry_.Mid(v, ns.Name_txt_w_colon().length, v.length); // EX: "Template:A" -> "Template:" + "A"
|
||||
}
|
||||
ns_id = ns.Id();
|
||||
return this;
|
||||
}
|
||||
public void Clear() {
|
||||
id = Id_null; text_len = 0; // text_len should be 0 b/c text defaults to 0;
|
||||
text_db_id = tdb_row_idx = 0; // default to 0, b/c some tests do not set and will fail at -1
|
||||
ns_id = Int_.MinValue;
|
||||
ttl_full_db = ttl_page_db = null; text = Bry_.Empty; // default to Ary_empty for entries that have <text />
|
||||
ns = null;
|
||||
redirected = exists = false;
|
||||
modified_on = DateAdp_.MinValue;
|
||||
id_val = null;
|
||||
html_db_id = -1;
|
||||
redirect_id = -1;
|
||||
}
|
||||
public void Copy(Xowd_page_itm orig) {
|
||||
this.id = orig.id;
|
||||
this.text_len = orig.text_len;
|
||||
this.text_db_id = orig.text_db_id;
|
||||
this.tdb_row_idx = orig.tdb_row_idx;
|
||||
this.ns_id = orig.ns_id;
|
||||
this.ttl_full_db = orig.ttl_full_db;
|
||||
this.ttl_page_db = orig.ttl_page_db;
|
||||
this.text = orig.text;
|
||||
this.ns = orig.ns;
|
||||
this.redirected = orig.redirected;
|
||||
this.exists = orig.exists;
|
||||
this.modified_on = orig.modified_on;
|
||||
this.id_val = null;
|
||||
this.html_db_id = orig.html_db_id;
|
||||
}
|
||||
public void Srl_save(Bry_bfr bfr) {gplx.xowa.tdbs.Xotdb_page_itm_.Txt_id_save(bfr, this);}
|
||||
public static final int Id_null = -1, Modified_on_null_int = 0;
|
||||
public static final Xowd_page_itm[] Ary_empty = new Xowd_page_itm[0];
|
||||
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);}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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.lists.*; /*ComparerAble*/ import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xowd_page_itm_sorter implements ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Xowd_page_itm lhs = (Xowd_page_itm)lhsObj, rhs = (Xowd_page_itm)rhsObj;
|
||||
return order * Compare_rows(compareType, lhs, rhs);
|
||||
}
|
||||
private static int Compare_rows(byte compareType, Xowd_page_itm lhs, Xowd_page_itm rhs) {
|
||||
switch (compareType) {
|
||||
case Tid_ns_ttl: {
|
||||
int rv = Int_.Compare(lhs.Ns_id(), rhs.Ns_id());
|
||||
return rv == CompareAble_.Same ? Bry_.Compare(lhs.Ttl_page_db(), rhs.Ttl_page_db()) : rv;
|
||||
}
|
||||
case Tid_itm_len: return Int_.Compare(lhs.Text_len(), rhs.Text_len());
|
||||
case Tid_id: return Int_.Compare(lhs.Id(), rhs.Id());
|
||||
case Tid_ttl: return Bry_.Compare(lhs.Ttl_page_db(), rhs.Ttl_page_db());
|
||||
case Tid_ctg_tid_sortkey:
|
||||
gplx.xowa.ctgs.Xoctg_page_xtn lhs_xtn = (gplx.xowa.ctgs.Xoctg_page_xtn)lhs.Xtn();
|
||||
gplx.xowa.ctgs.Xoctg_page_xtn rhs_xtn = (gplx.xowa.ctgs.Xoctg_page_xtn)rhs.Xtn();
|
||||
if (lhs_xtn == null || rhs_xtn == null) return CompareAble_.Same;
|
||||
int tid_comparable = Byte_.Compare(lhs_xtn.Tid(), rhs_xtn.Tid());
|
||||
if (tid_comparable != CompareAble_.Same) return tid_comparable;
|
||||
return Bry_.Compare(lhs_xtn.Sortkey(), rhs_xtn.Sortkey());
|
||||
default: throw Exc_.new_unhandled(compareType);
|
||||
}
|
||||
}
|
||||
Xowd_page_itm_sorter(byte compareType, int order) {this.compareType = compareType; this.order = order;}
|
||||
byte compareType; int order;
|
||||
static final byte Tid_ns_ttl = 0, Tid_itm_len = 2, Tid_id = 3, Tid_ttl = 4, Tid_ctg_tid_sortkey = 5;
|
||||
static final int Asc = 1, Dsc = -1;
|
||||
public static final Xowd_page_itm_sorter TitleAsc = new Xowd_page_itm_sorter(Tid_ttl , Asc);
|
||||
public static final Xowd_page_itm_sorter EnyLenDsc = new Xowd_page_itm_sorter(Tid_itm_len , Dsc);
|
||||
public static final Xowd_page_itm_sorter IdAsc = new Xowd_page_itm_sorter(Tid_id , Asc);
|
||||
public static final Xowd_page_itm_sorter Ns_id_TtlAsc = new Xowd_page_itm_sorter(Tid_ns_ttl , Asc);
|
||||
public static final Xowd_page_itm_sorter Ctg_tid_sortkey_asc = new Xowd_page_itm_sorter(Tid_ctg_tid_sortkey , Asc);
|
||||
}
|
||||
@@ -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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xowd_page_itm_tst {
|
||||
@Before public void init() {fxt.Init();} private Xowd_page_itm_fxt fxt = new Xowd_page_itm_fxt();
|
||||
@Test public void Ttl_() {
|
||||
fxt.Test_ttl_("User_talk:A", Xow_ns_.Id_user_talk, "A");
|
||||
fxt.Test_ttl_("User talk:A", Xow_ns_.Id_user_talk, "A");
|
||||
}
|
||||
}
|
||||
class Xowd_page_itm_fxt {
|
||||
public void Init() {
|
||||
if (ns_mgr == null) {
|
||||
ns_mgr = new Xow_ns_mgr(gplx.xowa.langs.cases.Xol_case_mgr_.Ascii());
|
||||
ns_mgr.Add_new(Xow_ns_.Id_main, "");
|
||||
ns_mgr.Add_new(Xow_ns_.Id_user_talk, "User talk");
|
||||
ns_mgr.Init_w_defaults();
|
||||
tmp_page = new Xowd_page_itm();
|
||||
}
|
||||
} private Xow_ns_mgr ns_mgr; Xowd_page_itm tmp_page;
|
||||
public void Test_ttl_(String ttl, int expd_ns, String expd_ttl) {
|
||||
tmp_page.Ttl_(Bry_.new_a7(ttl), ns_mgr);
|
||||
Tfds.Eq(expd_ns, tmp_page.Ns_id());
|
||||
Tfds.Eq(expd_ttl, String_.new_a7(tmp_page.Ttl_page_db()));
|
||||
}
|
||||
}
|
||||
323
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_tbl.java
Normal file
323
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_tbl.java
Normal file
@@ -0,0 +1,323 @@
|
||||
/*
|
||||
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.core.primitives.*; import gplx.core.criterias.*;
|
||||
import gplx.dbs.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.dbs.qrys.*;
|
||||
public class Xowd_page_tbl implements RlsAble {
|
||||
private final String tbl_name = "page";
|
||||
private String fld_id, fld_ns, fld_title, fld_is_redirect, fld_touched, fld_len, fld_random_int, fld_text_db_id, fld_html_db_id, fld_redirect_id;
|
||||
private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final Db_conn conn; private Db_stmt stmt_select_all_by_ttl, stmt_select_all_by_id, stmt_select_id_by_ttl, stmt_insert; private boolean hdump_enabled;
|
||||
private final String[] flds_select_all, flds_select_idx;
|
||||
public String Tbl_name() {return tbl_name;}
|
||||
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_html_db_id() {return fld_html_db_id;}
|
||||
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 Db_conn Conn() {return conn;}
|
||||
public Xowd_page_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
String fld_text_db_id_name = "";
|
||||
if (schema_is_1) {fld_text_db_id_name = "page_file_idx";}
|
||||
else {fld_text_db_id_name = "page_text_db_id";}
|
||||
fld_id = flds.Add_int_pkey("page_id"); // int(10); unsigned -- MW:same
|
||||
fld_ns = flds.Add_int("page_namespace"); // int(11); -- MW:same
|
||||
fld_title = flds.Add_str("page_title", 255); // varbinary(255); -- MW:blob
|
||||
fld_is_redirect = flds.Add_int("page_is_redirect"); // tinyint(3); -- MW:same
|
||||
fld_touched = flds.Add_str("page_touched", 14); // binary(14); -- MW:blob; NOTE: should be revision!rev_timestamp, but needs extra join
|
||||
fld_len = flds.Add_int("page_len"); // int(10); unsigned -- MW:same except NULL REF: WikiPage.php!updateRevisionOn;"
|
||||
fld_random_int = flds.Add_int("page_random_int"); // MW:XOWA
|
||||
fld_text_db_id = flds.Add_int(fld_text_db_id_name); // MW:XOWA
|
||||
Hdump_enabled_(!schema_is_1);
|
||||
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);
|
||||
flds_select_idx = String_.Ary(fld_ns, fld_title, fld_id, fld_len);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds.To_fld_ary()));}
|
||||
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(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) {
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_id, page_id)
|
||||
.Val_int(fld_ns, ns_id)
|
||||
.Val_bry_as_str(fld_title, ttl_wo_ns)
|
||||
.Val_bool_as_byte(fld_is_redirect, page_is_redirect)
|
||||
.Val_str(fld_touched, modified_on.XtoStr_fmt(Page_touched_fmt))
|
||||
.Val_int(fld_len, page_len)
|
||||
.Val_int(fld_random_int, random_int)
|
||||
.Val_int(fld_text_db_id, text_db_id)
|
||||
.Val_int(fld_html_db_id, html_db_id)
|
||||
.Val_int(fld_redirect_id, -1)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Hdump_enabled_(boolean v) {
|
||||
this.hdump_enabled = v;
|
||||
if (v) {
|
||||
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
|
||||
}
|
||||
else {
|
||||
fld_html_db_id = Db_meta_fld.Key_null;
|
||||
fld_redirect_id = Db_meta_fld.Key_null;
|
||||
}
|
||||
}
|
||||
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();
|
||||
try {
|
||||
if (rdr.Move_next()) {
|
||||
Read_page__all(rv, rdr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
return false;
|
||||
}
|
||||
public boolean Select_by_id(Xowd_page_itm rv, int page_id) {
|
||||
if (stmt_select_all_by_id == null) stmt_select_all_by_id = conn.Stmt_select(tbl_name, flds_select_all, fld_id);
|
||||
Db_rdr rdr = stmt_select_all_by_id.Clear().Crt_int(fld_id, page_id).Exec_select__rls_manual();
|
||||
try {
|
||||
if (rdr.Move_next()) {
|
||||
Read_page__all(rv, rdr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
return false;
|
||||
}
|
||||
public Db_rdr Select_all() {
|
||||
Db_qry__select_cmd qry = Db_qry__select_cmd.new_().From_(tbl_name).Cols_(fld_id, fld_title).OrderBy_asc_(fld_id);
|
||||
return conn.Stmt_new(qry).Exec_select__rls_auto();
|
||||
}
|
||||
public int Select_id(int ns_id, byte[] ttl) {
|
||||
if (stmt_select_id_by_ttl == null) stmt_select_id_by_ttl = conn.Stmt_select(tbl_name, flds_select_all, fld_ns, fld_title);
|
||||
Db_rdr rdr = stmt_select_id_by_ttl.Clear().Crt_int(fld_ns, ns_id).Crt_bry_as_str(fld_title, ttl).Exec_select__rls_manual();
|
||||
try {
|
||||
return rdr.Move_next() ? rdr.Read_int(fld_id) : Xowd_page_itm.Id_null;
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Select_in__ttl(Cancelable cancelable, Ordered_hash rv, int ns_id, int bgn, int end) {
|
||||
Xowd_page_tbl__ttl wkr = new Xowd_page_tbl__ttl();
|
||||
wkr.Ctor(this, tbl_name, fld_title);
|
||||
wkr.Init(rv, ns_id);
|
||||
wkr.Select_in(cancelable, conn, bgn, end);
|
||||
}
|
||||
public void Select_in__ns_ttl(Cancelable cancelable, Ordered_hash rv, Xow_ns_mgr ns_mgr, boolean fill_idx_fields_only, int bgn, int end) {
|
||||
Xowd_page_tbl__ttl_ns wkr = new Xowd_page_tbl__ttl_ns();
|
||||
wkr.Fill_idx_fields_only_(fill_idx_fields_only);
|
||||
wkr.Ctor(this, tbl_name, fld_title);
|
||||
wkr.Init(ns_mgr, rv);
|
||||
wkr.Select_in(cancelable, conn, bgn, end);
|
||||
}
|
||||
public boolean Select_in__id(Cancelable cancelable, List_adp rv) {return Select_in__id(cancelable, false, rv, 0, rv.Count());}
|
||||
public boolean Select_in__id(Cancelable cancelable, boolean skip_table_read, List_adp rv) {return Select_in__id(cancelable, skip_table_read, rv, 0, rv.Count());}
|
||||
public boolean Select_in__id(Cancelable cancelable, boolean skip_table_read, List_adp rv, int bgn, int end) {
|
||||
Xowd_page_itm[] page_ary = (Xowd_page_itm[])rv.To_ary(Xowd_page_itm.class);
|
||||
int len = page_ary.length; if (len == 0) return false;
|
||||
Ordered_hash hash = Ordered_hash_.new_();
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (cancelable.Canceled()) return false;
|
||||
Xowd_page_itm p = page_ary[i];
|
||||
if (!hash.Has(p.Id_val())) // NOTE: must check if file already exists b/c dynamicPageList currently allows dupes; DATE:2013-07-22
|
||||
hash.Add(p.Id_val(), p);
|
||||
}
|
||||
hash.Sort_by(Xowd_page_itm_sorter.IdAsc); // sort by ID to reduce disk thrashing; DATE:2015-03-31
|
||||
conn.Txn_bgn();
|
||||
try {
|
||||
Xowd_page_tbl__id wkr = new Xowd_page_tbl__id();
|
||||
wkr.Ctor(this, tbl_name, fld_id);
|
||||
wkr.Init(rv, hash);
|
||||
wkr.Select_in(cancelable, conn, bgn, end);
|
||||
} finally {conn.Txn_end();}
|
||||
return true;
|
||||
}
|
||||
public byte[] Select_random(Xow_ns ns) {// ns should be ns_main
|
||||
int random_int = RandomAdp_.new_().Next(ns.Count());
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, String_.Ary(fld_title), fld_ns, fld_random_int)
|
||||
.Crt_int(fld_ns, ns.Id()).Crt_int(fld_random_int, random_int)
|
||||
.Exec_select__rls_auto();
|
||||
try {
|
||||
return rdr.Move_next() ? rdr.Read_bry_by_str(fld_title) : null;
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Select_by_search(Cancelable cancelable, List_adp rv, byte[] search, int results_max) {
|
||||
if (Bry_.Len_eq_0(search)) return; // do not allow empty search
|
||||
Criteria crt = Criteria_.And_many(Db_crt_.eq_(fld_ns, Xow_ns_.Id_main), Db_crt_.like_(fld_title, ""));
|
||||
Db_qry__select_cmd qry = Db_qry_.select_().From_(tbl_name).Cols_(fld_id, fld_len, fld_ns, fld_title).Where_(crt); // NOTE: use fields from main index only
|
||||
search = Bry_.Replace(search, Byte_ascii.Star, Byte_ascii.Percent);
|
||||
Db_rdr rdr = conn.Stmt_new(qry).Clear().Crt_int(fld_ns, Xow_ns_.Id_main).Val_bry_as_str(fld_title, search).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xowd_page_itm page = new Xowd_page_itm();
|
||||
page.Id_ (rdr.Read_int(fld_id));
|
||||
page.Ns_id_ (rdr.Read_int(fld_ns));
|
||||
page.Ttl_page_db_ (rdr.Read_bry_by_str(fld_title));
|
||||
page.Text_len_ (rdr.Read_int(fld_len));
|
||||
rv.Add(page);
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Select_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) {
|
||||
String search_bgn = String_.new_u8(key);
|
||||
String search_end = String_.new_u8(gplx.intl.Utf8_.Increment_char_at_last_pos(key));
|
||||
String sql = String_.Format
|
||||
( "SELECT {0}, {1}, {2}, {3} FROM {4} INDEXED BY {4}__title WHERE {1} = {5} AND {2} BETWEEN '{6}' AND '{7}' ORDER BY {3} DESC LIMIT {8};"
|
||||
, fld_id, fld_ns, fld_title, fld_len
|
||||
, tbl_name
|
||||
, Int_.Xto_str(ns.Id()), search_bgn, search_end, Int_.Xto_str(max_results)
|
||||
);
|
||||
Db_qry qry = Db_qry_sql.rdr_(sql);
|
||||
Db_rdr rdr = conn.Stmt_new(qry).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xowd_page_itm page = new Xowd_page_itm();
|
||||
Read_page__idx(page, rdr);
|
||||
rslt_list.Add(page);
|
||||
}
|
||||
rslt_list.Sort_by(Xowd_page_itm_sorter.TitleAsc);
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
private Db_rdr Load_ttls_starting_with_rdr(int ns_id, byte[] ttl_frag, boolean include_redirects, int max_results, int min_page_len, int browse_len, boolean fwd, boolean search_suggest) {
|
||||
String ttl_frag_str = String_.new_u8(ttl_frag);
|
||||
Criteria crt_ttl = fwd ? Db_crt_.mte_(fld_title, ttl_frag_str) : Db_crt_.lt_(fld_title, ttl_frag_str);
|
||||
Criteria crt = Criteria_.And_many(Db_crt_.eq_(fld_ns, ns_id), crt_ttl, Db_crt_.mte_(fld_len, min_page_len));
|
||||
if (!include_redirects)
|
||||
crt = Criteria_.And(crt, Db_crt_.eq_(fld_is_redirect, Byte_.Zero));
|
||||
String[] cols = search_suggest
|
||||
? flds_select_idx
|
||||
: flds_select_all
|
||||
;
|
||||
int limit = fwd ? max_results + 1 : max_results; // + 1 to get next item
|
||||
Db_qry__select_cmd qry = Db_qry_.select_cols_(tbl_name, crt, cols).Limit_(limit).OrderBy_(fld_title, fwd);
|
||||
Db_stmt stmt = conn.Stmt_new(qry).Crt_int(fld_ns, ns_id).Crt_str(fld_title, ttl_frag_str).Crt_int(fld_len, min_page_len);
|
||||
if (!include_redirects)
|
||||
stmt.Crt_bool_as_byte(fld_is_redirect, include_redirects);
|
||||
return stmt.Exec_select__rls_auto();
|
||||
}
|
||||
public void Select_for_special_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) {
|
||||
Xowd_page_itm nxt_itm = null;
|
||||
int rslt_idx = 0;
|
||||
boolean max_val_check = max_results == Int_.MaxValue;
|
||||
Db_rdr rdr = Load_ttls_starting_with_rdr(ns.Id(), key, include_redirects, max_results, min_page_len, browse_len, true, true);
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xowd_page_itm page = new Xowd_page_itm();
|
||||
Read_page__idx(page, rdr);
|
||||
if (max_val_check && !Bry_.Has_at_bgn(page.Ttl_page_db(), key)) break;
|
||||
nxt_itm = page;
|
||||
if (rslt_idx == max_results) {} // last item which is not meant for rslts, but only for nxt itm
|
||||
else {
|
||||
rslt_list.Add(page);
|
||||
++rslt_idx;
|
||||
}
|
||||
}
|
||||
if (rslt_nxt != null && nxt_itm != null) // occurs when range is empty; EX: "Module:A" in simplewikibooks
|
||||
rslt_nxt.Copy(nxt_itm);
|
||||
if (fetch_prv_item) { // NOTE: Special:AllPages passes in true, but Search_suggest passes in false
|
||||
if (cancelable.Canceled()) return;
|
||||
rdr = Load_ttls_starting_with_rdr(ns.Id(), key, include_redirects, max_results, min_page_len, browse_len, false, false);
|
||||
Xowd_page_itm prv_itm = new Xowd_page_itm();
|
||||
boolean found = false;
|
||||
while (rdr.Move_next()) {
|
||||
Read_page__all(prv_itm, rdr);
|
||||
found = true;
|
||||
}
|
||||
if (found)
|
||||
rslt_prv.Copy(prv_itm);
|
||||
else { // at beginning of range, so no items found; EX: "Module:A" is search, but 1st Module is "Module:B"
|
||||
if (rslt_list.Count() > 0) // use 1st item
|
||||
rslt_prv.Copy((Xowd_page_itm)rslt_list.Get_at(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
rslt_count.Val_(rslt_idx);
|
||||
}
|
||||
public void Read_page__idx(Xowd_page_itm page, Db_rdr rdr) {
|
||||
page.Id_ (rdr.Read_int(fld_id));
|
||||
page.Ns_id_ (rdr.Read_int(fld_ns));
|
||||
page.Ttl_page_db_ (rdr.Read_bry_by_str(fld_title));
|
||||
page.Text_len_ (rdr.Read_int(fld_len));
|
||||
}
|
||||
public void Read_page__all(Xowd_page_itm page, Db_rdr rdr) {
|
||||
int html_db_id = -1, redirected_id = -1;
|
||||
if (hdump_enabled) {
|
||||
html_db_id = rdr.Read_int(fld_html_db_id);
|
||||
redirected_id = rdr.Read_int(fld_redirect_id);
|
||||
}
|
||||
page.Init_by_sql
|
||||
( rdr.Read_int(fld_id)
|
||||
, rdr.Read_int(fld_ns)
|
||||
, rdr.Read_bry_by_str(fld_title)
|
||||
, DateAdp_.parse_fmt(rdr.Read_str(fld_touched), Page_touched_fmt)
|
||||
, rdr.Read_bool_by_byte(fld_is_redirect)
|
||||
, rdr.Read_int(fld_len)
|
||||
, rdr.Read_int(fld_text_db_id)
|
||||
, html_db_id
|
||||
, redirected_id
|
||||
);
|
||||
}
|
||||
public void Update__html_db_id(int page_id, int html_db_id) {
|
||||
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_html_db_id);
|
||||
stmt.Val_int(fld_html_db_id, html_db_id).Crt_int(fld_id, page_id).Exec_update();
|
||||
}
|
||||
public void Update__ns__ttl(int page_id, int trg_ns, byte[] trg_ttl) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
try {
|
||||
conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_ns, fld_title)
|
||||
.Val_int(fld_ns, trg_ns).Val_bry_as_str(fld_title, trg_ttl)
|
||||
.Crt_int(fld_id, page_id)
|
||||
.Exec_update();
|
||||
break;
|
||||
} catch (Exception exc) {
|
||||
if (String_.Has(Err_.Message_gplx_brief(exc), "columns page_namespace, page_random_int are not unique")) { // HACK: terrible hack, but moving pages across ns will break UNIQUE index
|
||||
conn.Exec_sql_args("DROP INDEX {0}__name_random;", tbl_name); // is UNIQUE by default
|
||||
conn.Exec_sql_args("CREATE INDEX {0}__name_random ON {0} ({1}, {2});", tbl_name, fld_ns, fld_random_int);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Update__redirect__modified(int page_id, boolean redirect, DateAdp modified) {
|
||||
conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_is_redirect, fld_touched)
|
||||
.Crt_int(fld_id, page_id)
|
||||
.Val_int(fld_is_redirect, redirect ? 1 : 0).Val_str(fld_touched, modified.XtoStr_fmt(Page_touched_fmt))
|
||||
.Exec_update()
|
||||
;
|
||||
}
|
||||
public void Create_index() {
|
||||
conn.Ddl_create_idx(Xoa_app_.Usr_dlg()
|
||||
, Db_meta_idx.new_normal_by_tbl(tbl_name, "title" , fld_ns, fld_title, fld_id, fld_len, fld_is_redirect)
|
||||
, Db_meta_idx.new_normal_by_tbl(tbl_name, "random" , fld_ns, fld_random_int)
|
||||
);
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_select_all_by_ttl = Db_stmt_.Rls(stmt_select_all_by_ttl);
|
||||
stmt_select_all_by_id = Db_stmt_.Rls(stmt_select_all_by_id);
|
||||
stmt_select_id_by_ttl = Db_stmt_.Rls(stmt_select_id_by_ttl);
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
private static final String Page_touched_fmt = "yyyyMMddHHmmss";
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
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.core.criterias.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
class Xowd_page_tbl__ttl_ns extends Xowd_page_tbl__in_wkr__base {
|
||||
private Xow_ns_mgr ns_mgr; private Ordered_hash hash;
|
||||
@Override protected int Interval() {return 64;} // NOTE: 96+ overflows; PAGE:en.w:Space_Liability_Convention; DATE:2013-10-24
|
||||
public void Init(Xow_ns_mgr ns_mgr, Ordered_hash hash) {this.ns_mgr = ns_mgr; this.hash = hash;}
|
||||
@Override protected Criteria In_filter(Object[] part_ary) {
|
||||
int len = part_ary.length;
|
||||
Criteria[] crt_ary = new Criteria[len];
|
||||
String fld_ns = tbl.Fld_page_ns(); String fld_ttl = tbl.Fld_page_title();
|
||||
for (int i = 0; i < len; i++)
|
||||
crt_ary[i] = Criteria_.And(Db_crt_.eq_(fld_ns, 0), Db_crt_.eq_(fld_ttl, Bry_.Empty));
|
||||
return Criteria_.Or_many(crt_ary);
|
||||
}
|
||||
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)hash.Get_at(i);
|
||||
stmt.Val_int(page.Ns_id());
|
||||
stmt.Val_bry_as_str(page.Ttl_page_db());
|
||||
}
|
||||
}
|
||||
@Override public Xowd_page_itm Read_data_to_page(Xowd_page_itm rdr_page) {
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(rdr_page.Ns_id());
|
||||
if (ns == null) return null; // NOTE: ns seems to "randomly" be null when threading during redlinks; guard against null; DATE:2014-01-03
|
||||
byte[] ttl_wo_ns = rdr_page.Ttl_page_db();
|
||||
rdr_page.Ttl_(ns, ttl_wo_ns);
|
||||
return (Xowd_page_itm)hash.Get_by(rdr_page.Ttl_full_db());
|
||||
}
|
||||
}
|
||||
class Xowd_page_tbl__ttl extends Xowd_page_tbl__in_wkr__base {
|
||||
private Ordered_hash hash; private int in_ns;
|
||||
@Override protected int Interval() {return 64;} // NOTE: 96+ overflows; EX: w:Space_Liability_Convention; DATE:2013-10-24
|
||||
public void Init(Ordered_hash hash, int in_ns) {this.hash = hash; this.in_ns = in_ns;}
|
||||
@Override protected Criteria In_filter(Object[] part_ary) {
|
||||
int len = part_ary.length;
|
||||
Criteria[] crt_ary = new Criteria[len];
|
||||
String fld_ns = tbl.Fld_page_ns(); String fld_ttl = tbl.Fld_page_title();
|
||||
for (int i = 0; i < len; i++)
|
||||
crt_ary[i] = Criteria_.And(Db_crt_.eq_(fld_ns, in_ns), Db_crt_.eq_(fld_ttl, Bry_.Empty));
|
||||
return Criteria_.Or_many(crt_ary);
|
||||
}
|
||||
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)hash.Get_at(i);
|
||||
stmt.Val_int(in_ns);
|
||||
stmt.Val_bry_as_str(page.Ttl_page_db());
|
||||
}
|
||||
}
|
||||
@Override public Xowd_page_itm Read_data_to_page(Xowd_page_itm rdr_page) {return (Xowd_page_itm)hash.Get_by(rdr_page.Ttl_page_db());}
|
||||
}
|
||||
class Xowd_page_tbl__id extends Xowd_page_tbl__in_wkr__base {
|
||||
private List_adp list; // list is original list of ids which may have dupes; needed to fill statement (which takes range of bgn - end); DATE:2013-12-08
|
||||
private Ordered_hash hash; // hash is unique list of ids; needed for fetch from rdr (which indexes by id)
|
||||
public void Init(List_adp list, Ordered_hash hash) {this.list = list; this.hash = hash; this.Fill_idx_fields_only_(true);}
|
||||
@Override protected boolean Show_progress() {return true;}
|
||||
@Override protected Criteria In_filter(Object[] part_ary) {
|
||||
return Db_crt_.in_(this.In_fld_name(), part_ary);
|
||||
}
|
||||
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)list.Get_at(i);
|
||||
stmt.Val_int(page.Id());
|
||||
}
|
||||
}
|
||||
@Override public Xowd_page_itm Read_data_to_page(Xowd_page_itm rdr_page) {return (Xowd_page_itm)hash.Get_by(rdr_page.Id_val());}
|
||||
}
|
||||
abstract class Xowd_page_tbl__in_wkr__base extends Db_in_wkr__base {
|
||||
protected Xowd_page_tbl tbl; private String tbl_name, fld_in_name;
|
||||
public String Tbl_name() {return tbl_name;}
|
||||
public void Ctor(Xowd_page_tbl tbl, String tbl_name, String fld_in_name) {this.tbl = tbl; this.tbl_name = tbl_name; this.fld_in_name = fld_in_name;}
|
||||
public String In_fld_name() {return fld_in_name;}
|
||||
protected abstract Criteria In_filter(Object[] part_ary);
|
||||
public abstract Xowd_page_itm Read_data_to_page(Xowd_page_itm rdr_page);
|
||||
public boolean Fill_idx_fields_only() {return fill_idx_fields_only;} public void Fill_idx_fields_only_(boolean v) {fill_idx_fields_only = v;} private boolean fill_idx_fields_only;
|
||||
@Override protected Db_qry Make_qry(int bgn, int end) {
|
||||
Object[] part_ary = In_ary(end - bgn);
|
||||
return Db_qry_.select_cols_
|
||||
( this.Tbl_name()
|
||||
, In_filter(part_ary)
|
||||
, fill_idx_fields_only ? tbl.Flds_select_idx() : tbl.Flds_select_all()
|
||||
)
|
||||
;
|
||||
}
|
||||
@Override protected void Read_data(Cancelable cancelable, Db_rdr rdr) {
|
||||
Xowd_page_itm temp = new Xowd_page_itm();
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
if (fill_idx_fields_only)
|
||||
tbl.Read_page__idx(temp, rdr);
|
||||
else
|
||||
tbl.Read_page__all(temp, rdr);
|
||||
Xowd_page_itm page = Read_data_to_page(temp);
|
||||
if (page == null) continue; // page not found
|
||||
temp.Exists_(true);
|
||||
page.Copy(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
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 org.junit.*; import gplx.xowa.bldrs.*; import gplx.xowa.ctgs.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xowd_page_tbl_tst {
|
||||
private Xowd_page_tbl_fxt fxt = new Xowd_page_tbl_fxt();
|
||||
@Test public void Find_search_end() {
|
||||
fxt.Test_find_search_end("ab", "ac");
|
||||
fxt.Test_find_search_end("ab%", "ac%");
|
||||
}
|
||||
}
|
||||
class Xowd_page_tbl_fxt {
|
||||
public void Test_find_search_end(String val, String expd) {Tfds.Eq(expd, String_.new_u8(Find_search_end(Bry_.new_u8(val))));}
|
||||
private static byte[] Find_search_end(byte[] orig) { // NOTE: moved from old Xowd_page_tbl; is probably obsolete
|
||||
byte[] rv = Bry_.Copy(orig);
|
||||
int rv_len = rv.length;
|
||||
int increment_pos = rv[rv_len - 1] == Byte_ascii.Percent ? rv_len - 2 : rv_len - 1; // increment last char, unless it is %; if %, increment one before it
|
||||
return Bry_.Increment_last(rv, increment_pos);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
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.core.primitives.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
public class Xowd_search_link_tbl {
|
||||
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_word_id, fld_page_id;
|
||||
private final Db_conn conn; private Db_stmt stmt_insert; private final Xowd_search_page_tbl__in_wkr in_wkr = new Xowd_search_page_tbl__in_wkr();
|
||||
public Xowd_search_link_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
String fld_prefix = "";
|
||||
if (schema_is_1) {tbl_name = "search_title_page"; fld_prefix = "stp_";}
|
||||
else {tbl_name = "search_link";}
|
||||
fld_word_id = flds.Add_int(fld_prefix + "word_id");
|
||||
fld_page_id = flds.Add_int(fld_prefix + "page_id");
|
||||
in_wkr.Ctor(tbl_name, flds, fld_page_id, fld_word_id);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;}
|
||||
public String Fld_word_id() {return fld_word_id;}
|
||||
public String Fld_page_id() {return fld_page_id;}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Create_idx_unique() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Db_meta_idx.new_unique_by_tbl(tbl_name, "main", fld_word_id, fld_page_id));}
|
||||
public void Create_idx_normal() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Db_meta_idx.new_normal_by_tbl(tbl_name, "main", fld_word_id, fld_page_id));}
|
||||
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int word_id, int page_id) {
|
||||
stmt_insert.Clear().Val_int(fld_word_id, word_id).Val_int(fld_page_id, page_id).Exec_insert();
|
||||
}
|
||||
public void Select_in(Cancelable cancelable, List_adp rv, List_adp words) {
|
||||
in_wkr.Init(words, rv);
|
||||
in_wkr.Select_in(cancelable, conn, 0, words.Count());
|
||||
}
|
||||
}
|
||||
class Xowd_search_page_tbl__in_wkr extends Db_in_wkr__base {
|
||||
private String tbl_name; private Db_meta_fld_list flds; private String fld_page_id, fld_word_id;
|
||||
private List_adp words, pages;
|
||||
public void Ctor(String tbl_name, Db_meta_fld_list flds, String fld_page_id, String fld_word_id) {
|
||||
this.tbl_name = tbl_name; this.flds = flds; this.fld_page_id = fld_page_id; this.fld_word_id = fld_word_id;
|
||||
}
|
||||
public void Init(List_adp words, List_adp pages) {this.words = words; this.pages = pages;}
|
||||
@Override protected Db_qry Make_qry(int bgn, int end) {
|
||||
Object[] part_ary = In_ary(end - bgn);
|
||||
return Db_qry_.select_cols_(tbl_name, Db_crt_.in_(fld_word_id, part_ary), flds.To_str_ary());
|
||||
}
|
||||
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Int_obj_val word_id = (Int_obj_val)words.Get_at(i);
|
||||
stmt.Crt_int(fld_word_id, word_id.Val());
|
||||
}
|
||||
}
|
||||
@Override protected void Read_data(Cancelable cancelable, Db_rdr rdr) {
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
int page_id = rdr.Read_int(fld_page_id);
|
||||
Xowd_page_itm page = new Xowd_page_itm().Id_(page_id);
|
||||
pages.Add(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
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.*; import gplx.dbs.engines.sqlite.*;
|
||||
public class Xowd_search_temp_tbl {
|
||||
private final String tbl_name = "search_temp"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_page_id, fld_word_text;
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
private final String sql_create_word, sql_create_link;
|
||||
public Xowd_search_temp_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
if (schema_is_1) {sql_create_word = Sql_create_word_v1; sql_create_link = Sql_create_link_v1;}
|
||||
else {sql_create_word = Sql_create_word_v2; sql_create_link = Sql_create_link_v2;}
|
||||
flds.Add_int_pkey_autonum("word_id");
|
||||
fld_page_id = flds.Add_int("page_id");
|
||||
fld_word_text = flds.Add_str("word_text", 255);
|
||||
}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int page_id, byte[] word) {
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_page_id, page_id).Val_bry_as_str(fld_word_text, word)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Make_data(Gfo_usr_dlg usr_dlg, Xowd_search_link_tbl search_link_tbl, Xowd_search_word_tbl search_word_tbl) {
|
||||
conn.Ddl_create_idx(usr_dlg, Db_meta_idx.new_unique_by_tbl(tbl_name, "main", fld_word_text, fld_page_id));
|
||||
conn.Exec_sql_plog_txn("search_temp.create_word", sql_create_word);
|
||||
conn.Exec_sql_plog_txn("search_temp.create_link", sql_create_link);
|
||||
Create_idx(usr_dlg, search_link_tbl, search_word_tbl);
|
||||
conn.Env_vacuum();
|
||||
}
|
||||
public void Create_idx(Gfo_usr_dlg usr_dlg, Xowd_search_link_tbl search_link_tbl, Xowd_search_word_tbl search_word_tbl) {
|
||||
conn.Ddl_delete_tbl(tbl_name);
|
||||
try {search_word_tbl.Create_idx();}
|
||||
catch (Exception e) {usr_dlg.Warn_many("", "", "bldr.search_word.unique_search_failed: err=~{0}", Err_.Message_gplx_brief(e));}
|
||||
try {search_link_tbl.Create_idx_unique();}
|
||||
catch (Exception e) {
|
||||
usr_dlg.Warn_many("", "", "bldr.search_page.unique_search_failed: err=~{0}", Err_.Message_gplx_brief(e));
|
||||
search_link_tbl.Create_idx_normal();;
|
||||
}
|
||||
}
|
||||
private static final String Sql_create_word_v1 = String_.Concat_lines_nl
|
||||
( "INSERT INTO search_title_word (stw_word_id, stw_word)"
|
||||
, "SELECT word_id"
|
||||
, ", word_text"
|
||||
, "FROM search_temp"
|
||||
, "GROUP BY "
|
||||
, " word_text"
|
||||
, ";"
|
||||
);
|
||||
private static final String Sql_create_link_v1 = String_.Concat_lines_nl
|
||||
( "INSERT INTO search_title_page (stp_word_id, stp_page_id)"
|
||||
, "SELECT w.stw_word_id"
|
||||
, ", t.page_id"
|
||||
, "FROM search_temp t"
|
||||
, " JOIN search_title_word w ON t.word_text = w.stw_word"
|
||||
, ";"
|
||||
);
|
||||
private static final String Sql_create_word_v2 = String_.Concat_lines_nl
|
||||
( "INSERT INTO search_word (word_id, word_text, word_page_count)"
|
||||
, "SELECT word_id"
|
||||
, ", word_text"
|
||||
, ", Count(DISTINCT page_id)"
|
||||
, "FROM search_temp"
|
||||
, "GROUP BY "
|
||||
, " word_text"
|
||||
, ";"
|
||||
);
|
||||
private static final String Sql_create_link_v2 = String_.Concat_lines_nl
|
||||
( "INSERT INTO search_link (word_id, page_id)"
|
||||
, "SELECT w.word_id"
|
||||
, ", t.page_id"
|
||||
, "FROM search_temp t"
|
||||
, " JOIN search_word w ON t.word_text = w.word_text"
|
||||
, ";"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
public class Xowd_search_word_row {
|
||||
public Xowd_search_word_row(int id, byte[] text, int page_count) {this.id = id; this.text = text; this.page_count = page_count;}
|
||||
public int Id() {return id;} private final int id;
|
||||
public byte[] Text() {return text;} private final byte[] text;
|
||||
public int Page_count() {return page_count;} private final int page_count;
|
||||
public static final Xowd_search_word_row Null = null;
|
||||
}
|
||||
129
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_search_word_tbl.java
Normal file
129
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_search_word_tbl.java
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
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.core.primitives.*; import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.dbs.qrys.*;
|
||||
public class Xowd_search_word_tbl implements RlsAble {
|
||||
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_id, fld_text; private String fld_page_count; private boolean page_count_exists;
|
||||
private final Db_conn conn; private Db_stmt stmt_insert, stmt_select_by, stmt_select_in;
|
||||
public Xowd_search_word_tbl(Db_conn conn, boolean schema_is_1, boolean page_count_exists) {
|
||||
this.conn = conn; this.page_count_exists = page_count_exists;
|
||||
String fld_prefix = "", fld_text_name = "word_text";
|
||||
if (schema_is_1) {tbl_name = "search_title_word"; fld_prefix = "stw_"; fld_text_name = "stw_word";}
|
||||
else {tbl_name = "search_word";}
|
||||
this.fld_id = flds.Add_int_pkey(fld_prefix + "word_id");
|
||||
this.fld_text = flds.Add_str(fld_text_name, 255);
|
||||
this.fld_page_count = page_count_exists ? flds.Add_int_dflt("word_page_count", 0) : Db_meta_fld.Key_null;
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Create_idx() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Db_meta_idx.new_unique_by_tbl(tbl_name, "main", fld_text, fld_id, fld_page_count));}
|
||||
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int id, byte[] word, int page_count) {
|
||||
stmt_insert.Clear().Val_int(fld_id, id).Val_bry_as_str(fld_text, word).Val_int(fld_page_count, page_count).Exec_insert();
|
||||
}
|
||||
public Xowd_search_word_row Select_by_or_null(byte[] word) {
|
||||
if (stmt_select_by == null) stmt_select_by = conn.Stmt_select(tbl_name, flds, fld_text);
|
||||
Db_rdr rdr = stmt_select_by.Clear().Crt_bry_as_str(fld_text, word).Exec_select__rls_manual();
|
||||
try {
|
||||
return rdr.Move_next() ? new_row(rdr) : Xowd_search_word_row.Null;
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
private Xowd_search_word_row new_row(Db_rdr rdr) {
|
||||
int page_count = fld_page_count == Db_meta_fld.Key_null ? 0 : rdr.Read_int(fld_page_count);
|
||||
return new Xowd_search_word_row(rdr.Read_int(fld_id), rdr.Read_bry_by_str(fld_text), page_count);
|
||||
}
|
||||
public Xowd_search_word_row[] Select_in(Cancelable cxl, byte[] word) {
|
||||
if (stmt_select_in == null) {
|
||||
Db_qry__select_cmd qry = Db_qry_.select_().From_(tbl_name).OrderBy_(fld_page_count, Bool_.N).Where_(Db_crt_.like_(fld_text, "")); // order by highest page count to look at most common words
|
||||
stmt_select_in = conn.Stmt_new(qry);
|
||||
}
|
||||
List_adp list = List_adp_.new_();
|
||||
Db_rdr rdr = stmt_select_in.Clear().Crt_bry_as_str(fld_text, Bry_.Replace(word, Byte_ascii.Star, Byte_ascii.Percent)).Exec_select__rls_manual();
|
||||
try {
|
||||
int row_count = 0;
|
||||
while (rdr.Move_next()) {
|
||||
if (cxl.Canceled()) break;
|
||||
Xowd_search_word_row word_row = new_row(rdr);
|
||||
if (++row_count % 10 == 0)
|
||||
Xoa_app_.Usr_dlg().Prog_many("", "", "search; reading pages for word: word=~{0} pages=~{1}", word_row.Text(), word_row.Page_count());
|
||||
list.Add(word_row);
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
return (Xowd_search_word_row[])list.To_ary_and_clear(Xowd_search_word_row.class);
|
||||
}
|
||||
public void Select_by_word(Cancelable cancelable, Xowd_search_link_tbl search_page_tbl, List_adp rv, byte[] search, int results_max) {
|
||||
gplx.core.criterias.Criteria crt = null;
|
||||
if (Bry_.Has(search, Byte_ascii.Star)) {
|
||||
search = Bry_.Replace(search, Byte_ascii.Star, Byte_ascii.Percent);
|
||||
crt = Db_crt_.like_ (fld_text, String_.new_u8(search));
|
||||
}
|
||||
else
|
||||
crt = Db_crt_.eq_ (fld_text, String_.new_u8(search));
|
||||
Db_qry__select_cmd qry = Db_qry_.select_().Cols_(fld_id).From_(tbl_name).Where_(crt);
|
||||
|
||||
List_adp words = List_adp_.new_();
|
||||
Db_rdr rdr = conn.Stmt_new(qry).Crt_bry_as_str(fld_text, search).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next())
|
||||
words.Add(Int_obj_val.new_(rdr.Read_int(fld_id)));
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
|
||||
search_page_tbl.Select_in(cancelable, rv, words);
|
||||
}
|
||||
public boolean Ddl__page_count() {return page_count_exists;}
|
||||
public void Ddl__page_count_y_() { // needed for search_cmd;
|
||||
page_count_exists = true;
|
||||
if (!flds.Has("word_page_count"))
|
||||
flds.Add_int_dflt("word_page_count", 0);
|
||||
}
|
||||
public void Ddl__page_count__add(Xowd_search_link_tbl link_tbl, Db_cfg_tbl cfg_tbl) {
|
||||
Db_meta_fld page_count_fld = Db_meta_fld.new_int("word_page_count").Default_(0);
|
||||
conn.Txn_bgn();
|
||||
conn.Ddl_append_fld(tbl_name, page_count_fld); // SQL: ALTER TABLE search_word ADD word_page_count integer NOT NULL DEFAULT 0;
|
||||
String sql = String_.Format(String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO {0} ({1}, {2}, word_page_count)"
|
||||
, "SELECT w.{1}"
|
||||
, ", w.{2}"
|
||||
, ", Count(l.{4})"
|
||||
, "FROM {0} w"
|
||||
, " JOIN {3} l ON w.{1} = l.{4}"
|
||||
, "GROUP BY w.{1}"
|
||||
, ", w.{2};"
|
||||
), tbl_name, fld_id, fld_text
|
||||
, link_tbl.Tbl_name(), link_tbl.Fld_word_id()
|
||||
);
|
||||
conn.Exec_sql_plog_ntx("calculating page count per word (please wait)", sql);
|
||||
Ddl__page_count__cfg(cfg_tbl);
|
||||
fld_page_count = page_count_fld.Name(); flds.Add(page_count_fld); this.Rls();
|
||||
conn.Txn_end();
|
||||
}
|
||||
public void Ddl__page_count__cfg(Db_cfg_tbl cfg_tbl) {
|
||||
cfg_tbl.Insert_yn(Xowd_db_file_schema_props.Grp, Xowd_db_file_schema_props.Key__col_search_word_page_count, Bool_.Y);
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_select_by = Db_stmt_.Rls(stmt_select_by);
|
||||
stmt_select_in = Db_stmt_.Rls(stmt_select_in);
|
||||
}
|
||||
public static final int Id_null = -1;
|
||||
}
|
||||
83
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_site_ns_tbl.java
Normal file
83
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_site_ns_tbl.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
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.*; import gplx.dbs.qrys.*;
|
||||
public class Xowd_site_ns_tbl {
|
||||
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
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";
|
||||
fld_id = flds.Add_int_pkey ("ns_id");
|
||||
fld_name = flds.Add_str ("ns_name", 255);
|
||||
fld_case = flds.Add_byte ("ns_case");
|
||||
fld_is_alias = flds.Add_bool ("ns_is_alias");
|
||||
fld_count = flds.Add_int ("ns_count");
|
||||
}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Insert(Xow_ns_mgr ns_mgr) {
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
int len = ns_mgr.Ids_len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_ns ns = ns_mgr.Ids_get_at(i);
|
||||
stmt.Clear()
|
||||
.Val_int(fld_id, ns.Id())
|
||||
.Val_str(fld_name, ns.Name_str())
|
||||
.Val_byte(fld_case, ns.Case_match())
|
||||
.Val_bool_as_byte(fld_is_alias, ns.Is_alias())
|
||||
.Val_int(fld_count, ns.Count())
|
||||
.Exec_insert();
|
||||
;
|
||||
}
|
||||
}
|
||||
public void Select_all(Xow_ns_mgr ns_mgr) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
|
||||
try {
|
||||
ns_mgr.Clear();
|
||||
while (rdr.Move_next()) {
|
||||
int ns_id = rdr.Read_int(fld_id);
|
||||
byte[] ns_name = rdr.Read_bry_by_str(fld_name);
|
||||
byte ns_case_match = rdr.Read_byte(fld_case);
|
||||
int ns_count = rdr.Read_int(fld_count);
|
||||
boolean ns_is_alias = rdr.Read_byte(fld_is_alias) == Bool_.Y_byte;
|
||||
ns_mgr.Add_new(ns_id, ns_name, ns_case_match, ns_is_alias);
|
||||
if (ns_id < 0) continue; // don't load counts for Special / Media
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_id);
|
||||
ns.Count_(ns_count);
|
||||
if (ns_count > 0) ns.Exists_(true); // ns has article; mark it as exists, else Talk tab won't show; DATE:2013-12-04
|
||||
}
|
||||
ns_mgr.Init();
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public int Select_ns_count(int ns_id) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, String_.Ary(fld_id))
|
||||
.Crt_int(fld_id, ns_id)
|
||||
.Exec_select__rls_auto();
|
||||
try {
|
||||
return rdr.Move_next() ? Int_.cast_(rdr.Read_int(fld_count)) : 0;
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Update_ns_count(int ns_id, int ns_count) {
|
||||
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_count);
|
||||
stmt.Clear()
|
||||
.Val_int(fld_count, ns_count)
|
||||
.Crt_int(fld_id, ns_id)
|
||||
.Exec_update();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
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_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 Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
public Xowd_site_stats_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
fld_row_id = flds.Add_int_pkey("ss_row_id");
|
||||
fld_good_articles = flds.Add_long("ss_good_articles");
|
||||
fld_total_pages = flds.Add_long("ss_total_pages");
|
||||
fld_images = flds.Add_int("ss_images");
|
||||
}
|
||||
public void Create_tbl() {
|
||||
conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));
|
||||
conn.Stmt_insert(tbl_name, flds).Val_int(fld_row_id, Site_stats_row_id).Val_long(fld_good_articles, 0).Val_long(fld_total_pages, 0).Val_int(fld_images, 0).Exec_insert();
|
||||
}
|
||||
public void Update(int num_articles, int num_pages, int num_files) {
|
||||
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_row_id), fld_good_articles, fld_total_pages, fld_images);
|
||||
stmt.Val_long(fld_good_articles, num_articles).Val_long(fld_total_pages, num_pages).Val_int(fld_images, num_files)
|
||||
.Crt_int(fld_row_id, Site_stats_row_id)
|
||||
.Exec_update();
|
||||
}
|
||||
public void Select(Xow_wiki_stats stats) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_row_id).Crt_int(fld_row_id, Site_stats_row_id).Exec_select__rls_auto();
|
||||
try {
|
||||
if (rdr.Move_next()) {
|
||||
stats.NumArticles_ ((int)rdr.Read_long(fld_good_articles)); // #<>(int)rdr.Read_long~rdr.Read_int
|
||||
stats.NumPages_ ((int)rdr.Read_long(fld_total_pages)); // #<>(int)rdr.Read_long~rdr.Read_int
|
||||
stats.NumFiles_ (rdr.Read_int(fld_images));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
private static final int Site_stats_row_id = 1;
|
||||
}
|
||||
59
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_text_tbl.java
Normal file
59
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_text_tbl.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
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.ios.*; import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
public class Xowd_text_tbl implements RlsAble {
|
||||
private final String tbl_name = "text"; private final Db_meta_fld_list flds = Db_meta_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;
|
||||
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;
|
||||
String fld_text_data_name = "";
|
||||
fld_text_data_name = schema_is_1 ? "old_text" : "text_data";
|
||||
fld_page_id = flds.Add_int_pkey("page_id");
|
||||
fld_text_data = flds.Add_bry(fld_text_data_name);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int page_id, byte[] text_data) {
|
||||
stmt_insert.Clear().Val_int(fld_page_id, page_id).Val_bry(fld_text_data, text_data).Exec_insert();
|
||||
}
|
||||
public void Update(int page_id, byte[] text) {
|
||||
Db_stmt stmt = conn.Stmt_update_exclude(tbl_name, flds, fld_page_id);
|
||||
text = zip_mgr.Zip(zip_tid, text);
|
||||
stmt.Clear().Val_bry(fld_text_data, text).Crt_int(fld_page_id, page_id).Exec_update();
|
||||
}
|
||||
public byte[] Select(int page_id) {
|
||||
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);
|
||||
rv = zip_mgr.Unzip(zip_tid, rv);
|
||||
return rv;
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public byte[] Zip(byte[] data) {return zip_mgr.Zip(zip_tid, data);}
|
||||
public void Rls() {
|
||||
stmt_select = Db_stmt_.Rls(stmt_select);
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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.*; import gplx.xowa.xtns.wdatas.*;
|
||||
public class Xowd_wbase_pid_tbl implements RlsAble {
|
||||
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_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;
|
||||
public Xowd_wbase_pid_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
String fld_prefix = "";
|
||||
if (schema_is_1) {tbl_name = "wdata_pids"; fld_prefix = "wp_";}
|
||||
else {tbl_name = "wbase_pid";}
|
||||
fld_src_lang = flds.Add_str(fld_prefix + "src_lang", 255);
|
||||
fld_src_ttl = flds.Add_str(fld_prefix + "src_ttl", 512);
|
||||
fld_trg_ttl = flds.Add_str(fld_prefix + "trg_ttl", 512);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Create_idx() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Db_meta_idx.new_normal_by_tbl(tbl_name, "src", fld_src_lang, fld_src_ttl));}
|
||||
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(byte[] src_lang, byte[] src_ttl, byte[] trg_ttl) {
|
||||
stmt_insert.Clear()
|
||||
.Val_bry_as_str(fld_src_lang, src_lang).Val_bry_as_str(fld_src_ttl, src_ttl).Val_bry_as_str(fld_trg_ttl, trg_ttl)
|
||||
.Exec_insert();
|
||||
}
|
||||
public int Select_pid(byte[] src_lang, byte[] src_ttl) {
|
||||
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_src_lang, fld_src_ttl);
|
||||
Db_rdr rdr = stmt_select.Clear()
|
||||
.Crt_bry_as_str(fld_src_lang, src_lang).Crt_bry_as_str(fld_src_ttl, src_ttl)
|
||||
.Exec_select__rls_manual();
|
||||
try {
|
||||
if (!rdr.Move_next()) return Wdata_wiki_mgr.Pid_null; // occurs when pid exists, but does not have entry for language; see hu.w:Marco Polo argali; DATE: 2014-02-01
|
||||
byte[] pid_bry = rdr.Read_bry_by_str(fld_trg_ttl);
|
||||
return pid_bry == null ? Wdata_wiki_mgr.Pid_null : Bry_.Xto_int_or(pid_bry, 1, pid_bry.length, Wdata_wiki_mgr.Pid_null);
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_select = Db_stmt_.Rls(stmt_select);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
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_wbase_qid_tbl implements RlsAble {
|
||||
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_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 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;
|
||||
String fld_prefix = "";
|
||||
if (schema_is_1) {tbl_name = "wdata_qids"; fld_prefix = "wq_";}
|
||||
else {tbl_name = "wbase_qid";}
|
||||
fld_src_wiki = flds.Add_str(fld_prefix + "src_wiki", 255);
|
||||
fld_src_ns = flds.Add_int(fld_prefix + "src_ns");
|
||||
fld_src_ttl = flds.Add_str(fld_prefix + "src_ttl", 512);
|
||||
fld_trg_ttl = flds.Add_str(fld_prefix + "trg_ttl", 512);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Create_idx() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Db_meta_idx.new_normal_by_tbl(tbl_name, "src", fld_src_wiki, fld_src_ns, fld_src_ttl));}
|
||||
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(byte[] src_wiki, int src_ns, byte[] src_ttl, byte[] trg_ttl) {
|
||||
stmt_insert.Clear()
|
||||
.Val_bry_as_str(fld_src_wiki, src_wiki).Val_int(fld_src_ns, src_ns).Val_bry_as_str(fld_src_ttl, src_ttl).Val_bry_as_str(fld_trg_ttl,trg_ttl)
|
||||
.Exec_insert();
|
||||
}
|
||||
public byte[] Select_qid(byte[] src_wiki, byte[] src_ns, byte[] src_ttl) {
|
||||
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_src_wiki, fld_src_ns, fld_src_ttl);
|
||||
if (src_ttl_has_spaces) src_ttl = Xoa_ttl.Replace_unders(src_ttl); // NOTE: v2.4.2.1-v2.4.3.2 stores ttl in spaces ("A B"), while xowa will use under form ("A_B"); DATE:2015-04-21
|
||||
Db_rdr rdr = stmt_select.Clear()
|
||||
.Crt_bry_as_str(fld_src_wiki, src_wiki).Crt_int(fld_src_ns, Bry_.Xto_int(src_ns)).Crt_bry_as_str(fld_src_ttl, src_ttl)
|
||||
.Exec_select__rls_manual();
|
||||
try {
|
||||
return rdr.Move_next() ? rdr.Read_bry_by_str(fld_trg_ttl) : null;
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_select = Db_stmt_.Rls(stmt_select);
|
||||
}
|
||||
}
|
||||
@@ -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.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import org.junit.*; import gplx.dbs.*;
|
||||
public class Xowd_wbase_qid_tbl_tst {
|
||||
private final Xowd_wbase_qid_tbl_fxt fxt = new Xowd_wbase_qid_tbl_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Space() {
|
||||
fxt.Exec_insert("enwiki", Xow_ns_.Id_main, "A B", "q1");
|
||||
fxt.Test_select("enwiki", Xow_ns_.Id_main, "A B", "q1");
|
||||
fxt.Test_select("enwiki", Xow_ns_.Id_main, "A_B", "q1");
|
||||
}
|
||||
}
|
||||
class Xowd_wbase_qid_tbl_fxt {
|
||||
private Xowd_wbase_qid_tbl qid_tbl;
|
||||
public void Clear() {
|
||||
Io_mgr.I.InitEngine_mem();
|
||||
Db_conn_bldr.I.Reg_default_mem();
|
||||
Db_conn conn = Db_conn_bldr.I.New(Io_url_.mem_fil_("mem/db/wbase.xowa"));
|
||||
this.qid_tbl = new Xowd_wbase_qid_tbl(conn, Bool_.N, Bool_.Y); // simulate v2.4.2 with bad "spaces"
|
||||
qid_tbl.Create_tbl();
|
||||
}
|
||||
public void Exec_insert(String src_wiki, int src_ns, String src_ttl, String trg_ttl) {
|
||||
qid_tbl.Insert_bgn();
|
||||
qid_tbl.Insert_cmd_by_batch(Bry_.new_u8(src_wiki), src_ns, Bry_.new_u8(src_ttl), Bry_.new_u8(trg_ttl));
|
||||
qid_tbl.Insert_end();
|
||||
}
|
||||
public void Test_select(String src_wiki, int src_ns, String src_ttl, String expd) {
|
||||
byte[] actl = qid_tbl.Select_qid(Bry_.new_u8(src_wiki), Bry_.new_a7(Int_.Xto_str(src_ns)), Bry_.new_u8(src_ttl));
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
89
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_xowa_db_tbl.java
Normal file
89
400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_xowa_db_tbl.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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.*; import gplx.dbs.qrys.*;
|
||||
import gplx.xowa.wikis.data.*;
|
||||
public class Xowd_xowa_db_tbl {
|
||||
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_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 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);
|
||||
if (schema_is_1) {
|
||||
fld_ns_ids = fld_part_id = fld_guid = Db_meta_fld.Key_null;
|
||||
}
|
||||
else {
|
||||
fld_ns_ids = flds.Add_str ("db_ns_ids", 255);
|
||||
fld_part_id = flds.Add_int ("db_part_id");
|
||||
fld_guid = flds.Add_str ("db_guid", 36);
|
||||
}
|
||||
stmt_bldr.Conn_(conn, tbl_name, flds, fld_id);
|
||||
}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.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_();
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
String ns_ids = ""; int part_id = -1; Guid_adp guid = Guid_adp_.Empty;
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
list.Sort_by(Xowd_db_file_sorter__id.I);
|
||||
return (Xowd_db_file[])list.To_ary(Xowd_db_file.class);
|
||||
}
|
||||
public void Commit_all(Xowd_db_mgr core_data_mgr) {
|
||||
stmt_bldr.Batch_bgn();
|
||||
try {
|
||||
int len = core_data_mgr.Dbs__len();
|
||||
for (int i = 0; i < len; i++)
|
||||
Commit_itm(core_data_mgr.Dbs__get_at(i));
|
||||
} finally {stmt_bldr.Batch_end();}
|
||||
}
|
||||
private void Commit_itm(Xowd_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;
|
||||
case Db_cmd_mode.Tid_update: stmt.Clear(); Commit_itm_vals(stmt, itm); stmt.Crt_int(fld_id, itm.Id()).Exec_update(); break;
|
||||
case Db_cmd_mode.Tid_delete: stmt.Clear().Crt_int(fld_id, itm.Id()).Exec_delete(); break;
|
||||
case Db_cmd_mode.Tid_ignore: break;
|
||||
default: throw Exc_.new_unhandled(itm.Cmd_mode());
|
||||
}
|
||||
itm.Cmd_mode_(Db_cmd_mode.Tid_ignore);
|
||||
}
|
||||
private void Commit_itm_vals(Db_stmt stmt, Xowd_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().XtoStr());
|
||||
}
|
||||
}
|
||||
class Xowd_db_file_sorter__id implements gplx.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;
|
||||
return Int_.Compare(lhs.Id(), rhs.Id());
|
||||
}
|
||||
public static final Xowd_db_file_sorter__id I = new Xowd_db_file_sorter__id(); Xowd_db_file_sorter__id() {}
|
||||
}
|
||||
Reference in New Issue
Block a user