mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.6.3.1'
This commit is contained in:
@@ -18,64 +18,54 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.sqls.*; import gplx.dbs.sqls.itms.*;
|
||||
public class Db_attach_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public final List_adp attached_dbs_list = List_adp_.new_();
|
||||
public String Attached_sql() {return attached_sql;} private String attached_sql; // TEST
|
||||
private Db_conn main_conn; private Io_url main_conn_url;
|
||||
private final Ordered_hash others_hash = Ordered_hash_.New();
|
||||
private final List_adp attach_list = List_adp_.New();
|
||||
public Db_attach_mgr() {}
|
||||
public Db_attach_mgr(Db_conn main_conn, Db_attach_itm... itms_ary) {
|
||||
this.Main_conn_(main_conn);
|
||||
this.Init(itms_ary);
|
||||
public Db_attach_mgr(Db_conn main_conn, Db_attach_itm... others_ary) {
|
||||
this.Conn_main_(main_conn);
|
||||
this.Conn_others_(others_ary);
|
||||
}
|
||||
public Db_attach_mgr Init(Db_attach_itm... itms_ary) {
|
||||
hash.Clear();
|
||||
int itms_len = itms_ary.length;
|
||||
for (int i = 0; i < itms_len; ++i) {
|
||||
Db_attach_itm itm = itms_ary[i];
|
||||
hash.Add(itm.Key, itm);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Db_attach_mgr Main_conn_(Db_conn conn) {
|
||||
public Db_attach_mgr Conn_main_(Db_conn conn) {
|
||||
this.main_conn = conn; this.main_conn_url = Db_conn_info_.To_url(conn.Conn_info());
|
||||
return this;
|
||||
}
|
||||
public void Attach() {
|
||||
int len = attached_dbs_list.Len();
|
||||
public Db_attach_mgr Conn_others_(Db_attach_itm... itms_ary) {
|
||||
others_hash.Clear();
|
||||
int len = itms_ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_attach_itm itm = (Db_attach_itm)attached_dbs_list.Get_at(i);
|
||||
Db_attach_itm itm = itms_ary[i];
|
||||
others_hash.Add(itm.Key, itm);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public void Attach() {
|
||||
int len = attach_list.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_attach_itm itm = (Db_attach_itm)attach_list.Get_at(i);
|
||||
main_conn.Env_db_attach(itm.Key, itm.Url);
|
||||
}
|
||||
}
|
||||
public void Detach() {
|
||||
int len = attached_dbs_list.Len();
|
||||
int len = attach_list.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_attach_itm itm = (Db_attach_itm)attached_dbs_list.Get_at(i);
|
||||
Db_attach_itm itm = (Db_attach_itm)attach_list.Get_at(i);
|
||||
main_conn.Env_db_detach(itm.Key);
|
||||
}
|
||||
attached_dbs_list.Clear(); // clear list so multiple detachs don't fail
|
||||
}
|
||||
public String List__to_str() {
|
||||
String rv = "";
|
||||
int len = attached_dbs_list.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_attach_itm itm = (Db_attach_itm)attached_dbs_list.Get_at(i);
|
||||
rv += itm.Key + ";";
|
||||
}
|
||||
return rv;
|
||||
attach_list.Clear(); // clear list so multiple detachs don't fail
|
||||
}
|
||||
public String Resolve_sql(String sql) {
|
||||
attached_dbs_list.Clear();
|
||||
int hash_len = hash.Count();
|
||||
attach_list.Clear();
|
||||
int hash_len = others_hash.Count();
|
||||
for (int i = 0; i < hash_len; ++i) {
|
||||
Db_attach_itm attach_itm = (Db_attach_itm)hash.Get_at(i);
|
||||
Db_attach_itm attach_itm = (Db_attach_itm)others_hash.Get_at(i);
|
||||
String tkn = "<" + attach_itm.Key + ">";
|
||||
if (String_.Has(sql, tkn)) {
|
||||
Io_url attach_url = attach_itm.Url;
|
||||
String repl = "";
|
||||
if (!attach_url.Eq(main_conn_url)) {
|
||||
repl = attach_itm.Key + ".";
|
||||
attached_dbs_list.Add(attach_itm);
|
||||
attach_list.Add(attach_itm);
|
||||
}
|
||||
sql = String_.Replace(sql, tkn, repl);
|
||||
}
|
||||
@@ -83,29 +73,6 @@ public class Db_attach_mgr {
|
||||
attached_sql = sql;
|
||||
return sql;
|
||||
}
|
||||
public Db_stmt Make_stmt_and_attach(Db_qry qry, gplx.dbs.sqls.itms.Sql_from_clause from_itm) {
|
||||
attached_dbs_list.Clear();
|
||||
Sql_qry_wtr sql_wtr = main_conn.Engine().Sql_wtr();
|
||||
List_adp from_tbls = from_itm.Tbls;
|
||||
int from_tbls_len = from_tbls.Count();
|
||||
for (int i = 0; i < from_tbls_len; ++i) {
|
||||
Sql_tbl_itm from_tbl = (Sql_tbl_itm)from_tbls.Get_at(i);
|
||||
String from_tbl_db = from_tbl.Db;
|
||||
if (String_.Eq(Sql_tbl_itm.Db__null, from_tbl_db)) continue; // tbl does not have db defined; only "tbl" not "db.tbl"; skip
|
||||
Db_attach_itm attach_itm = (Db_attach_itm)hash.Get_by(from_tbl_db); if (attach_itm == null) throw Err_.new_("dbs", "qry defines an unknown database for attach_wkr", "from_tbl_db", from_tbl_db, "sql", qry.To_sql__exec(sql_wtr));
|
||||
if (attach_itm.Url.Eq(main_conn_url)) // attach_db same as conn; blank db, so "tbl", not "db.tbl"
|
||||
from_tbl.Db_enabled = false;
|
||||
else
|
||||
attached_dbs_list.Add(attach_itm);
|
||||
}
|
||||
attached_sql = sql_wtr.To_sql_str(qry, true);
|
||||
this.Attach();
|
||||
for (int i = 0; i < from_tbls_len; ++i) { // reverse blanking from above
|
||||
Sql_tbl_itm from_tbl = (Sql_tbl_itm)from_tbls.Get_at(i);
|
||||
from_tbl.Db_enabled = true;
|
||||
}
|
||||
return main_conn.Stmt_sql(attached_sql);
|
||||
}
|
||||
public Db_attach_mgr Exec_sql_w_msg(String msg, String sql, Object... args) {
|
||||
Gfo_usr_dlg_.Instance.Plog_many("", "", msg);
|
||||
Exec_sql(sql, args);
|
||||
@@ -118,4 +85,37 @@ public class Db_attach_mgr {
|
||||
finally {this.Detach();}
|
||||
return this;
|
||||
}
|
||||
public String Test__attach_sql() {return attached_sql;} private String attached_sql;
|
||||
public String[] Test__attach_list_keys() {
|
||||
int rv_len = attach_list.Count();
|
||||
String[] rv = new String[rv_len];
|
||||
for (int i = 0; i < rv_len; ++i) {
|
||||
Db_attach_itm itm = (Db_attach_itm)attach_list.Get_at(i);
|
||||
rv[i] = itm.Key;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Db_stmt Test__make_stmt_and_attach(Db_qry qry, gplx.dbs.sqls.itms.Sql_from_clause from_itm) { // NOTE: tries to do attach via DOM not SQL
|
||||
attach_list.Clear();
|
||||
Sql_qry_wtr sql_wtr = main_conn.Engine().Sql_wtr();
|
||||
List_adp from_tbls = from_itm.Tbls;
|
||||
int from_tbls_len = from_tbls.Count();
|
||||
for (int i = 0; i < from_tbls_len; ++i) {
|
||||
Sql_tbl_itm from_tbl = (Sql_tbl_itm)from_tbls.Get_at(i);
|
||||
String from_tbl_db = from_tbl.Db;
|
||||
if (String_.Eq(Sql_tbl_itm.Db__null, from_tbl_db)) continue; // tbl does not have db defined; only "tbl" not "db.tbl"; skip
|
||||
Db_attach_itm attach_itm = (Db_attach_itm)others_hash.Get_by(from_tbl_db); if (attach_itm == null) throw Err_.new_("dbs", "qry defines an unknown database for attach_wkr", "from_tbl_db", from_tbl_db, "sql", qry.To_sql__exec(sql_wtr));
|
||||
if (attach_itm.Url.Eq(main_conn_url)) // attach_db same as conn; blank db, so "tbl", not "db.tbl"
|
||||
from_tbl.Db_enabled = false;
|
||||
else
|
||||
attach_list.Add(attach_itm);
|
||||
}
|
||||
attached_sql = sql_wtr.To_sql_str(qry, true);
|
||||
this.Attach();
|
||||
for (int i = 0; i < from_tbls_len; ++i) { // reverse blanking from above
|
||||
Sql_tbl_itm from_tbl = (Sql_tbl_itm)from_tbls.Get_at(i);
|
||||
from_tbl.Db_enabled = true;
|
||||
}
|
||||
return main_conn.Stmt_sql(attached_sql);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ 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; import gplx.*;
|
||||
import org.junit.*; import gplx.dbs.qrys.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.dbs.qrys.*;
|
||||
public class Db_attach_mgr__tst {
|
||||
private final Db_attach_mgr__fxt fxt = new Db_attach_mgr__fxt();
|
||||
@Test public void Basic() {
|
||||
@@ -29,7 +29,7 @@ public class Db_attach_mgr__tst {
|
||||
.Join_("db_3", "tbl_3", "t3", Db_qry_.New_join__same("t1", "fld_3"))
|
||||
.Join_( "tbl_4", "t4", Db_qry_.New_join__same("t1", "fld_4"))
|
||||
;
|
||||
fxt.Init("db_2", fxt.Make__itm("db_1"), fxt.Make__itm("db_2"), fxt.Make__itm("db_3"));
|
||||
fxt.Init("db_2", fxt.Make__other("db_1"), fxt.Make__other("db_2"), fxt.Make__other("db_3"));
|
||||
fxt.Test__make_stmt_and_attach(qry
|
||||
, "SELECT t1.fld_1, t2.fld_2, t3.fld_3 "
|
||||
+ "FROM db_1.tbl_1 t1 "
|
||||
@@ -45,24 +45,15 @@ class Db_attach_mgr__fxt {
|
||||
public Db_attach_mgr__fxt() {
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
}
|
||||
public Db_attach_itm Make__itm(String key) {return new Db_attach_itm(key, Io_url_.mem_fil_("mem/" + key));}
|
||||
public Db_conn Make__conn(String key) {return Db_conn_bldr.Instance.New(Io_url_.mem_fil_(key));}
|
||||
public Db_attach_itm Make__other(String key) {return new Db_attach_itm(key, Io_url_.mem_fil_("mem/" + key));}
|
||||
public void Init(String conn_key, Db_attach_itm... ary) {
|
||||
Db_conn conn = Make__conn(conn_key);
|
||||
mgr = new Db_attach_mgr(conn, ary);
|
||||
}
|
||||
public void Test__make_stmt_and_attach(Db_qry__select_cmd qry, String expd_sql, String[] expd_dbs) {
|
||||
mgr.Make_stmt_and_attach(qry, qry.From());
|
||||
Tfds.Eq_str(expd_sql, mgr.Attached_sql());
|
||||
Tfds.Eq_ary_str(expd_dbs, To_key_ary(mgr.attached_dbs_list));
|
||||
}
|
||||
private static String[] To_key_ary(List_adp attach_dbs_list) {
|
||||
int rv_len = attach_dbs_list.Count();
|
||||
String[] rv = new String[rv_len];
|
||||
for (int i = 0; i < rv_len; ++i) {
|
||||
Db_attach_itm itm = (Db_attach_itm)attach_dbs_list.Get_at(i);
|
||||
rv[i] = itm.Key;
|
||||
}
|
||||
return rv;
|
||||
mgr.Test__make_stmt_and_attach(qry, qry.From());
|
||||
Gftest.Eq__str(expd_sql, mgr.Test__attach_sql());
|
||||
Gftest.Eq__ary(expd_dbs, mgr.Test__attach_list_keys());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.core.stores.*; import gplx.dbs.metas.*; import gplx.dbs.engines.*; import gplx.dbs.qrys.*; import gplx.dbs.sys.*; import gplx.dbs.conn_props.*; import gplx.dbs.qrys.bats.*;
|
||||
public class Db_conn {
|
||||
private final List_adp rls_list = List_adp_.new_();
|
||||
private final List_adp rls_list = List_adp_.New();
|
||||
public Db_conn(Db_engine engine) {
|
||||
this.engine = engine;
|
||||
sys_mgr = new Db_sys_mgr(this);
|
||||
this.sys_mgr = new Db_sys_mgr(this);
|
||||
}
|
||||
public Db_conn_info Conn_info() {return engine.Conn_info();}
|
||||
public Db_conn_props_mgr Props() {return engine.Props();}
|
||||
@@ -40,20 +40,51 @@ public class Db_conn {
|
||||
public void Meta_tbl_create(Dbmeta_tbl_itm meta) {engine.Meta_tbl_create(meta); engine.Meta_idx_create(Gfo_usr_dlg_.Noop, meta.Idxs().To_ary());}
|
||||
public void Meta_tbl_delete(String tbl) {engine.Meta_tbl_delete(tbl);}
|
||||
public void Meta_tbl_remake(Dbmeta_tbl_itm meta) {engine.Meta_tbl_delete(meta.Name()); engine.Meta_tbl_create(meta);}
|
||||
public void Meta_idx_assert(String tbl, String suffix, String... flds) {if (engine.Meta_idx_exists(tbl + "__" + suffix)) return; this.Meta_idx_create(tbl, suffix, flds);}
|
||||
public void Meta_idx_assert(String tbl, String suffix, Dbmeta_idx_fld... flds) {if (engine.Meta_idx_exists(tbl + "__" + suffix)) return; this.Meta_idx_create(tbl, suffix, flds);}
|
||||
public void Meta_idx_create(String tbl, String suffix, String... flds) {engine.Meta_idx_create(Gfo_usr_dlg_.Instance, Dbmeta_idx_itm.new_normal_by_tbl(tbl, suffix, flds));}
|
||||
public void Meta_idx_create(String tbl, String suffix, Dbmeta_idx_fld... flds) {engine.Meta_idx_create(Gfo_usr_dlg_.Instance, Dbmeta_idx_itm.new_normal_by_tbl(tbl, suffix, flds));}
|
||||
public void Meta_idx_create(Dbmeta_idx_itm... idxs) {engine.Meta_idx_create(Gfo_usr_dlg_.Instance, idxs);}
|
||||
public void Meta_idx_delete(String idx) {engine.Meta_idx_delete(idx);}
|
||||
public void Meta_idx_create(Gfo_usr_dlg usr_dlg, Dbmeta_idx_itm... idxs) {engine.Meta_idx_create(usr_dlg, idxs);}
|
||||
public void Meta_idx_delete(String idx) {engine.Meta_idx_delete(idx);}
|
||||
public void Meta_idx_delete(String tbl, String suffix) {engine.Meta_idx_delete(tbl + "__" + suffix);}
|
||||
public void Meta_fld_append(String tbl, Dbmeta_fld_itm fld) {engine.Meta_fld_append(tbl, fld);}
|
||||
public void Meta_fld_assert(String tbl, String fld, Dbmeta_fld_tid tid, Object dflt) {if (!Meta_fld_exists(tbl, fld)) this.Meta_fld_append(tbl, new Dbmeta_fld_itm(fld, tid).Default_(dflt));}
|
||||
public boolean Meta_tbl_exists(String tbl) {return engine.Meta_tbl_exists(tbl);}
|
||||
public boolean Meta_fld_exists(String tbl, String fld) {return engine.Meta_fld_exists(tbl, fld);}
|
||||
public boolean Meta_idx_exists(String idx) {return engine.Meta_idx_exists(idx);}
|
||||
public boolean Meta_idx_exists(String tbl, String suffix) {return engine.Meta_idx_exists(tbl + "__" + suffix);}
|
||||
public void Meta_tbl_assert(Db_tbl... tbls) {
|
||||
boolean dirty = false;
|
||||
for (Db_tbl tbl : tbls) {
|
||||
if (!Meta_tbl_exists(tbl.Tbl_name())) {
|
||||
tbl.Create_tbl();
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
if (dirty) this.Meta_mgr().Load_all();
|
||||
}
|
||||
public String Meta_fld_append_if_missing(String tbl_name, Dbmeta_fld_list flds, Dbmeta_fld_itm fld) {
|
||||
String fld_name = fld.Name();
|
||||
if ( this.Meta_tbl_exists(tbl_name)
|
||||
&& !this.Meta_fld_exists(tbl_name, fld_name)) {
|
||||
try {this.Meta_fld_append(tbl_name, fld);}
|
||||
catch (Exception e) {
|
||||
Gfo_log_.Instance.Warn("failed to append fld", "conn", this.Conn_info().Db_api(), "tbl", tbl_name, "fld", fld_name, "err", Err_.Message_gplx_log(e));
|
||||
fld_name = Dbmeta_fld_itm.Key_null;
|
||||
}
|
||||
}
|
||||
else
|
||||
fld_name = flds.Add(fld);
|
||||
return fld_name;
|
||||
}
|
||||
public Dbmeta_tbl_mgr Meta_mgr() {return engine.Meta_mgr();}
|
||||
public Db_stmt Stmt_insert(String tbl, Dbmeta_fld_list flds) {return engine.Stmt_by_qry(Db_qry_insert.new_(tbl, flds.To_str_ary_wo_autonum()));}
|
||||
public Db_stmt Stmt_insert(String tbl, String... cols) {return engine.Stmt_by_qry(Db_qry_insert.new_(tbl, cols));}
|
||||
public Db_stmt Stmt_update(String tbl, String[] where, String... cols) {return engine.Stmt_by_qry(Db_qry_update.New(tbl, where, cols));}
|
||||
public Db_stmt Stmt_update_exclude(String tbl, Dbmeta_fld_list flds, String... where) {return engine.Stmt_by_qry(Db_qry_update.New(tbl, where, flds.To_str_ary_exclude(where)));}
|
||||
public Db_stmt Stmt_delete(String tbl, String... where) {return engine.Stmt_by_qry(Db_qry_delete.new_(tbl, where));}
|
||||
public Db_stmt Stmt_select_all(String tbl, Dbmeta_fld_list flds) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, String_.Ary_empty, flds.To_str_ary(), null));}
|
||||
public Db_stmt Stmt_select(String tbl, String[] cols, String... where) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, where, cols, null));}
|
||||
public Db_stmt Stmt_select(String tbl, Dbmeta_fld_list flds, String... where) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, where, flds.To_str_ary(), null));}
|
||||
public Db_stmt Stmt_select_order(String tbl, Dbmeta_fld_list flds, String[] where, String... orderbys) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, where, flds.To_str_ary(), orderbys));}
|
||||
@@ -85,7 +116,10 @@ public class Db_conn {
|
||||
try {return rdr.Move_next() ? rdr.Read_at(0) : null;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls_reg(Rls_able rls) {rls_list.Add(rls);}
|
||||
public void Rls_reg(Rls_able rls) {
|
||||
if (this == Db_conn_.Noop) return; // ignore Db_conn_.Noop, else memory leak
|
||||
rls_list.Add(rls);
|
||||
}
|
||||
public void Rls_conn() {
|
||||
int len = rls_list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
@@ -96,7 +130,10 @@ public class Db_conn {
|
||||
engine.Conn_term();
|
||||
Db_conn_pool.Instance.Del(engine.Conn_info());
|
||||
}
|
||||
|
||||
public void Reopen_conn() {
|
||||
engine.Conn_open();
|
||||
Db_conn_pool.Instance.Add_existing(this);
|
||||
}
|
||||
public Db_stmt Stmt_select_max(String tbl, String col, String... where) {
|
||||
Db_qry__select_in_tbl qry = new Db_qry__select_in_tbl(tbl, String_.Ary(String_.Format("Max({0}) AS {0}", col)), where, null, null, null, null);
|
||||
return engine.Stmt_by_qry(qry);
|
||||
|
||||
@@ -42,7 +42,7 @@ class Db_conn_bldr_wkr__sqlite implements Db_conn_bldr_wkr {
|
||||
public static final Db_conn_bldr_wkr__sqlite Instance = new Db_conn_bldr_wkr__sqlite(); Db_conn_bldr_wkr__sqlite() {}
|
||||
}
|
||||
class Db_conn_bldr_wkr__mem implements Db_conn_bldr_wkr {
|
||||
private final Hash_adp hash = Hash_adp_.new_();
|
||||
private final Hash_adp hash = Hash_adp_.New();
|
||||
public void Clear_for_tests() {hash.Clear(); Db_conn_pool.Instance.Rls_all();}
|
||||
public boolean Exists(Io_url url) {
|
||||
String io_url_str = url.Xto_api();
|
||||
|
||||
@@ -19,13 +19,13 @@ package gplx.dbs; import gplx.*;
|
||||
public abstract class Db_conn_info__base implements Db_conn_info {
|
||||
public Db_conn_info__base(String raw, String db_api, String database) {this.raw = raw; this.db_api = db_api; this.database = database;}
|
||||
public abstract String Key();
|
||||
public String Raw() {return raw;} private final String raw;
|
||||
public String Db_api() {return db_api;} private final String db_api;
|
||||
public String Database() {return database;} protected final String database;
|
||||
public String Raw() {return raw;} private final String raw;
|
||||
public String Db_api() {return db_api;} private final String db_api;
|
||||
public String Database() {return database;} protected final String database;
|
||||
public abstract Db_conn_info New_self(String raw, Keyval_hash hash);
|
||||
|
||||
protected static String Bld_raw(String... ary) {// "a", "b" -> "a=b;"
|
||||
Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String itm = ary[i];
|
||||
@@ -35,7 +35,7 @@ public abstract class Db_conn_info__base implements Db_conn_info {
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
protected static String Bld_api(Keyval_hash hash, Keyval... xtn_ary) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Keyval kv = hash.Get_at(i);
|
||||
|
||||
@@ -34,6 +34,9 @@ public class Db_conn_pool { // PURPOSE: cache one connection per connection_stri
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Add_existing(Db_conn conn) {
|
||||
hash.Add(conn.Conn_info().Db_api(), conn);
|
||||
}
|
||||
public void Rls_all() {
|
||||
int len = hash.Len();
|
||||
Db_conn[] rls_ary = new Db_conn[len];
|
||||
@@ -44,7 +47,7 @@ public class Db_conn_pool { // PURPOSE: cache one connection per connection_stri
|
||||
hash.Clear();
|
||||
}
|
||||
|
||||
private final Hash_adp prime_hash = Hash_adp_.new_();
|
||||
private final Hash_adp prime_hash = Hash_adp_.New();
|
||||
public static final Db_conn_pool Instance = new Db_conn_pool(); Db_conn_pool() {this.Init();}
|
||||
public void Primes__add(Db_engine... ary) { // PUBLIC.DRD:
|
||||
for (Db_engine itm : ary)
|
||||
|
||||
@@ -61,7 +61,7 @@ public class Db_conn_utl {
|
||||
}
|
||||
}
|
||||
public static Object[][] Select(Db_conn conn, Db_qry qry) {
|
||||
List_adp rv = List_adp_.new_();
|
||||
List_adp rv = List_adp_.New();
|
||||
Db_rdr rdr = conn.Stmt_new(qry).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
|
||||
@@ -22,7 +22,7 @@ interface Db_sql_qry {
|
||||
}
|
||||
class Db_sql_qry__select {
|
||||
public Db_sql_qry__select(String from) {this.from = from;}
|
||||
public String From() {return from;} private final String from;
|
||||
public String From() {return from;} private final String from;
|
||||
public Db_sql_col[] Select() {return select;} private Db_sql_col[] select;
|
||||
// public Criteria Where() {return where;} private Criteria where;
|
||||
// public Db_sql_col[] Group_bys() {return group_bys;} private Db_sql_col[] group_bys;
|
||||
@@ -51,7 +51,7 @@ class Db_sql_col_ {
|
||||
public static Db_sql_col[] Ary(Db_sql_col... v) {return v;}
|
||||
}
|
||||
class Db_sql_col_bldr {
|
||||
private final List_adp tmp_list = List_adp_.new_();
|
||||
private final List_adp tmp_list = List_adp_.New();
|
||||
public Db_sql_col[] new_fld_many(String[] ary) {
|
||||
tmp_list.Clear();
|
||||
int ord = -1;
|
||||
@@ -63,16 +63,16 @@ class Db_sql_col_bldr {
|
||||
}
|
||||
return (Db_sql_col[])tmp_list.To_ary_and_clear(Db_sql_col.class);
|
||||
}
|
||||
public static final Db_sql_col_bldr Instance = new Db_sql_col_bldr(); Db_sql_col_bldr() {}
|
||||
public static final Db_sql_col_bldr Instance = new Db_sql_col_bldr(); Db_sql_col_bldr() {}
|
||||
}
|
||||
class Db_sql_col__name {
|
||||
public Db_sql_col__name(int ord, String key) {this.ord = ord; this.key = key;}
|
||||
public int Ord() {return ord;} private final int ord;
|
||||
public String Key() {return key;} private final String key;
|
||||
public int Ord() {return ord;} private final int ord;
|
||||
public String Key() {return key;} private final String key;
|
||||
}
|
||||
class Db_sql_col__all implements Db_sql_col {
|
||||
public Db_sql_col__all(int ord, String tbl) {this.ord = ord; this.tbl = tbl;}
|
||||
public int Ord() {return ord;} private final int ord;
|
||||
public String Tbl() {return tbl;} private final String tbl;
|
||||
public int Ord() {return ord;} private final int ord;
|
||||
public String Tbl() {return tbl;} private final String tbl;
|
||||
public String Alias() {return "*";}
|
||||
}
|
||||
|
||||
@@ -49,19 +49,19 @@ public interface Db_stmt extends Rls_able {
|
||||
Db_stmt Crt_bry_as_str(String k, byte[] v);
|
||||
Db_stmt Val_bry_as_str(String k, byte[] v);
|
||||
Db_stmt Val_bry_as_str(byte[] v);
|
||||
Db_stmt Val_rdr_(gplx.core.ios.Io_stream_rdr rdr, long rdr_len);
|
||||
Db_stmt Val_rdr_(gplx.core.ios.streams.Io_stream_rdr rdr, long rdr_len);
|
||||
Db_stmt Crt_date(String k, DateAdp v);
|
||||
Db_stmt Val_date(String k, DateAdp v);
|
||||
Db_stmt Crt_text(String k, String v);
|
||||
Db_stmt Val_text(String k, String v);
|
||||
boolean Exec_insert();
|
||||
int Exec_update();
|
||||
int Exec_delete();
|
||||
DataRdr Exec_select();
|
||||
Db_rdr Exec_select__rls_auto(); // stmt is automatically released
|
||||
Db_rdr Exec_select__rls_manual(); // stmt must be released manually; for "batch" insert
|
||||
Object Exec_select_val();
|
||||
void Ctor_stmt(Db_engine engine, Db_qry qry);
|
||||
Db_stmt Clear();
|
||||
Db_stmt Reset_stmt();
|
||||
boolean Exec_insert();
|
||||
int Exec_update();
|
||||
int Exec_delete();
|
||||
DataRdr Exec_select();
|
||||
Db_rdr Exec_select__rls_auto(); // stmt is automatically released
|
||||
Db_rdr Exec_select__rls_manual(); // stmt must be released manually; for "batch" insert
|
||||
Object Exec_select_val();
|
||||
void Ctor_stmt(Db_engine engine, Db_qry qry);
|
||||
Db_stmt Clear();
|
||||
Db_stmt Reset_stmt();
|
||||
}
|
||||
|
||||
@@ -17,5 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public interface Db_tbl extends Rls_able {
|
||||
void Create_tbl();
|
||||
String Tbl_name();
|
||||
void Create_tbl();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Dbmeta_fld_itm {
|
||||
public Dbmeta_fld_tid Type() {return type;} private final Dbmeta_fld_tid type;
|
||||
public int Nullable_tid() {return nullable_tid;} public Dbmeta_fld_itm Nullable_tid_(int v) {nullable_tid = v; return this;} private int nullable_tid;
|
||||
public Dbmeta_fld_itm Nullable_y_() {return Nullable_tid_(Nullable_null);}
|
||||
public boolean Primary() {return primary;} public Dbmeta_fld_itm Primary_y_() {primary = true; return this;} private boolean primary;
|
||||
public boolean Primary() {return primary;} public Dbmeta_fld_itm Primary_y_() {primary = true; return this;} private boolean primary; public Dbmeta_fld_itm Primary_n_() {primary = false; return this;}
|
||||
public boolean Autonum() {return autonum;} public Dbmeta_fld_itm Autonum_y_() {autonum = true; return this;} private boolean autonum;
|
||||
public Object Default() {return default_val;} public Dbmeta_fld_itm Default_(Object v) {default_val = v; return this;} private Object default_val;
|
||||
public boolean Eq(Dbmeta_fld_itm comp) {
|
||||
|
||||
@@ -17,42 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Dbmeta_fld_list {
|
||||
private final Ordered_hash flds = Ordered_hash_.New();
|
||||
private final List_adp keys = List_adp_.new_();
|
||||
public void Clear() {flds.Clear(); keys.Clear(); str_ary = null; fld_ary = null;}
|
||||
public int Len() {return flds.Len();}
|
||||
public Dbmeta_fld_itm Get_by(String name) {return (Dbmeta_fld_itm)flds.Get_by(name);}
|
||||
public Dbmeta_fld_itm Get_at(int idx) {return (Dbmeta_fld_itm)flds.Get_at(idx);}
|
||||
public String[] To_str_ary() {if (str_ary == null) str_ary = (String[])keys.To_ary(String.class); return str_ary;} private String[] str_ary;
|
||||
public Dbmeta_fld_itm[] To_fld_ary() {if (fld_ary == null) fld_ary = (Dbmeta_fld_itm[])flds.To_ary(Dbmeta_fld_itm.class); return fld_ary;} private Dbmeta_fld_itm[] fld_ary;
|
||||
public String[] To_str_ary_wo_autonum() {
|
||||
int len = flds.Count();
|
||||
List_adp rv = List_adp_.new_();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbmeta_fld_itm fld = (Dbmeta_fld_itm)flds.Get_at(i);
|
||||
if (fld.Autonum()) continue;
|
||||
rv.Add(fld.Name());
|
||||
}
|
||||
return (String[])rv.To_ary(String.class);
|
||||
}
|
||||
public String[] To_str_ary_exclude(String[] ary) {
|
||||
Hash_adp ary_hash = Hash_adp_.new_();
|
||||
List_adp rv = List_adp_.new_();
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; ++i) {
|
||||
String ary_itm = ary[i];
|
||||
ary_hash.Add(ary_itm, ary_itm);
|
||||
}
|
||||
int fld_len = flds.Count();
|
||||
for (int i = 0; i < fld_len; ++i) {
|
||||
Dbmeta_fld_itm fld = (Dbmeta_fld_itm)flds.Get_at(i);
|
||||
String fld_key = fld.Name();
|
||||
if (ary_hash.Has(fld_key)) continue;
|
||||
rv.Add(fld_key);
|
||||
}
|
||||
return rv.To_str_ary();
|
||||
}
|
||||
private final Ordered_hash flds = Ordered_hash_.New();
|
||||
public void Clear() {flds.Clear(); str_ary = null; fld_ary = null;}
|
||||
public int Len() {return flds.Len();}
|
||||
public boolean Has(String key) {return flds.Has(key);}
|
||||
public Dbmeta_fld_itm Get_by(String name) {return (Dbmeta_fld_itm)flds.Get_by(name);}
|
||||
public Dbmeta_fld_itm Get_at(int idx) {return (Dbmeta_fld_itm)flds.Get_at(idx);}
|
||||
public String Add_bool(String name) {return Add(Dbmeta_fld_itm.new_bool(name));}
|
||||
public String Add_byte(String name) {return Add(Dbmeta_fld_itm.new_byte(name));}
|
||||
public String Add_short(String name) {return Add(Dbmeta_fld_itm.new_short(name));}
|
||||
@@ -76,8 +46,63 @@ public class Dbmeta_fld_list {
|
||||
fld_ary = null; str_ary = null;
|
||||
String name = fld.Name();
|
||||
flds.Add(name, fld);
|
||||
keys.Add(name);
|
||||
return name;
|
||||
}
|
||||
public static Dbmeta_fld_list new_() {return new Dbmeta_fld_list();}
|
||||
public void Del(String key) {
|
||||
fld_ary = null; str_ary = null;
|
||||
flds.Del(key);
|
||||
}
|
||||
public void Insert(int pos, Dbmeta_fld_itm fld) {
|
||||
fld_ary = null; str_ary = null;
|
||||
flds.Add_at(pos, fld);
|
||||
}
|
||||
|
||||
public Dbmeta_fld_list New_int(String name) {Add(Dbmeta_fld_itm.new_int(name)); return this;}
|
||||
public Dbmeta_fld_list New_fld(Dbmeta_fld_itm fld) {Add(fld); return this;}
|
||||
public Dbmeta_fld_list Clone() {
|
||||
Dbmeta_fld_list rv = new Dbmeta_fld_list();
|
||||
int len = this.Len();
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.Add(this.Get_at(i));
|
||||
return rv;
|
||||
}
|
||||
public Dbmeta_fld_itm[] To_fld_ary() {if (fld_ary == null) fld_ary = (Dbmeta_fld_itm[])flds.To_ary(Dbmeta_fld_itm.class); return fld_ary;} private Dbmeta_fld_itm[] fld_ary;
|
||||
public String[] To_str_ary() {
|
||||
if (str_ary == null) {
|
||||
int len = flds.Len();
|
||||
this.str_ary = new String[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbmeta_fld_itm fld = (Dbmeta_fld_itm)flds.Get_at(i);
|
||||
str_ary[i] = fld.Name();
|
||||
}
|
||||
}
|
||||
return str_ary;
|
||||
} private String[] str_ary;
|
||||
public String[] To_str_ary_wo_autonum() {
|
||||
int len = flds.Count();
|
||||
List_adp rv = List_adp_.New();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbmeta_fld_itm fld = (Dbmeta_fld_itm)flds.Get_at(i);
|
||||
if (fld.Autonum()) continue;
|
||||
rv.Add(fld.Name());
|
||||
}
|
||||
return (String[])rv.To_ary(String.class);
|
||||
}
|
||||
public String[] To_str_ary_exclude(String[] ary) {
|
||||
Hash_adp ary_hash = Hash_adp_.New();
|
||||
List_adp rv = List_adp_.New();
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; ++i) {
|
||||
String ary_itm = ary[i];
|
||||
ary_hash.Add(ary_itm, ary_itm);
|
||||
}
|
||||
int fld_len = flds.Count();
|
||||
for (int i = 0; i < fld_len; ++i) {
|
||||
Dbmeta_fld_itm fld = (Dbmeta_fld_itm)flds.Get_at(i);
|
||||
String fld_key = fld.Name();
|
||||
if (ary_hash.Has(fld_key)) continue;
|
||||
rv.Add(fld_key);
|
||||
}
|
||||
return rv.To_str_ary();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ public class Dbmeta_idx_itm {
|
||||
public Dbmeta_idx_itm(boolean unique, String tbl, String name, Dbmeta_idx_fld[] flds) {
|
||||
this.tbl = tbl; this.name = name; this.unique = unique; this.Flds = flds;
|
||||
}
|
||||
public String Tbl() {return tbl;} private final String tbl;
|
||||
public String Name() {return name;} private final String name;
|
||||
public boolean Unique() {return unique;} private final boolean unique;
|
||||
public final Dbmeta_idx_fld[] Flds;
|
||||
public String Tbl() {return tbl;} private final String tbl;
|
||||
public String Name() {return name;} private final String name;
|
||||
public boolean Unique() {return unique;} private final boolean unique;
|
||||
public final Dbmeta_idx_fld[] Flds;
|
||||
public String To_sql_create(Sql_qry_wtr sql_wtr) {return sql_wtr.Schema_wtr().Bld_create_idx(this);}
|
||||
public boolean Eq(Dbmeta_idx_itm comp) {
|
||||
return String_.Eq(name, comp.name)
|
||||
@@ -32,21 +32,22 @@ public class Dbmeta_idx_itm {
|
||||
&& tbl == comp.tbl
|
||||
&& Dbmeta_idx_fld.Ary_eq(Flds, comp.Flds);
|
||||
}
|
||||
public static Dbmeta_idx_itm new_unique_by_name (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.Y, tbl, name, To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_unique_by_name (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.Y, tbl, name, To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_normal_by_name (String tbl, String name, Dbmeta_idx_fld... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, name, flds);}
|
||||
public static Dbmeta_idx_itm new_normal_by_name (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, name, To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_unique_by_tbl (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.Y, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_normal_by_tbl (String tbl, String name, Dbmeta_idx_fld... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, Bld_idx_name(tbl, name), flds);}
|
||||
public static Dbmeta_idx_itm new_normal_by_tbl (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_unique_by_tbl_wo_null (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.Y, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_normal_by_tbl_wo_null (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static String Bld_idx_name(String tbl, String suffix) {return String_.Concat(tbl, "__", suffix);}
|
||||
public static final Dbmeta_idx_itm[] Ary_empty = new Dbmeta_idx_itm[0];
|
||||
public static final Dbmeta_idx_itm[] Ary_empty = new Dbmeta_idx_itm[0];
|
||||
public static Dbmeta_idx_fld[] To_fld_ary(String[] ary) {
|
||||
int len = ary.length;
|
||||
Dbmeta_idx_fld[] rv = new Dbmeta_idx_fld[len];
|
||||
int order = -1;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String itm = ary[i]; if (itm == null) continue;
|
||||
rv[i] = new Dbmeta_idx_fld(++order, itm, Dbmeta_idx_fld.Sort_tid__none);
|
||||
rv[i] = new Dbmeta_idx_fld(itm, Dbmeta_idx_fld.Sort_tid__none);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ public class Gfdb_rdr_utl_ {
|
||||
}
|
||||
return CompareAble_.Same;
|
||||
}
|
||||
public static void Stmt_args(Db_stmt stmt, Dbmeta_fld_itm[] flds, int len, Db_rdr rdr) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
public static void Stmt_args(Db_stmt stmt, Dbmeta_fld_itm[] flds, int bgn, int end, Db_rdr rdr) {
|
||||
for (int i = bgn; i < end; ++i) {
|
||||
Dbmeta_fld_itm fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
int tid = fld.Type().Tid_ansi();
|
||||
@@ -57,4 +57,22 @@ public class Gfdb_rdr_utl_ {
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void Stmt_args(Db_stmt stmt, Dbmeta_fld_list flds, int bgn, int end, Db_rdr rdr) {
|
||||
for (int i = bgn; i < end; ++i) {
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
String fld_name = fld.Name();
|
||||
int tid = fld.Type().Tid_ansi();
|
||||
switch (tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (fld_name, rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__byte: stmt.Val_byte (fld_name, rdr.Read_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__int: stmt.Val_int (fld_name, rdr.Read_int(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__long: stmt.Val_long (fld_name, rdr.Read_long(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__float: stmt.Val_float (fld_name, rdr.Read_float(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__double: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__str: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__bry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ class Gfdb_diff_bldr_fxt {
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_wkr__test implements Gfdb_diff_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private final List_adp list = List_adp_.New();
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
private Db_rdr old_rdr, new_rdr;
|
||||
public void Init_rdrs(Gdif_bldr_ctx ctx, Gfdb_diff_tbl tbl, Db_rdr old_rdr, Db_rdr new_rdr) {
|
||||
this.old_rdr = old_rdr; this.new_rdr = new_rdr;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class Gfdb_diff_wkr__db implements Gfdb_diff_wkr {
|
||||
.Val_int (Gdif_db_.Fld__dif_type , dif_type)
|
||||
.Val_int (Gdif_db_.Fld__dif_db_src , -1)
|
||||
.Val_int (Gdif_db_.Fld__dif_db_trg , -1);
|
||||
Gfdb_rdr_utl_.Stmt_args(stmt, flds, flds.length, rdr);
|
||||
Gfdb_rdr_utl_.Stmt_args(stmt, flds, 0, flds.length, rdr);
|
||||
stmt.Exec_insert();
|
||||
if ((++prog_count % prog_interval) == 0) dif_conn.Txn_sav();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class Gfo_srl_mgr_rdr__defn {
|
||||
}
|
||||
class Gfo_srl_mgr_rdr__db {
|
||||
public Object Get_subs (Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_itm proto, String defn_key, Dbmeta_dat_mgr crt_mgr) {
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
|
||||
Gfo_srl_mgr_rdr__defn defn = new Gfo_srl_mgr_rdr__defn(); // Get(key)
|
||||
Db_conn conn = Db_conn_.Noop;
|
||||
@@ -79,12 +79,12 @@ class Gfo_srl_mgr_rdr__db {
|
||||
}
|
||||
class Gfdb_diff_cmd__idx__delete {
|
||||
public Gfdb_diff_cmd__idx__delete(Dbmeta_idx_itm old) {this.Old = old;}
|
||||
public final Dbmeta_idx_itm Old;
|
||||
public final Dbmeta_idx_itm Old;
|
||||
}
|
||||
class Gfdb_diff_cmd__idx__modify {
|
||||
public Gfdb_diff_cmd__idx__modify(Dbmeta_idx_itm old, Dbmeta_idx_itm cur) {this.Old = old; this.Cur = cur;}
|
||||
public final Dbmeta_idx_itm Old;
|
||||
public final Dbmeta_idx_itm Cur;
|
||||
public final Dbmeta_idx_itm Old;
|
||||
public final Dbmeta_idx_itm Cur;
|
||||
}
|
||||
class Gfdb_diff_txn {
|
||||
public int Id = 0;
|
||||
@@ -125,20 +125,20 @@ class Gfdb_diff_cmd__fld__create {
|
||||
}
|
||||
class Gfdb_diff_cmd__fld__delete {
|
||||
public Gfdb_diff_cmd__fld__delete(Dbmeta_fld_itm old) {this.Old = old;}
|
||||
public final Dbmeta_fld_itm Old;
|
||||
public final Dbmeta_fld_itm Old;
|
||||
}
|
||||
class Gfdb_diff_cmd__fld__modify {
|
||||
public Gfdb_diff_cmd__fld__modify(Dbmeta_fld_itm old, Dbmeta_fld_itm cur) {this.Old = old; this.Cur = cur;}
|
||||
public final Dbmeta_fld_itm Old;
|
||||
public final Dbmeta_fld_itm Cur;
|
||||
public final Dbmeta_fld_itm Old;
|
||||
public final Dbmeta_fld_itm Cur;
|
||||
}
|
||||
class Gfdb_diff_cmd__tbl__create {
|
||||
public Gfdb_diff_cmd__tbl__create(Dbmeta_tbl_itm cur) {this.Cur = cur;}
|
||||
public final Dbmeta_tbl_itm Cur;
|
||||
public final Dbmeta_tbl_itm Cur;
|
||||
}
|
||||
class Gfdb_diff_cmd__tbl__delete {
|
||||
public Gfdb_diff_cmd__tbl__delete(Dbmeta_tbl_itm old) {this.Old = old;}
|
||||
public final Dbmeta_tbl_itm Old;
|
||||
public final Dbmeta_tbl_itm Old;
|
||||
}
|
||||
class Gfdb_diff_cmd_bldr {
|
||||
public void Chk_tbls(List_adp rv, Dbmeta_tbl_mgr old_tbls, Dbmeta_tbl_mgr cur_tbls) {
|
||||
@@ -234,8 +234,8 @@ class Gfdb_diff_cmd__insert {
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_cmd_sql_bldr {
|
||||
private final Bry_fmtr fmtr = Bry_fmtr.new_();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
private final Bry_fmtr fmtr = Bry_fmtr.new_();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
public void Bld_insert(Bry_bfr bfr, String tbl_name, String[] keys, String[] vals, int rng_bgn, int rng_end) {
|
||||
fmtr.Fmt_(Insert__fmt).Keys_(Insert__keys);
|
||||
fmtr.Bld_bfr_many(bfr, tbl_name, Bld_flds(tmp_bfr, ", ", "d.", keys, vals), Bld_join(keys), rng_bgn, rng_end);
|
||||
@@ -273,8 +273,8 @@ class Gfdb_diff_cmd_sql_bldr {
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
private static final String[] Insert__keys = String_.Ary("tbl", "flds", "join", "rng_bgn", "rng_end");
|
||||
private static final String Insert__fmt = String_.Concat_lines_nl_skip_last
|
||||
private static final String[] Insert__keys = String_.Ary("tbl", "flds", "join", "rng_bgn", "rng_end");
|
||||
private static final String Insert__fmt = String_.Concat_lines_nl_skip_last
|
||||
( "INSERT INTO db_curr.~{tbl}"
|
||||
, "SELECT ~{flds}"
|
||||
, "FROM db_temp.~{tbl}_pkey k"
|
||||
@@ -282,8 +282,8 @@ class Gfdb_diff_cmd_sql_bldr {
|
||||
, "WHERE k.diff_type = 1"
|
||||
, "AND k.diff_uid BETWEEN ~{rng_bgn} AND ~{rng_end};"
|
||||
);
|
||||
private static final String[] Update__keys = String_.Ary("tbl", "flds", "join", "rng_bgn", "rng_end");
|
||||
private static final String Update__fmt = String_.Concat_lines_nl_skip_last
|
||||
private static final String[] Update__keys = String_.Ary("tbl", "flds", "join", "rng_bgn", "rng_end");
|
||||
private static final String Update__fmt = String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO db_curr.~{tbl}"
|
||||
, "SELECT ~{flds}"
|
||||
, "FROM db_temp.~{tbl}_pkey k"
|
||||
@@ -291,8 +291,8 @@ class Gfdb_diff_cmd_sql_bldr {
|
||||
, "WHERE k.diff_type = 2"
|
||||
, "AND k.diff_uid BETWEEN ~{rng_bgn} AND ~{rng_end};"
|
||||
);
|
||||
private static final String[] Delete__keys = String_.Ary("tbl", "pkey_where", "pkey_select", "join", "rng_bgn", "rng_end");
|
||||
private static final String Delete__fmt = String_.Concat_lines_nl_skip_last
|
||||
private static final String[] Delete__keys = String_.Ary("tbl", "pkey_where", "pkey_select", "join", "rng_bgn", "rng_end");
|
||||
private static final String Delete__fmt = String_.Concat_lines_nl_skip_last
|
||||
( "DELETE db_curr.~{tbl}"
|
||||
, "WHERE ~{pkey_where} IN"
|
||||
, "( SELECT ~{pkey_select}"
|
||||
|
||||
@@ -55,21 +55,19 @@ class Gfdb_diff_cmd__idx__fld implements Gfo_srl_itm {
|
||||
// *_sdif_ddl_idx_fld : idx_uid,fld_order,fld_name,fld_asc
|
||||
public void Save(Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_mgr_wtr wtr) {
|
||||
wtr.Itm_bgn("idx_fld");
|
||||
wtr.Set_int ("fld_order" , cur.Order);
|
||||
wtr.Set_str ("fld_name" , cur.Name);
|
||||
wtr.Set_int ("fld_asc" , cur.Sort_tid);
|
||||
wtr.Itm_end();
|
||||
}
|
||||
public void Load(Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_mgr_rdr rdr) {
|
||||
rdr.Itm_bgn("idx_fld");
|
||||
int order = rdr.Get_int ("fld_order");
|
||||
String name = rdr.Get_str ("fld_name");
|
||||
int sort_tid = rdr.Get_int ("fld_sort");
|
||||
cur = new Dbmeta_idx_fld(order, name, sort_tid);
|
||||
cur = new Dbmeta_idx_fld(name, sort_tid);
|
||||
rdr.Itm_end();
|
||||
}
|
||||
|
||||
public static final Gfdb_diff_cmd__idx__fld Instance = new Gfdb_diff_cmd__idx__fld();
|
||||
public static final Gfdb_diff_cmd__idx__fld Instance = new Gfdb_diff_cmd__idx__fld();
|
||||
}
|
||||
// class Gfdb_diff_cmd__tbl__fld : Gfo_srl_itm {
|
||||
// public Gfdb_diff_cmd__tbl__fld(Dbmeta_fld_itm cur) {this.cur = cur;}
|
||||
@@ -115,5 +113,5 @@ class Gfdb_diff_cmd__idx__fld implements Gfo_srl_itm {
|
||||
//// Dbmeta_fld_tid tid = tbl.Flds().Get_by(name).Type();
|
||||
// }
|
||||
//
|
||||
// public static final Gfdb_diff_cmd__tbl__fld Instance = new Gfdb_diff_cmd__tbl__fld();
|
||||
// public static final Gfdb_diff_cmd__tbl__fld Instance = new Gfdb_diff_cmd__tbl__fld();
|
||||
// }
|
||||
|
||||
@@ -19,7 +19,7 @@ package gplx.dbs.diffs.cmds; import gplx.*; import gplx.dbs.*; import gplx.dbs.d
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; import gplx.dbs.engines.mems.*;
|
||||
public class Gfdb_diff_cmd_sql_bldr_tst {
|
||||
private final Gfdb_diff_cmd_sql_bldr_fxt fxt = new Gfdb_diff_cmd_sql_bldr_fxt();
|
||||
private final Gfdb_diff_cmd_sql_bldr_fxt fxt = new Gfdb_diff_cmd_sql_bldr_fxt();
|
||||
@Test public void Insert() {
|
||||
fxt.Test__insert("tbl1", String_.Ary("key1", "key2"), String_.Ary("fld1", "fld2"), 0, 99, String_.Concat_lines_nl_skip_last
|
||||
( "INSERT INTO db_curr.tbl1"
|
||||
@@ -55,7 +55,7 @@ public class Gfdb_diff_cmd_sql_bldr_tst {
|
||||
}
|
||||
class Gfdb_diff_cmd_sql_bldr_fxt {
|
||||
private Gfdb_diff_cmd_sql_bldr bldr = new Gfdb_diff_cmd_sql_bldr();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public void Test__insert(String tbl_name, String[] keys, String[] flds, int rng_bgn, int rng_end, String expd) {
|
||||
bldr.Bld_insert(bfr, tbl_name, keys, flds, 0, 99);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
|
||||
@@ -19,8 +19,8 @@ package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.d
|
||||
public class Gdif_cmd_tbl implements Rls_able {
|
||||
private String tbl_name = "gdif_cmd";
|
||||
private String fld_grp_id, fld_cmd_id, fld_tid, fld_data;
|
||||
private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
public Gdif_cmd_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
fld_grp_id = flds.Add_int("grp_id"); fld_cmd_id = flds.Add_int("cmd_id"); fld_tid = flds.Add_int("tid"); fld_data = flds.Add_text("data");
|
||||
|
||||
@@ -19,8 +19,8 @@ package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.d
|
||||
public class Gdif_job_tbl implements Rls_able {
|
||||
private String tbl_name = "gdif_job";
|
||||
private String fld_job_id, fld_name, fld_made_by, fld_made_on, fld_data;
|
||||
private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
public Gdif_job_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
fld_job_id = flds.Add_int_pkey("job_id"); fld_name = flds.Add_str("name", 255); fld_made_by = flds.Add_str("made_by", 255); fld_made_on = flds.Add_date("made_on"); fld_data = flds.Add_text("data");
|
||||
|
||||
@@ -19,8 +19,8 @@ package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.d
|
||||
public class Gdif_txn_tbl implements Rls_able {
|
||||
private String tbl_name = "gdif_txn";
|
||||
private String fld_job_id, fld_txn_id, fld_cmd_id, fld_owner_txn;
|
||||
private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
public Gdif_txn_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
fld_job_id = flds.Add_int("job_id"); fld_txn_id = flds.Add_int("txn_id"); fld_cmd_id = flds.Add_int("cmd_id"); fld_owner_txn = flds.Add_int("owner_txn");
|
||||
|
||||
@@ -23,7 +23,7 @@ class Mem_db_fxt {
|
||||
}
|
||||
public Db_conn Make_conn(String url) {return Db_conn_bldr.Instance.Get_or_autocreate(Bool_.Y, Io_url_.mem_fil_(url));}
|
||||
public Dbmeta_tbl_itm Exec__create_tbl(Db_conn conn, String tbl, String... fld_names) {
|
||||
Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
|
||||
Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
int len = fld_names.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
flds.Add_str(fld_names[i], 255);
|
||||
@@ -49,8 +49,8 @@ class Mem_db_fxt {
|
||||
public void Test__select(Db_conn conn, Db_qry qry, String[]... expd) {
|
||||
Db_stmt stmt = conn.Stmt_new(qry);
|
||||
Db_rdr rdr = new Mem_exec_select((Mem_engine)conn.Engine()).Select((Mem_stmt)stmt);
|
||||
List_adp actl_list = List_adp_.new_();
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
List_adp actl_list = List_adp_.New();
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
int expd_len = expd.length;
|
||||
String[] expd_rows = new String[expd_len];
|
||||
for (int i = 0; i < expd_len; ++i) {
|
||||
|
||||
@@ -18,7 +18,7 @@ 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.stores.*; import gplx.dbs.metas.*; import gplx.dbs.sqls.*; import gplx.dbs.conn_props.*; import gplx.dbs.qrys.bats.*;
|
||||
public class Mem_engine implements Db_engine {
|
||||
private final Hash_adp tbl_hash = Hash_adp_.new_();
|
||||
private final Hash_adp tbl_hash = Hash_adp_.New();
|
||||
Mem_engine(Db_conn_info conn_info) {
|
||||
this.conn_info = conn_info;
|
||||
this.qry_runner = new Mem_exec_select(this);
|
||||
@@ -55,7 +55,7 @@ public class Mem_engine implements Db_engine {
|
||||
Mem_tbl tbl = (Mem_tbl)tbl_hash.Get_by(tbl_key);
|
||||
if (tbl != null) tbl.rows.Clear();
|
||||
}
|
||||
public void Meta_idx_create(Gfo_usr_dlg usr_dlg, Dbmeta_idx_itm... ary) {} // TODO: implement unique index
|
||||
public void Meta_idx_create(Gfo_usr_dlg usr_dlg, Dbmeta_idx_itm... ary) {} // TODO_OLD: implement unique index
|
||||
public void Meta_idx_delete(String idx) {}
|
||||
public void Meta_fld_append(String tbl, Dbmeta_fld_itm fld) {}
|
||||
public Dbmeta_tbl_mgr Meta_mgr() {return meta_mgr;} private final Dbmeta_tbl_mgr meta_mgr = new Dbmeta_tbl_mgr(Dbmeta_reload_cmd_.Noop);
|
||||
|
||||
@@ -19,8 +19,8 @@ package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs
|
||||
import gplx.core.criterias.*;
|
||||
import gplx.dbs.qrys.*; import gplx.dbs.sqls.itms.*;
|
||||
public class Mem_exec_select {
|
||||
private final Mem_engine engine;
|
||||
private final List_adp tmp_where_rows = List_adp_.new_();
|
||||
private final Mem_engine engine;
|
||||
private final List_adp tmp_where_rows = List_adp_.New();
|
||||
public Mem_exec_select(Mem_engine engine) {this.engine = engine;}
|
||||
public Db_rdr Select(Mem_stmt stmt) {
|
||||
Db_qry stmt_qry = stmt.Qry();
|
||||
@@ -73,7 +73,7 @@ public class Mem_exec_select {
|
||||
}
|
||||
}
|
||||
class Mem_sorter implements gplx.core.lists.ComparerAble {
|
||||
private final Sql_order_fld[] flds;
|
||||
private final Sql_order_fld[] flds;
|
||||
public Mem_sorter(Sql_order_fld[] flds) {
|
||||
this.flds = flds;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ class Mem_sorter implements gplx.core.lists.ComparerAble {
|
||||
class Mem_exec_ {
|
||||
public static Mem_row[] Rows__join(int join_tid, Mem_row[] lhs_rows, Mem_row[] rhs_rows, String tbl_alias, Sql_join_fld[] join_flds) {
|
||||
int join_flds_len = join_flds.length;
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Hash_adp_bry rhs_hash = Hash_adp_bry.cs();
|
||||
int rhs_rows_len = rhs_rows.length;
|
||||
for (int i = 0; i < rhs_rows_len; ++i) {
|
||||
@@ -102,12 +102,12 @@ class Mem_exec_ {
|
||||
byte[] rhs_key = Rows__bld_key(bfr, Bool_.N, tbl_alias, rhs_row, join_flds, join_flds_len);
|
||||
List_adp rhs_list = (List_adp)rhs_hash.Get_by_bry(rhs_key);
|
||||
if (rhs_list == null) {
|
||||
rhs_list = List_adp_.new_();
|
||||
rhs_list = List_adp_.New();
|
||||
rhs_hash.Add(rhs_key, rhs_list);
|
||||
}
|
||||
rhs_list.Add(rhs_row);
|
||||
}
|
||||
List_adp rv = List_adp_.new_();
|
||||
List_adp rv = List_adp_.New();
|
||||
int lhs_len = lhs_rows.length;
|
||||
for (int i = 0; i < lhs_len; ++i) {
|
||||
Mem_row lhs_row = lhs_rows[i];
|
||||
|
||||
@@ -17,7 +17,7 @@ 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_();
|
||||
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);}
|
||||
|
||||
@@ -16,9 +16,9 @@ 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();
|
||||
private final Ordered_hash flds = Ordered_hash_.New();
|
||||
public class Mem_row implements Gfo_invk {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
private final Ordered_hash flds = Ordered_hash_.New();
|
||||
public int Len() {return hash.Len();}
|
||||
public String Fld_at(int i) {return (String)flds.Get_at(i);}
|
||||
public Object Get_at(int i) {return hash.Get_at(i);}
|
||||
@@ -31,9 +31,9 @@ public class Mem_row implements GfoInvkAble {
|
||||
public void Add(String key, Object val) {hash.Add(key, val); flds.Add_if_dupe_use_1st(key, key);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
Object rv = Get_by(k);
|
||||
if (rv == null) return GfoInvkAble_.Rv_unhandled;
|
||||
if (rv == null) return Gfo_invk_.Rv_unhandled;
|
||||
return rv;
|
||||
}
|
||||
public static final Mem_row[] Ary_empty = new Mem_row[0];
|
||||
public static final Mem_row Null_row = new Mem_row();
|
||||
public static final Mem_row[] Ary_empty = new Mem_row[0];
|
||||
public static final Mem_row Null_row = new Mem_row();
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@ package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs
|
||||
import gplx.core.stores.*;
|
||||
public class Mem_stmt 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();
|
||||
private final Ordered_hash val_list = Ordered_hash_.New();
|
||||
public Mem_stmt(Mem_engine engine, Db_qry qry) {Ctor_stmt(engine, qry);} private Mem_engine engine;
|
||||
public void Ctor_stmt(Db_engine engine, Db_qry qry) {this.engine = (Mem_engine)engine; this.qry = qry;}
|
||||
public Mem_stmt_args Stmt_args() {return stmt_args;} private final Mem_stmt_args stmt_args = new Mem_stmt_args();
|
||||
public Mem_stmt_args Stmt_args() {return stmt_args;} private final Mem_stmt_args stmt_args = new Mem_stmt_args();
|
||||
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);}
|
||||
@@ -111,10 +111,10 @@ public class Mem_stmt implements Db_stmt {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "text", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_rdr_(gplx.core.ios.Io_stream_rdr v, long rdr_len) {
|
||||
public Db_stmt Val_rdr_(gplx.core.ios.streams.Io_stream_rdr v, long rdr_len) {
|
||||
try {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
gplx.core.ios.Io_stream_rdr_.Load_all_to_bfr(bfr, v);
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
gplx.core.ios.streams.Io_stream_rdr_.Load_all_to_bfr(bfr, v);
|
||||
Add("", Bool_.N, bfr.To_str_and_clear());
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
|
||||
return this;
|
||||
|
||||
@@ -18,7 +18,7 @@ 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.criterias.*;
|
||||
public class Mem_stmt_args {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private final List_adp list = List_adp_.New();
|
||||
private int cur_idx = -1;
|
||||
public void Clear() {list.Clear(); cur_idx = -1;}
|
||||
public void Add(String k, Object v) {list.Add(Keyval_.new_(k, v));}
|
||||
|
||||
@@ -19,11 +19,11 @@ package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs
|
||||
import gplx.core.primitives.*; import gplx.core.criterias.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.itms.*;
|
||||
import gplx.dbs.metas.*;
|
||||
public class Mem_tbl {
|
||||
private final List_adp where_rows = List_adp_.new_();
|
||||
private final Hash_adp autonum_hash = Hash_adp_.new_();
|
||||
private final List_adp where_rows = List_adp_.New();
|
||||
private final Hash_adp autonum_hash = Hash_adp_.New();
|
||||
public Mem_tbl(Dbmeta_tbl_itm meta) {this.meta = meta;}
|
||||
public Dbmeta_tbl_itm Meta() {return meta;} private final Dbmeta_tbl_itm meta;
|
||||
public final List_adp rows = List_adp_.new_();
|
||||
public Dbmeta_tbl_itm Meta() {return meta;} private final Dbmeta_tbl_itm meta;
|
||||
public final List_adp rows = List_adp_.New();
|
||||
public int Insert(Mem_stmt stmt) {
|
||||
Mem_row itm = new Mem_row();
|
||||
Dbmeta_fld_mgr flds = meta.Flds();
|
||||
@@ -41,7 +41,7 @@ public class Mem_tbl {
|
||||
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_itm = Int_obj_ref.New(0);
|
||||
autonum_hash.Add(name, autonum_itm);
|
||||
}
|
||||
return autonum_itm.Val_add();
|
||||
|
||||
@@ -58,19 +58,23 @@ public class Sqlite_schema_mgr implements Dbmeta_reload_cmd {
|
||||
String type_str = rdr.Read_str("type");
|
||||
String name = rdr.Read_str("name");
|
||||
String sql = rdr.Read_str("sql");
|
||||
int type_int = Dbmeta_itm_tid.Xto_int(type_str);
|
||||
switch (type_int) {
|
||||
case Dbmeta_itm_tid.Tid_table:
|
||||
if (String_.Has_at_bgn(name, "sqlite_")) continue; // ignore b/c of non-orthodox syntax; EX: "CREATE TABLE sqlite_sequence(name, seq)"; also "CREATE TABLE sqlite_stat(tbl,idx,stat)";
|
||||
tbl_mgr.Add(tbl_parser.Parse(Bry_.new_u8(sql)));
|
||||
break;
|
||||
case Dbmeta_itm_tid.Tid_index:
|
||||
if (sql == null) continue; // ignore "autoindex"; EX: sqlite_autoindex_temp_page_len_avg_1
|
||||
idx_mgr.Add(idx_parser.Parse(Bry_.new_u8(sql)));
|
||||
break;
|
||||
default:
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.schema.unknown type: conn=~{0} type=~{1} name=~{2} sql=~{3}", engine.Conn_info().Db_api(), type_str, name, sql);
|
||||
break;
|
||||
try {
|
||||
int type_int = Dbmeta_itm_tid.Xto_int(type_str);
|
||||
switch (type_int) {
|
||||
case Dbmeta_itm_tid.Tid_table:
|
||||
if (String_.Has_at_bgn(name, "sqlite_")) continue; // ignore b/c of non-orthodox syntax; EX: "CREATE TABLE sqlite_sequence(name, seq)"; also "CREATE TABLE sqlite_stat(tbl,idx,stat)";
|
||||
tbl_mgr.Add(tbl_parser.Parse(Bry_.new_u8(sql)));
|
||||
break;
|
||||
case Dbmeta_itm_tid.Tid_index:
|
||||
if (sql == null) continue; // ignore "autoindex"; EX: sqlite_autoindex_temp_page_len_avg_1
|
||||
idx_mgr.Add(idx_parser.Parse(Bry_.new_u8(sql)));
|
||||
break;
|
||||
default:
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.schema.unknown type: conn=~{0} type=~{1} name=~{2} sql=~{3}", engine.Conn_info().Db_api(), type_str, name, sql);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) { // tables / indexes may be unparseable; skip them; EX: CREATE TABLE unparseable (col_1 /*comment*/ int); DATE:2016-06-08
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.schema.unparseable: conn=~{0} type=~{1} name=~{2} sql=~{3} err=~{4}", engine.Conn_info().Db_api(), type_str, name, sql, Err_.Message_gplx_log(e));
|
||||
}
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs.engines.sqlite; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
public class Sqlite_txn_mgr {
|
||||
private final List_adp txn_list = List_adp_.new_();
|
||||
private final List_adp txn_list = List_adp_.New();
|
||||
public Sqlite_txn_mgr(Db_engine engine) {this.engine = engine;} private final Db_engine engine;
|
||||
private boolean pragma_needed = Bool_.Y, txn_started = Bool_.N; // NOTE: txns only support 1 level; SQLite fails when nesting transactions; DATE:2015-03-11
|
||||
public void Txn_bgn(String name) {
|
||||
|
||||
@@ -52,7 +52,7 @@ class TdbDbSaveMgr {
|
||||
Io_mgr.Instance.SaveFilStr(fil.Path(), wtr.To_str());
|
||||
}
|
||||
List_adp FetchTablesWithSamePath(TdbDatabase db, Io_url filPath) {
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
for (Object tblObj : db.Tables()) {
|
||||
TdbTable tbl = (TdbTable)tblObj;
|
||||
if (tbl.File().Path().Eq (filPath))
|
||||
|
||||
@@ -21,7 +21,7 @@ class TdbDeleteWkr implements Db_qryWkr {
|
||||
public Object Exec(Db_engine engineObj, Db_qry cmdObj) {
|
||||
TdbEngine engine = TdbEngine.cast(engineObj); Db_qry_delete cmd = (Db_qry_delete)cmdObj;
|
||||
TdbTable tbl = engine.FetchTbl(cmd.Base_table());
|
||||
List_adp deleted = List_adp_.new_();
|
||||
List_adp deleted = List_adp_.New();
|
||||
int rv = 0;
|
||||
if (cmd.Where() == Db_qry_delete.Where__null) {
|
||||
rv = tbl.Rows().Count();
|
||||
|
||||
@@ -73,7 +73,7 @@ public class TdbEngine implements Db_engine {
|
||||
public void Env_db_detach(String alias) {}
|
||||
public Dbmeta_tbl_mgr Meta_mgr() {return meta_mgr;} private final Dbmeta_tbl_mgr meta_mgr = new Dbmeta_tbl_mgr(Dbmeta_reload_cmd_.Noop);
|
||||
|
||||
Hash_adp wkrs = Hash_adp_.new_(); TdbDbLoadMgr loadMgr = TdbDbLoadMgr.new_(); TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_();
|
||||
Hash_adp wkrs = Hash_adp_.New(); TdbDbLoadMgr loadMgr = TdbDbLoadMgr.new_(); TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_();
|
||||
public static final TdbEngine Instance = new TdbEngine();
|
||||
void CtorTdbEngine(Db_conn_info conn_info) {
|
||||
this.conn_info = conn_info;
|
||||
|
||||
@@ -57,7 +57,7 @@ class TdbInsertWkr implements Db_qryWkr {
|
||||
return 1;
|
||||
}
|
||||
private String To_str(Sql_select_fld_list flds) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
for (int i = 0; i < flds.Len(); i++) {
|
||||
Sql_select_fld fld = flds.Get_at(i);
|
||||
bfr.Add_str_u8(String_.Format("{0},{1}|", fld.Fld, fld.Alias));
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Dbmeta_fld_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Count();}
|
||||
public void Clear() {hash.Clear();}
|
||||
public void Add(Dbmeta_fld_itm itm) {hash.Add(itm.Name(), itm);}
|
||||
@@ -26,7 +26,7 @@ public class Dbmeta_fld_mgr {
|
||||
public Dbmeta_fld_itm Get_by(String name) {return (Dbmeta_fld_itm)hash.Get_by(name);}
|
||||
public Dbmeta_fld_itm[] To_ary() {return hash.Count() == 0 ? Dbmeta_fld_itm.Ary_empty : (Dbmeta_fld_itm[])hash.To_ary(Dbmeta_fld_itm.class);}
|
||||
public Dbmeta_fld_list To_fld_list() {
|
||||
Dbmeta_fld_list rv = Dbmeta_fld_list.new_();
|
||||
Dbmeta_fld_list rv = new Dbmeta_fld_list();
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.Add(Get_at(i));
|
||||
|
||||
@@ -17,17 +17,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Dbmeta_idx_fld {
|
||||
public Dbmeta_idx_fld(int order, String name, int sort_tid) {this.Name = name; this.Order = order; this.Sort_tid = sort_tid;}
|
||||
public int Order;
|
||||
public Dbmeta_idx_fld(String name, int sort_tid) {this.Name = name; this.Sort_tid = sort_tid;}
|
||||
public String Name;
|
||||
public int Sort_tid;
|
||||
public boolean Eq(Dbmeta_idx_fld comp) {
|
||||
return String_.Eq(Name, comp.Name)
|
||||
&& Order == comp.Order
|
||||
&& Sort_tid == comp.Sort_tid;
|
||||
}
|
||||
|
||||
public static final Dbmeta_idx_fld[] Ary_empty = new Dbmeta_idx_fld[0];
|
||||
public static final Dbmeta_idx_fld[] Ary_empty = new Dbmeta_idx_fld[0];
|
||||
public static final int Sort_tid__none = 0, Sort_tid__asc = 1, Sort_tid__desc = 2;
|
||||
public static boolean Ary_eq(Dbmeta_idx_fld[] lhs_ary, Dbmeta_idx_fld[] rhs_ary) {
|
||||
int lhs_len = lhs_ary.length, rhs_len = rhs_ary.length;
|
||||
@@ -36,4 +34,6 @@ public class Dbmeta_idx_fld {
|
||||
if (!lhs_ary[i].Eq(rhs_ary[i])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Dbmeta_idx_fld Dsc(String name) {return new Dbmeta_idx_fld(name, Sort_tid__desc);}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
public class Dbmeta_parser__idx {
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
private final List_adp tmp_list = List_adp_.new_();
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
private final List_adp tmp_list = List_adp_.New();
|
||||
public Dbmeta_idx_itm Parse(byte[] src) {
|
||||
rdr.Init_by_page(Bry_.Empty, src, src.length);
|
||||
rdr.Skip_ws().Chk_trie_val(trie, Tid__create);
|
||||
@@ -34,11 +34,10 @@ public class Dbmeta_parser__idx {
|
||||
rdr.Skip_ws().Chk_trie_val(trie, Tid__on);
|
||||
byte[] tbl_name = rdr.Read_sql_identifier();
|
||||
rdr.Skip_ws().Chk(Byte_ascii.Paren_bgn);
|
||||
int order = -1;
|
||||
while (true) {
|
||||
byte[] fld_bry = rdr.Read_sql_identifier(); if (fld_bry == null) throw Err_.new_("db", "index parse failed; index field is not an identifier", "src", src);
|
||||
// TODO: check for ASC / DESC
|
||||
Dbmeta_idx_fld fld_itm = new Dbmeta_idx_fld(++order, String_.new_u8(fld_bry), Dbmeta_idx_fld.Sort_tid__none);
|
||||
// TODO_OLD: check for ASC / DESC
|
||||
Dbmeta_idx_fld fld_itm = new Dbmeta_idx_fld(String_.new_u8(fld_bry), Dbmeta_idx_fld.Sort_tid__none);
|
||||
tmp_list.Add(fld_itm);
|
||||
byte sym = rdr.Skip_ws().Read_byte();
|
||||
if (sym == Byte_ascii.Paren_end) break;
|
||||
@@ -46,12 +45,12 @@ public class Dbmeta_parser__idx {
|
||||
return new Dbmeta_idx_itm(unique, String_.new_u8(tbl_name), String_.new_u8(idx_name), (Dbmeta_idx_fld[])tmp_list.To_ary_and_clear(Dbmeta_idx_fld.class));
|
||||
}
|
||||
private static final byte Tid__create = 0, Tid__unique = 1, Tid__index = 2, Tid__on = 3;
|
||||
private static final byte[]
|
||||
private static final byte[]
|
||||
Bry__create = Bry_.new_a7("create")
|
||||
, Bry__unique = Bry_.new_a7("unique")
|
||||
, Bry__index = Bry_.new_a7("index")
|
||||
, Bry__on = Bry_.new_a7("on");
|
||||
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
|
||||
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
|
||||
.Add_bry_byte(Bry__create , Tid__create)
|
||||
.Add_bry_byte(Bry__unique , Tid__unique)
|
||||
.Add_bry_byte(Bry__index , Tid__index)
|
||||
|
||||
@@ -23,10 +23,10 @@ public class Db_qry__select_in_tbl implements Db_qry {
|
||||
}
|
||||
public int Tid() {return Db_qry_.Tid_select_in_tbl;}
|
||||
public boolean Exec_is_rdr() {return true;}
|
||||
public String Base_table() {return base_table;} private final String base_table;
|
||||
public String Base_table() {return base_table;} private final String base_table;
|
||||
public Criteria Where() {return where;} private Criteria where;
|
||||
public String[] Select_flds() {return select_flds;} private final String[] select_flds;
|
||||
private final String[] where_flds;
|
||||
public String[] Select_flds() {return select_flds;} private final String[] select_flds;
|
||||
private final String[] where_flds;
|
||||
public void Where_sql(String_bldr sb) {
|
||||
if (where_flds == null) return;
|
||||
int where_flds_len = where_flds.length;
|
||||
@@ -36,10 +36,10 @@ public class Db_qry__select_in_tbl implements Db_qry {
|
||||
sb.Add(where_flds[i]).Add(" = ? ");
|
||||
}
|
||||
}
|
||||
public String Group_by_sql() {return group_by_sql;} private final String group_by_sql;
|
||||
public String Having_sql() {return having_sql;} private final String having_sql;
|
||||
public String Group_by_sql() {return group_by_sql;} private final String group_by_sql;
|
||||
public String Having_sql() {return having_sql;} private final String having_sql;
|
||||
public String Order_by_sql() {return order_by_sql;} public Db_qry__select_in_tbl Order_by_sql_(String v) {order_by_sql = v; return this;} private String order_by_sql;
|
||||
public String Limit_sql() {return limit_sql;} private final String limit_sql;
|
||||
public String Limit_sql() {return limit_sql;} private final String limit_sql;
|
||||
public String To_sql__exec(gplx.dbs.sqls.Sql_qry_wtr wtr) {
|
||||
synchronized (this) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
@@ -66,7 +66,7 @@ public class Db_qry__select_in_tbl implements Db_qry {
|
||||
case 0: break;
|
||||
case 1: order_by_sql = order_flds[0]; break;
|
||||
default:
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String order_fld = order_flds[i];
|
||||
if (i != 0) bfr.Add_byte_comma();
|
||||
@@ -81,6 +81,6 @@ public class Db_qry__select_in_tbl implements Db_qry {
|
||||
return rv;
|
||||
}
|
||||
public static Db_qry__select_in_tbl as_(Object obj) {return obj instanceof Db_qry__select_in_tbl ? (Db_qry__select_in_tbl)obj : null;}
|
||||
public static final String[] Where_flds__all = String_.Ary_empty;
|
||||
public static final String[] Order_by_null = null;
|
||||
public static final String[] Where_flds__all = String_.Ary_empty;
|
||||
public static final String[] Order_by_null = null;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Db_qry_sql implements Db_qry {
|
||||
byte[] src = Bry_.new_u8(Sql_qry_wtr_.Gen_placeholder_parameters(qry));
|
||||
int src_len = src.length;
|
||||
int args_idx = 0, args_len = args.length, pos = 0;
|
||||
Bry_bfr bfr = Bry_bfr.new_(src_len);
|
||||
Bry_bfr bfr = Bry_bfr_.New_w_size(src_len);
|
||||
while (pos < src_len) {
|
||||
int question_pos = Bry_find_.Find_fwd(src, Byte_ascii.Question, pos);
|
||||
if (question_pos == Bry_find_.Not_found)
|
||||
@@ -78,5 +78,5 @@ public class Db_qry_sql implements Db_qry {
|
||||
val_bry = Bry_.Replace(val_bry, Byte_ascii.Apos_bry, Bry_escape_apos);
|
||||
bfr.Add_byte_apos().Add(val_bry).Add_byte_apos();
|
||||
}
|
||||
} private static final byte[] Bry_null = Bry_.new_u8("NULL"), Bry_escape_apos = Bry_.new_a7("''");
|
||||
} private static final byte[] Bry_null = Bry_.new_u8("NULL"), Bry_escape_apos = Bry_.new_a7("''");
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
try {stmt.setString(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "text", "val", v, "sql", sql);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_rdr_(gplx.core.ios.Io_stream_rdr v, long rdr_len) {
|
||||
public Db_stmt Val_rdr_(gplx.core.ios.streams.Io_stream_rdr v, long rdr_len) {
|
||||
try {stmt.setBinaryStream(++val_idx, (java.io.InputStream)v.Under(), (int)rdr_len);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ import gplx.core.brys.fmtrs.*; import gplx.core.stores.*;
|
||||
import gplx.dbs.engines.*;
|
||||
public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statements; not used for actual insert into database
|
||||
private static final String Key_na = ""; // key is not_available; only called by procs with signature of Val(<type> v);
|
||||
private final List_adp args = List_adp_.new_();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
private final Bry_fmtr tmp_fmtr = Bry_fmtr.new_();
|
||||
private final List_adp args = List_adp_.New();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
private final Bry_fmtr tmp_fmtr = Bry_fmtr.new_();
|
||||
public void Ctor_stmt(Db_engine engine, Db_qry qry) {}
|
||||
public Db_conn Conn() {return conn;} public void Conn_(Db_conn v) {this.conn = v;} Db_conn conn;
|
||||
public Db_stmt Reset_stmt() {return this;}
|
||||
@@ -103,10 +103,10 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
|
||||
try {Add(k, Val_str_wrap(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "text", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_rdr_(gplx.core.ios.Io_stream_rdr v, long rdr_len) {
|
||||
public Db_stmt Val_rdr_(gplx.core.ios.streams.Io_stream_rdr v, long rdr_len) {
|
||||
try {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
gplx.core.ios.Io_stream_rdr_.Load_all_to_bfr(bfr, v);
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
gplx.core.ios.streams.Io_stream_rdr_.Load_all_to_bfr(bfr, v);
|
||||
Add(Key_na, bfr.To_str_and_clear());
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
|
||||
return this;
|
||||
|
||||
@@ -28,15 +28,15 @@ public class Db_obj_ary_tst {
|
||||
}
|
||||
}
|
||||
class Db_obj_ary_fxt {
|
||||
private final Db_obj_ary_crt crt = new Db_obj_ary_crt();
|
||||
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
|
||||
public Db_obj_ary_fxt Init_fld(String name, int tid) {flds_list.Add(new Db_obj_ary_fld(name, tid)); return this;} private List_adp flds_list = List_adp_.new_();
|
||||
public Db_obj_ary_fxt Init_vals(Object... ary) {vals_list.Add(ary); return this;} private List_adp vals_list = List_adp_.new_();
|
||||
private final Db_obj_ary_crt crt = new Db_obj_ary_crt();
|
||||
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
|
||||
public Db_obj_ary_fxt Init_fld(String name, int tid) {flds_list.Add(new Db_obj_ary_fld(name, tid)); return this;} private List_adp flds_list = List_adp_.New();
|
||||
public Db_obj_ary_fxt Init_vals(Object... ary) {vals_list.Add(ary); return this;} private List_adp vals_list = List_adp_.New();
|
||||
public Db_obj_ary_fxt Test_sql(String expd) {
|
||||
Sql_core_wtr cmd_wtr = (Sql_core_wtr)Sql_qry_wtr_.Basic;
|
||||
crt.Flds_((Db_obj_ary_fld[])flds_list.To_ary_and_clear(Db_obj_ary_fld.class));
|
||||
crt.Vals_((Object[][])vals_list.To_ary_and_clear(Object[].class));
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
cmd_wtr.Where_wtr().Bld_where__db_obj(bfr, ctx, crt);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
return this;
|
||||
|
||||
@@ -21,6 +21,6 @@ public class Sql_from_clause {
|
||||
this.Base_tbl = base_tbl;
|
||||
Tbls.Add(base_tbl);
|
||||
}
|
||||
public final List_adp Tbls = List_adp_.new_();
|
||||
public final Sql_tbl_itm Base_tbl;
|
||||
public final List_adp Tbls = List_adp_.New();
|
||||
public final Sql_tbl_itm Base_tbl;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_group_clause {
|
||||
public List_adp Flds() {return flds;} List_adp flds = List_adp_.new_();
|
||||
public List_adp Flds() {return flds;} List_adp flds = List_adp_.New();
|
||||
|
||||
public static Sql_group_clause new_(String... ary) {
|
||||
Sql_group_clause rv = new Sql_group_clause();
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_order_clause {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private final List_adp list = List_adp_.New();
|
||||
private Sql_order_fld[] ary;
|
||||
public void Flds__add(Sql_order_fld fld) {list.Add(fld);}
|
||||
public Sql_order_fld[] Flds() {
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import gplx.core.criterias.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.wtrs.*; import gplx.dbs.sqls.itms.*;
|
||||
public class Sql_core_wtr implements Sql_qry_wtr {
|
||||
private final Bry_bfr bfr = Bry_bfr.new_(64);
|
||||
private final Bry_bfr bfr = Bry_bfr_.New_w_size(64);
|
||||
public byte[] Seq__nl = Byte_ascii.Space_bry;
|
||||
public byte Seq__quote = Byte_ascii.Apos, Seq__escape = Byte_ascii.Backslash;
|
||||
public Sql_core_wtr() {
|
||||
|
||||
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import gplx.core.criterias.*;
|
||||
class Sql_core_wtr_fxt {
|
||||
private final Sql_core_wtr__sqlite wtr = new Sql_core_wtr__sqlite();
|
||||
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private final Sql_core_wtr__sqlite wtr = new Sql_core_wtr__sqlite();
|
||||
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public Sql_core_wtr_fxt Sql_wtr_(Sql_qry_wtr v) {sql_wtr = v; return this;} private Sql_qry_wtr sql_wtr = Sql_qry_wtr_.Sqlite;
|
||||
public void Test__val(Object val, String expd) {
|
||||
wtr.Val_wtr().Bld_val(bfr, ctx, val);
|
||||
|
||||
@@ -51,10 +51,10 @@ public class Sql_qry_wtr__iosql__tst {
|
||||
}
|
||||
Criteria ioCrt_(String fld, Criteria crt) {return Criteria_fld.new_(fld, crt);}
|
||||
String fld;
|
||||
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
|
||||
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
|
||||
void tst_Write(String expd, Criteria crt) {
|
||||
Sql_where_wtr where_wtr = ((Sql_core_wtr)Sql_qry_wtr_.Basic).Where_wtr();
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
where_wtr.Bld_where_elem(bfr, ctx, crt);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import gplx.dbs.metas.*;
|
||||
public class Sql_schema_wtr {
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
public Sql_schema_wtr Bfr_(Bry_bfr bfr) {this.tmp_bfr = bfr; return this;}
|
||||
public String Bld_create_idx(Dbmeta_idx_itm idx) {
|
||||
tmp_bfr.Add_str_a7("CREATE ");
|
||||
@@ -101,5 +101,5 @@ public class Sql_schema_wtr {
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
// public static final Sql_schema_wtr Instance = new Sql_schema_wtr();
|
||||
// public static final Sql_schema_wtr Instance = new Sql_schema_wtr();
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import org.junit.*;
|
||||
public class Sql_schema_wtr_tst {
|
||||
@Before public void setup() {} private final Sql_schema_wtr_fxt fxt = new Sql_schema_wtr_fxt();
|
||||
@Before public void setup() {} private final Sql_schema_wtr_fxt fxt = new Sql_schema_wtr_fxt();
|
||||
@Test public void Idx_unique() {
|
||||
fxt.Test_create_idx(Dbmeta_idx_itm.new_unique_by_tbl("tbl_name", "idx_name", "fld_1", "fld_2")
|
||||
, "CREATE UNIQUE INDEX IF NOT EXISTS tbl_name__idx_name ON tbl_name (fld_1, fld_2);"
|
||||
);
|
||||
}
|
||||
@Test public void Tbl_basic() {
|
||||
Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
|
||||
Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
flds.Add_int_pkey("fld_int_pkey");
|
||||
flds.Add_bool("fld_bool");
|
||||
flds.Add_short("fld_short");
|
||||
@@ -53,7 +53,7 @@ public class Sql_schema_wtr_tst {
|
||||
));
|
||||
}
|
||||
@Test public void Tbl_alter_tbl_add() {
|
||||
Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
|
||||
Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
flds.Add_int_dflt("fld_int", -1);
|
||||
flds.Add_str_dflt("fld_str", 255, "a");
|
||||
fxt.Test_alter_tbl_add("tbl_name", flds.Get_by("fld_int"), "ALTER TABLE tbl_name ADD fld_int integer NOT NULL DEFAULT -1;");
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_val_wtr {
|
||||
// private final Bry_bfr tmp_bfr = Bry_bfr.new_(32);
|
||||
// private final Bry_bfr tmp_bfr = Bry_bfr_.New(32);
|
||||
public byte Seq__quote = Byte_ascii.Apos, Seq__escape = Byte_ascii.Backslash;
|
||||
public void Bld_val(Bry_bfr bfr, Sql_wtr_ctx ctx, Object val) {
|
||||
if (ctx.Mode_is_prep) {
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.stmts; import gplx.*; import gplx.dbs.*;
|
||||
public class Db_stmt_arg_list {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private final List_adp list = List_adp_.New();
|
||||
public void Clear() {list.Clear();}
|
||||
public int Len() {return list.Len();}
|
||||
public Db_stmt_arg Get_at(int i) {return (Db_stmt_arg)list.Get_at(i);}
|
||||
@@ -49,7 +49,7 @@ public class Db_stmt_arg_list {
|
||||
default: throw Err_.new_unhandled_default(tid);
|
||||
}
|
||||
}
|
||||
private static void Fill_val(Db_stmt stmt, int tid, String key, Object val) {
|
||||
public static void Fill_val(Db_stmt stmt, int tid, String key, Object val) {
|
||||
switch (tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (key, Bool_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__byte: stmt.Val_byte (key, Byte_.cast(val)); break;
|
||||
|
||||
@@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.stmts; import gplx.*; import gplx.dbs.*;
|
||||
public class Db_stmt_mgr {
|
||||
private final List_adp fmt_list = List_adp_.new_();
|
||||
private final List_adp fmt_list = List_adp_.New();
|
||||
private final Db_stmt_arg_list arg_list = new Db_stmt_arg_list();
|
||||
public boolean Mode_is_stmt() {return mode_is_stmt;} public Db_stmt_mgr Mode_is_stmt_(boolean v) {mode_is_stmt = v; return this;} private boolean mode_is_stmt = true;
|
||||
public void Clear() {arg_list.Clear(); fmt_list.Clear(); bfr.Clear();}
|
||||
public Bry_bfr Bfr() {return bfr;} private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
public Bry_bfr Bfr() {return bfr;} private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public void Add_var_many(Object... ary) {
|
||||
for (Object o : ary)
|
||||
fmt_list.Add(o);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Db_sys_mgr {
|
||||
private boolean assert_exists = true;
|
||||
public Db_sys_mgr(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
sys_tbl = new Db_sys_tbl(conn);
|
||||
this.sys_tbl = new Db_sys_tbl(conn);
|
||||
}
|
||||
public int Autonum_next(String tbl, String fld) {return Autonum_next(String_.Concat(tbl, ".", fld));}
|
||||
public int Autonum_next(String key) {
|
||||
|
||||
@@ -17,10 +17,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.sys; import gplx.*; import gplx.dbs.*;
|
||||
class Db_sys_tbl implements Rls_able {
|
||||
private final String tbl_name = "gfdb_sys";
|
||||
private final String tbl_name = "gfdb_sys";
|
||||
private String fld_key, fld_val;
|
||||
private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert, stmt_update, stmt_select;
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert, stmt_update, stmt_select;
|
||||
public Db_sys_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
fld_key = flds.Add_str_pkey("sys_key", 255); fld_val = flds.Add_text("sys_val");
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.utls; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.core.envs.*;
|
||||
public class Db_cmd_backup implements GfoInvkAble {
|
||||
public class Db_cmd_backup implements Gfo_invk {
|
||||
public String DbName() {return dbName;} public Db_cmd_backup DbName_(String val) {dbName = val; return this;} private String dbName = "db";
|
||||
public Io_url ExeUrl() {return exeUrl;} public Db_cmd_backup ExeUrl_(Io_url val) {exeUrl = val; return this;} Io_url exeUrl;
|
||||
public Io_url BkpDir() {return bkpDir;} public Db_cmd_backup BkpDir_(Io_url val) {bkpDir = val; return this;} Io_url bkpDir;
|
||||
@@ -41,9 +41,9 @@ public class Db_cmd_backup implements GfoInvkAble {
|
||||
else if (ctx.Match(k, Invk_Pwd_)) pwd = GfoMsgUtl.SetStr(ctx, m, pwd);
|
||||
else if (ctx.Match(k, Invk_DteFmt_)) dteFmt = GfoMsgUtl.SetStr(ctx, m, dteFmt);
|
||||
else if (ctx.Match(k, Invk_BkpFilNameFmt_)) bkpFilNameFmt = GfoMsgUtl.SetStr(ctx, m, bkpFilNameFmt);
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} public static final String
|
||||
} public static final String
|
||||
Invk_ExeUrl = "ExeUrl", Invk_BkpDir = "BkpDir", Invk_Usr = "Usr", Invk_Pwd = "Pwd", Invk_DteFmt = "DteFmt", Invk_BkpFilNameFmt = "BkpFilNameFmt"
|
||||
, Invk_ExeUrl_ = "ExeUrl_", Invk_BkpDir_ = "BkpDir_", Invk_Usr_ = "Usr_", Invk_Pwd_ = "Pwd_", Invk_DteFmt_ = "DteFmt_", Invk_BkpFilNameFmt_ = "BkpFilNameFmt_"
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user