mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.2.1
This commit is contained in:
33
140_dbs/src/gplx/dbs/engines/mems/Db_conn_info__mem.java
Normal file
33
140_dbs/src/gplx/dbs/engines/mems/Db_conn_info__mem.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class Db_conn_info__mem extends Db_conn_info__base {
|
||||
@Override public String Tid() {return Tid_const;} public static final String Tid_const = "mem";
|
||||
@Override public Db_conn_info New_self(String raw, GfoMsg m) {
|
||||
Db_conn_info__mem rv = new Db_conn_info__mem();
|
||||
rv.Ctor("", m.ReadStr("database"), raw, raw);
|
||||
return rv;
|
||||
}
|
||||
public static Db_conn_info new_(String database) {
|
||||
return Db_conn_info_.parse_(Bld_raw
|
||||
( "gplx_key", Tid_const
|
||||
, "database", database
|
||||
));
|
||||
}
|
||||
public static final Db_conn_info__mem I = new Db_conn_info__mem(); Db_conn_info__mem() {}
|
||||
}
|
||||
56
140_dbs/src/gplx/dbs/engines/mems/Db_engine__mem.java
Normal file
56
140_dbs/src/gplx/dbs/engines/mems/Db_engine__mem.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
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.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class Db_engine__mem implements Db_engine {
|
||||
private final Hash_adp tbl_hash = Hash_adp_.new_();
|
||||
Db_engine__mem(Db_conn_info conn_info) {this.conn_info = conn_info;}
|
||||
public String Tid() {return Db_conn_info__mem.Tid_const;}
|
||||
public Db_conn_info Conn_info() {return conn_info;} private Db_conn_info conn_info;
|
||||
public Db_engine New_clone(Db_conn_info conn_info) {return new Db_engine__mem(conn_info);}
|
||||
public Db_stmt New_stmt_prep(Db_qry qry) {return new Db_stmt__mem(this, qry);}
|
||||
public Mem_tbl Tbls_get(String name) {return (Mem_tbl)tbl_hash.Get_by(name);}
|
||||
public void Txn_bgn(String name) {++txn_count;} private int txn_count = 0;
|
||||
public void Txn_end() {--txn_count;}
|
||||
public void Txn_cxl() {--txn_count;}
|
||||
public void Txn_sav() {this.Txn_end(); this.Txn_bgn("");}
|
||||
public Object Exec_as_obj(Db_qry qry) {throw Exc_.new_unimplemented();}
|
||||
public void Conn_open() {}
|
||||
public void Conn_term() {
|
||||
if (txn_count != 0) throw Exc_.new_("Conn_term.txns still open", "txn_count", txn_count);
|
||||
}
|
||||
public Db_rdr New_rdr__rls_manual(Object rdr_obj, String sql) {throw Exc_.new_unimplemented();}
|
||||
public Db_rdr New_rdr__rls_auto(Db_stmt stmt, Object rdr_obj, String sql) {throw Exc_.new_unimplemented();}
|
||||
public DataRdr New_rdr(java.sql.ResultSet rdr, String sql) {throw Exc_.new_unimplemented();}
|
||||
public Object New_stmt_prep_as_obj(String sql) {throw Exc_.new_unimplemented();}
|
||||
public void Ddl_create_tbl(Db_meta_tbl meta) {
|
||||
Mem_tbl mem_tbl = new Mem_tbl(meta);
|
||||
tbl_hash.Add_if_dupe_use_nth(meta.Name(), mem_tbl);
|
||||
}
|
||||
public void Ddl_create_idx(Gfo_usr_dlg usr_dlg, Db_meta_idx... ary) {} // TODO: implement unique index
|
||||
public void Ddl_append_fld(String tbl, Db_meta_fld fld) {}
|
||||
public void Ddl_delete_tbl(String tbl) {}
|
||||
public void Env_db_attach(String alias, Io_url db_url) {}
|
||||
public void Env_db_detach(String alias) {}
|
||||
public boolean Meta_tbl_exists(String tbl) {return tbl_hash.Has(tbl);}
|
||||
public boolean Meta_fld_exists(String tbl, String fld) {
|
||||
Mem_tbl mem_tbl = (Mem_tbl)tbl_hash.Get_by(tbl); if (mem_tbl == null) return false;
|
||||
return mem_tbl.Meta().Flds_has(fld);
|
||||
}
|
||||
// public boolean Meta_fld_exists(String name) {return tbl_hash.Has(name);}
|
||||
public static final Db_engine__mem _ = new Db_engine__mem(); Db_engine__mem() {}
|
||||
}
|
||||
44
140_dbs/src/gplx/dbs/engines/mems/Db_rdr__mem.java
Normal file
44
140_dbs/src/gplx/dbs/engines/mems/Db_rdr__mem.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class Db_rdr__mem implements Db_rdr {
|
||||
private final Mem_row[] rows; private int row_idx = -1; private final int rows_len;
|
||||
private Mem_row row;
|
||||
public Db_rdr__mem(String[] cols, Mem_row[] rows) {
|
||||
this.rows = rows; this.rows_len = rows.length;
|
||||
}
|
||||
public boolean Move_next() {
|
||||
boolean rv = ++row_idx < rows_len;
|
||||
if (rv)
|
||||
row = rows[row_idx];
|
||||
return rv;
|
||||
}
|
||||
public byte[] Read_bry(String k) {return (byte[])row.Get_by(k);}
|
||||
public String Read_str(String k) {return (String)row.Get_by(k);}
|
||||
public byte[] Read_bry_by_str(String k) {return Bry_.new_u8_safe((String)row.Get_by(k));} // NOTE: null b/c db can have NULL
|
||||
@gplx.Virtual public void Save_bry_in_parts(Io_url url, String tbl, String fld, String crt_key, Object crt_val) {throw Exc_.new_unimplemented();}
|
||||
public DateAdp Read_date_by_str(String k) {return DateAdp_.parse_iso8561((String)row.Get_by(k));}
|
||||
public byte Read_byte(String k) {return Byte_.cast_(row.Get_by(k));}
|
||||
public int Read_int(String k) {return Int_.cast_(row.Get_by(k));}
|
||||
public long Read_long(String k) {return Long_.cast_(row.Get_by(k));}
|
||||
public float Read_float(String k) {return Float_.cast_(row.Get_by(k));}
|
||||
public double Read_double(String k) {return Double_.cast_(row.Get_by(k));}
|
||||
public boolean Read_bool_by_byte(String k) {return Byte_.cast_(row.Get_by(k)) == 1;}
|
||||
public Object Read_obj(String k) {return row.Get_by(k);}
|
||||
public void Rls() {}
|
||||
}
|
||||
140
140_dbs/src/gplx/dbs/engines/mems/Db_stmt__mem.java
Normal file
140
140_dbs/src/gplx/dbs/engines/mems/Db_stmt__mem.java
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
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.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class Db_stmt__mem implements Db_stmt {
|
||||
private static final String Key_na = ""; // key is not_available; only called by procs with signature of Val(<type> v);
|
||||
private final Ordered_hash val_list = Ordered_hash_.new_();
|
||||
public Db_stmt__mem(Db_engine__mem engine, Db_qry qry) {Ctor_stmt(engine, qry);} private Db_engine__mem engine;
|
||||
public void Ctor_stmt(Db_engine engine, Db_qry qry) {this.engine = (Db_engine__mem)engine; this.qry = qry;}
|
||||
public Hash_adp Crts() {return crt_hash;} private final Hash_adp crt_hash = Hash_adp_.new_();
|
||||
public int Args_len() {return val_list.Count();}
|
||||
public Object Args_get_at(int i) {return val_list.Get_at(i);}
|
||||
public Object Args_get_by(String k) {return val_list.Get_by(k);}
|
||||
public Db_qry Qry() {return qry;} private Db_qry qry;
|
||||
public Db_stmt Reset_stmt() {return this;}
|
||||
public Db_stmt Clear() {
|
||||
val_list.Clear();
|
||||
crt_hash.Clear();
|
||||
return this;
|
||||
}
|
||||
public void Rls() {this.Clear();}
|
||||
public Db_stmt Crt_bool_as_byte(String k, boolean v) {return Add_byte_by_bool(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_bool_as_byte(String k, boolean v) {return Add_byte_by_bool(Bool_.N, k, v);}
|
||||
public Db_stmt Val_bool_as_byte(boolean v) {return Add_byte_by_bool(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_byte_by_bool(boolean where, String k, boolean v) {return Add_byte(where, k, v ? Bool_.Y_byte : Bool_.N_byte);}
|
||||
public Db_stmt Crt_byte(String k, byte v) {return Add_byte(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_byte(String k, byte v) {return Add_byte(Bool_.N, k, v);}
|
||||
public Db_stmt Val_byte(byte v) {return Add_byte(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_byte(boolean where, String k, byte v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_int(String k, int v) {return Add_int(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_int(String k, int v) {return Add_int(Bool_.N, k, v);}
|
||||
public Db_stmt Val_int(int v) {return Add_int(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_int(boolean where, String k, int v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "int", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_long(String k, long v) {return Add_long(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_long(String k, long v) {return Add_long(Bool_.N, k, v);}
|
||||
public Db_stmt Val_long(long v) {return Add_long(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_long(boolean where, String k, long v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "long", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_float(String k, float v) {return Add_float(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_float(String k, float v) {return Add_float(Bool_.N, k, v);}
|
||||
public Db_stmt Val_float(float v) {return Add_float(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_float(boolean where, String k, float v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "float", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_double(String k, double v) {return Add_double(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_double(String k, double v) {return Add_double(Bool_.N, k, v);}
|
||||
public Db_stmt Val_double(double v) {return Add_double(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_double(boolean where, String k, double v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "double", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.N, k, v);}
|
||||
public Db_stmt Val_decimal(DecimalAdp v) {return Add_decimal(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_decimal(boolean where, String k, DecimalAdp v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_bry(String k, byte[] v) {return Add_bry(Bool_.N, k, v);}
|
||||
public Db_stmt Val_bry(byte[] v) {return Add_bry(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_bry(boolean where, String k, byte[] v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "byte[]", "val", v.length);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_bry_as_str(String k, byte[] v) {return Add_bry_as_str(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_bry_as_str(String k, byte[] v) {return Add_bry_as_str(Bool_.N, k, v);}
|
||||
public Db_stmt Val_bry_as_str(byte[] v) {return Add_bry_as_str(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_bry_as_str(boolean where, String k, byte[] v) {return Add_str(where, k, String_.new_u8(v));}
|
||||
public Db_stmt Crt_str(String k, String v) {return Add_str(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_str(String k, String v) {return Add_str(Bool_.N, k, v);}
|
||||
public Db_stmt Val_str(String v) {return Add_str(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_str(boolean where, String k, String v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "String", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_rdr_(gplx.ios.Io_stream_rdr v, long rdr_len) {
|
||||
try {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
gplx.ios.Io_stream_rdr_.Load_all_to_bfr(bfr, v);
|
||||
Add("", Bool_.N, bfr.Xto_str_and_clear());
|
||||
} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public boolean Exec_insert() {
|
||||
Mem_tbl tbl = engine.Tbls_get(qry.Base_table());
|
||||
if (tbl == null) throw Exc_.new_("must call Create_tbl", "tbl", qry.Base_table());
|
||||
return tbl.Insert(this) == 1;
|
||||
}
|
||||
public int Exec_update() {
|
||||
Mem_tbl tbl = engine.Tbls_get(qry.Base_table());
|
||||
return tbl.Update(this);
|
||||
}
|
||||
public int Exec_delete() {
|
||||
Mem_tbl tbl = engine.Tbls_get(qry.Base_table());
|
||||
return tbl.Delete(this);
|
||||
}
|
||||
public DataRdr Exec_select() {throw Exc_.new_unimplemented();}
|
||||
public Db_rdr Exec_select__rls_auto() {return this.Exec_select__rls_manual();}
|
||||
public Db_rdr Exec_select__rls_manual() {
|
||||
Mem_tbl tbl = engine.Tbls_get(qry.Base_table());
|
||||
return tbl.Select(this);
|
||||
}
|
||||
public Object Exec_select_val() {throw Exc_.new_unimplemented();}
|
||||
private void Add(String k, boolean where, Object v) {
|
||||
if (k == Db_meta_fld.Key_null) return; // key is explicitly null; ignore; allows schema_2+ type definitions
|
||||
val_list.Add_if_dupe_use_1st(k, v); // NOTE: only add if new; WHERE with IN will call Add many times; fld_ttl IN ('A.png', 'B.png');
|
||||
if (where) {
|
||||
List_adp list = (List_adp)crt_hash.Get_by(k);
|
||||
if (list == null) {
|
||||
list = List_adp_.new_();
|
||||
crt_hash.Add(k, list);
|
||||
}
|
||||
list.Add(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
24
140_dbs/src/gplx/dbs/engines/mems/Mem_qry_set.java
Normal file
24
140_dbs/src/gplx/dbs/engines/mems/Mem_qry_set.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class Mem_qry_set {
|
||||
private final List_adp rows = List_adp_.new_();
|
||||
public int Len() {return rows.Count();}
|
||||
public Mem_row Get_at(int i) {return (Mem_row)rows.Get_at(i);}
|
||||
public void Add(Mem_row row) {rows.Add(row);}
|
||||
}
|
||||
30
140_dbs/src/gplx/dbs/engines/mems/Mem_row.java
Normal file
30
140_dbs/src/gplx/dbs/engines/mems/Mem_row.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class Mem_row implements GfoInvkAble {
|
||||
private final Ordered_hash hash = Ordered_hash_.new_();
|
||||
public Object Get_by(String key) {return hash.Get_by(key);}
|
||||
public Object Get_at(int i) {return hash.Get_at(i);}
|
||||
public void Set_by(String key, Object val) {hash.Add_if_dupe_use_nth(key, val);}
|
||||
public void Add(String key, Object val) {hash.Add(key, val);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
Object rv = Get_by(k);
|
||||
if (rv == null) return GfoInvkAble_.Rv_unhandled;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
95
140_dbs/src/gplx/dbs/engines/mems/Mem_tbl.java
Normal file
95
140_dbs/src/gplx/dbs/engines/mems/Mem_tbl.java
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
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.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.core.primitives.*; import gplx.core.criterias.*; import gplx.dbs.qrys.*;
|
||||
public class Mem_tbl {
|
||||
private final List_adp rows = List_adp_.new_(); private final List_adp where_rows = List_adp_.new_();
|
||||
private final Hash_adp autonum_hash = Hash_adp_.new_();
|
||||
public Mem_tbl(Db_meta_tbl meta) {this.meta = meta;}
|
||||
public Db_meta_tbl Meta() {return meta;} private final Db_meta_tbl meta;
|
||||
public int Insert(Db_stmt__mem stmt) {
|
||||
Mem_row itm = new Mem_row();
|
||||
Db_meta_fld[] flds = meta.Flds();
|
||||
int len = flds.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_meta_fld fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
Object val = fld.Autonum() ? Autonum_calc(fld_name) : stmt.Args_get_by(fld_name);
|
||||
itm.Set_by(fld_name, val);
|
||||
}
|
||||
rows.Add(itm);
|
||||
return 1;
|
||||
}
|
||||
private int Autonum_calc(String name) {
|
||||
Int_obj_ref autonum_itm = (Int_obj_ref)autonum_hash.Get_by(name);
|
||||
if (autonum_itm == null) {
|
||||
autonum_itm = Int_obj_ref.new_(0);
|
||||
autonum_hash.Add(name, autonum_itm);
|
||||
}
|
||||
return autonum_itm.Val_add();
|
||||
}
|
||||
public int Update(Db_stmt__mem stmt) {
|
||||
Db_qry_update qry = (Db_qry_update)stmt.Qry();
|
||||
qry.Where().Val_from_args(stmt.Crts());
|
||||
Select_rows_where(where_rows, stmt, qry.Where());
|
||||
int where_rows_len = where_rows.Count();
|
||||
String[] update_cols = qry.Cols_for_update(); int update_cols_len = update_cols.length;
|
||||
for (int i = 0; i < where_rows_len; ++i) {
|
||||
Mem_row itm = (Mem_row)where_rows.Get_at(i);
|
||||
for (int j = 0; j < update_cols_len; ++j)
|
||||
itm.Set_by(update_cols[j], stmt.Args_get_at(j));
|
||||
}
|
||||
return where_rows_len;
|
||||
}
|
||||
public int Delete(Db_stmt__mem stmt) {
|
||||
Db_qry_delete qry = (Db_qry_delete)stmt.Qry();
|
||||
qry.Where().Val_from_args(stmt.Crts());
|
||||
Select_rows_where(where_rows, stmt, qry.Where());
|
||||
int where_rows_len = where_rows.Count();
|
||||
for (int i = 0; i < where_rows_len; ++i) {
|
||||
Mem_row itm = (Mem_row)where_rows.Get_at(i);
|
||||
rows.Del(itm);
|
||||
}
|
||||
return where_rows_len;
|
||||
}
|
||||
public Db_rdr Select(Db_stmt__mem stmt) {
|
||||
String[] select = null; Criteria where = null;
|
||||
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.as_(stmt.Qry());
|
||||
if (qry == null) {
|
||||
Db_qry__select_cmd qry2 = (Db_qry__select_cmd)stmt.Qry();
|
||||
select = qry2.Cols_ary();
|
||||
where = qry2.Where();
|
||||
}
|
||||
else {
|
||||
select = qry.Select_flds();
|
||||
where = qry.Where();
|
||||
}
|
||||
where.Val_from_args(stmt.Crts());
|
||||
Select_rows_where(where_rows, stmt, where);
|
||||
return new Db_rdr__mem(select, (Mem_row[])where_rows.To_ary_and_clear(Mem_row.class));
|
||||
}
|
||||
private void Select_rows_where(List_adp rv, Db_stmt__mem stmt, Criteria crt) {
|
||||
rv.Clear();
|
||||
int rows_len = rows.Count();
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
Mem_row itm = (Mem_row)rows.Get_at(i);
|
||||
if (crt.Matches(itm))
|
||||
rv.Add(itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user