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

Embeddable: Create core dbs in proper subdirectory

This commit is contained in:
gnosygnu
2017-10-23 20:50:22 -04:00
parent dc22c15895
commit 1336d44f34
4537 changed files with 0 additions and 311750 deletions

View File

@@ -13,13 +13,3 @@ 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.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
public class Xocfg_meta_itm {
public Xocfg_meta_itm(String key, String type, String dflt, String version) {
this.key = key; this.type = type; this.dflt = dflt; this.version = version;
}
public String Key() {return key;} private final String key;
public String Type() {return type;} private String type;
public String Dflt() {return dflt;} private String dflt;
public String Version() {return version;} private String version;
}

View File

@@ -13,26 +13,3 @@ 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.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
import gplx.dbs.*;
public class Xocfg_meta_tbl implements Rls_able {
private final String tbl_name; public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_key, fld_type, fld_dflt, fld_version;
private final Db_conn conn;
public Xocfg_meta_tbl(Db_conn conn) {
this.conn = conn;
tbl_name = Tbl_name;
fld_key = flds.Add_str_pkey ("cfg_key" , 1024); // EX: "xowa.net.web_enabled"
fld_type = flds.Add_str ("cfg_type" , 255); // EX: "yn"
fld_dflt = flds.Add_str ("cfg_dflt" , 1024); // EX: "n"
fld_version = flds.Add_str ("cfg_version" , 16); // EX: "v1.1.1.1"
}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Insert(String key, String type, String dflt, String version) {
Db_stmt stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear().Val_str(fld_key, key).Val_str(fld_type, type).Val_str(fld_dflt, dflt).Val_str(fld_version, version)
.Exec_insert();
}
public void Rls() {}
public static final String Tbl_name = "cfg_meta";
}

View File

@@ -13,16 +13,3 @@ 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.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
public class Xou_cfg_itm {
public Xou_cfg_itm(int usr, String ctx, String key, String val) {
this.usr = usr; this.ctx = ctx; this.key = key; this.val = val;
this.uid = Xou_cfg_mgr.Bld_uid(usr, ctx, key);
}
public String Uid() {return uid;} private final String uid;
public int Usr() {return usr;} private final int usr;
public String Ctx() {return ctx;} private final String ctx;
public String Key() {return key;} private final String key;
public String Val() {return val;} private String val;
public void Val_(String v) {this.val = v;}
}

View File

@@ -13,59 +13,3 @@ 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.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
import gplx.dbs.*;
public class Xou_cfg_mgr {
private Xou_cfg_tbl tbl;
private final Hash_adp hash = Hash_adp_.New();
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
public void Init_by_app(Db_conn conn) {
tbl = new Xou_cfg_tbl(conn);
tbl.Conn().Meta_tbl_assert(tbl);
this.Reg(tbl.Select_by_usr_ctx(Usr__anonymous, Ctx__app));
}
public String Get_app_str_or(String key, String or) { // NOTE: app-level is always loaded at start; don't check db
synchronized (hash) { // LOCK:app-level
String uid = Bld_uid(tmp_bfr, Usr__anonymous, Ctx__app, key);
Xou_cfg_itm itm = (Xou_cfg_itm)hash.Get_by(uid);
return itm == null ? or : itm.Val();
}
}
public void Set_app_bry(String key, byte[] val) {this.Set_app_str(key, String_.new_u8(val));}
public void Set_app_str(String key, String val) {
synchronized (hash) { // LOCK:app-level
// update val in reg
String uid = Bld_uid(tmp_bfr, Usr__anonymous, Ctx__app, key);
boolean insert = false;
Xou_cfg_itm itm = (Xou_cfg_itm)hash.Get_by(uid);
if (itm == null) {
itm = new Xou_cfg_itm(Usr__anonymous, Ctx__app, key, val);
hash.Add(uid, itm);
insert = true;
}
itm.Val_(val);
// save to db
tbl.Upsert(insert, itm.Usr(), itm.Ctx(), itm.Key(), itm.Val());
}
}
private void Reg(Xou_cfg_itm[] itms) {
synchronized (hash) { // LOCK:app-level
for (Xou_cfg_itm itm : itms)
hash.Add(itm.Uid(), itm);
}
}
private static final int Usr__anonymous = 1;
private static final String Ctx__app = "app";
public static String Bld_uid(int usr, String ctx, String key) {
return String_.Concat(Int_.To_str(usr), "|", ctx, "|", key);
}
private static String Bld_uid(Bry_bfr tmp_bfr, int usr, String ctx, String key) {
tmp_bfr.Add_int_variable(usr).Add_byte_pipe();
tmp_bfr.Add_str_a7(ctx).Add_byte_pipe();
tmp_bfr.Add_str_u8(key);
return tmp_bfr.To_str_and_clear();
}
}

View File

@@ -13,56 +13,3 @@ 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.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
import gplx.dbs.*;
public class Xou_cfg_tbl implements Db_tbl {
public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_key, fld_usr, fld_ctx, fld_val;
public Xou_cfg_tbl(Db_conn conn) {
this.conn = conn;
this.fld_usr = flds.Add_int ("cfg_usr"); // EX: 1=anonymous; others will require usr_regy
this.fld_ctx = flds.Add_str ("cfg_ctx", 1024); // EX: "app"; "en.w"
this.fld_key = flds.Add_str ("cfg_key", 1024); // EX: "xowa.net.web_enabled"
this.fld_val = flds.Add_str ("cfg_val", 4096); // EX: "y"
conn.Rls_reg(this);
}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public String Tbl_name() {return tbl_name;} private final String tbl_name = "user_cfg";
public void Create_tbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, fld_key, fld_key)
));
}
public void Upsert(boolean insert, int usr, String ctx, String key, String val) {
if (insert)
Insert(usr, ctx, key, val);
else
Update(usr, ctx, key, val);
}
private void Insert(int usr, String ctx, String key, String val) {
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
stmt.Clear().Val_int(fld_usr, usr).Val_str(fld_ctx, ctx).Val_str(fld_key, key).Val_str(fld_val, val).Exec_insert();
stmt.Rls();
}
private void Update(int usr, String ctx, String key, String val) {
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_usr, fld_ctx, fld_key), fld_val);
stmt.Clear().Val_str(fld_val, val).Crt_int(fld_usr, usr).Crt_str(fld_ctx, ctx).Crt_str(fld_key, key).Exec_update();
stmt.Rls();
}
public Xou_cfg_itm[] Select_by_usr_ctx(int usr, String ctx) {
List_adp list = List_adp_.New();
Db_stmt stmt_select = conn.Stmt_select(tbl_name, flds, fld_usr, fld_ctx);
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_usr, usr).Crt_str(fld_ctx, ctx).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
list.Add(Make_itm(rdr));
}
} finally {rdr.Rls();}
return (Xou_cfg_itm[])list.To_ary_and_clear(Xou_cfg_itm.class);
}
public void Rls() {}
private Xou_cfg_itm Make_itm(Db_rdr rdr) {
return new Xou_cfg_itm(rdr.Read_int(fld_usr), rdr.Read_str(fld_ctx), rdr.Read_str(fld_key), rdr.Read_str(fld_val));
}
}