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

Xtns.TemplateStyles: Cache TemplateStyles for HTML databases [#482]

This commit is contained in:
gnosygnu
2019-06-02 12:50:56 -04:00
parent fbe158537e
commit 3d9491e2de
29 changed files with 725 additions and 31 deletions

View File

@@ -16,7 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx.xowa.htmls.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import gplx.core.ios.*;
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.core.makes.*; import gplx.xowa.htmls.core.hzips.*;
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*; import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.wikis.pages.htmls.*;
import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
public class Xow_hdump_mgr__load implements Gfo_invk {
@@ -34,6 +34,7 @@ public class Xow_hdump_mgr__load implements Gfo_invk {
gplx.xowa.addons.apps.cfgs.Xocfg_mgr cfg_mgr = wiki.App().Cfg();
Xow_hdump_mode.Cfg__reg_type(cfg_mgr.Type_mgr());
cfg_mgr.Bind_many_wiki(this, wiki, Cfg__read_preferred, Cfg__html_mode);
wiki.Hxtn_mgr().Init_by_wiki(wiki, Bool_.N);
}
public void Load_by_xowe(Xoae_page wpg) {
tmp_hpg.Ctor_by_hview(wpg.Wiki(), wpg.Url(), wpg.Ttl(), wpg.Db().Page().Id());
@@ -72,6 +73,7 @@ public class Xow_hdump_mgr__load implements Gfo_invk {
}
hpg.Db().Html().Html_bry_(src);
wiki.Hxtn_mgr().Load_by_page(hpg, ttl);
return true;
}
}
@@ -102,6 +104,8 @@ public class Xow_hdump_mgr__load implements Gfo_invk {
html_data.Display_ttl_(tmp_hpg.Display_ttl());
html_data.Content_sub_(tmp_hpg.Content_sub());
html_data.Xtn_skin_mgr().Add(new Xopg_xtn_skin_itm_stub(tmp_hpg.Sidebar_div()));
html_data.Custom_head_tags().Add(hpg.Html_data().Custom_head_tags().To_ary());
Xoh_head_mgr wpg_head = html_data.Head_mgr();
Xopg_module_mgr hpg_head = hpg.Head_mgr();
wpg_head.Itm__mathjax().Enabled_ (hpg_head.Math_exists());

View File

@@ -0,0 +1,96 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.hxtns.blobs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hxtns.*;
import gplx.dbs.*;
import gplx.core.ios.*;
public class Hxtn_blob_tbl implements Rls_able {
private static final String tbl_name = "hxtn_blob"; private static final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private static final String
fld_blob_tid = flds.Add_int("blob_tid"), fld_wiki_id = flds.Add_int("wiki_id"), fld_blob_id = flds.Add_int("blob_id")
, fld_zip_tid = flds.Add_byte("zip_tid"), fld_blob_data = flds.Add_bry("blob_data");
private final Db_conn conn; private Db_stmt stmt_insert;
private final byte zip_tid_default;
private final Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr();
public Hxtn_blob_tbl(Db_conn conn, byte zip_tid_default) {
this.conn = conn;
conn.Rls_reg(this);
this.zip_tid_default = zip_tid_default;
}
public String Tbl_name() {return tbl_name;}
public Db_conn Conn() {return conn;}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
public void Stmt_bgn() {
stmt_insert = conn.Stmt_insert(tbl_name, flds);
}
public void Stmt_end() {
this.Rls();
conn.Meta_idx_create(Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "pkey", fld_blob_id, fld_wiki_id, fld_blob_tid));
}
public void Insert_by_rdr(Db_rdr rdr) {
Db_stmt_.Insert_by_rdr(flds, rdr, stmt_insert);
}
public void Insert_exec(int blob_tid, int wiki_id, int blob_id, byte[] blob_data) {
blob_data = zip_mgr.Zip(zip_tid_default, blob_data);
stmt_insert.Clear()
.Val_int(fld_blob_tid , blob_tid)
.Val_int(fld_wiki_id , wiki_id)
.Val_int(fld_blob_id , blob_id)
.Val_byte(fld_zip_tid , zip_tid_default)
.Val_bry(fld_blob_data , blob_data)
.Exec_insert();
}
public void Select_to_regy(Bry_bfr temp_bfr, Hash_adp_bry blob_data_hash) {
Db_rdr rdr = conn.Stmt_select(tbl_name, String_.Ary(fld_wiki_id, fld_blob_id, fld_blob_tid))
.Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
byte[] key = Make_key(temp_bfr, rdr.Read_int(fld_wiki_id), rdr.Read_int(fld_blob_id), rdr.Read_int(fld_blob_tid));
blob_data_hash.Add_as_key_and_val(key);
}
} finally {
rdr.Rls();
}
}
public byte[] Select_text(int blob_tid, int wiki_id, int blob_id) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_blob_id, fld_wiki_id, fld_blob_tid)
.Crt_int(fld_blob_id, blob_id)
.Crt_int(fld_wiki_id, wiki_id)
.Crt_int(fld_blob_tid, blob_tid)
.Exec_select__rls_auto();
try {
if (rdr.Move_next()) {
byte[] rv = rdr.Read_bry(fld_blob_data);
byte zip_type = rdr.Read_byte(fld_zip_tid);
rv = zip_mgr.Unzip(zip_type, rv);
return rv;
}
else {
return null;
}
} finally {
rdr.Rls();
}
}
public static byte[] Make_key(Bry_bfr temp_bfr, int blob_id, int wiki_id, int blob_tid) {
return temp_bfr.Add_int_variable(blob_id).Add_byte_pipe().Add_int_variable(wiki_id).Add_byte_pipe().Add_int_variable(blob_tid).To_bry_and_clear();
}
public static final int Blob_tid__wtxt = 0, Blob_tid__html = 1;
}

View File

@@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.hxtns.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hxtns.*;
class Hxtn_page_itm {
public Hxtn_page_itm(int page_id, int wkr_id, int data_id) {
this.page_id = page_id;
this.wkr_id = wkr_id;
this.data_id = data_id;
}
public int Page_id() {return page_id;} private final int page_id;
public int Wkr_id() {return wkr_id;} private final int wkr_id;
public int Data_id() {return data_id;} private final int data_id;
}

View File

@@ -0,0 +1,102 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.hxtns.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hxtns.*;
import gplx.dbs.*;
import gplx.core.lists.*; import gplx.core.lists.hashs.*;
import gplx.xowa.htmls.hxtns.pages.*; import gplx.xowa.htmls.hxtns.blobs.*; import gplx.xowa.htmls.hxtns.wkrs.*; import gplx.xowa.htmls.hxtns.wikis.*;
import gplx.xowa.wikis.*;
public class Hxtn_page_mgr {
private Hxtn_page_tbl page_tbl;
private Hxtn_blob_tbl blob_tbl;
private Hash_adp_bry blob_hash;
private final Hash_adp__int wkrs = new Hash_adp__int();
private boolean dbs_missing = true;
private Bry_bfr temp_bfr;
public Hxtn_page_tbl Page_tbl() {return page_tbl;}
public Hxtn_blob_tbl Blob_tbl() {return blob_tbl;}
public void Init_by_xomp_wkr(Db_conn wkr_db_conn, byte zip_tid) {
// init tbls and other members
this.page_tbl = new Hxtn_page_tbl(wkr_db_conn);
this.blob_tbl = new Hxtn_blob_tbl(wkr_db_conn, zip_tid);
this.blob_hash = Hash_adp_bry.cs();
this.temp_bfr = Bry_bfr_.New();
// if tbl exists, xomp_resume has run; load known blobs to prevent dupes
if (wkr_db_conn.Meta_tbl_exists(page_tbl.Tbl_name())) {
blob_tbl.Select_to_regy(temp_bfr, blob_hash);
}
// else tbl doesn't exist, so create them
else {
page_tbl.Create_tbl();
blob_tbl.Create_tbl();
}
}
public void Init_by_wiki(Xow_wiki wiki, boolean is_merge) {
Io_url core_db_url = Make_url(wiki, "-html.hxtn-core.xowa");
if (!is_merge && !Io_mgr.Instance.ExistsFil(core_db_url)) return;
dbs_missing = false;
Db_conn page_conn = Db_conn_bldr.Instance.Get_or_new(core_db_url).Conn();
this.page_tbl = new Hxtn_page_tbl(page_conn);
Io_url blob_db_url = Make_url(wiki, "-html.hxtn-blob.xowa");
this.blob_tbl = new Hxtn_blob_tbl(Db_conn_bldr.Instance.Get_or_new(blob_db_url).Conn(), gplx.core.ios.streams.Io_stream_tid_.Tid__raw);
if (is_merge) {
page_tbl.Create_tbl();
blob_tbl.Create_tbl();
Hxtn_wkr_mgr wkr_mgr = new Hxtn_wkr_mgr();
wkr_mgr.Init_by_xomp_merge(page_conn);
Hxtn_wiki_mgr wiki_mgr = new Hxtn_wiki_mgr();
wiki_mgr.Init_by_xomp_merge(page_conn, wiki.Domain_str());
}
}
public void Insert_bgn(boolean is_merge) {
page_tbl.Stmt_bgn();
blob_tbl.Stmt_bgn();
}
public void Insert_end(boolean is_merge) {
page_tbl.Stmt_end();
blob_tbl.Stmt_end();
}
public void Page_tbl__insert(int page_id, int wkr_id, int data_id) {
page_tbl.Insert_exec(page_id, wkr_id, data_id);
}
public void Blob_tbl__insert(int blob_tid, int wiki_id, int blob_id, byte[] blob_text) {
byte[] key = Hxtn_blob_tbl.Make_key(temp_bfr, blob_tid, wiki_id, blob_id);
if (!blob_hash.Has(key)) {// multiple pages can refer to same template; only insert if not seen
blob_hash.Add_as_key_and_val(key);
blob_tbl.Insert_exec(blob_tid, wiki_id, blob_id, blob_text);
}
}
public void Reg_wkr(Hxtn_page_wkr wkr) {
wkrs.Add(wkr.Id(), wkr);
}
public void Load_by_page(Xoh_page hpg, Xoa_ttl ttl) {
if (dbs_missing) return; // PERF:do not call SELECT if dbs don't exist
List_adp list = page_tbl.Select_by_page(hpg.Page_id());
int len = list.Len();
for (int i = 0; i < len; i++) {
Hxtn_page_itm itm = (Hxtn_page_itm)list.Get_at(i);
Hxtn_page_wkr wkr = (Hxtn_page_wkr)wkrs.Get_by_or_fail(itm.Wkr_id());
wkr.Load_by_page(hpg, ttl, itm.Data_id());
}
}
private static Io_url Make_url(Xow_wiki wiki, String file_name) {return wiki.Fsys_mgr().Root_dir().GenSubFil(wiki.Domain_str() + file_name);}
public static final int Id__template_styles = 0;
}

View File

@@ -0,0 +1,68 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.hxtns.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hxtns.*;
import gplx.dbs.*;
public class Hxtn_page_tbl implements Rls_able {
private static final String tbl_name = "hxtn_page"; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_page_id, fld_wkr_id, fld_data_id;
private final Db_conn conn; private Db_stmt stmt_insert;
public Hxtn_page_tbl(Db_conn conn) {
this.conn = conn;
conn.Rls_reg(this);
flds.Add_int_pkey_autonum("id");
this.fld_page_id = flds.Add_int("page_id");
this.fld_wkr_id = flds.Add_int("wkr_id");
this.fld_data_id = flds.Add_int("data_id");
}
public String Tbl_name() {return tbl_name;}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public Db_conn Conn() {return conn;}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
public void Stmt_bgn() {
stmt_insert = conn.Stmt_insert(tbl_name, flds);
}
public void Stmt_end() {
this.Rls();
conn.Meta_idx_create(Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "pkey", fld_page_id, fld_wkr_id, fld_data_id));
}
public void Insert_by_rdr(Db_rdr rdr) {
Db_stmt_.Insert_by_rdr(flds, rdr, stmt_insert);
}
public void Insert_exec(int page_id, int wkr_id, int data_id) {
stmt_insert.Clear()
.Val_int(fld_page_id , page_id)
.Val_int(fld_wkr_id , wkr_id)
.Val_int(fld_data_id , data_id)
.Exec_insert();
}
public List_adp Select_by_page(int page_id) {
List_adp rv = List_adp_.New();
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_page_id)
.Crt_int(fld_page_id, page_id)
.Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Hxtn_page_itm itm = new Hxtn_page_itm(rdr.Read_int(fld_page_id), rdr.Read_int(fld_wkr_id), rdr.Read_int(fld_data_id));
rv.Add(itm);
}
} finally {
rdr.Rls();
}
return rv;
}
}

View File

@@ -0,0 +1,22 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.hxtns.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hxtns.*;
import gplx.xowa.htmls.*;
public interface Hxtn_page_wkr {
int Id();
String Key();
void Load_by_page(Xoh_page hpg, Xoa_ttl ttl, int id);
}

View File

@@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.hxtns.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hxtns.*;
public class Hxtn_wiki_itm {
public Hxtn_wiki_itm(int tid, String domain) {
this.tid = tid;
this.domain = domain;
}
public int Tid() {return tid;} private final int tid;
public String Domain() {return domain;} private final String domain;
public static final int Tid__self = 0, Tid__commons = 1, Tid__wikidata = 2, Tid__next_id = 32;
}

View File

@@ -0,0 +1,27 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.hxtns.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hxtns.*;
import gplx.dbs.*;
public class Hxtn_wiki_mgr {
private Hxtn_wiki_tbl wiki_tbl;
public void Init_by_xomp_merge(Db_conn conn, String wiki_domain) {
wiki_tbl = new Hxtn_wiki_tbl(conn);
wiki_tbl.Create_tbl();
wiki_tbl.Insert(Hxtn_wiki_itm.Tid__self , wiki_domain);
wiki_tbl.Insert(Hxtn_wiki_itm.Tid__commons , "commons.wikimedia.org");
wiki_tbl.Insert(Hxtn_wiki_itm.Tid__wikidata, "www.wikidata.org");
}
}

View File

@@ -0,0 +1,51 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.hxtns.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hxtns.*;
import gplx.dbs.*;
public class Hxtn_wiki_tbl implements Rls_able {
private static final String tbl_name = "hxtn_wiki"; private static final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private static final String
fld_wiki_id = flds.Add_int_pkey("wiki_id"), fld_wiki_domain = flds.Add_str("wiki_domain", 255)
;
private final Db_conn conn;
public Hxtn_wiki_tbl(Db_conn conn) {
this.conn = conn;
conn.Rls_reg(this);
}
public void Create_tbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
}
public void Rls() {}
public void Insert(int wiki_id, String wiki_domain) {
conn.Stmt_insert(tbl_name, flds).Clear()
.Val_int(fld_wiki_id , wiki_id)
.Val_str(fld_wiki_domain , wiki_domain)
.Exec_insert();
}
public Hash_adp Select() {
Hash_adp rv = Hash_adp_.New();
Db_rdr rdr = conn.Stmt_select_all(tbl_name, flds).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Hxtn_wiki_itm itm = new Hxtn_wiki_itm(rdr.Read_int(fld_wiki_id), rdr.Read_str(fld_wiki_domain));
rv.Add(itm.Domain(), itm);
}
} finally {
rdr.Rls();
}
return rv;
}
}

View File

@@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.hxtns.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hxtns.*;
import gplx.dbs.*;
import gplx.xowa.htmls.hxtns.pages.*;
public class Hxtn_wkr_mgr {
private Hxtn_wkr_tbl wkr_tbl;
public void Init_by_xomp_merge(Db_conn conn) {
wkr_tbl = new Hxtn_wkr_tbl(conn);
wkr_tbl.Create_tbl();
Reg_wkr(new gplx.xowa.xtns.template_styles.Hxtn_page_wkr__template_styles(null)); // TODO:do formal registration of extensions; WHEN: rework tkn_mkr
}
private void Reg_wkr(Hxtn_page_wkr wkr) {
wkr_tbl.Insert(wkr.Id(), wkr.Key());
}
}

View File

@@ -0,0 +1,57 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.hxtns.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hxtns.*;
import gplx.dbs.*;
import gplx.core.lists.hashs.*;
public class Hxtn_wkr_tbl implements Rls_able {
private static final String tbl_name = "hxtn_wkr"; private static final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private static final String
fld_wkr_id = flds.Add_int_pkey("wkr_id"), fld_wkr_key = flds.Add_str("wkr_key", 255)
;
private final Db_conn conn;
public Hxtn_wkr_tbl(Db_conn conn) {
this.conn = conn;
conn.Rls_reg(this);
}
public void Create_tbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
}
public void Rls() {}
public int Select_max() {
return Int_.Cast(conn.Stmt_select_max(tbl_name, fld_wkr_id).Exec_select_val());
}
public void Insert(int wkr_id, String wkr_key) {
conn.Stmt_insert(tbl_name, flds).Clear()
.Val_int(fld_wkr_id , wkr_id)
.Val_str(fld_wkr_key , wkr_key)
.Exec_insert();
}
public void Select(Hash_adp__int wkrs_by_id, Hash_adp wkrs_by_key) {
wkrs_by_id.Clear();
wkrs_by_key.Clear();
Db_rdr rdr = conn.Stmt_select_all(tbl_name, flds).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
int wkr_id = rdr.Read_int(fld_wkr_id);
String wkr_key = rdr.Read_str(fld_wkr_key);
wkrs_by_id.Add(wkr_id, wkr_key);
wkrs_by_key.Add(wkr_key, wkr_id);
}
} finally {
rdr.Rls();
}
}
}