mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Embeddable: Fix if_exists
This commit is contained in:
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
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.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;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
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.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();}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
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.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);}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
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.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 {
|
||||
private final Fsd_bin_tbl tbl;
|
||||
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 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;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
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.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();
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
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.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() {}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
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.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";
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
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.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;
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
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.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);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
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.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() {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
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
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.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";
|
||||
}
|
||||
Reference in New Issue
Block a user