mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
User_wiki: Simplify creation of wiki database file and tables
This commit is contained in:
@@ -92,7 +92,7 @@ public class Xow_db_file {
|
||||
}
|
||||
|
||||
public static final Xow_db_file Null = null;
|
||||
public static Xow_db_file make_(Xob_info_session info_session, Xowd_core_db_props props, int id, byte tid, Io_url url, String ns_ids, int part_id, String core_file_name, Db_conn conn) {
|
||||
public static Xow_db_file Make(Xob_info_session info_session, Xowd_core_db_props props, int id, byte tid, Io_url url, String ns_ids, int part_id, String core_file_name, Db_conn conn) {
|
||||
Guid_adp guid = Guid_adp_.New();
|
||||
Xob_info_file info_file = new Xob_info_file(id, Xow_db_file_.To_key(tid), ns_ids, part_id, guid, props.Schema(), core_file_name, url.NameAndExt());
|
||||
Db_cfg_tbl cfg_tbl = gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn);
|
||||
@@ -100,7 +100,7 @@ public class Xow_db_file {
|
||||
cfg_tbl.Create_tbl(); // always create cfg in each db
|
||||
return rv;
|
||||
}
|
||||
public static Xow_db_file load_(Xowd_core_db_props props, int id, byte tid, Io_url url, String ns_ids, int part_id, Guid_adp guid) {
|
||||
public static Xow_db_file Load(Xowd_core_db_props props, int id, byte tid, Io_url url, String ns_ids, int part_id, Guid_adp guid) {
|
||||
Db_conn conn = Db_conn_bldr.Instance.Get(url);
|
||||
if (conn == null) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "wiki.db:missing db; tid=~{0} url=~{1}", Xow_db_file_.To_key(tid), url.Raw());
|
||||
|
||||
@@ -58,7 +58,7 @@ public class Xow_db_file__core_ {
|
||||
Db_conn core_conn = Db_conn_bldr.Instance.Get_or_fail(itm);
|
||||
|
||||
// if db has "xowa_db" then assume that it is the core
|
||||
if (core_conn.Meta_tbl_exists(gplx.xowa.wikis.data.tbls.Xowd_xowa_db_tbl.Tbl_name)) {
|
||||
if (core_conn.Meta_tbl_exists(gplx.xowa.wikis.data.tbls.Xowd_xowa_db_tbl.TBL_NAME)) {
|
||||
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.v2.renamed: url=~{0}", itm.Raw());
|
||||
return itm;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class Xow_db_file__core_ {
|
||||
Db_conn core_conn = Db_conn_bldr.Instance.New(core_db_url);
|
||||
|
||||
// make tbls
|
||||
Xow_db_file rv = Xow_db_file.make_(info_session, props, Xow_db_file_.Uid__core, core_db_tid, core_db_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, core_file_name, core_conn);
|
||||
Xow_db_file rv = Xow_db_file.Make(info_session, props, Xow_db_file_.Uid__core, core_db_tid, core_db_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, core_file_name, core_conn);
|
||||
rv.Tbl__db().Create_tbl();
|
||||
rv.Tbl__ns().Create_tbl();
|
||||
rv.Tbl__site_stats().Create_tbl();
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Xow_db_mgr {
|
||||
// create core_conn / core_db
|
||||
Db_conn core_conn = Db_conn_bldr.Instance.Get(core_url);
|
||||
props = Xowd_core_db_props.Cfg_load(core_conn); // load props to get layout_text
|
||||
Dbs__set_by_tid(Xow_db_file.load_(props, Xow_db_file_.Uid__core, Xow_db_file__core_.Core_db_tid(props.Layout_text()), core_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, Guid_adp_.Empty));
|
||||
Dbs__set_by_tid(Xow_db_file.Load(props, Xow_db_file_.Uid__core, Xow_db_file__core_.Core_db_tid(props.Layout_text()), core_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, Guid_adp_.Empty));
|
||||
wiki.Props().Init_by_load(wiki.App(), Tbl__cfg()); // load Main_page
|
||||
|
||||
// load dbs from "xowa_db" tbl
|
||||
@@ -108,7 +108,7 @@ public class Xow_db_mgr {
|
||||
}
|
||||
public Xow_db_file Dbs__make_by_id(int id, byte tid, String ns_ids, int part_id, String file_name_suffix) {
|
||||
Io_url url = wiki_root_dir.GenSubFil(domain_str + file_name_suffix);
|
||||
Xow_db_file rv = Xow_db_file.make_(db__core.Info_session(), props, id, tid, url, ns_ids, part_id, db__core.Url().NameAndExt(), Db_conn_bldr.Instance.New(url));
|
||||
Xow_db_file rv = Xow_db_file.Make(db__core.Info_session(), props, id, tid, url, ns_ids, part_id, db__core.Url().NameAndExt(), Db_conn_bldr.Instance.New(url));
|
||||
Dbs__add_and_save(rv);
|
||||
Dbs__set_by_tid(rv);
|
||||
return rv;
|
||||
|
||||
@@ -17,8 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data.site_stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.site_stats.*;
|
||||
public class Xow_site_stats_tbl {
|
||||
private final String tbl_name = "site_stats";
|
||||
public class Xow_site_stats_tbl implements Db_tbl {
|
||||
private final String fld_row_id, fld_good_articles, fld_total_pages, fld_images;
|
||||
private final Db_conn conn; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
public Xow_site_stats_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
@@ -28,6 +27,7 @@ public class Xow_site_stats_tbl {
|
||||
fld_total_pages = flds.Add_long("ss_total_pages");
|
||||
fld_images = flds.Add_int("ss_images");
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name = TBL_NAME;
|
||||
public void Create_tbl() {
|
||||
conn.Meta_tbl_create(Dbmeta_tbl_itm.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();
|
||||
@@ -50,5 +50,9 @@ public class Xow_site_stats_tbl {
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {}
|
||||
private static final int Site_stats_row_id = 1;
|
||||
|
||||
public static final String TBL_NAME = "site_stats";
|
||||
public static Xow_site_stats_tbl Get_by_key(Db_tbl_owner owner) {return (Xow_site_stats_tbl)owner.Tbls__get_by_key(TBL_NAME);}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,8 @@ package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gpl
|
||||
import gplx.core.primitives.*; import gplx.core.criterias.*;
|
||||
import gplx.dbs.*; import gplx.xowa.*; import gplx.xowa.wikis.dbs.*; import gplx.dbs.qrys.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xowd_page_tbl implements Rls_able {
|
||||
private final Object thread_lock = new Object();
|
||||
private final String tbl_name = "page";
|
||||
public class Xowd_page_tbl implements Db_tbl {
|
||||
private final Object thread_lock = new Object();
|
||||
public final boolean schema_is_1;
|
||||
private String fld_id, fld_ns, fld_title, fld_is_redirect, fld_touched, fld_len, fld_random_int, fld_score, fld_text_db_id, fld_html_db_id, fld_redirect_id, fld_cat_db_id;
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
@@ -55,7 +54,7 @@ public class Xowd_page_tbl implements Rls_able {
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public String Tbl_name() {return tbl_name;}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name = TBL_NAME;
|
||||
public Dbmeta_fld_list Flds__all() {return flds;}
|
||||
public String Fld_page_id() {return fld_id;}
|
||||
public String Fld_page_ns() {return fld_ns;}
|
||||
@@ -377,4 +376,6 @@ public class Xowd_page_tbl implements Rls_able {
|
||||
}
|
||||
}
|
||||
public static final String Page_touched_fmt = "yyyyMMddHHmmss";
|
||||
public static final String TBL_NAME = "page";
|
||||
public static Xowd_page_tbl Get_by_key(Db_tbl_owner owner) {return (Xowd_page_tbl)owner.Tbls__get_by_key(TBL_NAME);}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ 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.nss.*;
|
||||
public class Xowd_site_ns_tbl {
|
||||
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
public class Xowd_site_ns_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_id, fld_name, fld_case, fld_count, fld_is_alias;
|
||||
private final Db_conn conn;
|
||||
public Xowd_site_ns_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
@@ -31,6 +31,7 @@ public class Xowd_site_ns_tbl {
|
||||
fld_is_alias = flds.Add_bool ("ns_is_alias");
|
||||
fld_count = flds.Add_int ("ns_count");
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Insert(Xow_ns_mgr ns_mgr) {
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
@@ -81,4 +82,8 @@ public class Xowd_site_ns_tbl {
|
||||
.Crt_int(fld_id, ns_id)
|
||||
.Exec_update();
|
||||
}
|
||||
public void Rls() {}
|
||||
|
||||
public static final String TBL_NAME = "site_ns";
|
||||
public static Xowd_site_ns_tbl Get_by_key(Db_tbl_owner owner) {return (Xowd_site_ns_tbl)owner.Tbls__get_by_key(TBL_NAME);}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.core.ios.*; import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
public class Xowd_text_tbl implements Rls_able {
|
||||
public class Xowd_text_tbl implements Db_tbl {
|
||||
private final Object thread_lock = new Object();
|
||||
private final String tbl_name = "text"; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_page_id, fld_text_data;
|
||||
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
|
||||
private final Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr(); private final byte zip_tid;
|
||||
@@ -32,6 +32,7 @@ public class Xowd_text_tbl implements Rls_able {
|
||||
fld_text_data = flds.Add_bry(fld_text_data_name);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name = TBL_NAME;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Insert_bgn() {conn.Txn_bgn("schema__text__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
@@ -65,4 +66,7 @@ public class Xowd_text_tbl implements Rls_able {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String TBL_NAME = "text";
|
||||
public static Xowd_text_tbl Get_by_key(Db_tbl_owner owner) {return (Xowd_text_tbl)owner.Tbls__get_by_key(TBL_NAME);}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@ 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 {
|
||||
public static final String Tbl_name = "xowa_db", Fld_id = "db_id", Fld_type = "db_type", Fld_url = "db_url";
|
||||
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
public class Xowd_xowa_db_tbl implements Db_tbl {
|
||||
public static final String Fld_id = "db_id", Fld_type = "db_type", Fld_url = "db_url";
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_id, fld_type, fld_url, fld_ns_ids, fld_part_id, fld_guid; private boolean schema_is_1;
|
||||
private final Db_conn conn; private final Db_stmt_bldr stmt_bldr = new Db_stmt_bldr();
|
||||
public Xowd_xowa_db_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn; this.schema_is_1 = schema_is_1;
|
||||
this.tbl_name = Tbl_name;
|
||||
this.tbl_name = TBL_NAME;
|
||||
fld_id = flds.Add_int_pkey (Fld_id);
|
||||
fld_type = flds.Add_byte (Fld_type);
|
||||
fld_url = flds.Add_str (Fld_url, 512);
|
||||
@@ -39,6 +39,7 @@ public class Xowd_xowa_db_tbl {
|
||||
}
|
||||
stmt_bldr.Conn_(conn, tbl_name, flds, fld_id);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name; public static final String TBL_NAME = "xowa_db";
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public Xow_db_file[] Select_all(Xowd_core_db_props props, Io_url wiki_root_dir) {
|
||||
List_adp list = List_adp_.New();
|
||||
@@ -52,7 +53,7 @@ public class Xowd_xowa_db_tbl {
|
||||
guid = Guid_adp_.Parse(rdr.Read_str(fld_guid));
|
||||
}
|
||||
int db_id = rdr.Read_int(fld_id);
|
||||
Xow_db_file db_file = Xow_db_file.load_(props, db_id, rdr.Read_byte(fld_type), wiki_root_dir.GenSubFil(rdr.Read_str(fld_url)), ns_ids, part_id, guid);
|
||||
Xow_db_file db_file = Xow_db_file.Load(props, db_id, rdr.Read_byte(fld_type), wiki_root_dir.GenSubFil(rdr.Read_str(fld_url)), ns_ids, part_id, guid);
|
||||
list.Add(db_file);
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
@@ -67,6 +68,9 @@ public class Xowd_xowa_db_tbl {
|
||||
Commit_itm(core_data_mgr.Dbs__get_at(i));
|
||||
} finally {stmt_bldr.Batch_end();}
|
||||
}
|
||||
public void Upsert(int id, byte tid, String url, String ns_ids, int part_id, String guid) {
|
||||
gplx.dbs.utls.Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld_id), id, tid, url, ns_ids, part_id, guid);
|
||||
}
|
||||
private void Commit_itm(Xow_db_file itm) {
|
||||
Db_stmt stmt = stmt_bldr.Get(itm.Cmd_mode());
|
||||
switch (itm.Cmd_mode()) {
|
||||
@@ -81,6 +85,9 @@ public class Xowd_xowa_db_tbl {
|
||||
private void Commit_itm_vals(Db_stmt stmt, Xow_db_file itm) {
|
||||
stmt.Val_byte(fld_type, itm.Tid()).Val_str(fld_url, itm.Url_rel()).Val_str(fld_ns_ids, itm.Ns_ids()).Val_int(fld_part_id, itm.Part_id()).Val_str(fld_guid, itm.Guid().To_str());
|
||||
}
|
||||
public void Rls() {}
|
||||
|
||||
public static Xowd_xowa_db_tbl Get_by_key(Db_tbl_owner owner) {return (Xowd_xowa_db_tbl)owner.Tbls__get_by_key(TBL_NAME);}
|
||||
}
|
||||
class Xow_db_file_sorter__id implements gplx.core.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
|
||||
Reference in New Issue
Block a user