mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
File_shrink: Add initial classes for file_shrink
This commit is contained in:
@@ -20,16 +20,16 @@ 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 {
|
||||
private final String fld_owner_id, fld_owner_tid, fld_part_id, fld_data_url, fld_data;
|
||||
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
|
||||
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";
|
||||
@@ -50,13 +50,16 @@ public class Fsd_bin_tbl implements Rls_able {
|
||||
}
|
||||
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)
|
||||
.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
|
||||
@@ -72,18 +75,18 @@ public class Fsd_bin_tbl implements Rls_able {
|
||||
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();
|
||||
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);}
|
||||
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);
|
||||
rdr.Save_bry_in_parts(url, tbl_name, fld__data, fld__owner_id, owner_id);
|
||||
saved_in_parts.Val_y_();
|
||||
}
|
||||
}
|
||||
@@ -95,16 +98,16 @@ public class Fsd_bin_tbl implements Rls_able {
|
||||
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();
|
||||
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)
|
||||
( 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
|
||||
|
||||
Reference in New Issue
Block a user