mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.6.3.1'
This commit is contained in:
@@ -21,13 +21,13 @@ import gplx.xowa.files.caches.*;
|
||||
import gplx.xowa.users.bmks.*; import gplx.xowa.users.history.*;
|
||||
public class Xou_db_mgr {
|
||||
private final Xoa_app app;
|
||||
private final Xoud_id_mgr id_mgr;
|
||||
private Db_conn conn;
|
||||
private final Xoud_id_mgr id_mgr;
|
||||
public Xou_db_mgr(Xoa_app app) {
|
||||
this.app = app;
|
||||
this.id_mgr = new Xoud_id_mgr(cfg_mgr);
|
||||
this.site_mgr = new Xoud_site_mgr(id_mgr);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private Db_conn conn;
|
||||
public Xou_db_file Db_file() {return db_file;} private Xou_db_file db_file;
|
||||
public Xoud_cfg_mgr Cfg_mgr() {return cfg_mgr;} private final Xoud_cfg_mgr cfg_mgr = new Xoud_cfg_mgr();
|
||||
public Xoud_site_mgr Site_mgr() {return site_mgr;} private final Xoud_site_mgr site_mgr;
|
||||
|
||||
@@ -54,9 +54,18 @@ public class Xoud_cfg_mgr {
|
||||
else
|
||||
Update_int(grp, key, val);
|
||||
}
|
||||
public void Upsert_str(String grp, String key, String val) {
|
||||
String exists = Select_str_or(grp, key, null);
|
||||
if (exists == null)
|
||||
Insert_str(grp, key, val);
|
||||
else
|
||||
Update_str(grp, key, val);
|
||||
}
|
||||
public void Update_str(String grp, String key, String val) {Update_bry(grp, key, Bry_.new_u8(val));}
|
||||
public void Update_bry(String key, byte[] val) {Update_bry("", key, val);}
|
||||
public void Update_bry(String grp, String key, byte[] val) {tbl.Update_bry(grp, key, val);}
|
||||
public void Update_int(String grp, String key, int val) {tbl.Update_int(grp, key, val);}
|
||||
public void Insert_str(String grp, String key, String val) {Insert_bry(grp, key, Bry_.new_u8(val));}
|
||||
public void Insert_bry(String key, byte[] val) {Insert_bry("", key, val);}
|
||||
public void Insert_bry(String grp, String key, byte[] val) {tbl.Insert_bry(grp, key, val);}
|
||||
public void Insert_int(String grp, String key, int val) {tbl.Insert_int(grp, key, val);}
|
||||
|
||||
@@ -21,18 +21,18 @@ import gplx.xowa.langs.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
class Xoud_opt_scope {
|
||||
public Xoud_opt_scope(int lang_id, int type_id) {this.lang_id = lang_id; this.type_id = type_id;}
|
||||
public int Lang_id() {return lang_id;} private final int lang_id;
|
||||
public int Type_id() {return type_id;} private final int type_id;
|
||||
public int Lang_id() {return lang_id;} private final int lang_id;
|
||||
public int Type_id() {return type_id;} private final int type_id;
|
||||
public String To_str() {
|
||||
String lang_str = lang_id == Lang_id_wildcard ? "*" : String_.new_u8(Xol_lang_stub_.Get_by_id(lang_id).Key());
|
||||
String type_str = type_id == Lang_id_wildcard ? "*" : String_.new_u8(Xow_domain_tid_.Get_type_as_bry(type_id));
|
||||
return lang_str + "." + type_str;
|
||||
}
|
||||
public static final int Lang_id_wildcard = -1, Type_id_wildcard = -1;
|
||||
public static final Xoud_opt_scope App = new Xoud_opt_scope(Lang_id_wildcard, Type_id_wildcard);
|
||||
public static final Xoud_opt_scope App = new Xoud_opt_scope(Lang_id_wildcard, Type_id_wildcard);
|
||||
}
|
||||
class Xoud_opt_scope_parser {
|
||||
private Gfo_usr_dlg usr_dlg; private final List_adp list = List_adp_.new_();
|
||||
private Gfo_usr_dlg usr_dlg; private final List_adp list = List_adp_.New();
|
||||
public Xoud_opt_scope[] Parse(byte[] src) {
|
||||
usr_dlg = Gfo_usr_dlg_.Instance;
|
||||
list.Clear();
|
||||
@@ -63,7 +63,7 @@ class Xoud_opt_scope_parser {
|
||||
usr_dlg.Warn_many("", "", fmt, String_.new_u8(src, bgn, end));
|
||||
return Xoud_opt_scope.App;
|
||||
}
|
||||
private static final Btrie_slim_mgr btrie_by_type = Btrie_slim_mgr.cs()
|
||||
private static final Btrie_slim_mgr btrie_by_type = Btrie_slim_mgr.cs()
|
||||
.Add_str_int("w" , Xow_domain_tid_.Int__wikipedia)
|
||||
.Add_str_int("d" , Xow_domain_tid_.Int__wiktionary)
|
||||
.Add_str_int("s" , Xow_domain_tid_.Int__wikisource)
|
||||
@@ -81,5 +81,5 @@ class Xoud_opt_scope_parser {
|
||||
.Add_str_int("mw" , Xow_domain_tid_.Int__mediawiki)
|
||||
.Add_str_int("wmf" , Xow_domain_tid_.Int__wmfblog)
|
||||
;
|
||||
private static final Xoud_opt_scope[] Ary_app = new Xoud_opt_scope[] {Xoud_opt_scope.App};
|
||||
private static final Xoud_opt_scope[] Ary_app = new Xoud_opt_scope[] {Xoud_opt_scope.App};
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Xoud_opt_scope_tst {
|
||||
}
|
||||
}
|
||||
class Xoud_opt_scope_fxt {
|
||||
private final Xoud_opt_scope_parser parser = new Xoud_opt_scope_parser();
|
||||
private final Xoud_opt_scope_parser parser = new Xoud_opt_scope_parser();
|
||||
public void Clear() {
|
||||
// Gfo_usr_dlg_.I = Xoa_app_.usr_dlg_console_();
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class Xoud_opt_scope_fxt {
|
||||
Tfds.Eq(To_str(expd), To_str(actl));
|
||||
}
|
||||
private static String To_str(Xoud_opt_scope[] ary) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoud_opt_scope itm = ary[i];
|
||||
|
||||
@@ -25,21 +25,17 @@ public class Xoud_site_mgr {
|
||||
tbl = new Xoud_site_tbl(conn);
|
||||
if (created) tbl.Create_tbl();
|
||||
}
|
||||
public Xoud_site_row[] Get_all() {return tbl.Select_all();}
|
||||
public void Import(String domain, String name, String path, String xtn) { // insert or update wiki
|
||||
Xoud_site_row[] ary = tbl.Select_by_domain(domain);
|
||||
int len = ary.length, update_id = -1, priority = 0;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoud_site_row itm = ary[i];
|
||||
if (priority <= itm.Priority()) priority = itm.Priority() + 1;
|
||||
if (String_.Eq(path, itm.Path())) { // same domain and same path; change insert to update;
|
||||
update_id = itm.Id();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (update_id == -1)
|
||||
tbl.Insert(id_mgr.Get_next_and_save("xowa.user.site"), priority, domain, name, path, xtn);
|
||||
public Xoud_site_row[] Get_all() {return tbl.Select_all();}
|
||||
public Xoud_site_row Select_by_domain(byte[] domain) {return tbl.Select_by_domain(domain);}
|
||||
public void Delete_by_domain(byte[] domain) {tbl.Delete_by_domain(domain);}
|
||||
public void Import(String domain, String name, String path, String date, String xtn) { // insert or update wiki
|
||||
Xoud_site_row itm = tbl.Select_by_domain(Bry_.new_u8(domain));
|
||||
if (itm == null)
|
||||
tbl.Insert(id_mgr.Get_next_and_save("xowa.user.site"), 0, domain, name, path, date, xtn);
|
||||
else
|
||||
tbl.Update(update_id, priority, domain, name, path, xtn);
|
||||
tbl.Update(itm.Id(), 0, domain, name, path, date, xtn);
|
||||
}
|
||||
public void Update(Xoud_site_row row) {
|
||||
tbl.Update(row.Id(), row.Priority(), row.Domain(), row.Name(), row.Path(), row.Date(), row.Xtn());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
public class Xoud_site_row {
|
||||
public Xoud_site_row(int id, int priority, String domain, String name, String path, String xtn) {
|
||||
this.id = id; this.priority = priority; this.domain = domain; this.name = name; this.path = path; this.xtn = xtn;
|
||||
public Xoud_site_row(int id, int priority, String domain, String name, String path, String date, String xtn) {
|
||||
this.id = id; this.priority = priority; this.domain = domain; this.name = name; this.path = path; this.date = date; this.xtn = xtn;
|
||||
}
|
||||
public int Id() {return id;} private final int id;
|
||||
public int Priority() {return priority;} private final int priority;
|
||||
public String Domain() {return domain;} private final String domain;
|
||||
public String Name() {return name;} private final String name;
|
||||
public String Path() {return path;} private final String path;
|
||||
public int Id() {return id;} private final int id;
|
||||
public int Priority() {return priority;} private final int priority;
|
||||
public String Domain() {return domain;} private final String domain;
|
||||
public String Name() {return name;} private final String name;
|
||||
public String Path() {return path;} private final String path;
|
||||
public String Date() {return date;} private String date; public void Date_(String v) {this.date = v;}
|
||||
public String Xtn() {return xtn;} private String xtn;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ package gplx.xowa.users.data; import gplx.*; import gplx.xowa.*; import gplx.xow
|
||||
import gplx.dbs.*;
|
||||
public class Xoud_site_tbl implements Rls_able {
|
||||
public static final String Tbl_name = "user_site";
|
||||
private final String tbl_name = Tbl_name; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
|
||||
private final String fld_site_id, fld_site_priority, fld_site_domain, fld_site_name, fld_site_path, fld_site_xtn;
|
||||
private final String tbl_name = Tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_site_id, fld_site_priority, fld_site_domain, fld_site_name, fld_site_path, fld_site_xtn, fld_site_date;
|
||||
private final Db_conn conn;
|
||||
public Xoud_site_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
@@ -29,54 +29,62 @@ public class Xoud_site_tbl implements Rls_able {
|
||||
fld_site_domain = flds.Add_str("site_domain", 255); // EX: en.wikipedia.org; NOTE: no protocol (https:)
|
||||
fld_site_name = flds.Add_str("site_name", 255); // EX: English Wikipedia
|
||||
fld_site_path = flds.Add_str("site_path", 255); // EX: ~{xowa_root}/wiki/en.wikipedia.org/
|
||||
fld_site_date = conn.Meta_fld_append_if_missing(tbl_name, flds, Dbmeta_fld_itm.new_str("site_date", 255).Default_("")); // EX: 2016-06-10
|
||||
fld_site_xtn = flds.Add_text("site_xtn");
|
||||
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 site_id, int priority, String domain, String name, String path, String xtn) {
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
stmt.Val_int(fld_site_id, site_id)
|
||||
.Val_int(fld_site_priority, priority).Val_str(fld_site_domain, domain).Val_str(fld_site_name, name).Val_str(fld_site_path, path).Val_str(fld_site_xtn, xtn)
|
||||
.Exec_insert();
|
||||
public void Insert(int site_id, int priority, String domain, String name, String path, String date, String xtn) {
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
Exec_stmt(stmt, Bool_.N, site_id, priority, domain, name, path, date, xtn);
|
||||
}
|
||||
public void Update(int site_id, int priority, String domain, String name, String path, String xtn) {
|
||||
public void Update(int site_id, int priority, String domain, String name, String path, String date, String xtn) {
|
||||
Db_stmt stmt = conn.Stmt_update_exclude(tbl_name, flds, fld_site_id);
|
||||
stmt.Val_int(fld_site_priority, priority).Val_str(fld_site_domain, domain).Val_str(fld_site_name, name).Val_str(fld_site_path, path).Val_str(fld_site_xtn, xtn)
|
||||
.Crt_int(fld_site_id, site_id)
|
||||
.Exec_update();
|
||||
Exec_stmt(stmt, Bool_.Y, site_id, priority, domain, name, path, date, xtn);
|
||||
}
|
||||
public void Delete(int site_id) {
|
||||
Db_stmt stmt = conn.Stmt_delete(tbl_name, fld_site_id);
|
||||
stmt.Crt_int(fld_site_id, site_id).Exec_delete();
|
||||
}
|
||||
public void Delete_by_domain(byte[] domain) {
|
||||
conn.Stmt_delete(tbl_name, fld_site_domain).Crt_bry_as_str(fld_site_domain, domain).Exec_delete();
|
||||
}
|
||||
public Xoud_site_row[] Select_all() {
|
||||
List_adp rv = List_adp_.new_();
|
||||
List_adp rv = List_adp_.New();
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next())
|
||||
rv.Add(new_row(rdr));
|
||||
rv.Add(New_site(rdr));
|
||||
return (Xoud_site_row[])rv.To_ary_and_clear(Xoud_site_row.class);
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public Xoud_site_row[] Select_by_domain(String domain) {
|
||||
List_adp rv = List_adp_.new_();
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_site_domain).Crt_str(fld_site_domain, domain).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next())
|
||||
rv.Add(new_row(rdr));
|
||||
return (Xoud_site_row[])rv.To_ary_and_clear(Xoud_site_row.class);
|
||||
}
|
||||
public Xoud_site_row Select_by_domain(byte[] domain) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_site_domain).Crt_bry_as_str(fld_site_domain, domain).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? New_site(rdr) : null;} // NOTE: old versions allowed multiple wikis with same domain; only return 1st
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
private Xoud_site_row new_row(Db_rdr rdr) {
|
||||
private void Exec_stmt(Db_stmt stmt, boolean update, int site_id, int priority, String domain, String name, String path, String date, String xtn) {
|
||||
if (!update)
|
||||
stmt.Val_int(fld_site_id, site_id);
|
||||
stmt.Val_int(fld_site_priority, priority).Val_str(fld_site_domain, domain).Val_str(fld_site_name, name).Val_str(fld_site_path, path)
|
||||
.Val_str(fld_site_date, date).Val_str(fld_site_xtn, xtn);
|
||||
if (update)
|
||||
stmt.Crt_int(fld_site_id, site_id);
|
||||
if (update)
|
||||
stmt.Exec_update();
|
||||
else
|
||||
stmt.Exec_insert();
|
||||
}
|
||||
private Xoud_site_row New_site(Db_rdr rdr) {
|
||||
return new Xoud_site_row
|
||||
( rdr.Read_int(fld_site_id)
|
||||
, rdr.Read_int(fld_site_priority)
|
||||
, rdr.Read_str(fld_site_domain)
|
||||
, rdr.Read_str(fld_site_name)
|
||||
, rdr.Read_str(fld_site_path)
|
||||
, rdr.Read_str(fld_site_date)
|
||||
, rdr.Read_str(fld_site_xtn)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class Xoud_user_mgr {
|
||||
}
|
||||
}
|
||||
class Xoud_user_tbl {
|
||||
private String tbl_name = "user_user_regy"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
|
||||
private String tbl_name = "user_user_regy"; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private String fld_id, fld_name;
|
||||
private Db_conn conn;
|
||||
public void Conn_(Db_conn new_conn, boolean created) {
|
||||
|
||||
Reference in New Issue
Block a user