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

@@ -1,26 +0,0 @@
/*
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.fsdb; import gplx.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*;
public class Fsdb_db_file {
public Fsdb_db_file(Io_url url, Db_conn conn) {
this.url = url; this.conn = conn;
this.tbl__core_cfg = gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn);
}
public Io_url Url() {return url;} private final Io_url url;
public Db_conn Conn() {return conn;} private final Db_conn conn;
public Db_cfg_tbl Tbl__cfg() {return tbl__core_cfg;} private final Db_cfg_tbl tbl__core_cfg;
}

View File

@@ -1,28 +0,0 @@
/*
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.fsdb; import gplx.*;
import gplx.dbs.*; import gplx.xowa.files.origs.*;
public interface Fsdb_db_mgr {
boolean File__schema_is_1();
boolean File__solo_file();
String File__cfg_tbl_name();
Xof_orig_tbl[] File__orig_tbl_ary();
Fsdb_db_file File__mnt_file();
Fsdb_db_file File__abc_file__at(int mnt_id);
Fsdb_db_file File__atr_file__at(int mnt_id);
Fsdb_db_file File__bin_file__at(int mnt_id, int bin_id, String file_name);
Fsdb_db_file File__bin_file__new(int mnt_id, String file_name);
}

View File

@@ -1,78 +0,0 @@
/*
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.fsdb; import gplx.*;
import gplx.dbs.*; import gplx.xowa.*; import gplx.xowa.wikis.data.*; import gplx.fsdb.meta.*;
public class Fsdb_db_mgr_ {
public static Fsdb_db_mgr new_detect(Xow_wiki wiki, Io_url wiki_dir, Io_url file_dir) {
Gfo_usr_dlg usr_dlg = Xoa_app_.Usr_dlg();
Io_url url = file_dir.GenSubFil(Fsdb_db_mgr__v1.Mnt_name); // EX: /xowa/file/en.wikipedia.org/wiki.mnt.sqlite3
if (Db_conn_bldr.Instance.Exists(url)) { // NOTE: check v1 before v2; note that as of v2.5.4, v2 files are automatically created on new import; DATE:2015-06-09
usr_dlg.Log_many("", "", "fsdb.db_core.v1: url=~{0}", url.Raw());
usr_dlg.Log_many("", "", "fsdb.db_core.v1 exists: orig=~{0} abc=~{1} atr_a=~{2}, atr_b=~{3}"
, Db_conn_bldr.Instance.Exists(file_dir.GenSubFil(Fsdb_db_mgr__v1.Orig_name))
, Db_conn_bldr.Instance.Exists(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_main, Fsdb_db_mgr__v1.Abc_name))
, Db_conn_bldr.Instance.Exists(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_main, Fsdb_db_mgr__v1.Atr_name_v1a))
, Db_conn_bldr.Instance.Exists(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_main, Fsdb_db_mgr__v1.Atr_name_v1b))
);
return new Fsdb_db_mgr__v1(file_dir);
}
// FOLDER.RENAME: handle renamed folders; EX:"/wiki/en.wikipedia.org-2016-12" DATE:2017-02-01
String domain_str = wiki.Domain_str();
try {
String cfg_domain_str = wiki.Data__core_mgr().Db__core().Tbl__cfg().Select_str_or("xowa.bldr.session", "wiki_domain", domain_str);
if (!String_.Eq(domain_str, cfg_domain_str)) {
Gfo_usr_dlg_.Instance.Note_many("", "", "fsdb.db_core.init: fsys.domain doesn't match db.domain; fsys=~{0} db=~{1}", domain_str, cfg_domain_str);
domain_str = cfg_domain_str;
}
} catch (Exception e) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "fsdb.db_core.init: failed to get domain from config; err=~{0}", Err_.Message_gplx_log(e));
}
Fsdb_db_mgr rv = null;
rv = load_or_null(Xow_db_layout.Itm_few, usr_dlg, wiki_dir, wiki, domain_str); if (rv != null) return rv;
rv = load_or_null(Xow_db_layout.Itm_lot, usr_dlg, wiki_dir, wiki, domain_str); if (rv != null) return rv;
rv = load_or_null(Xow_db_layout.Itm_all, usr_dlg, wiki_dir, wiki, domain_str); if (rv != null) return rv;
usr_dlg.Log_many("", "", "fsdb.db_core.none: wiki_dir=~{0} file_dir=~{1}", wiki_dir.Raw(), file_dir.Raw());
return null;
}
private static Fsdb_db_mgr load_or_null(Xow_db_layout layout, Gfo_usr_dlg usr_dlg, Io_url wiki_dir, Xow_wiki wiki, String domain_str) {
Io_url main_core_url = wiki_dir.GenSubFil(Fsdb_db_mgr__v2_bldr.Main_core_name(layout, domain_str));
if (!Db_conn_bldr.Instance.Exists(main_core_url)) return null;
usr_dlg.Log_many("", "", "fsdb.db_core.v2: type=~{0} url=~{1}", layout.Key(), main_core_url.Raw());
Db_conn main_core_conn = Db_conn_bldr.Instance.Get(main_core_url);
if (wiki.Data__core_mgr().Props().Layout_file().Tid_is_all()) {
return new Fsdb_db_mgr__v2(Fsdb_db_mgr__v2.Cfg__layout_file__get(main_core_conn), wiki_dir, new Fsdb_db_file(main_core_url, main_core_conn), new Fsdb_db_file(main_core_url, main_core_conn));
}
Io_url user_core_url = wiki_dir.GenSubFil(Fsdb_db_mgr__v2_bldr.Make_user_name(domain_str));
if (!Db_conn_bldr.Instance.Exists(user_core_url)) { // if user file does not exist, create it; needed b/c offline packages don't include file; DATE:2015-04-19
try {Fsdb_db_mgr__v2_bldr.Make_core_file_user(wiki, user_core_url, user_core_url.NameAndExt(), main_core_url.NameAndExt());}
catch (Exception e) { // do not fail if read-only permissions
usr_dlg.Warn_many("", "", "failed to create user db: url=~{0} err=~{1}", user_core_url.Raw(), Err_.Message_gplx_log(e));
user_core_url = null; // null out for conditional below
}
}
Db_conn user_core_conn = null;
if (user_core_url == null) { // null when write permissions do not exist; for example, on Andriod; DATE:2016-04-22
user_core_url = main_core_url; // default to main_core; note that downloading will still fail, but at least app won't crash; DATE:2016-04-22
user_core_conn = main_core_conn;
}
else {
user_core_conn = Db_conn_bldr.Instance.Get(user_core_url);
}
return new Fsdb_db_mgr__v2(Fsdb_db_mgr__v2.Cfg__layout_file__get(main_core_conn), wiki_dir, new Fsdb_db_file(main_core_url, main_core_conn), new Fsdb_db_file(user_core_url, user_core_conn));
}
}

View File

@@ -1,111 +0,0 @@
/*
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.fsdb; import gplx.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.fsdb.meta.*; import gplx.fsdb.data.*; import gplx.xowa.files.origs.*;
public class Fsdb_db_mgr__v1 implements Fsdb_db_mgr {
private final Io_url file_dir;
private final Fsdb_db_file orig_file, mnt_file, abc_file__main, abc_file__user, atr_file__main, atr_file__user;
private final Xof_orig_tbl[] orig_tbl_ary;
private String bin_prefix__main = "fsdb.bin.", bin_prefix__user = "fsdb.bin.";
public Fsdb_db_mgr__v1(Io_url file_dir) {
this.file_dir = file_dir;
this.orig_file = get_db(file_dir.GenSubFil(Orig_name)); // EX: /xowa/enwiki/wiki.orig#00.sqlite3
this.mnt_file = get_db(file_dir.GenSubFil(Mnt_name)); // EX: /xowa/enwiki/wiki.mnt.sqlite3
this.abc_file__main = get_db(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_main, Abc_name)); // EX: /xowa/enwiki/fsdb.main/fsdb.abc.sqlite3
this.atr_file__main = get_db(Get_atr_db_url(Bool_.Y, file_dir, Fsm_mnt_tbl.Mnt_name_main)); // EX: /xowa/enwiki/fsdb.main/fsdb.atr.00.sqlite3
if (Db_conn_bldr.Instance.Get(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_user, Abc_name)) == null) // user doesn't exist; create; DATE:2015-04-20
Fsdb_db_mgr__v1_bldr.Instance.Make_core_dir(file_dir, Fsm_mnt_mgr.Mnt_idx_user, Fsm_mnt_tbl.Mnt_name_user);
this.abc_file__user = get_db(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_user, Abc_name)); // EX: /xowa/enwiki/fsdb.user/fsdb.abc.sqlite3
this.atr_file__user = get_db(Get_atr_db_url(Bool_.N, file_dir, Fsm_mnt_tbl.Mnt_name_user)); // EX: /xowa/enwiki/fsdb.user/fsdb.atr.00.sqlite3
this.orig_tbl_ary = new Xof_orig_tbl[] {new Xof_orig_tbl(orig_file.Conn(), this.File__schema_is_1())};
}
public boolean File__schema_is_1() {return Bool_.Y;}
public boolean File__solo_file() {return Bool_.N;}
public String File__cfg_tbl_name() {return "fsdb_cfg";}
public Xof_orig_tbl[] File__orig_tbl_ary() {return orig_tbl_ary;}
public Fsdb_db_file File__mnt_file() {return mnt_file;}
public Fsdb_db_file File__abc_file__at(int mnt_id) {return mnt_id == Fsm_mnt_mgr.Mnt_idx_main ? abc_file__main : abc_file__user;}
public Fsdb_db_file File__atr_file__at(int mnt_id) {return mnt_id == Fsm_mnt_mgr.Mnt_idx_main ? atr_file__main : atr_file__user;}
public Fsdb_db_file File__bin_file__at(int mnt_id, int bin_id, String file_name) {
boolean mnt_is_main = mnt_id == Fsm_mnt_mgr.Mnt_idx_main;
String bin_name = (mnt_is_main ? bin_prefix__main : bin_prefix__user) + Int_.To_str_pad_bgn_zero(bin_id, 4) + ".sqlite3";
String mnt_name = mnt_is_main ? Fsm_mnt_tbl.Mnt_name_main : Fsm_mnt_tbl.Mnt_name_user;
Io_url url = file_dir.GenSubFil_nest(mnt_name, bin_name); // EX: /xowa/enwiki/fsdb.main/fsdb.bin.0000.sqlite3
Db_conn conn = Db_conn_bldr.Instance.Get(url);
if (conn == null) { // NOTE: handle wikis with missing bin files; EX:sv.w missing bin.0010; DATE:2015-07-04
gplx.xowa.Xoa_app_.Usr_dlg().Warn_many("", "", "fsdb.v1: missing db; db=~{0}", url.Raw());
return Fsdb_db_mgr__v1_bldr.Instance.new_db__bin(url);
}
else
return new Fsdb_db_file(url, conn);
}
public Fsdb_db_file File__bin_file__new(int mnt_id, String file_name) {
String mnt_name = mnt_id == Fsm_mnt_mgr.Mnt_idx_main ? Fsm_mnt_tbl.Mnt_name_main : Fsm_mnt_tbl.Mnt_name_user;
Io_url url = file_dir.GenSubFil_nest(mnt_name, file_name); // EX: /xowa/enwiki/fsdb.main/fsdb.bin.0000.sqlite3
Db_conn conn = Db_conn_bldr.Instance.New(url);
Fsd_bin_tbl bin_tbl = new Fsd_bin_tbl(conn, Bool_.Y); bin_tbl.Create_tbl();
return new Fsdb_db_file(url, conn);
}
private Io_url Get_atr_db_url(boolean main, Io_url file_dir, String mnt_name) {
Io_url rv = null;
rv = file_dir.GenSubFil_nest(mnt_name, Atr_name_v1a);
if (Io_mgr.Instance.ExistsFil(rv)) {
if (main)
bin_prefix__main = "fsdb.bin#";
else
bin_prefix__user = "fsdb.bin#";
return rv;
}
rv = file_dir.GenSubFil_nest(mnt_name, Atr_name_v1b); if (Io_mgr.Instance.ExistsFil(rv)) return rv;
throw Err_.new_wo_type("could not find atr file", "dir", file_dir.Raw(), "mnt", mnt_name);
}
public static final String Orig_name = "wiki.orig#00.sqlite3", Mnt_name = "wiki.mnt.sqlite3", Abc_name = "fsdb.abc.sqlite3"
, Atr_name_v1a = "fsdb.atr#00.sqlite3", Atr_name_v1b = "fsdb.atr.00.sqlite3";
private static Fsdb_db_file get_db(Io_url file) {
Db_conn conn = Db_conn_bldr.Instance.Get(file);
if (conn == null) conn = Db_conn_.Noop;
return new Fsdb_db_file(file, conn);
}
}
class Fsdb_db_mgr__v1_bldr {
public void Make_core_dir(Io_url file_dir, int mnt_id, String mnt_name) {
boolean schema_is_1 = true;
Io_url mnt_dir = file_dir.GenSubDir(mnt_name);
// make abc_fil
Fsdb_db_file db_abc = new_db(mnt_dir.GenSubFil(Fsdb_db_mgr__v1.Abc_name));
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(db_abc.Conn(), "fsdb_cfg"); cfg_tbl.Create_tbl();
Fsm_mnt_mgr.Patch(cfg_tbl);
Fsm_atr_tbl dba_tbl = new Fsm_atr_tbl(db_abc.Conn(), schema_is_1); dba_tbl.Create_tbl();
dba_tbl.Insert(mnt_id, mnt_name);
Fsm_bin_tbl dbb_tbl = new Fsm_bin_tbl(db_abc.Conn(), schema_is_1, mnt_id); dbb_tbl.Create_tbl();
dbb_tbl.Insert(0, "fsdb.bin.0000.sqlite3");
// make atr_fil
Fsdb_db_file db_atr = new_db(mnt_dir.GenSubFil(Fsdb_db_mgr__v1.Atr_name_v1b)); // create atr database in v1b style; "fsdb.atr.00.sqlite3" not "fsdb.atr#00.sqlite3"
Fsd_dir_tbl dir_tbl = new Fsd_dir_tbl(db_atr.Conn(), schema_is_1); dir_tbl.Create_tbl();
Fsd_fil_tbl fil_tbl = new Fsd_fil_tbl(db_atr.Conn(), schema_is_1, mnt_id); fil_tbl.Create_tbl();
Fsd_thm_tbl thm_tbl = new Fsd_thm_tbl(db_atr.Conn(), schema_is_1, mnt_id, Bool_.Y); thm_tbl.Create_tbl();
// make bin_fil
new_db__bin(mnt_dir.GenSubFil("fsdb.bin.0000.sqlite3"));
}
private Fsdb_db_file new_db(Io_url url) {return new Fsdb_db_file(url, Db_conn_bldr.Instance.New(url));}
public Fsdb_db_file new_db__bin(Io_url url) {
Fsdb_db_file rv = new_db(url);
Fsd_bin_tbl bin_tbl = new Fsd_bin_tbl(rv.Conn(), true); // NOTE: schema_is_1 is always true b/c it is in Fsdb_db_mgr__v1_bldr
bin_tbl.Create_tbl();
return rv;
}
public static final Fsdb_db_mgr__v1_bldr Instance = new Fsdb_db_mgr__v1_bldr(); Fsdb_db_mgr__v1_bldr() {}
}

View File

@@ -1,64 +0,0 @@
/*
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.fsdb; import gplx.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.fsdb.meta.*; import gplx.xowa.files.origs.*; import gplx.xowa.wikis.data.*;
public class Fsdb_db_mgr__v2 implements Fsdb_db_mgr {
private final Xow_db_layout layout; private final Io_url wiki_dir;
private final Fsdb_db_file file_main_core, file_user_core;
private final Xof_orig_tbl[] orig_tbl_ary;
public Fsdb_db_mgr__v2(Xow_db_layout layout, Io_url wiki_dir, Fsdb_db_file file_main_core, Fsdb_db_file file_user_core) {
this.layout = layout; this.wiki_dir = wiki_dir;
this.file_main_core = file_main_core; this.file_user_core = file_user_core;
this.orig_tbl_ary = new Xof_orig_tbl[]
{ new Xof_orig_tbl(file_main_core.Conn(), this.File__schema_is_1())
, new Xof_orig_tbl(file_user_core.Conn(), this.File__schema_is_1())
};
}
public boolean File__schema_is_1() {return Bool_.N;}
public boolean File__solo_file() {return layout.Tid_is_all_or_few();}
public String File__cfg_tbl_name() {return gplx.xowa.wikis.data.Xowd_cfg_tbl_.Tbl_name;}
public Xof_orig_tbl[] File__orig_tbl_ary() {return orig_tbl_ary;}
public Fsdb_db_file File__mnt_file() {return file_main_core;}
public Fsdb_db_file File__abc_file__at(int mnt_id) {return mnt_id == Fsm_mnt_mgr.Mnt_idx_main ? file_main_core: file_user_core;}
public Fsdb_db_file File__atr_file__at(int mnt_id) {return mnt_id == Fsm_mnt_mgr.Mnt_idx_main ? file_main_core: file_user_core;}
public Fsdb_db_file File__bin_file__at(int mnt_id, int bin_id, String file_name) {
if (mnt_id == Fsm_mnt_mgr.Mnt_idx_user) return file_user_core;
if (layout.Tid_is_all_or_few()) return file_main_core;
Io_url url = wiki_dir.GenSubFil(file_name);
Db_conn conn = Db_conn_bldr.Instance.Get(url);
if (conn == null) { // bin file deleted or not downloaded; use Noop Db_conn and continue; do not fail; DATE:2015-04-16
Gfo_usr_dlg_.Instance.Warn_many("", "", "fsdb.bin:file does not exist; url=~{0}", url);
conn = Db_conn_.Noop;
}
return new Fsdb_db_file(url, conn);
}
public Fsdb_db_file File__bin_file__new(int mnt_id, String file_name) {
if (mnt_id == Fsm_mnt_mgr.Mnt_idx_user) return Fsdb_db_mgr__v2_bldr.Make_bin_tbl(file_user_core);
if (layout.Tid_is_all_or_few()) return Fsdb_db_mgr__v2_bldr.Make_bin_tbl(file_main_core);
Io_url url = wiki_dir.GenSubFil(file_name);
Db_conn conn = Db_conn_bldr.Instance.New(url);
gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn).Create_tbl();
return Fsdb_db_mgr__v2_bldr.Make_bin_tbl(new Fsdb_db_file(url, conn));
}
public static Xow_db_layout Cfg__layout_file__get(Db_conn main_core_conn) {
Db_cfg_tbl cfg_tbl = gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(main_core_conn);
return Xow_db_layout.Get_by_name(cfg_tbl.Select_str_or(gplx.xowa.wikis.data.Xowd_cfg_key_.Grp__bldr_fsdb, Cfg_key__layout_file, Xow_db_layout.Key__few));
}
public static void Cfg__layout_file__set(Db_cfg_tbl cfg_tbl, Xow_db_layout v) {
cfg_tbl.Insert_str(gplx.xowa.wikis.data.Xowd_cfg_key_.Grp__bldr_fsdb, Cfg_key__layout_file, v.Key());
}
private static final String Cfg_key__layout_file = "layout_file";
}

View File

@@ -1,110 +0,0 @@
/*
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.fsdb; import gplx.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.fsdb.meta.*; import gplx.fsdb.data.*; import gplx.xowa.files.origs.*;
import gplx.xowa.*; import gplx.xowa.wikis.data.*; import gplx.xowa.bldrs.infos.*;
public class Fsdb_db_mgr__v2_bldr {
public static Fsdb_db_mgr__v2 Get_or_make(Xow_wiki wiki, boolean delete_if_exists) { // NOTE: must check if file exists else imports with existing v2 dbs will fail; DATE:2015-05-23
Xow_db_layout layout = wiki.Data__core_mgr().Props().Layout_file();
String domain_str = wiki.Domain_str();
Io_url wiki_dir = wiki.Fsys_mgr().Root_dir();
String main_core_name = Main_core_name(layout, domain_str);
String user_core_name = Make_user_name(domain_str);
Io_url main_core_url = wiki_dir.GenSubFil(main_core_name);
Io_url user_core_url = wiki_dir.GenSubFil(user_core_name);
if (delete_if_exists) {
Db_conn_bldr.Instance.Get_or_noop(main_core_url).Rls_conn();
Db_conn_bldr.Instance.Get_or_noop(user_core_url).Rls_conn();
Io_mgr.Instance.DeleteFil(main_core_url);
Io_mgr.Instance.DeleteFil(user_core_url);
}
Fsdb_db_file main_core_file = Io_mgr.Instance.ExistsFil(main_core_url) ? Load_core_file(main_core_url) : Make_core_file_main(wiki, main_core_url, main_core_name, layout);
Fsdb_db_file user_core_file = Io_mgr.Instance.ExistsFil(user_core_url) ? Load_core_file(user_core_url) : Make_core_file_user(wiki, user_core_url, user_core_name, main_core_name);
return new Fsdb_db_mgr__v2(layout, wiki_dir, main_core_file, user_core_file);
}
private static Fsdb_db_file Load_core_file(Io_url url) {return new Fsdb_db_file(url, Db_conn_bldr.Instance.Get(url));}
public static Fsdb_db_file Make_core_file_main(Xow_wiki wiki, Io_url main_core_url, String main_core_name, Xow_db_layout layout) {
Db_conn conn = layout.Tid_is_all() ? Db_conn_bldr.Instance.Get(main_core_url) : Db_conn_bldr.Instance.New(main_core_url); // if all, use existing (assumes same file name); else, create new
conn.Txn_bgn("fsdb__core_file");
Fsdb_db_file rv = Make_core_file(main_core_url, conn, schema_is_1, Fsm_mnt_mgr.Mnt_idx_main);
if (!layout.Tid_is_all()) // do not make cfg data if all
Make_cfg_data(wiki, main_core_name, rv, Main_core_tid(layout), -1);
Fsdb_db_mgr__v2.Cfg__layout_file__set(rv.Tbl__cfg(), layout);
conn.Txn_end();
return rv;
}
public static Fsdb_db_file Make_core_file_user(Xow_wiki wiki, Io_url user_core_url, String user_file_name, String main_core_name) { // always create file; do not create mnt_tbl;
Db_conn conn = Db_conn_bldr.Instance.New(user_core_url);
conn.Txn_bgn("fsdb__core_user");
Fsdb_db_file rv = Make_core_file(user_core_url, conn, schema_is_1, Fsm_mnt_mgr.Mnt_idx_user);
Fsm_bin_tbl dbb_tbl = new Fsm_bin_tbl(conn, schema_is_1, Fsm_mnt_mgr.Mnt_idx_user); dbb_tbl.Insert(0, user_file_name);
Make_bin_tbl(rv);
Make_cfg_data(wiki, main_core_name, rv, Xow_db_file_.Tid__file_user, -1);
conn.Txn_end();
return rv;
}
private static Fsdb_db_file Make_core_file(Io_url core_url, Db_conn core_conn, boolean schema_is_1, int mnt_id) {
Fsdb_db_file rv = new Fsdb_db_file(core_url, core_conn);
Db_cfg_tbl cfg_tbl = rv.Tbl__cfg();
cfg_tbl.Create_tbl();
Fsm_mnt_mgr.Patch(cfg_tbl);
Fsm_mnt_mgr.Patch_core(cfg_tbl);
Xof_orig_tbl orig_tbl = new Xof_orig_tbl(core_conn, schema_is_1); orig_tbl.Create_tbl();
if (mnt_id == Fsm_mnt_mgr.Mnt_idx_main) {
Fsm_mnt_tbl mnt_tbl = new Fsm_mnt_tbl(core_conn, schema_is_1); mnt_tbl.Create_tbl();
cfg_tbl.Insert_int("core", "mnt.insert_idx", Fsm_mnt_mgr.Mnt_idx_user);
}
Fsm_atr_tbl dba_tbl = new Fsm_atr_tbl(core_conn, schema_is_1); dba_tbl.Create_tbl();
dba_tbl.Insert(mnt_id, core_url.NameAndExt());
Fsm_bin_tbl dbb_tbl = new Fsm_bin_tbl(core_conn, schema_is_1, mnt_id); dbb_tbl.Create_tbl();
Fsd_dir_tbl dir_tbl = new Fsd_dir_tbl(core_conn, schema_is_1); dir_tbl.Create_tbl();
Fsd_fil_tbl fil_tbl = new Fsd_fil_tbl(core_conn, schema_is_1, mnt_id); fil_tbl.Create_tbl();
Fsd_thm_tbl thm_tbl = new Fsd_thm_tbl(core_conn, schema_is_1, mnt_id, Bool_.Y); thm_tbl.Create_tbl();
return rv;
}
public static Fsdb_db_file Make_bin_tbl(Fsdb_db_file file) {
Fsd_bin_tbl bin_tbl = new Fsd_bin_tbl(file.Conn(), schema_is_1); bin_tbl.Create_tbl();
return file;
}
public static String Main_core_name(Xow_db_layout layout, String wiki_domain) {
switch (layout.Tid()) {
case Xow_db_layout.Tid__all: return Main_core_name_all(wiki_domain);
case Xow_db_layout.Tid__few: return Main_core_name_few(wiki_domain);
case Xow_db_layout.Tid__lot: return Main_core_name_lot(wiki_domain);
default: throw Err_.new_unimplemented();
}
}
private static byte Main_core_tid(Xow_db_layout layout) {
switch (layout.Tid()) {
case Xow_db_layout.Tid__all: return Xow_db_file_.Tid__core;
case Xow_db_layout.Tid__few: return Xow_db_file_.Tid__file_solo;
case Xow_db_layout.Tid__lot: return Xow_db_file_.Tid__file_core;
default: throw Err_.new_unimplemented();
}
}
public static void Make_cfg_data(Xow_wiki wiki, String file_core_name, Fsdb_db_file file, byte file_tid, int part_id) {
Db_cfg_tbl cfg_tbl = file.Tbl__cfg();
Xow_db_file core_db = wiki.Data__core_mgr().Db__core();
core_db.Info_session().Save(cfg_tbl);
Xob_info_file info_file = new Xob_info_file(-1, Xow_db_file_.To_key(file_tid), Xob_info_file.Ns_ids_empty, part_id, Guid_adp_.New(), 2, file_core_name, file.Url().NameAndExt());
info_file.Save(cfg_tbl);
}
private static String Main_core_name_all(String wiki_domain) {return wiki_domain + ".xowa";} // EX: en.wikipedia.org.xowa
private static String Main_core_name_few(String wiki_domain) {return wiki_domain + "-file.xowa";} // EX: en.wikipedia.org-file.xowa
private static String Main_core_name_lot(String wiki_domain) {return wiki_domain + "-file-core.xowa";} // EX: en.wikipedia.org-file-core.xowa
public static String Make_user_name(String wiki_domain) {return wiki_domain + "-file-user.xowa";} // EX: en.wikipedia.org-file-user.xowa
private static final boolean schema_is_1 = false;
}

View File

@@ -13,20 +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.fsdb.data; import gplx.*; import gplx.fsdb.*;
public class Fsd_bin_itm {
public Fsd_bin_itm(int bin_owner_id, byte bin_owner_tid, int bin_part_id, String bin_data_url, byte[] bin_data) {
this.bin_owner_id = bin_owner_id;
this.bin_owner_tid = bin_owner_tid;
this.bin_part_id = bin_part_id;
this.bin_data_url = bin_data_url;
this.bin_data = bin_data;
}
public int Bin_owner_id() {return bin_owner_id;} private final int bin_owner_id;
public byte Bin_owner_tid() {return bin_owner_tid;} private final byte bin_owner_tid;
public int Bin_part_id() {return bin_part_id;} private final int bin_part_id;
public String Bin_data_url() {return bin_data_url;} private final String bin_data_url;
public byte[] Bin_data() {return bin_data;} private final byte[] bin_data;
public static final int Db_row_size_fixed = (3 * 4); // bin_owner_id, bin_part_id, bin_owner_tid (assume byte saved as int in SQLITE)
}

View File

@@ -13,108 +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.fsdb.data; import gplx.*; import gplx.fsdb.*;
import gplx.core.primitives.*; import gplx.core.envs.*;
import gplx.dbs.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
import gplx.dbs.engines.sqlite.*;
public class Fsd_bin_tbl implements Rls_able {
public final String fld__owner_id, fld__owner_tid, fld__part_id, fld__data_url, fld__data;
private Db_conn conn; private Db_stmt stmt_insert, stmt_select, stmt_select_itm; private Bry_bfr tmp_bfr;
private final Bool_obj_ref saved_in_parts = Bool_obj_ref.n_();
public Fsd_bin_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
fld__owner_id = flds.Add_int_pkey ("bin_owner_id");
fld__owner_tid = flds.Add_byte ("bin_owner_tid");
fld__part_id = flds.Add_int ("bin_part_id");
fld__data_url = flds.Add_str ("bin_data_url", 255);
fld__data = flds.Add_bry ("bin_data"); // mediumblob
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name = "fsdb_bin";
public Dbmeta_fld_list Flds() {return flds;} private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_select_itm = Db_stmt_.Rls(stmt_select_itm);
}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Insert_bgn() {conn.Txn_bgn("fsdb_bin__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_commit() {conn.Txn_sav();}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_rdr(int id, byte tid, long bin_len, Io_stream_rdr bin_rdr) {
if (stmt_insert == null) {
stmt_insert = conn.Stmt_insert(tbl_name, flds);
tmp_bfr = Bry_bfr_.Reset(Io_mgr.Len_kb);
}
byte[] bin_ary = Io_stream_rdr_.Load_all_as_bry(tmp_bfr, bin_rdr);
stmt_insert.Clear()
.Val_int(fld__owner_id, id)
.Val_byte(fld__owner_tid, tid)
.Val_int(fld__part_id, Part_id_null)
.Val_str(fld__data_url, Data_url_null)
.Val_bry(fld__data, bin_ary)
.Exec_insert();
}
public void Update(Db_stmt stmt, int id, byte[] data) {
stmt.Clear().Val_bry(fld__data, data).Crt_int(fld__owner_id, id).Exec_update();
}
public Io_stream_rdr Select_as_rdr(int owner_id) {
byte[] rv = Select(owner_id, null);
return rv == null
? Io_stream_rdr_.Noop
: Io_stream_rdr_.New__mem(rv);
}
public boolean Select_to_url(int owner_id, Io_url url) {
saved_in_parts.Val_n();
byte[] rv = Select(owner_id, url);
if (rv == null) return false;
if (saved_in_parts.Val_y()) return true;
Io_mgr.Instance.SaveFilBry(url, rv);
return true;
}
private byte[] Select(int owner_id, Io_url url) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, String_.Ary(fld__data), fld__owner_id);
Db_rdr rdr = stmt_select.Clear().Crt_int(fld__owner_id, owner_id).Exec_select__rls_manual();
try {
if (rdr.Move_next()) {
byte[] rv = null;
try {rv = rdr.Read_bry(fld__data);}
catch (Exception e) {
if ( Op_sys.Cur().Tid_is_drd() // drd error when selecting large blobs (> 4 MB?)
&& url != null // called by Select_to_url
&& String_.Has(Err_.Message_lang(e), "get field slot from row") // get field slot from row 0 col 0 failed
) {
rdr.Save_bry_in_parts(url, tbl_name, fld__data, fld__owner_id, owner_id);
saved_in_parts.Val_y_();
}
}
return rv == null ? Bry_.Empty : rv; // NOTE: bug in v0.10.1 where .ogg would save as null; return Bry_.Empty instead, else java.io.ByteArrayInputStream would fail on null
}
else
return null;
}
finally {rdr.Rls();}
}
public Fsd_bin_itm Select_as_itm(int owner_id) {
if (stmt_select_itm == null) stmt_select_itm = conn.Stmt_select(tbl_name, flds, fld__owner_id);
Db_rdr rdr = stmt_select_itm.Clear().Crt_int(fld__owner_id, owner_id).Exec_select__rls_manual();
try {
if (rdr.Move_next()) {
return new Fsd_bin_itm
( rdr.Read_int(fld__owner_id)
, rdr.Read_byte(fld__owner_tid)
, rdr.Read_int(fld__part_id)
, rdr.Read_str(fld__data_url)
, rdr.Read_bry(fld__data)
);
}
else
return null;
}
finally {rdr.Rls();}
}
public static final byte Owner_tid_fil = 1, Owner_tid_thm = 2;
public static final int Bin_db_id_null = -1, Size_null = -1;
private static final int Part_id_null = -1;
private static final String Data_url_null = "";
}

View File

@@ -13,17 +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.fsdb.data; import gplx.*; import gplx.fsdb.*;
public class Fsd_dir_itm {
public Fsd_dir_itm(int dir_id, int owner, byte[] name) {
this.dir_id = dir_id;
this.owner = owner;
this.name = name;
}
public int Dir_id() {return dir_id;} private final int dir_id;
public int Owner() {return owner;} private final int owner;
public byte[] Name() {return name;} private final byte[] name;
public static final int Owner_root = 0;
public static final Fsd_dir_itm Null = null;
}

View File

@@ -13,55 +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.fsdb.data; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*;
public class Fsd_dir_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_id, fld_owner_id, fld_name;
private final Db_conn conn; private Db_stmt stmt_select_by_name;
public Fsd_dir_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
this.fld_id = flds.Add_int_pkey ("dir_id");
this.fld_owner_id = flds.Add_int ("dir_owner_id");
this.fld_name = flds.Add_str ("dir_name", 255);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name = "fsdb_dir";
public void Create_tbl() {
conn.Meta_tbl_create
( Dbmeta_tbl_itm.New(tbl_name, flds
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "name", fld_name, fld_owner_id, fld_id)));
}
public void Insert(int id, byte[] name, int owner_id) {
Db_stmt stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear()
.Val_int(fld_id, id)
.Val_int(fld_owner_id, owner_id)
.Val_bry_as_str(fld_name, name)
.Exec_insert();
stmt_insert.Rls();
}
public void Update(int id, byte[] name, int owner_id) {
Db_stmt stmt_update = conn.Stmt_update_exclude(tbl_name, flds, fld_id);
stmt_update.Clear()
.Val_int(fld_owner_id, owner_id)
.Val_bry_as_str(fld_name, name)
.Crt_int(fld_id, id)
.Exec_update();
stmt_update.Rls();
}
public Fsd_dir_itm Select_or_null(byte[] name) {
if (stmt_select_by_name == null) stmt_select_by_name = conn.Stmt_select(tbl_name, flds, fld_name);
Db_rdr rdr = stmt_select_by_name.Clear().Crt_bry_as_str(fld_name, name).Exec_select__rls_manual();
try {
return rdr.Move_next()
? new Fsd_dir_itm(rdr.Read_int(fld_id), rdr.Read_int(fld_owner_id), name)
: Fsd_dir_itm.Null
;
}
finally {rdr.Rls();}
}
public void Rls() {
stmt_select_by_name = Db_stmt_.Rls(stmt_select_by_name);
}
}

View File

@@ -13,33 +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.fsdb.data; import gplx.*; import gplx.fsdb.*;
public class Fsd_fil_itm {
public Fsd_fil_itm (int mnt_id, int dir_id, int fil_id, int xtn_id, int ext_id, byte[] name, long size, String modified_on, String hash_md5, int bin_db_id) {
this.mnt_id = mnt_id; this.dir_id = dir_id; this.fil_id = fil_id; this.xtn_id = xtn_id; this.ext_id = ext_id;
this.name = name; this.size = size; this.modified_on = modified_on; this.hash_md5 = hash_md5; this.bin_db_id = bin_db_id;
}
public int Mnt_id() {return mnt_id;} private final int mnt_id;
public int Dir_id() {return dir_id;} private final int dir_id;
public int Fil_id() {return fil_id;} private final int fil_id;
public int Xtn_id() {return xtn_id;} private final int xtn_id;
public int Ext_id() {return ext_id;} private final int ext_id;
public byte[] Name() {return name;} private final byte[] name;
public long Size() {return size;} private final long size;
public String Modified_on() {return modified_on;} private final String modified_on;
public String Hash_md5() {return hash_md5;} private final String hash_md5;
public int Bin_db_id() {return bin_db_id;} private final int bin_db_id;
public int Db_row_size() {return Db_row_size_fixed + name.length;}
private static final int Db_row_size_fixed =
(7 * 4) // 6 int fields + 1 byte field
+ 8 // 1 long field
+ 32 // hash_md5
+ 14 // modified_on
;
public static final Fsd_fil_itm Null = null;
public static byte[] Gen_cache_key(Bry_bfr bfr, int dir_id, byte[] name) {
return bfr.Add_int_variable(dir_id).Add_byte_pipe().Add(name).To_bry_and_clear();
}
}

View File

@@ -13,106 +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.fsdb.data; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.engines.sqlite.*;
public class Fsd_fil_tbl implements Db_tbl {
public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public final String fld_id, fld_owner_id, fld_name, fld_xtn_id, fld_ext_id, fld_size, fld_modified, fld_hash, fld_bin_db_id;
private final String idx_owner;
public final Db_conn conn; private Db_stmt stmt_insert, stmt_update, stmt_select_by_name; private int mnt_id;
public Fsd_fil_tbl(Db_conn conn, boolean schema_is_1, int mnt_id) {
this.conn = conn; this.mnt_id = mnt_id;
this.fld_id = flds.Add_int_pkey ("fil_id");
this.fld_owner_id = flds.Add_int ("fil_owner_id");
this.fld_xtn_id = flds.Add_int ("fil_xtn_id");
this.fld_ext_id = flds.Add_int ("fil_ext_id");
this.fld_bin_db_id = flds.Add_int ("fil_bin_db_id"); // group ints at beginning of table
this.fld_name = flds.Add_str ("fil_name", 255);
this.fld_size = flds.Add_long ("fil_size");
this.fld_modified = flds.Add_str ("fil_modified", 14); // stored as yyyyMMddHHmmss
this.fld_hash = flds.Add_str ("fil_hash", 40);
this.idx_owner = Dbmeta_idx_itm.Bld_idx_name(tbl_name, "owner");
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name = "fsdb_fil";
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_update = Db_stmt_.Rls(stmt_update);
stmt_select_by_name = Db_stmt_.Rls(stmt_select_by_name);
}
public void Create_tbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds
, Dbmeta_idx_itm.new_unique_by_name(tbl_name, idx_owner, fld_owner_id, fld_name, fld_id)
));
}
public void Insert(int id, int owner_id, byte[] name, int xtn_id, int ext_id, long size, int bin_db_id) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
Insert(stmt_insert, id, owner_id, name, xtn_id, ext_id, size, bin_db_id, String_.Empty, String_.Empty);
}
public void Insert(Db_stmt stmt, int id, int owner_id, byte[] name, int xtn_id, int ext_id, long size, int bin_db_id, String modified_on, String hash_md5) {
stmt.Clear()
.Val_int(fld_id, id)
.Val_int(fld_owner_id, owner_id)
.Val_int(fld_xtn_id, xtn_id)
.Val_int(fld_ext_id, ext_id)
.Val_int(fld_bin_db_id, bin_db_id)
.Val_bry_as_str(fld_name, name)
.Val_long(fld_size, size)
.Val_str(fld_modified, modified_on)
.Val_str(fld_hash, hash_md5)
.Exec_insert();
}
public void Update(int id, int owner_id, byte[] name, int xtn_id, int ext_id, long size, int bin_db_id) {
if (stmt_update == null) stmt_update = conn.Stmt_update_exclude(tbl_name, flds, fld_id);
stmt_update.Clear()
.Val_int(fld_owner_id, owner_id)
.Val_int(fld_xtn_id, xtn_id)
.Val_int(fld_ext_id, ext_id)
.Val_int(fld_bin_db_id, bin_db_id)
.Val_bry_as_str(fld_name, name)
.Val_long(fld_size, size)
.Val_str(fld_modified, String_.Empty)
.Val_str(fld_hash, String_.Empty)
.Crt_int(fld_id, id)
.Exec_update();
}
public Fsd_fil_itm Select_or_null(int dir_id, byte[] fil_name) {
if (stmt_select_by_name == null) {
Db_qry__select_cmd qry = new Db_qry__select_cmd().From_(tbl_name).Cols_(flds.To_str_ary()).Where_(Db_crt_.eq_many_(fld_owner_id, fld_name)).Indexed_by_(idx_owner);
stmt_select_by_name = conn.Stmt_new(qry);
}
Db_rdr rdr = stmt_select_by_name.Clear()
.Crt_int(fld_owner_id, dir_id)
.Crt_bry_as_str(fld_name, fil_name)
.Exec_select__rls_manual();
try {
return rdr.Move_next() ? New_by_rdr(mnt_id, rdr) : Fsd_fil_itm.Null;
}
finally {rdr.Rls();}
}
public void Select_all(Bry_bfr key_bfr, gplx.core.caches.Gfo_cache_mgr_bry cache) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, Dbmeta_fld_itm.Str_ary_empty).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Fsd_fil_itm fil = New_by_rdr(mnt_id, rdr);
byte[] cache_key = Fsd_fil_itm.Gen_cache_key(key_bfr, fil.Dir_id(), fil.Name());
cache.Add(cache_key, fil);
}
}
finally {rdr.Rls();}
}
public Fsd_fil_itm New_by_rdr(int mnt_id, Db_rdr rdr) {
return new Fsd_fil_itm
( mnt_id
, rdr.Read_int(fld_owner_id)
, rdr.Read_int(fld_id)
, rdr.Read_int(fld_xtn_id)
, rdr.Read_int(fld_ext_id)
, rdr.Read_bry_by_str(fld_name)
, rdr.Read_long(fld_size)
, rdr.Read_str(fld_modified)
, rdr.Read_str(fld_hash)
, rdr.Read_int(fld_bin_db_id)
);
}
}

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.fsdb.data; import gplx.*; import gplx.fsdb.*;
public class Fsd_img_itm {
public Fsd_img_itm(int mnt_id, int dir_id, int fil_id, int bin_db_id) {
this.mnt_id = mnt_id; this.dir_id = dir_id; this.fil_id = fil_id; this.bin_db_id = bin_db_id;
}
public int Mnt_id() {return mnt_id;} private final int mnt_id;
public int Dir_id() {return dir_id;} private final int dir_id;
public int Fil_id() {return fil_id;} private final int fil_id;
public int Bin_db_id() {return bin_db_id;} private final int bin_db_id;
}

View File

@@ -13,54 +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.fsdb.data; import gplx.*; import gplx.fsdb.*;
public class Fsd_thm_itm {
public void Ctor(int mnt_id, int dir_id, int fil_id, int thm_id, int bin_db_id, int w, int h, double time, int page, long size, String modified, String hash) {
this.mnt_id = mnt_id; this.dir_id = dir_id; this.fil_id = fil_id; this.thm_id = thm_id; this.bin_db_id = bin_db_id;
this.w = w; this.h = h; this.time = time; this.page = page;
this.size = size; this.modified = modified; this.hash = hash;
}
public int Mnt_id() {return mnt_id;} private int mnt_id;
public int Dir_id() {return dir_id;} private int dir_id;
public int Fil_id() {return fil_id;} private int fil_id;
public int Thm_id() {return thm_id;} private int thm_id;
public int Bin_db_id() {return bin_db_id;} private int bin_db_id;
public int W() {return w;} private int w;
public int H() {return h;} private int h;
public double Time() {return time;} private double time;
public int Page() {return page;} private int page;
public long Size() {return size;} private long size;
public String Modified() {return modified;} private String modified;
public String Hash() {return hash;} private String hash;
public int Req_w() {return req_w;} private int req_w;
public double Req_time() {return req_time;} private double req_time;
public int Req_page() {return req_page;} private int req_page;
public void Init_by_req(int w, double time, int page) {this.w = w; this.time = time; this.page = page;}
public void Init_by_match(Fsd_thm_itm comp) {
this.req_w = w; this.req_time = time; this.req_page = page;
this.mnt_id = comp.mnt_id; this.dir_id = comp.dir_id; this.fil_id = comp.fil_id; this.thm_id = comp.thm_id; this.bin_db_id = comp.bin_db_id;
this.w = comp.w; this.h = comp.h; this.time = comp.time; this.page = comp.page;
this.size = comp.size; this.modified = comp.modified; this.hash = comp.hash;
}
public int Db_row_size() {return Db_row_size_fixed;}
private static final int Db_row_size_fixed =
(7 * 4) // 7 ints
+ (2 * 8) // 1 long; 1 double
+ 32 // hash_md5
+ 14 // modified_on
;
public static final Fsd_thm_itm Null = null;
public static final Fsd_thm_itm[] Ary_empty = new Fsd_thm_itm[0];
public static Fsd_thm_itm new_() {return new Fsd_thm_itm();} Fsd_thm_itm() {}
}
class Fsdb_thm_itm_sorter implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Fsd_thm_itm lhs = (Fsd_thm_itm)lhsObj;
Fsd_thm_itm rhs = (Fsd_thm_itm)rhsObj;
int comp = Int_.Compare (lhs.W() , rhs.W()); if (comp != CompareAble_.Same) return -comp; // sort by decreasing width
comp = Double_.Compare (lhs.Time() , rhs.Time()); if (comp != CompareAble_.Same) return comp; // sort by increasing time
return Int_.Compare (lhs.Page() , rhs.Page()); // sort by increasing page
}
public static final Fsdb_thm_itm_sorter Instance = new Fsdb_thm_itm_sorter(); Fsdb_thm_itm_sorter() {}
}

View File

@@ -13,145 +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.fsdb.data; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*; import gplx.fsdb.meta.*; import gplx.xowa.files.*;
public class Fsd_thm_tbl implements Db_tbl {
public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public final String fld_id, fld_owner_id, fld_w, fld_h, fld_time, fld_page, fld_bin_db_id, fld_size, fld_modified, fld_hash;
public final Db_conn conn; private Db_stmt stmt_insert, stmt_select_by_fil_exact, stmt_select_by_fil_near; private int mnt_id; private boolean schema_thm_page;
public Fsd_thm_tbl(Db_conn conn, boolean schema_is_1, int mnt_id, boolean schema_thm_page) {
this.conn = conn; this.mnt_id = mnt_id; this.schema_thm_page = schema_thm_page;
this.tbl_name = schema_is_1 ? "fsdb_xtn_thm" : "fsdb_thm";
this.fld_id = flds.Add_int_pkey ("thm_id");
this.fld_owner_id = flds.Add_int ("thm_owner_id");
this.fld_w = flds.Add_int ("thm_w");
this.fld_h = flds.Add_int ("thm_h");
if (schema_thm_page) {
this.fld_time = flds.Add_double ("thm_time");
this.fld_page = flds.Add_int ("thm_page");
}
else {
this.fld_time = flds.Add_int ("thm_thumbtime");
this.fld_page = Dbmeta_fld_itm.Key_null;
}
this.fld_bin_db_id = flds.Add_int ("thm_bin_db_id");
this.fld_size = flds.Add_long ("thm_size");
this.fld_modified = flds.Add_str ("thm_modified", 14); // stored as yyyyMMddHHmmss
this.fld_hash = flds.Add_str ("thm_hash", 40);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds
, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "owner", fld_owner_id, fld_id, fld_w, fld_time, fld_page)
));
}
public void Insert(int id, int thm_owner_id, int width, int height, double thumbtime, int page, int bin_db_id, long size) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
this.Insert(stmt_insert, id, thm_owner_id, width, height, thumbtime, page, bin_db_id, size, Modified_null_str, Hash_null);
}
public void Insert(Db_stmt stmt, int id, int thm_owner_id, int width, int height, double thumbtime, int page, int bin_db_id, long size, String modified, String hash_md5) {
stmt.Clear()
.Val_int(fld_id, id)
.Val_int(fld_owner_id, thm_owner_id)
.Val_int(fld_w, width)
.Val_int(fld_h, height);
if (schema_thm_page) {
stmt.Val_double (fld_time, Xof_lnki_time.Db_save_double(thumbtime));
stmt.Val_int (fld_page, Xof_lnki_page.Db_save_int(page));
}
else
stmt.Val_int (fld_time, Xof_lnki_time.Db_save_int(thumbtime));
stmt
.Val_int(fld_bin_db_id, bin_db_id)
.Val_long(fld_size, size)
.Val_str(fld_modified, modified)
.Val_str(fld_hash, hash_md5)
.Exec_insert();
}
public boolean Select_itm_by_w_exact(int dir_id, int fil_id, Fsd_thm_itm thm) {
if (stmt_select_by_fil_exact == null) stmt_select_by_fil_exact = conn.Stmt_select(tbl_name, flds, String_.Ary_wo_null(fld_owner_id, fld_w, fld_time, fld_page));
stmt_select_by_fil_exact.Clear().Crt_int(fld_owner_id, fil_id).Crt_int(fld_w, thm.W());
if (schema_thm_page) {
stmt_select_by_fil_exact.Crt_double (fld_time, Xof_lnki_time.Db_save_double(thm.Time()));
stmt_select_by_fil_exact.Crt_int (fld_page, Xof_lnki_page.Db_save_int(thm.Page()));
}
else {
stmt_select_by_fil_exact.Crt_int (fld_time, Xof_lnki_time.Db_save_int(thm.Time()));
}
Db_rdr rdr = stmt_select_by_fil_exact.Exec_select__rls_manual();
try {
return rdr.Move_next()
? Ctor_by_load(thm, rdr, dir_id)
: false;
}
finally {rdr.Rls();}
}
public boolean Select_itm_by_w_near(int dir_id, int fil_id, Fsd_thm_itm thm) {
if (stmt_select_by_fil_near == null) stmt_select_by_fil_near = conn.Stmt_select(tbl_name, flds, fld_owner_id);
List_adp list = List_adp_.New();
Db_rdr rdr = stmt_select_by_fil_near.Clear().Crt_int(fld_owner_id, fil_id).Exec_select__rls_manual();
try {
while (rdr.Move_next()) {
Fsd_thm_itm itm = Fsd_thm_itm.new_();
Ctor_by_load(itm, rdr, dir_id);
list.Add(itm);
}
return Match_nearest(list, thm, schema_thm_page);
}
finally {rdr.Rls();}
}
public boolean Ctor_by_load(Fsd_thm_itm itm, Db_rdr rdr, int dir_id) {
int thm_id = rdr.Read_int(fld_id);
int fil_id = rdr.Read_int(fld_owner_id);
int w = rdr.Read_int(fld_w);
int h = rdr.Read_int(fld_h);
long size = rdr.Read_long(fld_size);
String modified = rdr.Read_str(fld_modified);
String hash = rdr.Read_str(fld_hash);
int bin_db_id = rdr.Read_int(fld_bin_db_id);
double time = 0;
int page = 0;
if (schema_thm_page) {
time = Xof_lnki_time.Db_load_double(rdr, fld_time);
page = Xof_lnki_page.Db_load_int(rdr, fld_page);
}
else {
time = Xof_lnki_time.Db_load_int(rdr, fld_time);
page = Xof_lnki_page.Null;
}
itm.Ctor(mnt_id, dir_id, fil_id, thm_id, bin_db_id, w, h, time, page, size, modified, hash);
return true;
}
public static final DateAdp Modified_null = null;
public static final String Hash_null = "", Modified_null_str = "";
public static boolean Match_nearest(List_adp list, Fsd_thm_itm thm, boolean schema_thm_page) {
int len = list.Count(); if (len == 0) return Bool_.N;
list.Sort_by(Fsdb_thm_itm_sorter.Instance);
int thm_w = thm.W(), thm_page = thm.Page(); double thm_time = thm.Time();
Fsd_thm_itm max = null;
for (int i = 0; i < len; ++i) {
Fsd_thm_itm comp = (Fsd_thm_itm)list.Get_at(i);
int comp_w = comp.W();
int comp_page = schema_thm_page ? comp.Page() : thm_page;
if ( thm_w == comp_w
&& thm_time == comp.Time()
&& thm_page == comp_page
) { // exact match
thm.Init_by_match(comp);
return Bool_.Y;
}
if (comp_w > thm_w) max = comp;
else if (max == null) max = comp;
else break;
}
if (max == null) return Bool_.N;
thm.Init_by_match(max);
return Bool_.Y;
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_select_by_fil_exact = Db_stmt_.Rls(stmt_select_by_fil_exact);
stmt_select_by_fil_near = Db_stmt_.Rls(stmt_select_by_fil_near);
}
}

View File

@@ -13,44 +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.fsdb.data; import gplx.*; import gplx.fsdb.*;
import org.junit.*;
public class Fsd_thm_tbl_tst {
@Before public void init() {fxt.Clear();} private Fsd_thm_tbl_fxt fxt = new Fsd_thm_tbl_fxt();
@Test public void Basic() {
fxt.Init_list(fxt.Make(100), fxt.Make(200), fxt.Make(400));
fxt.Test_match_nearest_itm(fxt.Make(400), fxt.Make(400));
fxt.Test_match_nearest_itm(fxt.Make(200), fxt.Make(200));
fxt.Test_match_nearest_itm(fxt.Make(100), fxt.Make(100));
fxt.Test_match_nearest_itm(fxt.Make(350), fxt.Make(400));
fxt.Test_match_nearest_itm(fxt.Make(150), fxt.Make(200));
fxt.Test_match_nearest_itm(fxt.Make(999), fxt.Make(400));
}
@Test public void Empty() {
fxt.Init_list(); // no items
fxt.Test_match_nearest_itm(fxt.Make(100), Fsd_thm_itm.Null);
}
}
class Fsd_thm_tbl_fxt {
private final List_adp list = List_adp_.New();
public void Clear() {list.Clear();}
public Fsd_thm_itm Make(int w) {
double time = gplx.xowa.files.Xof_lnki_time.Null;
int page = gplx.xowa.files.Xof_lnki_page.Null;
Fsd_thm_itm rv = Fsd_thm_itm.new_();
rv.Init_by_req(w, time, page);
return rv;
}
public void Init_list(Fsd_thm_itm... ary) {list.Add_many((Object[])ary);}
public void Test_match_nearest_itm(Fsd_thm_itm req, Fsd_thm_itm expd) {
Fsd_thm_tbl.Match_nearest(list, req, Bool_.Y);
if (expd == Fsd_thm_itm.Null) {
Tfds.Eq(req.Req_w(), 0);
}
else {
Tfds.Eq(expd.W(), req.W());
Tfds.Eq(expd.Time(), req.Time());
Tfds.Eq(expd.Page(), req.Page());
}
}
}

View File

@@ -13,95 +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.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.core.primitives.*; import gplx.core.caches.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*; import gplx.fsdb.data.*;
public class Fsm_atr_fil {
private final Fsm_mnt_itm mnt_itm; private final int mnt_id;
private Fsd_dir_tbl tbl_dir; private Fsd_fil_tbl tbl_fil; private Fsd_thm_tbl tbl_thm;
private final Gfo_cache_mgr_bry dir_cache = new Gfo_cache_mgr_bry(); private Gfo_cache_mgr_bry fil_cache; private Bry_bfr fil_cache_key_bfr;
public Fsm_atr_fil(Fsm_mnt_itm mnt_itm, int id, String url_rel, Db_conn conn, boolean schema_is_1, boolean schema_thm_page) {
this.mnt_itm = mnt_itm; this.mnt_id = mnt_itm.Id();
this.id = id; this.url_rel = url_rel; this.conn = conn;
this.tbl_dir = new Fsd_dir_tbl(conn, schema_is_1);
this.tbl_fil = new Fsd_fil_tbl(conn, schema_is_1, mnt_id);
this.tbl_thm = new Fsd_thm_tbl(conn, schema_is_1, mnt_id, schema_thm_page);
}
public int Id() {return id;} private final int id;
public String Url_rel() {return url_rel;} private final String url_rel;
public Db_conn Conn() {return conn;} private final Db_conn conn;
public Fsd_fil_itm Select_fil_or_null(byte[] dir, byte[] fil) {
int dir_id = Get_dir_id_or_neg1(dir);
return dir_id == Int_.Neg1 ? Fsd_fil_itm.Null : tbl_fil.Select_or_null(dir_id, fil);
}
public boolean Select_thm(boolean exact, Fsd_thm_itm rv, int dir_id, int fil_id) {
return exact ? tbl_thm.Select_itm_by_w_exact(dir_id, fil_id, rv) : tbl_thm.Select_itm_by_w_near(dir_id, fil_id, rv);
}
public Fsd_fil_itm Insert_fil(byte[] dir, byte[] fil, int ext_id, int bin_db_id, long bin_len, Io_stream_rdr bin_rdr) {
int dir_id = Get_dir_id_or_make(dir);
int fil_id = Get_fil_id_or_make(Tid_none, dir_id, fil, ext_id, bin_db_id, bin_len);
return new Fsd_fil_itm(mnt_id, dir_id, fil_id, 0, ext_id, fil, bin_len, null, null, bin_db_id);
}
public Fsd_img_itm Insert_img(byte[] dir, byte[] fil, int ext_id, int img_w, int img_h, int bin_db_id, long bin_len, Io_stream_rdr bin_rdr) {
int dir_id = Get_dir_id_or_make(dir);
int fil_id = Get_fil_id_or_make(Tid_img, dir_id, fil, ext_id, bin_db_id, bin_len);
return new Fsd_img_itm(mnt_id, dir_id, fil_id, bin_db_id);
}
public int Insert_thm(Fsd_thm_itm rv, byte[] dir, byte[] fil, int ext_id, int w, int h, double time, int page, int bin_db_id, long bin_len, Io_stream_rdr bin_rdr) {
int dir_id = Get_dir_id_or_make(dir);
int fil_id = Get_fil_id_or_make(Tid_thm, dir_id, fil, ext_id, Fsd_bin_tbl.Bin_db_id_null, Fsd_bin_tbl.Size_null); // NOTE: bin_db_id must be set to NULL
int thm_id = mnt_itm.Next_id();
tbl_thm.Insert(thm_id, fil_id, w, h, time, page, bin_db_id, bin_len);
rv.Ctor(mnt_id, dir_id, fil_id, thm_id, bin_db_id, w, h, time, page, bin_len, Fsd_thm_tbl.Modified_null_str, Fsd_thm_tbl.Hash_null);
return thm_id;
}
public void Fil_cache_enabled_y_() {
fil_cache = new Gfo_cache_mgr_bry();
fil_cache_key_bfr = Bry_bfr_.Reset(255);
tbl_fil.Select_all(fil_cache_key_bfr, fil_cache);
}
private int Get_dir_id_or_neg1(byte[] dir_bry) {
Object rv_obj = dir_cache.Get_or_null(dir_bry);
if (rv_obj == null) { // not in mem
Fsd_dir_itm itm = tbl_dir.Select_or_null(dir_bry); // try db
if (itm == Fsd_dir_itm.Null) return -1; // not in db
int dir_id = itm.Dir_id();
dir_cache.Add(dir_bry, Int_obj_ref.New(dir_id)); // add to mem
return dir_id;
}
else
return ((Int_obj_ref)rv_obj).Val();
}
private int Get_dir_id_or_make(byte[] dir_bry) {
int rv = Get_dir_id_or_neg1(dir_bry);
if (rv == -1) {
rv = mnt_itm.Next_id();
tbl_dir.Insert(rv, dir_bry, Fsd_dir_itm.Owner_root);
dir_cache.Add(dir_bry, Int_obj_ref.New(rv));
}
return rv;
}
private int Get_fil_id_or_make(int xtn_tid, int dir_id, byte[] fil, int ext_id, int bin_db_id, long bin_len) {
if (fil_cache != null) {
byte[] cache_key = Fsd_fil_itm.Gen_cache_key(fil_cache_key_bfr, dir_id, fil);
Object cache_obj = fil_cache.Get_or_null(cache_key);
if (cache_obj != null) return ((Fsd_fil_itm)cache_obj).Fil_id();
}
Fsd_fil_itm fil_itm = tbl_fil.Select_or_null(dir_id, fil);
int fil_id = -1;
if (fil_itm == Fsd_fil_itm.Null) { // new item
fil_id = mnt_itm.Next_id();
tbl_fil.Insert(fil_id, dir_id, fil, xtn_tid, ext_id, bin_len, bin_db_id);
}
else { // existing item
fil_id = fil_itm.Fil_id();
if ( fil_itm.Bin_db_id() == Fsd_bin_tbl.Bin_db_id_null // prv row was previously inserted by thumb
&& xtn_tid != Tid_thm // cur row is not thumb
) {
tbl_fil.Update(fil_id, dir_id, fil, xtn_tid, ext_id, bin_len, bin_db_id); // update props; note that thumb inserts null props, whereas file will insert real props (EX: bin_db_id)
}
}
return fil_id;
}
private static final int Tid_none = 0, Tid_thm = 1, Tid_img = 2;
}

View File

@@ -13,20 +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.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*; import gplx.fsdb.data.*;
public class Fsm_atr_mgr {
private Fsdb_db_mgr core_mgr; private Fsm_atr_tbl tbl; private Fsm_atr_fil db__core; private Fsm_mnt_itm mnt_itm;
public Fsm_atr_mgr(Fsdb_db_mgr core_mgr, Db_conn conn, Fsm_mnt_itm mnt_itm) {
this.core_mgr = core_mgr; this.mnt_itm = mnt_itm;
this.tbl = new Fsm_atr_tbl(conn, core_mgr.File__schema_is_1());
}
public void Ctor_by_load(boolean schema_thm_page) {
this.db__core = tbl.Select_1st_or_fail(mnt_itm, core_mgr, mnt_itm.Id(), schema_thm_page);
}
public Fsm_atr_fil Db__core() {return db__core;}
public Fsd_fil_itm Select_fil_or_null(byte[] dir, byte[] fil) {return db__core.Select_fil_or_null(dir, fil);}
public boolean Select_thm(boolean exact, Fsd_thm_itm rv, int dir_id, int fil_id) {return db__core.Select_thm(exact, rv, dir_id, fil_id);}
public void Txn_bgn() {db__core.Conn().Txn_bgn("fsdb__fsm_atr_mgr");}
public void Txn_end() {db__core.Conn().Txn_end();}
}

View File

@@ -13,46 +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.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*; import gplx.dbs.qrys.*;
public class Fsm_atr_tbl implements Db_tbl {
public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_uid, fld_url;
private final Db_conn conn;
public Fsm_atr_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
String fld_prefix = "";
if (schema_is_1) {tbl_name = "fsdb_db_atr";}
else {tbl_name = "fsdb_dba"; fld_prefix = "dba_";}
this.fld_uid = flds.Add_int_pkey (fld_prefix + "uid");
this.fld_url = flds.Add_str (fld_prefix + "url", 255);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public Fsm_atr_fil Select_1st_or_fail(Fsm_mnt_itm mnt_itm, Fsdb_db_mgr core_mgr, int mnt_id, boolean schema_thm_page) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, Dbmeta_fld_itm.Str_ary_empty).Exec_select__rls_auto();
boolean schema_is_1 = core_mgr.File__schema_is_1();
try {
if (rdr.Move_next()) {
String url_rel = rdr.Read_str(fld_url);
return new Fsm_atr_fil
( mnt_itm
, rdr.Read_int(fld_uid)
, url_rel
, core_mgr.File__atr_file__at(mnt_id).Conn()
, schema_is_1
, schema_thm_page
);
}
}
finally {rdr.Rls();}
throw Err_.new_wo_type("missing atr db", "conn", conn.Conn_info().Db_api());
}
public void Insert(int id, String url_rel) {
conn.Stmt_insert(tbl_name, flds).Val_int(fld_uid, id).Val_str(fld_url, url_rel).Exec_insert();
}
public void Rls() {}
public static final String TBL_NAME = "fsdb_dba";
public static Fsm_atr_tbl Get_by_key(Db_tbl_owner owner) {return (Fsm_atr_tbl)owner.Tbls__get_by_key(TBL_NAME);}
}

View File

@@ -13,27 +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.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.dbs.*;
import gplx.fsdb.data.*;
public class Fsm_bin_fil {
public Fsm_bin_fil(boolean schema_is_1, int id, Io_url url, String url_rel, Db_conn conn, long bin_len) {
this.id = id; this.url = url; this.url_rel = url_rel; this.conn = conn; this.bin_len = bin_len;
this.tbl = new Fsd_bin_tbl(conn, schema_is_1);
}
public int Id() {return id;} private final int id;
public Io_url Url() {return url;} private Io_url url;
public String Url_rel() {return url_rel;} private final String url_rel;
public long Bin_len() {return bin_len;} public void Bin_len_(long v) {bin_len = v;} private long bin_len;
public Db_conn Conn() {return conn;} private final Db_conn conn;
public Fsd_bin_tbl Tbl() {return tbl;} private final Fsd_bin_tbl tbl;
public boolean Select_to_url(int id, Io_url url) {return tbl.Select_to_url(id, url);}
public Io_stream_rdr Select_as_rdr(int id) {return tbl.Select_as_rdr(id);}
public Fsd_bin_itm Select_as_itm(int id) {return tbl.Select_as_itm(id);}
public void Insert(int bin_id, byte owner_tid, long rdr_len, gplx.core.ios.streams.Io_stream_rdr rdr) {
tbl.Insert_rdr(bin_id, owner_tid, rdr_len, rdr);
Bin_len_(bin_len + rdr_len);
}
public static final Fsm_bin_fil[] Ary_empty = new Fsm_bin_fil[0];
public static final long Bin_len_null = 0;
}

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.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.dbs.*;
public class Fsm_bin_mgr {
private final Fsdb_db_mgr core_mgr; private final int mnt_id; private final Fsm_bin_tbl tbl;
private final Ordered_hash db_hash = Ordered_hash_.New();
private Fsm_bin_fil nth_db;
public Fsm_bin_mgr(Fsdb_db_mgr core_mgr, Db_conn conn, int mnt_id) {
this.core_mgr = core_mgr; this.mnt_id = mnt_id;
this.tbl = new Fsm_bin_tbl(conn, core_mgr.File__schema_is_1(), mnt_id);
}
public void Ctor_by_load() {
Fsm_bin_fil[] db_ary = tbl.Select_all(core_mgr);
int len = db_ary.length;
for (int i = 0; i < len; ++i) {
Fsm_bin_fil db_fil = db_ary[i];
db_hash.Add(db_fil.Id(), db_fil);
}
if (len > 0) this.nth_db = db_ary[len - 1];
}
public int Dbs__len() {return db_hash.Len();}
public Fsm_bin_fil Dbs__get_nth() {return nth_db;}
public Fsm_bin_fil Dbs__get_at(int i) {return (Fsm_bin_fil)db_hash.Get_at(i);}
public Fsm_bin_fil Dbs__get_by_or_null(int i) {return (Fsm_bin_fil)db_hash.Get_by(i);}
public Fsm_bin_fil Dbs__make(String file_name) {return Dbs__make(db_hash.Len(), file_name);}
public Fsm_bin_fil Dbs__make(int id, String file_name) {
Fsdb_db_file db = core_mgr.File__bin_file__new(mnt_id, file_name);
Fsm_bin_fil rv = new Fsm_bin_fil(core_mgr.File__schema_is_1(), id, db.Url(), db.Url().NameAndExt(), db.Conn(), Fsm_bin_fil.Bin_len_null);
tbl.Insert(id, rv.Url_rel());
db_hash.Add(id, rv);
this.nth_db = rv;
return rv;
}
public void Insert(int db_id, int bin_id, byte owner_tid, long bin_len, Io_stream_rdr bin_rdr) {
Fsm_bin_fil fil = (Fsm_bin_fil)db_hash.Get_by(db_id);
fil.Insert(bin_id, owner_tid, bin_len, bin_rdr);
fil.Insert(bin_id, owner_tid, bin_len, bin_rdr);
}
public void Txn_bgn() {
int len = db_hash.Len();
for (int i = 0; i < len; ++i)
this.Dbs__get_at(i).Conn().Txn_bgn("fsdb__meta__bin");
}
public void Txn_end() {
int len = db_hash.Len();
for (int i = 0; i < len; ++i)
this.Dbs__get_at(i).Conn().Txn_end();
}
public void Rls() {
int len = db_hash.Len();
for (int i = 0; i < len; ++i)
this.Dbs__get_at(i).Conn().Rls_conn();
}
}

View File

@@ -13,46 +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.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*; import gplx.dbs.qrys.*;
public class Fsm_bin_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_uid, fld_url, fld_bin_len, fld_bin_max;
private final Db_conn conn; private int mnt_id;
public Fsm_bin_tbl(Db_conn conn, boolean schema_is_1, int mnt_id) {
this.conn = conn; this.mnt_id = mnt_id;
String fld_prefix = "";
if (schema_is_1) {tbl_name = "fsdb_db_bin";}
else {tbl_name = "fsdb_dbb"; fld_prefix = "dbb_";}
fld_uid = flds.Add_int_pkey (fld_prefix + "uid");
fld_url = flds.Add_str (fld_prefix + "url", 255);
if (schema_is_1) {
fld_bin_len = flds.Add_long("bin_len");
fld_bin_max = flds.Add_long("bin_max");
}
else {
fld_bin_len = Dbmeta_fld_itm.Key_null;
fld_bin_max = Dbmeta_fld_itm.Key_null;
}
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Insert(int id, String url_rel) {
conn.Stmt_insert(tbl_name, flds).Crt_int(fld_uid, id).Val_str(fld_url, url_rel).Val_long(fld_bin_len, 0).Val_long(fld_bin_max, 0).Exec_insert();
}
public Fsm_bin_fil[] Select_all(Fsdb_db_mgr db_conn_mgr) {
List_adp rv = List_adp_.New();
Db_rdr rdr = conn.Stmt_select_order(tbl_name, flds, Dbmeta_fld_itm.Str_ary_empty, fld_uid).Clear().Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
int bin_id = rdr.Read_int(fld_uid);
String bin_url = rdr.Read_str(fld_url);
Fsdb_db_file bin_db = db_conn_mgr.File__bin_file__at(mnt_id, bin_id, bin_url);
Fsm_bin_fil itm = new Fsm_bin_fil(db_conn_mgr.File__schema_is_1(), bin_id, bin_db.Url(), bin_url, bin_db.Conn(), Fsm_bin_fil.Bin_len_null);
rv.Add(itm);
}
} finally {rdr.Rls();}
return (Fsm_bin_fil[])rv.To_ary(Fsm_bin_fil.class);
}
public void Rls() {}
}

View File

@@ -13,40 +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.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.fsdb.meta.*;
public class Fsm_cfg_mgr {
private final Db_cfg_tbl tbl; private final Hash_adp grp_hash = Hash_adp_.New();
public Fsm_cfg_mgr(Fsdb_db_mgr db_conn_mgr, Db_conn conn) {
this.tbl = new Db_cfg_tbl(conn, db_conn_mgr.File__cfg_tbl_name());
}
public void Ctor_by_load() {
Db_cfg_hash hash = Grps_get_or_load(Grp_core);
this.next_id = hash.Get_by(Key_next_id).To_int_or(-1); if (next_id == -1) throw Err_.new_wo_type("next_id not found in cfg", "url", tbl.Conn().Conn_info().Db_api());
this.schema_thm_page = hash.Get_by(Key_schema_thm_page).To_yn_or_n();
this.patch__next_id = hash.Get_by(Key_patch__next_id).To_yn_or_n();
this.patch__page_gt_1 = hash.Get_by(Key_patch__page_gt_1).To_yn_or_n();
}
public Db_cfg_tbl Tbl() {return tbl;}
public int Next_id() {return next_id++;} private int next_id = 1;
public void Next_id_commit() {tbl.Update_int("core", "next_id", next_id);}
public boolean Schema_thm_page() {return schema_thm_page;} private boolean schema_thm_page = true;
public boolean Patch_next_id() {return patch__next_id;} private boolean patch__next_id = true;
public void Patch_next_id_exec(int last_id) {
if (last_id >= next_id)
next_id = last_id + 1;
tbl.Insert_yn(Grp_core, Key_patch__next_id, Bool_.Y);
}
public boolean Patch__page_gt_1() {return patch__page_gt_1;} private boolean patch__page_gt_1 = false;
public void Patch__save(String cfg_key) {tbl.Insert_yn(Fsm_cfg_mgr.Grp_core, cfg_key, Bool_.Y);}
public Db_cfg_hash Grps_get_or_load(String grp_key) {
Db_cfg_hash rv = (Db_cfg_hash)grp_hash.Get_by(grp_key);
if (rv == null) {
rv = tbl.Select_as_hash(grp_key);
grp_hash.Add(grp_key, rv);
}
return rv;
}
public static final String Grp_core = "core";
public static final String Key_next_id = "next_id", Key_schema_thm_page = "schema.thm.page", Key_patch__next_id = "patch.next_id", Key_patch__page_gt_1 = "patch.page_gt_1";
}

View File

@@ -13,10 +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.fsdb.meta; import gplx.*; import gplx.fsdb.*;
public class Fsm_id_itm {
public Fsm_id_itm(String key, int id, int version) {this.key = key; this.id = id; this.version = version;}
public String Key() {return key;} private final String key;
public int Id() {return id;} private final int id;
public int Version() {return version;} private final int version;
}

View File

@@ -13,65 +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.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.dbs.*; import gplx.fsdb.data.*;
public class Fsm_mnt_itm {
public Fsm_mnt_itm(int id, String name, String url_rel) {this.id = id; this.name = name; this.url_rel = url_rel;}
public int Id() {return id;} private final int id;
public String Name() {return name;} private final String name;
public String Url_rel() {return url_rel;} private final String url_rel;
public Fsm_atr_mgr Atr_mgr() {return atr_mgr;} private Fsm_atr_mgr atr_mgr;
public Fsm_bin_mgr Bin_mgr() {return bin_mgr;} private Fsm_bin_mgr bin_mgr;
public Fsm_cfg_mgr Cfg_mgr() {return cfg_mgr;} private Fsm_cfg_mgr cfg_mgr;
public Fsdb_db_mgr Db_mgr() {return db_mgr;} private Fsdb_db_mgr db_mgr;
public void Ctor_by_load(Fsdb_db_mgr db_mgr) {
this.db_mgr = db_mgr;
Db_conn conn = db_mgr.File__abc_file__at(id).Conn();
cfg_mgr = new Fsm_cfg_mgr(db_mgr, conn);
atr_mgr = new Fsm_atr_mgr(db_mgr, conn, this);
bin_mgr = new Fsm_bin_mgr(db_mgr, conn, id);
cfg_mgr.Ctor_by_load();
atr_mgr.Ctor_by_load(cfg_mgr.Schema_thm_page());
bin_mgr.Ctor_by_load();
if (!cfg_mgr.Patch_next_id()) Fsm_mnt_itm_.Patch_next_id(this, name);
}
public int Next_id() {return cfg_mgr.Next_id();}
public Fsd_fil_itm Select_fil_or_null(byte[] dir, byte[] fil) {return atr_mgr.Select_fil_or_null(dir, fil);}
public boolean Select_thm(boolean exact, Fsd_thm_itm rv, byte[] dir, byte[] fil) {
Fsd_fil_itm fil_itm = atr_mgr.Select_fil_or_null(dir, fil);
return fil_itm == Fsd_fil_itm.Null ? Bool_.N : atr_mgr.Select_thm(exact, rv, fil_itm.Dir_id(), fil_itm.Fil_id());
}
public Fsd_img_itm Insert_img(Fsm_atr_fil atr_fil, Fsm_bin_fil bin_fil, byte[] dir, byte[] fil, int ext_id, int img_w, int img_h, long bin_len, Io_stream_rdr bin_rdr) {
Fsd_img_itm rv = atr_fil.Insert_img(dir, fil, ext_id, img_w, img_h, bin_fil.Id(), bin_len, bin_rdr);
bin_fil.Insert(rv.Fil_id(), Fsd_bin_tbl.Owner_tid_fil, bin_len, bin_rdr);
return rv;
}
public Fsd_fil_itm Insert_fil(Fsm_atr_fil atr_fil, Fsm_bin_fil bin_fil, byte[] dir, byte[] fil, int ext_id, long bin_len, gplx.core.ios.streams.Io_stream_rdr bin_rdr) {
Fsd_fil_itm rv = atr_fil.Insert_fil(dir, fil, ext_id, bin_fil.Id(), bin_len, bin_rdr);
bin_fil.Insert(rv.Fil_id(), Fsd_bin_tbl.Owner_tid_fil, bin_len, bin_rdr);
return rv;
}
public void Insert_thm(Fsd_thm_itm rv, Fsm_atr_fil atr_fil, Fsm_bin_fil bin_fil, byte[] dir, byte[] fil, int ext_id, int w, int h, double time, int page, long bin_len, Io_stream_rdr bin_rdr) {
int thm_id = atr_fil.Insert_thm(rv, dir, fil, ext_id, w, h, time, page, bin_fil.Id(), bin_len, bin_rdr);
bin_fil.Insert(thm_id, Fsd_bin_tbl.Owner_tid_thm, bin_len, bin_rdr);
}
public void Txn_bgn() {atr_mgr.Txn_bgn(); bin_mgr.Txn_bgn();}
public void Txn_end() {atr_mgr.Txn_end(); bin_mgr.Txn_end();}
public void Rls() {
atr_mgr.Db__core().Conn().Rls_conn();
bin_mgr.Rls();
}
}
class Fsm_mnt_itm_ {
public static void Patch_next_id(Fsm_mnt_itm abc_mgr, String name) {
if (!String_.Eq(name, "fsdb.user")) return;
Fsm_atr_mgr atr_mgr = abc_mgr.Atr_mgr();
Fsm_cfg_mgr cfg_mgr = abc_mgr.Cfg_mgr();
int last_id = -1;
Fsm_atr_fil atr_fil = atr_mgr.Db__core();
int max_fil_id = atr_fil.Conn().Exec_select_as_int("SELECT Max(fil_id) AS MaxId FROM fsdb_fil;", -1);
int max_thm_id = atr_fil.Conn().Exec_select_as_int("SELECT Max(thm_id) AS MaxId FROM fsdb_xtn_thm;", -1);
last_id = max_fil_id > max_thm_id ? max_fil_id : max_thm_id;
cfg_mgr.Patch_next_id_exec(last_id);
}
}

View File

@@ -13,51 +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.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
public class Fsm_mnt_mgr implements Gfo_invk {
private Db_cfg_tbl cfg_tbl; private Fsm_mnt_tbl mnt_tbl;
private Fsm_mnt_itm[] mnt_ary; private int mnt_ary_len = 0;
public void Ctor_by_load(Fsdb_db_mgr db_core) {
Db_conn conn = db_core.File__mnt_file().Conn();
this.cfg_tbl = new Db_cfg_tbl (conn, db_core.File__cfg_tbl_name());
this.mnt_tbl = new Fsm_mnt_tbl (conn, db_core.File__schema_is_1());
this.mnt_ary = mnt_tbl.Select_all();
this.mnt_ary_len = mnt_ary.length;
for (int i = 0; i < mnt_ary_len; ++i) {
mnt_ary[i].Ctor_by_load(db_core);
}
this.insert_idx = cfg_tbl.Select_int(Cfg_grp_core, Cfg_key_mnt_insert_idx);
Db_cfg_hash cfg_hash = this.Mnts__get_main().Cfg_mgr().Grps_get_or_load(Xof_fsdb_mgr_cfg.Grp_xowa);
boolean use_thumb_w = cfg_hash.Get_by(Xof_fsdb_mgr_cfg.Key_upright_use_thumb_w).To_yn_or_n();
boolean fix_default = cfg_hash.Get_by(Xof_fsdb_mgr_cfg.Key_upright_fix_default).To_yn_or_n();
this.patch_upright_tid = Xof_patch_upright_tid_.Merge(use_thumb_w, fix_default);
}
public int Mnts__len() {return mnt_ary_len;}
public Fsm_mnt_itm Mnts__get_at(int i) {return mnt_ary[i];}
public Fsm_mnt_itm Mnts__get_main_or_null() {return mnt_ary == null ? null : mnt_ary[Mnt_idx_main];} // NOTE: can be null for embeddable parser; DATE:2017-06-06
public Fsm_mnt_itm Mnts__get_main() {return mnt_ary[Mnt_idx_main];}
public Fsm_mnt_itm Mnts__get_insert() {return mnt_ary[insert_idx];} public void Mnts__get_insert_idx_(int v) {insert_idx = v;} private int insert_idx = Mnt_idx_user;
public Fsm_bin_fil Bins__at(int mnt_id, int bin_db_id) {return mnt_ary[mnt_id].Bin_mgr().Dbs__get_by_or_null(bin_db_id);}
public int Patch_upright() {return patch_upright_tid;} private int patch_upright_tid = Xof_patch_upright_tid_.Tid_all;
public void Rls() {
for (int i = 0; i < mnt_ary_len; ++i) {
Fsm_mnt_itm mnt = mnt_ary[i];
mnt.Rls();
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return Gfo_invk_.Rv_unhandled;}
public static final int Mnt_idx_main = 0, Mnt_idx_user = 1, Insert_to_bin_null = -1;
public static void Patch(Db_cfg_tbl cfg_tbl) {
cfg_tbl.Upsert_str(Xof_fsdb_mgr_cfg.Grp_xowa, Xof_fsdb_mgr_cfg.Key_gallery_fix_defaults , "y");
cfg_tbl.Upsert_str(Xof_fsdb_mgr_cfg.Grp_xowa, Xof_fsdb_mgr_cfg.Key_gallery_packed , "y");
cfg_tbl.Upsert_str(Xof_fsdb_mgr_cfg.Grp_xowa, Xof_fsdb_mgr_cfg.Key_upright_use_thumb_w , "y");
cfg_tbl.Upsert_str(Xof_fsdb_mgr_cfg.Grp_xowa, Xof_fsdb_mgr_cfg.Key_upright_fix_default , "y");
}
public static void Patch_core(Db_cfg_tbl cfg_tbl) { // NOTE: thes need to be upserts else upgrading will fail; DATE:2015-05-23
cfg_tbl.Upsert_int (Fsm_cfg_mgr.Grp_core, Fsm_cfg_mgr.Key_next_id , 1); // start next_id at 1
cfg_tbl.Upsert_yn (Fsm_cfg_mgr.Grp_core, Fsm_cfg_mgr.Key_schema_thm_page , Bool_.Y); // new dbs automatically have page and time in fsdb_xtn_tm
cfg_tbl.Upsert_yn (Fsm_cfg_mgr.Grp_core, Fsm_cfg_mgr.Key_patch__next_id , Bool_.Y); // new dbs automatically have correct next_id
}
public static final String Cfg_grp_core = "core", Cfg_key_mnt_insert_idx = "mnt.insert_idx"; // SERIALIZED
}

View File

@@ -13,46 +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.fsdb.meta; import gplx.*; import gplx.fsdb.*;
import gplx.dbs.*;
public class Fsm_mnt_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_id, fld_name, fld_url;
private final Db_conn conn;
public Fsm_mnt_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
fld_id = flds.Add_int_pkey ("mnt_id");
fld_name = flds.Add_str ("mnt_name", 255);
fld_url = flds.Add_str ("mnt_url", 255);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name = "fsdb_mnt";
public void Create_tbl() {
Dbmeta_tbl_itm meta = Dbmeta_tbl_itm.New(tbl_name, flds);
conn.Meta_tbl_create(meta);
this.Insert(Fsm_mnt_mgr.Mnt_idx_main, Mnt_name_main, Mnt_name_main);
this.Insert(Fsm_mnt_mgr.Mnt_idx_user, Mnt_name_user, Mnt_name_user);
}
public void Rls() {}
public void Insert(int id, String name, String url) {
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
stmt.Clear().Val_int(fld_id, id).Val_str(fld_name, name).Val_str(fld_url, url).Exec_insert();
}
public void Update(int id, String name, String url) {
Db_stmt stmt = conn.Stmt_update_exclude(tbl_name, flds, fld_id);
stmt.Clear().Val_str(fld_name, name).Val_str(fld_url, url).Crt_int(fld_id, id).Exec_update();
}
public Fsm_mnt_itm[] Select_all() {
List_adp list = List_adp_.New();
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, Dbmeta_fld_itm.Str_ary_empty).Clear().Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Fsm_mnt_itm itm = new Fsm_mnt_itm(rdr.Read_int(fld_id), rdr.Read_str(fld_name), rdr.Read_str(fld_url));
list.Add(itm);
}
}
finally {rdr.Rls();}
return (Fsm_mnt_itm[])list.To_ary_and_clear(Fsm_mnt_itm.class);
}
public static final String Mnt_name_main = "fsdb.main", Mnt_name_user = "fsdb.user";
}