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:
46
400_xowa/src/gplx/xowa/users/data/Xou_db_file.java
Normal file
46
400_xowa/src/gplx/xowa/users/data/Xou_db_file.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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.dbs.metas.*;
|
||||
import gplx.xowa.files.caches.*;
|
||||
import gplx.xowa.users.bmks.*;
|
||||
public class Xou_db_file {
|
||||
private final Db_conn conn;
|
||||
public Xou_db_file(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl__cfg = new Db_cfg_tbl(conn, "xowa_cfg");
|
||||
this.tbl__site = new Xoud_site_tbl(conn);
|
||||
this.tbl__history = new Xoud_history_tbl(conn);
|
||||
this.tbl__cache = new Xou_cache_tbl(conn);
|
||||
// this.tbl__bmk = new Xoud_bmk_tbl(conn);
|
||||
}
|
||||
public Db_cfg_tbl Tbl__cfg() {return tbl__cfg;} private final Db_cfg_tbl tbl__cfg;
|
||||
public Xoud_site_tbl Tbl__site() {return tbl__site;} private final Xoud_site_tbl tbl__site;
|
||||
public Xoud_history_tbl Tbl__history() {return tbl__history;} private final Xoud_history_tbl tbl__history;
|
||||
public Xou_cache_tbl Tbl__cache() {return tbl__cache;} private final Xou_cache_tbl tbl__cache;
|
||||
// public Xoud_bmk_tbl Tbl__bmk() {return tbl__bmk;} private final Xoud_bmk_tbl tbl__bmk;
|
||||
public void Init_assert() {
|
||||
if (!conn.Meta_tbl_exists(tbl__cache.Tbl_name())) {
|
||||
tbl__cfg.Create_tbl();
|
||||
tbl__cache.Create_tbl();
|
||||
}
|
||||
// if (!conn.Meta_tbl_exists(tbl__bmk.Tbl_name())) {
|
||||
// tbl__bmk.Create_tbl();
|
||||
// }
|
||||
}
|
||||
}
|
||||
50
400_xowa/src/gplx/xowa/users/data/Xou_db_mgr.java
Normal file
50
400_xowa/src/gplx/xowa/users/data/Xou_db_mgr.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.core.threads.*; import gplx.dbs.*; import gplx.dbs.metas.updates.*; import gplx.dbs.metas.*;
|
||||
import gplx.xowa.files.caches.*;
|
||||
import gplx.xowa.users.bmks.*;
|
||||
public class Xou_db_mgr {
|
||||
private final Xoa_app app;
|
||||
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 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;
|
||||
public Xoud_history_mgr History_mgr() {return history_mgr;} private final Xoud_history_mgr history_mgr = new Xoud_history_mgr();
|
||||
public Xoud_bmk_mgr Bmk_mgr() {return bmk_mgr;} private final Xoud_bmk_mgr bmk_mgr = new Xoud_bmk_mgr();
|
||||
public Xou_cache_mgr Cache_mgr() {return cache_mgr;} private Xou_cache_mgr cache_mgr;
|
||||
public Xou_file_itm_finder File__xfer_itm_finder() {return xfer_itm_finder;} private Xou_file_itm_finder xfer_itm_finder;
|
||||
public void Init_by_app(boolean drd, Io_url db_url) {
|
||||
Db_conn_bldr_data db_conn_bldr = Db_conn_bldr.I.Get_or_new(db_url);
|
||||
Db_conn conn = db_conn_bldr.Conn(); boolean created = db_conn_bldr.Created();
|
||||
this.db_file = new Xou_db_file(conn); db_file.Init_assert();
|
||||
this.cache_mgr = new Xou_cache_mgr(app.Wiki_mgri(), app.Fsys_mgr().File_dir(), db_file);
|
||||
this.xfer_itm_finder = new Xou_file_itm_finder(cache_mgr);
|
||||
this.bmk_mgr.Conn_(conn, created);
|
||||
if (drd) {
|
||||
cfg_mgr.Conn_(conn, created);
|
||||
site_mgr.Conn_(conn, created);
|
||||
// history_mgr.Conn_(user_conn, created);
|
||||
}
|
||||
}
|
||||
}
|
||||
64
400_xowa/src/gplx/xowa/users/data/Xoud_cfg_mgr.java
Normal file
64
400_xowa/src/gplx/xowa/users/data/Xoud_cfg_mgr.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*;
|
||||
public class Xoud_cfg_mgr {
|
||||
public Db_cfg_tbl Tbl() {return tbl;} private Db_cfg_tbl tbl;
|
||||
public void Conn_(Db_conn new_conn, boolean created) {
|
||||
tbl = new Db_cfg_tbl(new_conn, "user_opt");
|
||||
if (created) tbl.Create_tbl();
|
||||
}
|
||||
public int Select_int_or(String grp, String key, int or) {
|
||||
String rv = Select_str_or(grp, key, null);
|
||||
return rv == null ? or : Int_.parse_or_(rv, or);
|
||||
}
|
||||
public byte[] Select_bry_or(String key, byte[] or) {return Select_bry_or("" , key, or);}
|
||||
public byte[] Select_bry_or(String grp, String key, byte[] or) {
|
||||
String rv = Select_str_or(grp, key, null);
|
||||
return rv == null ? or : Bry_.new_u8(rv);
|
||||
}
|
||||
public String Select_str_or(String grp, String key, String or) {
|
||||
String rv = tbl.Select_str_or(grp, key, null);
|
||||
return rv == null ? or : rv;
|
||||
}
|
||||
public byte[] Assert_bry_or(String key, byte[] or) {return Assert_bry_or("", key, or);}
|
||||
public byte[] Assert_bry_or(String grp, String key, byte[] or) {
|
||||
String rv = tbl.Select_str_or(grp, key, null);
|
||||
if (rv == null) {
|
||||
Insert_bry(grp, key, or);
|
||||
return or;
|
||||
}
|
||||
else
|
||||
return Bry_.new_u8(rv);
|
||||
}
|
||||
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 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);}
|
||||
public int Next_id(String tbl_name) {
|
||||
String grp = "xowa." + tbl_name, key = "next_id";
|
||||
int next_id = tbl.Select_int_or(grp, key, 1); // EX: xowa.cfg_history|next_id|1
|
||||
int new_val = next_id + 1;
|
||||
if (next_id == 1)
|
||||
tbl.Insert_int(grp, key, new_val);
|
||||
else
|
||||
tbl.Update_int(grp, key, new_val);
|
||||
return next_id;
|
||||
}
|
||||
}
|
||||
57
400_xowa/src/gplx/xowa/users/data/Xoud_history_mgr.java
Normal file
57
400_xowa/src/gplx/xowa/users/data/Xoud_history_mgr.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.core.threads.*; import gplx.dbs.*;
|
||||
import gplx.xowa.specials.*;
|
||||
public class Xoud_history_mgr implements GfoInvkAble {
|
||||
private Xoud_history_tbl history_tbl;
|
||||
public void Conn_(Db_conn new_conn, boolean created) {
|
||||
history_tbl = new Xoud_history_tbl(new_conn);
|
||||
if (created) history_tbl.Create_tbl();
|
||||
}
|
||||
public void Update_async(Gfo_async_mgr async_mgr, Xoa_ttl ttl, Xoa_url url) {
|
||||
// if (Skip_history(ttl)) return;
|
||||
// async_mgr.Queue(this, Invk_update, "wiki", String_.new_u8(url.Wiki_bry()), "page", String_.new_u8(url.Page_bry()), "qarg", String_.new_u8(url.Args_all_as_bry()));
|
||||
}
|
||||
private void Update(String wiki, String page, String qarg) {
|
||||
Xoud_history_row row = history_tbl.Select_by_page(wiki, page, qarg);
|
||||
DateAdp time = DateAdp_.Now();
|
||||
if (row == null)
|
||||
history_tbl.Insert(wiki, page, qarg, time, 1);
|
||||
else
|
||||
history_tbl.Update(wiki, page, qarg, time, row.History_count() + 1);
|
||||
}
|
||||
public void Select(List_adp rv, int top) {
|
||||
history_tbl.Select_by_top(rv, top);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_update)) Update(m.ReadStr("wiki"), m.ReadStr("page"), m.ReadStr("qarg"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_update = "update";
|
||||
public static boolean Skip_history(Xoa_ttl ttl) {
|
||||
byte[] page_db = ttl.Page_db();
|
||||
return ( ttl.Ns().Id_special()
|
||||
&& ( Bry_.Eq(page_db, gplx.xowa.users.history.Xou_history_mgr.Ttl_name) // do not add XowaPageHistory to history
|
||||
|| Bry_.Eq(page_db, Xows_special_meta_.Itm__popup_history.Key_bry())
|
||||
|| Bry_.Eq(page_db, Xows_special_meta_.Itm__default_tab.Key_bry())
|
||||
|| Bry_.Eq(page_db, Xows_special_meta_.Itm__page_history.Key_bry())
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
33
400_xowa/src/gplx/xowa/users/data/Xoud_history_row.java
Normal file
33
400_xowa/src/gplx/xowa/users/data/Xoud_history_row.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
public class Xoud_history_row {
|
||||
public Xoud_history_row(String history_wiki, String history_page, String history_qarg, DateAdp history_time, int history_count) {
|
||||
this.history_wiki = history_wiki;
|
||||
this.history_page = history_page;
|
||||
this.history_qarg = history_qarg;
|
||||
this.history_time = history_time;
|
||||
this.history_count = history_count;
|
||||
}
|
||||
public String History_wiki() {return history_wiki;} private final String history_wiki;
|
||||
public String History_page() {return history_page;} private final String history_page;
|
||||
public String History_qarg() {return history_qarg;} private final String history_qarg;
|
||||
public DateAdp History_time() {return history_time;} private final DateAdp history_time;
|
||||
public int History_count() {return history_count;} private final int history_count;
|
||||
public static final Xoud_history_row Null = null;
|
||||
}
|
||||
59
400_xowa/src/gplx/xowa/users/data/Xoud_history_special.java
Normal file
59
400_xowa/src/gplx/xowa/users/data/Xoud_history_special.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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.xowa.specials.*;
|
||||
public class Xoud_history_special implements Bry_fmtr_arg, Xows_page {
|
||||
private List_adp rows = List_adp_.new_();
|
||||
public Xows_special_meta Special_meta() {return Xows_special_meta_.Itm__page_history;}
|
||||
public void Special_gen(Xowe_wiki wiki, Xoae_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
Xoae_app app = wiki.Appe();
|
||||
Xoud_history_mgr mgr = app.User().User_db_mgr().History_mgr();
|
||||
mgr.Select(rows, 100);
|
||||
Bry_bfr bfr = app.Utl__bfr_mkr().Get_m001();
|
||||
html_grp.Bld_bfr_many(bfr, this);
|
||||
page.Data_raw_(bfr.To_bry_and_rls());
|
||||
}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
int len = rows.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoud_history_row row = (Xoud_history_row)rows.Get_at(i);
|
||||
html_itm.Bld_bfr_many(bfr, row.History_wiki(), row.History_page(), row.History_count(), row.History_time().XtoStr_fmt_yyyy_MM_dd_HH_mm());
|
||||
}
|
||||
}
|
||||
private static Bry_fmtr html_grp = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<table class='sortable'>"
|
||||
, " <tr>"
|
||||
, " <th>page</th>"
|
||||
, " <th>wiki</th>"
|
||||
, " <th>views</th>"
|
||||
, " <th>time</th>"
|
||||
, " </tr>~{itms}"
|
||||
, "</table>"
|
||||
), "itms"
|
||||
);
|
||||
private static Bry_fmtr html_itm = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <tr>"
|
||||
, " <td>[[~{itm_wiki}:~{itm_page}|~{itm_page}]]</td>"
|
||||
, " <td>~{itm_wiki}</td>"
|
||||
, " <td>~{itm_count}</td>"
|
||||
, " <td>~{itm_last}</td>"
|
||||
, " </tr>"
|
||||
), "itm_wiki", "itm_page", "itm_count", "itm_last"
|
||||
);
|
||||
}
|
||||
94
400_xowa/src/gplx/xowa/users/data/Xoud_history_tbl.java
Normal file
94
400_xowa/src/gplx/xowa/users/data/Xoud_history_tbl.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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.metas.*; import gplx.dbs.metas.updates.*;
|
||||
public class Xoud_history_tbl implements RlsAble {
|
||||
private final String tbl_name = "user_history"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_wiki, fld_page, fld_qarg, fld_time, fld_count;
|
||||
private final Db_conn conn; private Db_stmt stmt_select_by_page, stmt_select_by_top, stmt_insert, stmt_update, stmt_delete;
|
||||
public Xoud_history_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
fld_wiki = flds.Add_str("hist_wiki", 255);
|
||||
fld_page = flds.Add_str("hist_page", 255);
|
||||
fld_qarg = flds.Add_str("hist_qarg", 255);
|
||||
fld_time = flds.Add_str("hist_time", 20);
|
||||
fld_count = flds.Add_int("hist_count");
|
||||
stmt_insert = stmt_update = stmt_delete = stmt_select_by_page = stmt_select_by_top = null;
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds, Db_meta_idx.new_unique_by_tbl(tbl_name, "pkey", fld_wiki, fld_page, fld_qarg)));}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_update = Db_stmt_.Rls(stmt_update);
|
||||
stmt_delete = Db_stmt_.Rls(stmt_delete);
|
||||
stmt_select_by_page = Db_stmt_.Rls(stmt_select_by_page);
|
||||
stmt_select_by_top = Db_stmt_.Rls(stmt_select_by_top);
|
||||
}
|
||||
public void Insert(String wiki, String page, String qarg, DateAdp time, int count) {
|
||||
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
|
||||
stmt_insert.Clear()
|
||||
.Val_str(fld_wiki, wiki).Val_str(fld_page, page).Val_str(fld_qarg, qarg)
|
||||
.Val_str(fld_time, time.XtoStr_fmt_iso_8561()).Val_int(fld_count, count)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Update(String wiki, String page, String qarg, DateAdp time, int count) {
|
||||
if (stmt_update == null) stmt_update = conn.Stmt_update(tbl_name, String_.Ary(fld_wiki, fld_page, fld_qarg), fld_time, fld_count);
|
||||
stmt_update.Clear()
|
||||
.Val_str(fld_time, time.XtoStr_fmt_iso_8561()).Val_int(fld_count, count)
|
||||
.Crt_str(fld_wiki, wiki).Crt_str(fld_page, page).Crt_str(fld_qarg, qarg)
|
||||
.Exec_update();
|
||||
}
|
||||
public void Delete(String wiki, String page, String qarg) {
|
||||
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_wiki, fld_page, fld_qarg);
|
||||
stmt_delete.Clear()
|
||||
.Crt_str(fld_wiki, wiki).Crt_str(fld_page, page).Crt_str(fld_qarg, qarg)
|
||||
.Exec_delete();
|
||||
}
|
||||
public Xoud_history_row Select_by_page(String wiki, String page, String qarg) {
|
||||
if (stmt_select_by_page == null) stmt_select_by_page = conn.Stmt_select(tbl_name, flds, fld_wiki, fld_page, fld_qarg);
|
||||
Db_rdr rdr = stmt_select_by_page.Clear().Crt_str(fld_wiki, wiki).Crt_str(fld_page, page).Crt_str(fld_qarg, qarg).Exec_select__rls_manual();
|
||||
try {
|
||||
return rdr.Move_next() ? new_row(rdr) : Xoud_history_row.Null;
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Select_by_top(List_adp rv, int count) {
|
||||
if (stmt_select_by_top == null) {
|
||||
Db_qry__select_in_tbl qry = new Db_qry__select_in_tbl(tbl_name, flds.To_str_ary(), null, null, null, fld_time + " DESC", " LIMIT " + Int_.Xto_str(count));
|
||||
stmt_select_by_top = conn.Stmt_new(qry);
|
||||
}
|
||||
Db_rdr rdr = stmt_select_by_top.Clear().Exec_select__rls_manual();
|
||||
try {
|
||||
rv.Clear();
|
||||
while (rdr.Move_next()) {
|
||||
Xoud_history_row row = new_row(rdr);
|
||||
rv.Add(row);
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
private Xoud_history_row new_row(Db_rdr rdr) {
|
||||
return new Xoud_history_row
|
||||
( rdr.Read_str(fld_wiki)
|
||||
, rdr.Read_str(fld_page)
|
||||
, rdr.Read_str(fld_qarg)
|
||||
, rdr.Read_date_by_str(fld_time)
|
||||
, rdr.Read_int(fld_count)
|
||||
);
|
||||
}
|
||||
}
|
||||
30
400_xowa/src/gplx/xowa/users/data/Xoud_id_mgr.java
Normal file
30
400_xowa/src/gplx/xowa/users/data/Xoud_id_mgr.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
public class Xoud_id_mgr {
|
||||
private Xoud_cfg_mgr cfg_mgr;
|
||||
public Xoud_id_mgr(Xoud_cfg_mgr cfg_mgr) {this.cfg_mgr = cfg_mgr;}
|
||||
public int Get_next(String key) {return cfg_mgr.Select_int_or(Grp_key, key, 1);}
|
||||
public void Set_next(String key, int v) {cfg_mgr.Insert_int(Grp_key, key, v);}
|
||||
public int Get_next_and_save(String key) {
|
||||
int rv = Get_next(key);
|
||||
Set_next(key, rv + 1);
|
||||
return rv;
|
||||
}
|
||||
private static final String Grp_key = "gplx.next_id";
|
||||
}
|
||||
84
400_xowa/src/gplx/xowa/users/data/Xoud_opt_scope.java
Normal file
84
400_xowa/src/gplx/xowa/users/data/Xoud_opt_scope.java
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.wikis.*;
|
||||
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 String To_str() {
|
||||
String lang_str = lang_id == Lang_id_wildcard ? "*" : String_.new_u8(Xol_lang_itm_.Get_by_id(lang_id).Key());
|
||||
String type_str = type_id == Lang_id_wildcard ? "*" : String_.new_u8(Xow_domain_type_.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);
|
||||
}
|
||||
class Xoud_opt_scope_parser {
|
||||
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_.I;
|
||||
list.Clear();
|
||||
int pos = 0; int src_len = src.length;
|
||||
while (pos < src_len) {
|
||||
int comma_pos = Bry_finder.Find_fwd(src, Byte_ascii.Comma, pos, src_len); if (comma_pos == Bry_finder.Not_found) comma_pos = src_len;
|
||||
Xoud_opt_scope itm = Parse_itm(src, pos, comma_pos);
|
||||
if (itm == Xoud_opt_scope.App) return Ary_app;
|
||||
list.Add(itm);
|
||||
pos = comma_pos + 1;
|
||||
}
|
||||
return (Xoud_opt_scope[])list.To_ary_and_clear(Xoud_opt_scope.class);
|
||||
}
|
||||
public Xoud_opt_scope Parse_itm(byte[] src, int bgn, int end) {
|
||||
int lang_dot = Bry_finder.Find_fwd(src, Byte_ascii.Dot, bgn, end); if (lang_dot == Bry_finder.Not_found) return Warn("scope.parse.missing_lang_dot: src=~{0}", src, bgn, end);
|
||||
int lang_id = Int_.MinValue;
|
||||
if (lang_dot == 1 && src[bgn] == Byte_ascii.Star)
|
||||
lang_id = Xoud_opt_scope.Lang_id_wildcard;
|
||||
else {
|
||||
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key_or_null(src, bgn, lang_dot); if (lang_itm == null) return Warn("scope.parse.invalid_lang: src=~{0}", src, bgn, end);
|
||||
lang_id = lang_itm.Id();
|
||||
}
|
||||
Object type_tid_obj = btrie_by_type.Match_bgn(src, lang_dot + 1, end); if (type_tid_obj == null) return Warn("scope.parse.invalid_type: src=~{0}", src, bgn, end);
|
||||
int type_id = ((Int_obj_val)type_tid_obj).Val();
|
||||
return new Xoud_opt_scope(lang_id, type_id);
|
||||
}
|
||||
private Xoud_opt_scope Warn(String fmt, byte[] src, int bgn, int end) {
|
||||
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_()
|
||||
.Add_str_int("w" , Xow_domain_type_.Tid_wikipedia)
|
||||
.Add_str_int("d" , Xow_domain_type_.Tid_wiktionary)
|
||||
.Add_str_int("s" , Xow_domain_type_.Tid_wikisource)
|
||||
.Add_str_int("v" , Xow_domain_type_.Tid_wikivoyage)
|
||||
.Add_str_int("q" , Xow_domain_type_.Tid_wikiquote)
|
||||
.Add_str_int("b" , Xow_domain_type_.Tid_wikibooks)
|
||||
.Add_str_int("u" , Xow_domain_type_.Tid_wikiversity)
|
||||
.Add_str_int("n" , Xow_domain_type_.Tid_wikinews)
|
||||
.Add_str_int("*" , Xoud_opt_scope.Type_id_wildcard)
|
||||
.Add_str_int("xowa" , Xow_domain_type_.Tid_home)
|
||||
.Add_str_int("wd" , Xow_domain_type_.Tid_wikidata)
|
||||
.Add_str_int("c" , Xow_domain_type_.Tid_commons)
|
||||
.Add_str_int("species" , Xow_domain_type_.Tid_species)
|
||||
.Add_str_int("meta" , Xow_domain_type_.Tid_meta)
|
||||
.Add_str_int("mw" , Xow_domain_type_.Tid_mediawiki)
|
||||
.Add_str_int("wmf" , Xow_domain_type_.Tid_wmfblog)
|
||||
;
|
||||
private static final Xoud_opt_scope[] Ary_app = new Xoud_opt_scope[] {Xoud_opt_scope.App};
|
||||
}
|
||||
51
400_xowa/src/gplx/xowa/users/data/Xoud_opt_scope_tst.java
Normal file
51
400_xowa/src/gplx/xowa/users/data/Xoud_opt_scope_tst.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.wikis.*;
|
||||
public class Xoud_opt_scope_tst {
|
||||
private Xoud_opt_scope_fxt fxt = new Xoud_opt_scope_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Test_parse("en.w" , fxt.Make(Xol_lang_itm_.Id_en, Xow_domain_type_.Tid_wikipedia));
|
||||
fxt.Test_parse("en.*" , fxt.Make(Xol_lang_itm_.Id_en, Xoud_opt_scope.Type_id_wildcard));
|
||||
fxt.Test_parse("*.w" , fxt.Make(Xoud_opt_scope.Lang_id_wildcard, Xow_domain_type_.Tid_wikipedia));
|
||||
fxt.Test_parse("<any>" , Xoud_opt_scope.App);
|
||||
fxt.Test_parse("en.w,fr.d" , fxt.Make(Xol_lang_itm_.Id_en, Xow_domain_type_.Tid_wikipedia), fxt.Make(Xol_lang_itm_.Id_fr, Xow_domain_type_.Tid_wiktionary));
|
||||
}
|
||||
}
|
||||
class Xoud_opt_scope_fxt {
|
||||
private final Xoud_opt_scope_parser parser = new Xoud_opt_scope_parser();
|
||||
public void Clear() {
|
||||
// Gfo_usr_dlg_.I = Xoa_app_.usr_dlg_console_();
|
||||
}
|
||||
public Xoud_opt_scope Make(int lang_id, int type_id) {return new Xoud_opt_scope(lang_id, type_id);}
|
||||
public void Test_parse(String raw, Xoud_opt_scope... expd) {
|
||||
Xoud_opt_scope[] actl = parser.Parse(Bry_.new_u8(raw));
|
||||
Tfds.Eq(To_str(expd), To_str(actl));
|
||||
}
|
||||
private static String To_str(Xoud_opt_scope[] ary) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoud_opt_scope itm = ary[i];
|
||||
if (i != 0) bfr.Add_str_a7(",");
|
||||
bfr.Add_str_a7(itm.To_str());
|
||||
}
|
||||
return bfr.Xto_str_and_clear();
|
||||
}
|
||||
}
|
||||
24
400_xowa/src/gplx/xowa/users/data/Xoud_regy_row.java
Normal file
24
400_xowa/src/gplx/xowa/users/data/Xoud_regy_row.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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
public class Xoud_regy_row {
|
||||
public Xoud_regy_row(String cfg_grp, String cfg_key, String cfg_val) {this.cfg_grp = cfg_grp; this.cfg_key = cfg_key; this.cfg_val = cfg_val;}
|
||||
public String Cfg_grp() {return cfg_grp;} private final String cfg_grp;
|
||||
public String Cfg_key() {return cfg_key;} private final String cfg_key;
|
||||
public String Cfg_val() {return cfg_val;} private final String cfg_val;
|
||||
}
|
||||
89
400_xowa/src/gplx/xowa/users/data/Xoud_regy_tbl.java
Normal file
89
400_xowa/src/gplx/xowa/users/data/Xoud_regy_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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.metas.*; import gplx.dbs.metas.updates.*;
|
||||
public class Xoud_regy_tbl {
|
||||
public static final String Tbl_name = "user_regy", Fld_regy_grp = "regy_grp", Fld_regy_key = "regy_key", Fld_regy_val = "regy_val";
|
||||
private static final String[] Flds__all = new String[] {Fld_regy_grp, Fld_regy_key, Fld_regy_val};
|
||||
public static final Db_idx_itm Idx_core = Db_idx_itm.sql_("CREATE UNIQUE INDEX user_regy_core ON user_regy (regy_grp, regy_key);");
|
||||
public static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE user_regy"
|
||||
, "( regy_grp nvarchar(255) NOT NULL -- EX: xowa.schema.site"
|
||||
, ", regy_key nvarchar(255) NOT NULL -- EX: next_id"
|
||||
, ", regy_val nvarchar(255) NOT NULL -- EX: 1"
|
||||
, ");"
|
||||
);
|
||||
private Db_stmt stmt_select_grp, stmt_select_key, stmt_insert, stmt_update, stmt_delete;
|
||||
public Db_conn Conn() {return conn;}
|
||||
public Xoud_regy_tbl Conn_(Db_conn v, boolean created) {
|
||||
this.Rls_all(); conn = v;
|
||||
if (created) {
|
||||
Schema_update_cmd cmd = Schema_update_cmd_.Make_tbl_create(Xoud_regy_tbl.Tbl_name , Xoud_regy_tbl.Tbl_sql , Xoud_regy_tbl.Idx_core);
|
||||
cmd.Exec(null, conn);
|
||||
// conn.Ddl_create_tbl(meta);
|
||||
}
|
||||
return this;
|
||||
} private Db_conn conn;
|
||||
@gplx.Virtual public void Insert(String grp, String key, String val) {
|
||||
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(conn, Tbl_name, Flds__all);
|
||||
stmt_insert.Clear().Val_str(grp).Val_str(key).Val_str(val).Exec_insert();
|
||||
}
|
||||
@gplx.Virtual public void Update(String grp, String key, String val) {
|
||||
if (stmt_update == null) stmt_update = Db_stmt_.new_update_(conn, Tbl_name, String_.Ary(Fld_regy_grp, Fld_regy_key), Fld_regy_val);
|
||||
stmt_update.Clear().Val_str(val).Val_str(grp).Val_str(key).Exec_update();
|
||||
}
|
||||
@gplx.Virtual public void Delete(String grp, String key) {
|
||||
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(conn, Tbl_name, Fld_regy_grp, Fld_regy_key);
|
||||
stmt_delete.Clear().Val_str(grp).Val_str(key).Exec_delete();
|
||||
}
|
||||
@gplx.Virtual public void Select_by_grp(List_adp rv, String grp) {
|
||||
if (stmt_select_grp == null) stmt_select_grp = Db_stmt_.new_select_as_rdr(conn, Db_qry__select_in_tbl.new_(Tbl_name, String_.Ary(Fld_regy_grp), Flds__all, Db_qry__select_in_tbl.Order_by_null));
|
||||
Db_rdr rdr = stmt_select_grp.Clear().Val_str(grp).Exec_select__rls_manual();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
Xoud_regy_row row = Make_row(rdr);
|
||||
rv.Add(row);
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
@gplx.Virtual public String Select_val(String grp, String key) {
|
||||
if (stmt_select_key == null) stmt_select_key = Db_stmt_.new_select_as_rdr(conn, Db_qry__select_in_tbl.new_(Tbl_name, String_.Ary(Fld_regy_grp, Fld_regy_key), Flds__all, Db_qry__select_in_tbl.Order_by_null));
|
||||
Db_rdr rdr = stmt_select_key.Clear().Val_str(Fld_regy_grp, grp).Val_str(Fld_regy_key, key).Exec_select__rls_manual();
|
||||
String rv = null;
|
||||
if (rdr.Move_next())
|
||||
rv = rdr.Read_str(Fld_regy_val);
|
||||
rdr.Rls();
|
||||
return rv;
|
||||
}
|
||||
private Xoud_regy_row Make_row(Db_rdr rdr) {
|
||||
return new Xoud_regy_row
|
||||
( rdr.Read_str(Fld_regy_grp)
|
||||
, rdr.Read_str(Fld_regy_key)
|
||||
, rdr.Read_str(Fld_regy_val)
|
||||
);
|
||||
}
|
||||
public void Rls_all() {
|
||||
if (stmt_select_grp != null) {stmt_select_grp.Rls(); stmt_select_grp = null;}
|
||||
if (stmt_select_key != null) {stmt_select_key.Rls(); stmt_select_key = null;}
|
||||
if (stmt_insert != null) {stmt_insert.Rls(); stmt_insert = null;}
|
||||
if (stmt_update != null) {stmt_update.Rls(); stmt_update = null;}
|
||||
if (stmt_delete != null) {stmt_delete.Rls(); stmt_delete = null;}
|
||||
conn = null;
|
||||
}
|
||||
}
|
||||
45
400_xowa/src/gplx/xowa/users/data/Xoud_site_mgr.java
Normal file
45
400_xowa/src/gplx/xowa/users/data/Xoud_site_mgr.java
Normal file
@@ -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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.dbs.*; import gplx.xowa.users.data.*;
|
||||
public class Xoud_site_mgr {
|
||||
private Xoud_site_tbl tbl;
|
||||
private final Xoud_id_mgr id_mgr;
|
||||
public Xoud_site_mgr(Xoud_id_mgr id_mgr) {this.id_mgr = id_mgr;}
|
||||
public void Conn_(Db_conn conn, boolean created) {
|
||||
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);
|
||||
else
|
||||
tbl.Update(update_id, priority, domain, name, path, xtn);
|
||||
}
|
||||
}
|
||||
29
400_xowa/src/gplx/xowa/users/data/Xoud_site_row.java
Normal file
29
400_xowa/src/gplx/xowa/users/data/Xoud_site_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.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 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 Xtn() {return xtn;} private String xtn;
|
||||
}
|
||||
82
400_xowa/src/gplx/xowa/users/data/Xoud_site_tbl.java
Normal file
82
400_xowa/src/gplx/xowa/users/data/Xoud_site_tbl.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xoud_site_tbl implements RlsAble {
|
||||
private final String tbl_name = "user_site"; private final Db_meta_fld_list flds = Db_meta_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 Db_conn conn;
|
||||
public Xoud_site_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
fld_site_id = flds.Add_int_pkey("site_id");
|
||||
fld_site_priority = flds.Add_int("site_priority"); // EX: 0=default; 1+ is order if 0 is unavailable
|
||||
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_xtn = flds.Add_text("site_xtn");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.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 Update(int site_id, int priority, String domain, String name, String path, 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();
|
||||
}
|
||||
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 Xoud_site_row[] Select_all() {
|
||||
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));
|
||||
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);
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
private Xoud_site_row new_row(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_xtn)
|
||||
);
|
||||
}
|
||||
}
|
||||
71
400_xowa/src/gplx/xowa/users/data/Xoud_user_tbl.java
Normal file
71
400_xowa/src/gplx/xowa/users/data/Xoud_user_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.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
|
||||
import gplx.dbs.*;
|
||||
class Xoud_user_mgr {
|
||||
private Xoud_user_tbl tbl = new Xoud_user_tbl();
|
||||
public void Conn_(Db_conn conn, boolean created) {tbl.Conn_(conn, created);}
|
||||
public int Get_id_or_new(String name) {
|
||||
int rv = tbl.Select_id_by_name(name);
|
||||
if (rv == Int_.MinValue) {
|
||||
rv = tbl.Select_id_next();
|
||||
tbl.Insert(rv, name);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Xoud_user_tbl {
|
||||
private String tbl_name = "user_user_regy"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private String fld_id, fld_name;
|
||||
private Db_conn conn;
|
||||
public void Conn_(Db_conn new_conn, boolean created) {
|
||||
this.conn = new_conn; flds.Clear();
|
||||
fld_id = flds.Add_int_pkey("id");
|
||||
fld_name = flds.Add_str("name", 255);
|
||||
if (created) {
|
||||
Db_meta_tbl meta = Db_meta_tbl.new_(tbl_name, flds
|
||||
, Db_meta_idx.new_unique_by_tbl(tbl_name, "name", fld_name)
|
||||
);
|
||||
conn.Ddl_create_tbl(meta);
|
||||
}
|
||||
}
|
||||
public void Insert(int id, String name) {
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
stmt.Val_int(fld_id, id).Val_str(fld_name, name)
|
||||
.Exec_insert();
|
||||
}
|
||||
public int Select_id_by_name(String name) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_name).Crt_str(fld_name, name).Exec_select__rls_auto();
|
||||
try {
|
||||
return rdr.Move_next() ? rdr.Read_int(fld_id) : Int_.MinValue;
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public int Select_id_next() {
|
||||
int rv = 1;
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, Db_meta_fld.Ary_empty).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
int cur = rdr.Read_int(fld_id);
|
||||
if (cur >= rv) rv = cur + 1;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user