mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Pull more classes into baselib
This commit is contained in:
@@ -13,13 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.srls; import gplx.*;
|
||||
package gplx.core.srls;
|
||||
import gplx.dbs.*;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
public class Dbmeta_dat_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public Dbmeta_dat_mgr Clear() {hash.Clear(); return this;}
|
||||
public int Len() {return hash.Len();}
|
||||
public Dbmeta_dat_itm Get_at(int idx) {return (Dbmeta_dat_itm)hash.Get_at(idx);}
|
||||
public Dbmeta_dat_itm Get_at(int idx) {return (Dbmeta_dat_itm)hash.GetAt(idx);}
|
||||
public Dbmeta_dat_mgr Add_int(String key, int val) {
|
||||
Dbmeta_dat_itm itm = new Dbmeta_dat_itm(DbmetaFldType.TidInt, key, val);
|
||||
hash.Add(key, itm);
|
||||
|
||||
@@ -13,7 +13,16 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores; import gplx.*;
|
||||
package gplx.core.stores;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.basics.lists.Hash_adp;
|
||||
import gplx.types.basics.lists.Hash_adp_;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public class DbMaprItm {
|
||||
public String TableName() {return tableName;} public DbMaprItm TableName_(String val) {tableName = val; return this;} private String tableName;
|
||||
public Ordered_hash Flds() {return flds;} Ordered_hash flds = Ordered_hash_.New();
|
||||
@@ -27,7 +36,7 @@ public class DbMaprItm {
|
||||
contextFlds.Add(arg.ObjProp(), arg);
|
||||
return this;
|
||||
}
|
||||
public DbMaprItm ConstantFlds_add(String dbFld, Object dbVal) {constantFlds.Add(dbFld, Keyval_.new_(dbFld, dbVal)); return this;}
|
||||
public DbMaprItm ConstantFlds_add(String dbFld, Object dbVal) {constantFlds.Add(dbFld, KeyVal.NewStr(dbFld, dbVal)); return this;}
|
||||
public DbMaprItm Subs_add(DbMaprItm... ary) {
|
||||
for (DbMaprItm itm : ary)
|
||||
subs.Add(itm);
|
||||
@@ -36,9 +45,9 @@ public class DbMaprItm {
|
||||
public DbMaprItm Subs_get(String find) {
|
||||
for (Object itmObj : subs) {
|
||||
DbMaprItm itm = (DbMaprItm)itmObj;
|
||||
if (String_.Eq(find, itm.key)) return itm;
|
||||
if (StringUtl.Eq(find, itm.key)) return itm;
|
||||
}
|
||||
throw Err_.new_missing_key(find);
|
||||
throw ErrUtl.NewMissingKey(find);
|
||||
}
|
||||
public DbMaprArg Flds_get(String key) {return (DbMaprArg)flds.GetByOrNull(key);}
|
||||
SrlObj proto; String key; List_adp subs = List_adp_.New();
|
||||
|
||||
@@ -13,7 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores; import gplx.*;
|
||||
package gplx.core.stores;
|
||||
import gplx.frameworks.invks.Gfo_invk;
|
||||
import gplx.frameworks.invks.Gfo_invk_;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
public class DbMaprMgr {
|
||||
public DbMaprArg[] RootIndexFlds() {return rootIndexFlds;} public DbMaprMgr RootIndexFlds_(DbMaprArg... val) {rootIndexFlds = val; return this;} DbMaprArg[] rootIndexFlds;
|
||||
public DbMaprItm Root() {return root;} public DbMaprMgr Root_(DbMaprItm v) {root = v; return this;} DbMaprItm root;
|
||||
@@ -34,8 +40,8 @@ public class DbMaprMgr {
|
||||
DbMaprArg arg = (DbMaprArg)argObj;
|
||||
this.ContextVars().Del(arg.DbFld());
|
||||
}
|
||||
List_adp_.Del_at_last(this.OwnerStack());
|
||||
List_adp_.Del_at_last(this.MaprStack());
|
||||
List_adp_.DelAtLast(this.OwnerStack());
|
||||
List_adp_.DelAtLast(this.MaprStack());
|
||||
}
|
||||
public void Clear() {
|
||||
ownerStack.Clear();
|
||||
|
||||
@@ -13,15 +13,32 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores; import gplx.*;
|
||||
import gplx.core.criterias.*; import gplx.dbs.*; import gplx.core.gfo_ndes.*;
|
||||
package gplx.core.stores;
|
||||
import gplx.frameworks.invks.Gfo_invk;
|
||||
import gplx.frameworks.invks.Gfo_invk_;
|
||||
import gplx.types.basics.lists.Hash_adp;
|
||||
import gplx.types.basics.lists.Hash_adp_;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.core.criterias.Criteria;
|
||||
import gplx.core.criterias.Criteria_;
|
||||
import gplx.core.gfo_ndes.GfoNde;
|
||||
import gplx.core.gfo_ndes.GfoNdeList;
|
||||
import gplx.core.gfo_ndes.GfoNde_;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_conn_info;
|
||||
import gplx.dbs.Db_conn_pool;
|
||||
import gplx.dbs.Db_crt_;
|
||||
import gplx.dbs.Db_qry_;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.commons.KeyVal;
|
||||
public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
@Override public String NameOfNode() {return "DbMaprRdr";}
|
||||
@Override public Object StoreRoot(SrlObj subProto, String key) {
|
||||
mgr = (DbMaprMgr)this.EnvVars().GetByOrFail(DbMaprWtr.Key_Mgr);
|
||||
DbMaprItm rootMapr = mgr.Root();
|
||||
|
||||
GfoNde tbl = GetTbl(rootMapr, rootCrt); int subsCount = tbl.Subs().Count(); if (subsCount == 0) return null; if (subsCount > 1) throw Err_.new_wo_type("criteria returned > 1 row", "criteria", rootCrt.To_str(), "subsCount", subsCount);
|
||||
GfoNde tbl = GetTbl(rootMapr, rootCrt); int subsCount = tbl.Subs().Count(); if (subsCount == 0) return null; if (subsCount > 1) throw ErrUtl.NewArgs("criteria returned > 1 row", "criteria", rootCrt.ToStr(), "subsCount", subsCount);
|
||||
SrlObj root = subProto.SrlObj_New(null);
|
||||
mgr.EnvStack_add(rootMapr, root); RowStack_add(tbl, 0);
|
||||
root.SrlObj_Srl(this);
|
||||
@@ -41,15 +58,15 @@ public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
GfoNde subRow = tbl.Subs().FetchAt_asGfoNde(i);
|
||||
mgr.EnvStack_add(subMapr, sub); rowStack.Add(subRow);
|
||||
sub.SrlObj_Srl(this); list.Add(sub);
|
||||
mgr.EnvStack_del(subMapr, sub); List_adp_.Del_at_last(rowStack);
|
||||
mgr.EnvStack_del(subMapr, sub); List_adp_.DelAtLast(rowStack);
|
||||
}
|
||||
}
|
||||
Criteria MakeCrt(DbMaprMgr mgr, DbMaprItm mapr) {
|
||||
Criteria rv = null, cur = null;
|
||||
List_adp list = GetIdxFlds(mgr, mapr);
|
||||
for (Object kvObj : list) {
|
||||
Keyval kv = (Keyval)kvObj;
|
||||
cur = Db_crt_.New_eq(kv.Key(), kv.Val());
|
||||
KeyVal kv = (KeyVal)kvObj;
|
||||
cur = Db_crt_.New_eq(kv.KeyToStr(), kv.Val());
|
||||
rv = (rv == null) ? cur : Criteria_.And(rv, cur);
|
||||
}
|
||||
return rv;
|
||||
@@ -58,16 +75,16 @@ public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
List_adp rv = List_adp_.New();
|
||||
int maprStackCount = mgr.MaprStack().Len() - 0; // -1 b/c current is added to stack
|
||||
for (int i = 0; i < maprStackCount; i ++) {
|
||||
DbMaprItm mapr = (DbMaprItm)mgr.MaprStack().Get_at(i);
|
||||
SrlObj gobj = (SrlObj)mgr.OwnerStack().Get_at(i);
|
||||
DbMaprItm mapr = (DbMaprItm)mgr.MaprStack().GetAt(i);
|
||||
SrlObj gobj = (SrlObj)mgr.OwnerStack().GetAt(i);
|
||||
for (Object argObj : mapr.ContextFlds()) {
|
||||
DbMaprArg arg = (DbMaprArg)argObj;
|
||||
Object propVal = Gfo_invk_.Invk_by_key((Gfo_invk)gobj, arg.ObjProp());
|
||||
rv.Add(Keyval_.new_(arg.DbFld(), propVal));
|
||||
rv.Add(KeyVal.NewStr(arg.DbFld(), propVal));
|
||||
}
|
||||
}
|
||||
for (Object argObj : curMapr.ConstantFlds()) {
|
||||
Keyval arg = (Keyval)argObj;
|
||||
KeyVal arg = (KeyVal)argObj;
|
||||
rv.Add(arg);
|
||||
}
|
||||
return rv;
|
||||
@@ -92,22 +109,22 @@ public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
return rv;
|
||||
}
|
||||
void RowStack_add(GfoNde tbl, int i) {
|
||||
GfoNdeList ndeList = tbl.Subs(); if (i >= ndeList.Count()) throw Err_.new_missing_idx(i, ndeList.Count());
|
||||
GfoNdeList ndeList = tbl.Subs(); if (i >= ndeList.Count()) throw ErrUtl.NewMissingIdx(i, ndeList.Count());
|
||||
rowStack.Add(tbl.Subs().FetchAt_asGfoNde(i));
|
||||
}
|
||||
@Override public Object Read(String key) {
|
||||
DbMaprItm mapr = (DbMaprItm)mgr.MaprStack().GetAtLast();
|
||||
GfoNde row = (GfoNde)rowStack.GetAtLast();
|
||||
DbMaprArg arg = mapr.Flds_get(key);
|
||||
Object dbVal = null; try {dbVal = row.Read(arg.DbFld());} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to read dbVal from row", "key", key, "fld", arg.DbFld());}
|
||||
Object dbVal = null; try {dbVal = row.Read(arg.DbFld());} catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to read dbVal from row", "key", key, "fld", arg.DbFld());}
|
||||
return dbVal;
|
||||
}
|
||||
@Override public DataRdr Subs_byName_moveFirst(String name) {throw Err_.new_unimplemented();}
|
||||
@Override public DataRdr Subs() {throw Err_.new_unimplemented();}
|
||||
@Override public int FieldCount() {throw Err_.new_unimplemented();}
|
||||
@Override public String KeyAt(int i) {throw Err_.new_unimplemented();}
|
||||
@Override public Object ReadAt(int i) {throw Err_.new_unimplemented();}
|
||||
@Override public Keyval KeyValAt(int i) {throw Err_.new_unimplemented();}
|
||||
@Override public DataRdr Subs_byName_moveFirst(String name) {throw ErrUtl.NewUnimplemented();}
|
||||
@Override public DataRdr Subs() {throw ErrUtl.NewUnimplemented();}
|
||||
@Override public int FieldCount() {throw ErrUtl.NewUnimplemented();}
|
||||
@Override public String KeyAt(int i) {throw ErrUtl.NewUnimplemented();}
|
||||
@Override public Object ReadAt(int i) {throw ErrUtl.NewUnimplemented();}
|
||||
@Override public KeyVal KeyValAt(int i) {throw ErrUtl.NewUnimplemented();}
|
||||
@Override public SrlMgr SrlMgr_new(Object o) {return new DbMaprRdr();}
|
||||
Hash_adp tables = Hash_adp_.New();
|
||||
Db_conn conn; Criteria rootCrt;
|
||||
|
||||
@@ -13,9 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores; import gplx.*;
|
||||
package gplx.core.stores;
|
||||
import gplx.core.criterias.*; import gplx.core.gfo_ndes.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*;
|
||||
import gplx.frameworks.invks.Gfo_invk;
|
||||
import gplx.frameworks.invks.Gfo_invk_;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.utls.ClassUtl;
|
||||
public class DbMaprWtr extends DataWtr_base implements DataWtr {
|
||||
public void InitWtr(String key, Object val) {}
|
||||
@Override public Object StoreRoot(SrlObj root, String key) {
|
||||
@@ -45,8 +50,8 @@ public class DbMaprWtr extends DataWtr_base implements DataWtr {
|
||||
void WriteContextFlds() {
|
||||
int maprStackCount = mgr.MaprStack().Len() - 1; // -1 b/c current is added to stack
|
||||
for (int i = 0; i < maprStackCount; i ++) {
|
||||
DbMaprItm mapr = (DbMaprItm)mgr.MaprStack().Get_at(i);
|
||||
SrlObj gobj = (SrlObj)mgr.OwnerStack().Get_at(i);
|
||||
DbMaprItm mapr = (DbMaprItm)mgr.MaprStack().GetAt(i);
|
||||
SrlObj gobj = (SrlObj)mgr.OwnerStack().GetAt(i);
|
||||
for (Object argObj : mapr.ContextFlds()) {
|
||||
DbMaprArg arg = (DbMaprArg)argObj;
|
||||
Object argVal = Gfo_invk_.Invk_by_key((Gfo_invk)gobj, arg.ObjProp());
|
||||
@@ -61,12 +66,12 @@ public class DbMaprWtr extends DataWtr_base implements DataWtr {
|
||||
}
|
||||
@Override public void WriteData(String name, Object val) {
|
||||
DbMaprItm ownerMapr = (DbMaprItm)mgr.MaprStack().GetAtLast();
|
||||
String fld = ""; try {fld = ownerMapr.Flds_get(name).DbFld();} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to fetch fld from mapr", "key", name);}
|
||||
String fld = ""; try {fld = ownerMapr.Flds_get(name).DbFld();} catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to fetch fld from mapr", "key", name);}
|
||||
WriteDataVal(fld, val);
|
||||
}
|
||||
void WriteDataVal(String fld, Object val) {
|
||||
if (insertCmd == null) insertCmd = Db_qry_.insert_(curTableName);
|
||||
if (Type_.Eq_by_obj(val, String.class))
|
||||
if (ClassUtl.EqByObj(String.class, val))
|
||||
insertCmd.Val_obj_type(fld, val, Db_val_type.Tid_varchar);
|
||||
else
|
||||
insertCmd.Val_obj(fld, val);
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores; import gplx.*; import gplx.core.*;
|
||||
import java.sql.Date;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.commons.GfoDate;
|
||||
import gplx.types.commons.GfoDateUtl;
|
||||
import gplx.types.commons.GfoDecimal;
|
||||
import gplx.types.commons.GfoDecimalUtl;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.GregorianCalendar;
|
||||
import gplx.dbs.*;
|
||||
public class Db_data_rdr extends DataRdr_base implements DataRdr {
|
||||
@Override public String NameOfNode() {return commandText;} public String To_str() {return commandText;} private String commandText;
|
||||
private ResultSet rdr;
|
||||
@@ -28,27 +32,27 @@ public class Db_data_rdr extends DataRdr_base implements DataRdr {
|
||||
@Override public String KeyAt(int i) {
|
||||
String rv = null;
|
||||
try {rv = rdr.getMetaData().getColumnLabel(i + List_adp_.Base1);}
|
||||
catch (SQLException e) {throw Err_.new_exc(e, "db", "get columnName failed", "i", i, "commandText", commandText);}
|
||||
catch (SQLException e) {throw ErrUtl.NewArgs(e, "get columnName failed", "i", i, "commandText", commandText);}
|
||||
return rv;
|
||||
}
|
||||
@Override public Object ReadAt(int i) {
|
||||
Object rv;
|
||||
try {rv = rdr.getObject(i + List_adp_.Base1);} catch(Exception exc) {throw Err_.new_wo_type("could not read val from dataReader; idx not found or rdr not open", "idx", i, "sql", commandText);}
|
||||
try {rv = rdr.getObject(i + List_adp_.Base1);} catch(Exception exc) {throw ErrUtl.NewArgs("could not read val from dataReader; idx not found or rdr not open", "idx", i, "sql", commandText);}
|
||||
return rv;
|
||||
}
|
||||
@Override public Object Read(String key) {
|
||||
Object rv;
|
||||
try {rv = rdr.getObject(key);} catch(Exception exc) {throw Err_.new_wo_type("could not read val from dataReader; key not found or rdr may not be open", "key", key, "sql", commandText);}
|
||||
try {rv = rdr.getObject(key);} catch(Exception exc) {throw ErrUtl.NewArgs("could not read val from dataReader; key not found or rdr may not be open", "key", key, "sql", commandText);}
|
||||
return rv;
|
||||
}
|
||||
@Override public DateAdp ReadDate(String key) {
|
||||
@Override public GfoDate ReadDate(String key) {
|
||||
Object o = this.Read(key);
|
||||
Timestamp ts = (Timestamp)o;
|
||||
GregorianCalendar g = new GregorianCalendar();
|
||||
g.setTime(ts);
|
||||
return DateAdp_.dateTime_(g);
|
||||
return GfoDateUtl.NewByCalendar(g);
|
||||
}
|
||||
@Override public Decimal_adp ReadDecimal(String key) {return Decimal_adp_.db_(this.Read(key));}
|
||||
@Override public GfoDecimal ReadDecimal(String key) {return GfoDecimalUtl.NewDb(this.Read(key));}
|
||||
@Override public gplx.core.ios.streams.Io_stream_rdr ReadRdr(String key) {
|
||||
try {
|
||||
java.io.InputStream input_stream = rdr.getBinaryStream(key);
|
||||
@@ -59,20 +63,20 @@ public class Db_data_rdr extends DataRdr_base implements DataRdr {
|
||||
|
||||
public boolean MoveNextPeer() {
|
||||
try {return rdr.next();}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "could not move next; check column casting error in SQL", "sql", commandText);}
|
||||
catch (Exception e) {throw ErrUtl.NewArgs(e, "could not move next; check column casting error in SQL", "sql", commandText);}
|
||||
}
|
||||
@Override public DataRdr Subs() {throw Err_.new_unimplemented();}
|
||||
public DataRdr Subs_byName(String fld) {throw Err_.new_unimplemented();}
|
||||
@Override public DataRdr Subs_byName_moveFirst(String fld) {throw Err_.new_unimplemented();}
|
||||
@Override public DataRdr Subs() {throw ErrUtl.NewUnimplemented();}
|
||||
public DataRdr Subs_byName(String fld) {throw ErrUtl.NewUnimplemented();}
|
||||
@Override public DataRdr Subs_byName_moveFirst(String fld) {throw ErrUtl.NewUnimplemented();}
|
||||
public void Rls() {
|
||||
try {rdr.close();}
|
||||
catch (SQLException e) {throw Err_.new_exc(e, "db", "reader dispose failed", "commandText", commandText);}
|
||||
catch (SQLException e) {throw ErrUtl.NewArgs(e, "reader dispose failed", "commandText", commandText);}
|
||||
this.EnvVars().Clear();
|
||||
}
|
||||
@gplx.Internal protected Db_data_rdr ctor_db_data_rdr(ResultSet rdr, String commandText) {
|
||||
public Db_data_rdr ctor_db_data_rdr(ResultSet rdr, String commandText) {
|
||||
this.rdr = rdr; this.commandText = commandText; this.Parse_set(false);
|
||||
try {fieldCount = this.rdr.getMetaData().getColumnCount();}
|
||||
catch (SQLException e) {Err_.new_exc(e, "xo", "get columnCount failed", "commandText", commandText);}
|
||||
catch (SQLException e) {ErrUtl.NewArgs(e, "get columnCount failed", "commandText", commandText);}
|
||||
return this;
|
||||
}
|
||||
@Override public SrlMgr SrlMgr_new(Object o) {return new Db_data_rdr();}
|
||||
|
||||
@@ -13,7 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.stores;
|
||||
import gplx.frameworks.invks.GfoMsg;
|
||||
import gplx.frameworks.invks.Gfo_invk;
|
||||
import gplx.frameworks.invks.Gfo_invk_;
|
||||
import gplx.frameworks.invks.GfsCtx;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
class MockDisc implements SrlObj, Gfo_invk {
|
||||
public int Id() {return id;} public MockDisc Id_(int val) {id = val; return this;} int id; public static final String id_idk = "id";
|
||||
public String Name() {return name;} public MockDisc Name_(String val) {name = val; return this;} private String name; public static final String name_idk = "name";
|
||||
|
||||
@@ -13,14 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_attach_itm {
|
||||
public Db_attach_itm(String key, Io_url url) {
|
||||
this.Key = key; this.Url = url;
|
||||
}
|
||||
public Db_attach_itm(String key, Db_conn conn) {
|
||||
this.Key = key; this.Url = gplx.dbs.engines.sqlite.Sqlite_conn_info.To_url(conn);
|
||||
}
|
||||
public final String Key;
|
||||
public final Io_url Url;
|
||||
}
|
||||
package gplx.dbs;
|
||||
import gplx.libs.files.Io_url;
|
||||
public class Db_attach_itm {
|
||||
public Db_attach_itm(String key, Io_url url) {
|
||||
this.Key = key; this.Url = url;
|
||||
}
|
||||
public Db_attach_itm(String key, Db_conn conn) {
|
||||
this.Key = key; this.Url = gplx.dbs.engines.sqlite.Sqlite_conn_info.To_url(conn);
|
||||
}
|
||||
public final String Key;
|
||||
public final Io_url Url;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,16 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
package gplx.dbs;
|
||||
import gplx.dbs.sqls.*; import gplx.dbs.sqls.itms.*;
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg_;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.libs.files.Io_url;
|
||||
public class Db_attach_mgr {
|
||||
private Db_conn main_conn; private Io_url main_conn_url;
|
||||
private final Ordered_hash links_hash = Ordered_hash_.New();
|
||||
@@ -41,14 +49,14 @@ public class Db_attach_mgr {
|
||||
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);
|
||||
Db_attach_itm itm = (Db_attach_itm)attach_list.GetAt(i);
|
||||
main_conn.Env_db_attach(itm.Key, itm.Url);
|
||||
}
|
||||
}
|
||||
public void Detach() {
|
||||
int len = attach_list.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_attach_itm itm = (Db_attach_itm)attach_list.Get_at(i);
|
||||
Db_attach_itm itm = (Db_attach_itm)attach_list.GetAt(i);
|
||||
main_conn.Env_db_detach(itm.Key);
|
||||
}
|
||||
attach_list.Clear(); // clear list so multiple detachs don't fail
|
||||
@@ -57,16 +65,16 @@ public class Db_attach_mgr {
|
||||
attach_list.Clear();
|
||||
int hash_len = links_hash.Len();
|
||||
for (int i = 0; i < hash_len; ++i) {
|
||||
Db_attach_itm attach_itm = (Db_attach_itm)links_hash.Get_at(i);
|
||||
Db_attach_itm attach_itm = (Db_attach_itm)links_hash.GetAt(i);
|
||||
String tkn = "<" + attach_itm.Key + ">";
|
||||
if (String_.Has(sql, tkn)) {
|
||||
if (StringUtl.Has(sql, tkn)) {
|
||||
Io_url attach_url = attach_itm.Url;
|
||||
String repl = "";
|
||||
if (!attach_url.Eq(main_conn_url)) {
|
||||
repl = attach_itm.Key + ".";
|
||||
attach_list.Add(attach_itm);
|
||||
}
|
||||
sql = String_.Replace(sql, tkn, repl);
|
||||
sql = StringUtl.Replace(sql, tkn, repl);
|
||||
}
|
||||
}
|
||||
attached_sql = sql;
|
||||
@@ -78,7 +86,7 @@ public class Db_attach_mgr {
|
||||
return this;
|
||||
}
|
||||
public Db_attach_mgr Exec_sql(String sql, Object... args) {
|
||||
String attach_sql = String_.Format(Resolve_sql(sql), args);
|
||||
String attach_sql = StringUtl.Format(Resolve_sql(sql), args);
|
||||
this.Attach();
|
||||
try {main_conn.Exec_sql(attach_sql);}
|
||||
finally {this.Detach();}
|
||||
@@ -89,7 +97,7 @@ public class Db_attach_mgr {
|
||||
int rv_len = attach_list.Len();
|
||||
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);
|
||||
Db_attach_itm itm = (Db_attach_itm)attach_list.GetAt(i);
|
||||
rv[i] = itm.Key;
|
||||
}
|
||||
return rv;
|
||||
@@ -100,10 +108,10 @@ public class Db_attach_mgr {
|
||||
List_adp from_tbls = from_itm.Tbls;
|
||||
int from_tbls_len = from_tbls.Len();
|
||||
for (int i = 0; i < from_tbls_len; ++i) {
|
||||
Sql_tbl_itm from_tbl = (Sql_tbl_itm)from_tbls.Get_at(i);
|
||||
Sql_tbl_itm from_tbl = (Sql_tbl_itm)from_tbls.GetAt(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)links_hash.GetByOrNull(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.ToSqlExec(sql_wtr));
|
||||
if (StringUtl.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)links_hash.GetByOrNull(from_tbl_db); if (attach_itm == null) throw ErrUtl.NewArgs("qry defines an unknown database for attach_wkr", "from_tbl_db", from_tbl_db, "sql", qry.ToSqlExec(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
|
||||
@@ -112,7 +120,7 @@ public class Db_attach_mgr {
|
||||
attached_sql = sql_wtr.ToSqlStr(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);
|
||||
Sql_tbl_itm from_tbl = (Sql_tbl_itm)from_tbls.GetAt(i);
|
||||
from_tbl.Db_enabled = true;
|
||||
}
|
||||
return main_conn.Stmt_sql(attached_sql);
|
||||
|
||||
@@ -13,8 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.dbs.qrys.*;
|
||||
package gplx.dbs;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.libs.files.Io_url_;
|
||||
import org.junit.*;
|
||||
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() {
|
||||
@@ -34,7 +38,7 @@ public class Db_attach_mgr__tst {
|
||||
+ "INNER JOIN tbl_2 t2 ON t1.fld_2 = t2.fld_2 " // NOTE: curr is db_2 so do not prefix tbl_2 with db_2; fails if "db_2.tbl_2"
|
||||
+ "INNER JOIN db_3.tbl_3 t3 ON t1.fld_3 = t3.fld_3 "
|
||||
+ "INNER JOIN tbl_4 t4 ON t1.fld_4 = t4.fld_4"
|
||||
, String_.Ary("db_1", "db_3") // NOTE: no "db_2"
|
||||
, StringUtl.Ary("db_1", "db_3") // NOTE: no "db_2"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -51,7 +55,7 @@ class Db_attach_mgr__fxt {
|
||||
}
|
||||
public void Test__make_stmt_and_attach(Db_qry__select_cmd qry, String expd_sql, String[] expd_dbs) {
|
||||
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());
|
||||
GfoTstr.Eq(expd_sql, mgr.Test__attach_sql());
|
||||
GfoTstr.EqLines(expd_dbs, mgr.Test__attach_list_keys());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class Db_cmd_mode {
|
||||
Db_cmd_mode(int val) {this.val = val;}
|
||||
public int Val() {return val;} int val;
|
||||
@@ -34,7 +35,7 @@ public class Db_cmd_mode {
|
||||
case Tid_ignore: // must mark for update
|
||||
case Tid_update: // return self
|
||||
return Tid_update;
|
||||
default: throw Err_.new_unhandled(cur);
|
||||
default: throw ErrUtl.NewUnhandled(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,18 +15,18 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Double_;
|
||||
import gplx.Err_;
|
||||
import gplx.Gfo_log_;
|
||||
import gplx.Gfo_usr_dlg;
|
||||
import gplx.Gfo_usr_dlg_;
|
||||
import gplx.Int_;
|
||||
import gplx.Io_url;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.Rls_able;
|
||||
import gplx.String_;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
import gplx.types.basics.utls.DoubleUtl;
|
||||
import gplx.libs.logs.Gfo_log_;
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg;
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg_;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.frameworks.objects.Rls_able;
|
||||
import gplx.core.stores.DataRdr;
|
||||
import gplx.core.stores.DataRdr_;
|
||||
import gplx.dbs.conn_props.Db_conn_props_mgr;
|
||||
@@ -56,7 +56,7 @@ public class Db_conn {
|
||||
public Db_engine Engine() {return engine;} private final Db_engine engine;
|
||||
public Db_sys_mgr Sys_mgr() {return sys_mgr;} private final Db_sys_mgr sys_mgr; // autonum and other functions
|
||||
public SqlWkrMgr WkrMgr() {return wkrMgr;} private final SqlWkrMgr wkrMgr;
|
||||
public boolean Eq(Db_conn comp) {return String_.Eq(engine.Conn_info().Db_api(), comp.Conn_info().Db_api());}
|
||||
public boolean Eq(Db_conn comp) {return StringUtl.Eq(engine.Conn_info().Db_api(), comp.Conn_info().Db_api());}
|
||||
public void Txn_bgn(String name) {engine.Txn_bgn(name);}
|
||||
public void Txn_end() {engine.Txn_end();}
|
||||
public void Txn_cxl() {engine.Txn_cxl();}
|
||||
@@ -101,7 +101,7 @@ public class Db_conn {
|
||||
&& !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));
|
||||
Gfo_log_.Instance.Warn("failed to append fld", "conn", this.Conn_info().Db_api(), "tbl", tbl_name, "fld", fld_name, "err", ErrUtl.ToStrLog(e));
|
||||
fld_name = DbmetaFldItm.KeyNull;
|
||||
}
|
||||
}
|
||||
@@ -118,21 +118,21 @@ public class Db_conn {
|
||||
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, DbmetaFldList flds, String... where) {return engine.Stmt_by_qry(Db_qry_update.New(tbl, where, flds.ToStrAryExclude(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, DbmetaFldList flds) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, String_.Ary_empty, flds.ToStrAry(), null));}
|
||||
public Db_stmt Stmt_select_all(String tbl, DbmetaFldList flds) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, StringUtl.AryEmpty, flds.ToStrAry(), 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, DbmetaFldList flds, String... where) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, where, flds.ToStrAry(), null));}
|
||||
public Db_stmt Stmt_select_order(String tbl, DbmetaFldList flds, String[] where, String... orderbys) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, where, flds.ToStrAry(), orderbys));}
|
||||
public Db_stmt Stmt_select_order(String tbl, String[] flds, String[] where, String... orderbys) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, where, flds, orderbys));}
|
||||
public Db_stmt Stmt_new(Db_qry qry) {return engine.Stmt_by_qry(qry);}
|
||||
public Db_stmt Stmt_sql(String sql) {return engine.Stmt_by_qry(Db_qry_sql.sql_(sql));}
|
||||
public int Exec_qry(Db_qry qry) {return Int_.Cast(engine.Exec_as_obj(qry));}
|
||||
public int Exec_sql_concat(String... ary) {return this.Exec_qry(Db_qry_sql.dml_(String_.Concat_lines_nl_skip_last(ary)));}
|
||||
public int Exec_qry(Db_qry qry) {return IntUtl.Cast(engine.Exec_as_obj(qry));}
|
||||
public int Exec_sql_concat(String... ary) {return this.Exec_qry(Db_qry_sql.dml_(StringUtl.ConcatLinesNlSkipLast(ary)));}
|
||||
public int Exec_sql_concat_w_msg(String msg, String... ary) {Gfo_usr_dlg_.Instance.Plog_many("", "", msg); return Exec_sql_concat(ary);}
|
||||
public int Exec_sql(String sql) {return this.Exec_qry(Db_qry_sql.dml_(sql));}
|
||||
public int Exec_sql(String msg, String sql) {Gfo_usr_dlg_.Instance.Plog_many("", "", msg); return this.Exec_sql(sql);}
|
||||
public Db_rdr Exec_rdr(String sql) {return this.Stmt_sql(sql).Exec_select__rls_auto();}
|
||||
public void Exec_delete_all(String tbl) {Stmt_delete(tbl).Exec_delete();}
|
||||
public int Exec_sql_args(String sql, Object... args) {return this.Exec_qry(Db_qry_sql.dml_(String_.Format(sql, args)));}
|
||||
public int Exec_sql_args(String sql, Object... args) {return this.Exec_qry(Db_qry_sql.dml_(StringUtl.Format(sql, args)));}
|
||||
public int Exec_sql_plog_ntx(String msg, String sql) {return Exec_sql_plog(BoolUtl.N, msg, sql);}
|
||||
public int Exec_sql_plog_txn(String msg, String sql) {return Exec_sql_plog(BoolUtl.Y, msg, sql);}
|
||||
public int Exec_sql_plog(boolean txn, String msg, String sql) {
|
||||
@@ -144,15 +144,15 @@ public class Db_conn {
|
||||
return rv;
|
||||
}
|
||||
public int Exec_select_max_as_int (String tbl_name, String fld_name, int or) {
|
||||
Object rv = Exec_select_as_obj(String_.Format("SELECT Max({0}) FROM {1}", fld_name, tbl_name));
|
||||
return rv == null ? or : Int_.Cast(rv);
|
||||
Object rv = Exec_select_as_obj(StringUtl.Format("SELECT Max({0}) FROM {1}", fld_name, tbl_name));
|
||||
return rv == null ? or : IntUtl.Cast(rv);
|
||||
}
|
||||
public int Exec_select_count_as_int(String tbl_name, int or) {
|
||||
Object rv = Exec_select_as_obj(String_.Format("SELECT Count(*) FROM {0}", tbl_name));
|
||||
return rv == null ? or : Int_.Cast(rv);
|
||||
Object rv = Exec_select_as_obj(StringUtl.Format("SELECT Count(*) FROM {0}", tbl_name));
|
||||
return rv == null ? or : IntUtl.Cast(rv);
|
||||
}
|
||||
public int Exec_select_as_int (String sql, int or) {Object rv = Exec_select_as_obj(sql); return rv == null ? or : Int_.Cast(rv);}
|
||||
public double Exec_select_as_double (String sql, double or) {Object rv = Exec_select_as_obj(sql); return rv == null ? or : Double_.cast(rv);}
|
||||
public int Exec_select_as_int (String sql, int or) {Object rv = Exec_select_as_obj(sql); return rv == null ? or : IntUtl.Cast(rv);}
|
||||
public double Exec_select_as_double (String sql, double or) {Object rv = Exec_select_as_obj(sql); return rv == null ? or : DoubleUtl.Cast(rv);}
|
||||
private Object Exec_select_as_obj(String sql) {
|
||||
Db_rdr rdr = Exec_rdr(sql);
|
||||
try {return rdr.Move_next() ? rdr.Read_at(0) : null;}
|
||||
@@ -165,7 +165,7 @@ public class Db_conn {
|
||||
public void Rls_conn() {
|
||||
int len = rls_list.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Rls_able itm = (Rls_able)rls_list.Get_at(i);
|
||||
Rls_able itm = (Rls_able)rls_list.GetAt(i);
|
||||
itm.Rls();
|
||||
}
|
||||
// rls_list.Clear(); // TOMBSTONE: do not clear rls_list, else tables which self-registered won't get called again; DATE:2016-07-06
|
||||
@@ -177,7 +177,7 @@ public class Db_conn {
|
||||
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);
|
||||
Db_qry__select_in_tbl qry = new Db_qry__select_in_tbl(tbl, StringUtl.Ary(StringUtl.Format("Max({0}) AS {0}", col)), where, null, null, null, null);
|
||||
qry.Where_(where.length == 0 ? Db_crt_.Wildcard : Db_crt_.eq_many_(where));
|
||||
return engine.Stmt_by_qry(qry);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
package gplx.dbs;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.libs.files.Io_url;
|
||||
public class Db_conn_bldr {
|
||||
private final Object thread_lock = new Object(); // LOCK:synchronized else random failures in Schema_mgr due to diff conn pointing to same db; DATE:2016-07-12
|
||||
private Db_conn_bldr_wkr wkr;
|
||||
@@ -40,12 +42,12 @@ public class Db_conn_bldr {
|
||||
boolean exists = wkr.Exists(url);
|
||||
if (exists) return Get(url);
|
||||
if (autocreate) return New(url);
|
||||
else throw Err_.new_("dbs", "db does not exist", "url", url.Raw());
|
||||
else throw ErrUtl.NewArgs("db does not exist", "url", url.Raw());
|
||||
}
|
||||
}
|
||||
public Db_conn Get_or_fail(Io_url url) {
|
||||
Db_conn rv = Get(url);
|
||||
if (rv == Db_conn_.Noop) throw Err_.new_wo_type("connection is null; file does not exist: file={0}", "file", url.Raw());
|
||||
if (rv == Db_conn_.Noop) throw ErrUtl.NewArgs("connection is null; file does not exist: file={0}", "file", url.Raw());
|
||||
return rv;
|
||||
}
|
||||
public static final Db_conn_bldr Instance = new Db_conn_bldr(); Db_conn_bldr() {}
|
||||
|
||||
@@ -13,8 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
package gplx.dbs;
|
||||
import gplx.dbs.engines.sqlite.*;
|
||||
import gplx.libs.files.Io_mgr;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.types.basics.lists.Hash_adp;
|
||||
import gplx.types.basics.lists.Hash_adp_;
|
||||
public interface Db_conn_bldr_wkr {
|
||||
void Clear_for_tests();
|
||||
boolean Exists(Io_url url);
|
||||
|
||||
@@ -13,9 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
package gplx.dbs;
|
||||
import gplx.core.stores.*;
|
||||
import gplx.dbs.engines.sqlite.*; import gplx.dbs.engines.mysql.*; import gplx.dbs.engines.postgres.*; import gplx.core.gfo_ndes.*;
|
||||
import gplx.frameworks.objects.Rls_able;
|
||||
import gplx.frameworks.tests.GfoDbTstr;
|
||||
import gplx.frameworks.tests.GfoIoTstr;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
public class Db_conn_fxt implements Rls_able {
|
||||
public Db_conn Conn() {return conn;} public Db_conn_fxt Conn_(Db_conn v) {conn = v; return this;} Db_conn conn;
|
||||
public void DmlAffectedAvailable_(boolean v) {dmlAffectedAvailable = v;} private boolean dmlAffectedAvailable = true;
|
||||
@@ -23,7 +27,7 @@ public class Db_conn_fxt implements Rls_able {
|
||||
public void tst_ExecDml(int expd, Db_qry qry) {
|
||||
int actl = conn.Exec_qry(qry);
|
||||
if (dmlAffectedAvailable)
|
||||
Tfds.Eq(expd, actl, "Exec_qry failed: sql={0}", qry.ToSqlExec(conn.Engine().Sql_wtr()));
|
||||
GfoTstr.EqObj(expd, actl, "Exec_qry failed: sql={0}", qry.ToSqlExec(conn.Engine().Sql_wtr()));
|
||||
}
|
||||
public void tst_ExecRdrTbl(int expd, String tblName) {tst_ExecRdr(expd, Db_qry_.select_tbl_(tblName));}
|
||||
public void tst_ExecRdr(int expd, Db_qry qry) {
|
||||
@@ -32,22 +36,22 @@ public class Db_conn_fxt implements Rls_able {
|
||||
rdr = conn.Exec_qry_as_old_rdr(qry);
|
||||
tbl = GfoNde_.rdr_(rdr);
|
||||
}
|
||||
catch (Exception e) {Err_.Noop(e); rdr.Rls();}
|
||||
Tfds.Eq(expd, tbl.Subs().Count(), "Exec_qry_as_rdr failed: sql={0}", qry.ToSqlExec(conn.Engine().Sql_wtr()));
|
||||
catch (Exception e) {rdr.Rls();}
|
||||
GfoTstr.EqObj(expd, tbl.Subs().Count(), "Exec_qry_as_rdr failed: sql={0}", qry.ToSqlExec(conn.Engine().Sql_wtr()));
|
||||
} GfoNde tbl;
|
||||
public GfoNde tst_RowAry(int index, Object... expdValAry) {
|
||||
GfoNde record = tbl.Subs().FetchAt_asGfoNde(index);
|
||||
Object[] actlValAry = new Object[expdValAry.length];
|
||||
for (int i = 0; i < actlValAry.length; i++)
|
||||
actlValAry[i] = record.ReadAt(i);
|
||||
Tfds.Eq_ary(actlValAry, expdValAry);
|
||||
GfoTstr.EqAryObj(actlValAry, expdValAry);
|
||||
return record;
|
||||
}
|
||||
public void Rls() {conn.Rls_conn();}
|
||||
|
||||
public static Db_conn Mysql() {return Db_conn_pool.Instance.Get_or_new(Mysql_conn_info.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_conn Tdb(String fileName) {return Db_conn_pool.Instance.Get_or_new(Db_conn_info_.tdb_(Tfds.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));}
|
||||
public static Db_conn Tdb(String fileName) {return Db_conn_pool.Instance.Get_or_new(Db_conn_info_.tdb_(GfoIoTstr.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));}
|
||||
public static Db_conn Postgres() {return Db_conn_pool.Instance.Get_or_new(Postgres_conn_info.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_conn Sqlite() {return Db_conn_pool.Instance.Get_or_new(Sqlite_conn_info.load_(Tfds.RscDir.GenSubFil_nest("140_dbs", "sqlite", "unit_tests.db")));}
|
||||
public static final boolean SkipPostgres = Tfds.SkipDb || true;
|
||||
public static Db_conn Sqlite() {return Db_conn_pool.Instance.Get_or_new(Sqlite_conn_info.load_(GfoIoTstr.RscDir.GenSubFil_nest("140_dbs", "sqlite", "unit_tests.db")));}
|
||||
public static final boolean SkipPostgres = GfoDbTstr.SkipDb || true;
|
||||
}
|
||||
@@ -13,11 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public interface Db_conn_info {
|
||||
String Key(); // EX: "sqlite"
|
||||
String Raw(); // EX: "gplx_key=sqlite;data source=/db.sqlite3;version=3"
|
||||
String Db_api(); // EX: "data source=/db.sqlite3;version=3"
|
||||
String Database(); // EX: /db.sqlite3 -> "db" ; xowa -> "xowa"
|
||||
Db_conn_info New_self(String raw, Keyval_hash hash);
|
||||
}
|
||||
package gplx.dbs;
|
||||
import gplx.types.commons.KeyValHash;
|
||||
public interface Db_conn_info {
|
||||
String Key(); // EX: "sqlite"
|
||||
String Raw(); // EX: "gplx_key=sqlite;data source=/db.sqlite3;version=3"
|
||||
String Db_api(); // EX: "data source=/db.sqlite3;version=3"
|
||||
String Database(); // EX: /db.sqlite3 -> "db" ; xowa -> "xowa"
|
||||
Db_conn_info New_self(String raw, KeyValHash hash);
|
||||
}
|
||||
|
||||
@@ -13,9 +13,20 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.engines.noops.*; import gplx.dbs.engines.mems.*; import gplx.dbs.engines.sqlite.*; import gplx.dbs.engines.tdbs.*;
|
||||
import gplx.dbs.engines.mysql.*; import gplx.dbs.engines.postgres.*;
|
||||
package gplx.dbs;
|
||||
import gplx.dbs.engines.mems.Mem_conn_info;
|
||||
import gplx.dbs.engines.mysql.Mysql_conn_info;
|
||||
import gplx.dbs.engines.noops.Noop_conn_info;
|
||||
import gplx.dbs.engines.postgres.Postgres_conn_info;
|
||||
import gplx.dbs.engines.sqlite.Sqlite_conn_info;
|
||||
import gplx.dbs.engines.tdbs.Tdb_conn_info;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.libs.files.Io_url_;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.commons.KeyValHash;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class Db_conn_info_ {
|
||||
public static final Db_conn_info Null = Noop_conn_info.Instance;
|
||||
public static final Db_conn_info Test = Mysql_conn_info.new_("127.0.0.1", "unit_tests", "root", "mysql7760");
|
||||
@@ -25,9 +36,9 @@ public class Db_conn_info_ {
|
||||
public static Db_conn_info mem_(String db) {return Mem_conn_info.new_(db);}
|
||||
public static final String Key_tdb = Tdb_conn_info.Tid_const;
|
||||
public static Io_url To_url(Db_conn_info cs) {
|
||||
if (String_.Eq(cs.Key(), Sqlite_conn_info.Key_const)) return ((Sqlite_conn_info)cs).Url();
|
||||
else if (String_.Eq(cs.Key(), Mem_conn_info.Instance.Key())) return Io_url_.mem_fil_("mem/" + ((Mem_conn_info)cs).Database());
|
||||
else throw Err_.new_unhandled_default(cs.Key());
|
||||
if (StringUtl.Eq(cs.Key(), Sqlite_conn_info.Key_const)) return ((Sqlite_conn_info)cs).Url();
|
||||
else if (StringUtl.Eq(cs.Key(), Mem_conn_info.Instance.Key())) return Io_url_.mem_fil_("mem/" + ((Mem_conn_info)cs).Database());
|
||||
else throw ErrUtl.NewUnhandled(cs.Key());
|
||||
}
|
||||
}
|
||||
class Db_conn_info_pool {
|
||||
@@ -39,13 +50,13 @@ class Db_conn_info_pool {
|
||||
public Db_conn_info_pool Add(Db_conn_info itm) {regy.AddIfDupeUseNth(itm.Key(), itm); return this;}
|
||||
public Db_conn_info Parse(String raw) {// assume each pair has format of: name=val;
|
||||
try {
|
||||
Keyval_hash hash = new Keyval_hash();
|
||||
String[] terms = String_.Split(raw, ";");
|
||||
KeyValHash hash = new KeyValHash();
|
||||
String[] terms = StringUtl.Split(raw, ";");
|
||||
String url_tid = "";
|
||||
for (String term : terms) {
|
||||
if (String_.Len(term) == 0) continue;
|
||||
String[] kv = String_.Split(term, "=");
|
||||
if (String_.Eq(kv[0], "gplx_key"))
|
||||
if (StringUtl.Len(term) == 0) continue;
|
||||
String[] kv = StringUtl.Split(term, "=");
|
||||
if (StringUtl.Eq(kv[0], "gplx_key"))
|
||||
url_tid = kv[1]; // NOTE: do not add to GfoMsg; will not be part of ApiStr
|
||||
else
|
||||
hash.Add(kv[0], kv[1]);
|
||||
@@ -53,19 +64,19 @@ class Db_conn_info_pool {
|
||||
Db_conn_info prototype = (Db_conn_info)regy.GetByOrNull(url_tid);
|
||||
return prototype.New_self(raw, hash);
|
||||
}
|
||||
catch(Exception exc) {throw Err_.new_parse_exc(exc, Db_conn_info.class, raw);}
|
||||
catch(Exception exc) {throw ErrUtl.NewParse(exc, Db_conn_info.class, raw);}
|
||||
}
|
||||
public Db_conn_info Parse_or_sqlite_or_fail(String raw) {// assume each pair has format of: name=val;
|
||||
Keyval_hash hash = new Keyval_hash();
|
||||
String[] kvps = String_.Split(raw, ";");
|
||||
KeyValHash hash = new KeyValHash();
|
||||
String[] kvps = StringUtl.Split(raw, ";");
|
||||
String cs_tid = null;
|
||||
int kvps_len = kvps.length;
|
||||
for (int i = 0; i < kvps_len; ++i) {
|
||||
String kvp_str = kvps[i];
|
||||
if (String_.Len(kvp_str) == 0) continue; // ignore empty; EX: "data source=/db.sqlite;;"
|
||||
String[] kvp = String_.Split(kvp_str, "=");
|
||||
if (StringUtl.Len(kvp_str) == 0) continue; // ignore empty; EX: "data source=/db.sqlite;;"
|
||||
String[] kvp = StringUtl.Split(kvp_str, "=");
|
||||
String key = kvp[0], val = kvp[1];
|
||||
if (String_.Eq(key, "gplx_key"))
|
||||
if (StringUtl.Eq(key, "gplx_key"))
|
||||
cs_tid = val; // NOTE: do not add to GfoMsg; will not be part of ApiStr
|
||||
else
|
||||
hash.Add(key, val);
|
||||
@@ -73,7 +84,7 @@ class Db_conn_info_pool {
|
||||
if (cs_tid == null) { // gplx_key not found; try url as sqlite; EX: "/db.sqlite"
|
||||
Io_url sqlite_url = null;
|
||||
try {sqlite_url = Io_url_.new_any_(raw);}
|
||||
catch (Exception exc) {throw Err_.new_exc(exc, "dbs", "invalid connection String", "raw", raw);}
|
||||
catch (Exception exc) {throw ErrUtl.NewArgs(exc, "invalid connection String", "raw", raw);}
|
||||
hash.Clear();
|
||||
cs_tid = Sqlite_conn_info.Key_const;
|
||||
hash.Add(Sqlite_conn_info.Cs__data_source, sqlite_url.Raw());
|
||||
|
||||
@@ -13,37 +13,40 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
package gplx.dbs;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
import gplx.types.basics.constants.AsciiByte;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.types.commons.KeyValHash;
|
||||
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 abstract Db_conn_info New_self(String raw, Keyval_hash hash);
|
||||
public abstract Db_conn_info New_self(String raw, KeyValHash hash);
|
||||
|
||||
protected static String Bld_raw(String... ary) {// "a", "b" -> "a=b;"
|
||||
Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
BryWtr bfr = BryWtr.NewAndReset(255);
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String itm = ary[i];
|
||||
bfr.Add_str_u8(itm);
|
||||
bfr.Add_byte(i % 2 == 0 ? AsciiByte.Eq : AsciiByte.Semic);
|
||||
bfr.AddStrU8(itm);
|
||||
bfr.AddByte(i % 2 == 0 ? AsciiByte.Eq : AsciiByte.Semic);
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
return bfr.ToStrAndClear();
|
||||
}
|
||||
protected static String Bld_api(Keyval_hash hash, Keyval... xtn_ary) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int len = hash.Count();
|
||||
protected static String Bld_api(KeyValHash hash, KeyVal... xtn_ary) {
|
||||
BryWtr bfr = BryWtr.New();
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Keyval kv = hash.Get_at(i);
|
||||
bfr.Add_str_u8_fmt("{0}={1};", kv.Key(), kv.Val_to_str_or_empty());
|
||||
KeyVal kv = hash.GetAt(i);
|
||||
bfr.AddStrU8Fmt("{0}={1};", kv.KeyToStr(), kv.ValToStrOrEmpty());
|
||||
}
|
||||
for (Keyval xtn : xtn_ary) {
|
||||
if (hash.Has(xtn.Key())) continue;
|
||||
bfr.Add_str_u8_fmt("{0}={1};", xtn.Key(), xtn.Val_to_str_or_empty());
|
||||
for (KeyVal xtn : xtn_ary) {
|
||||
if (hash.Has(xtn.KeyToStr())) continue;
|
||||
bfr.AddStrU8Fmt("{0}={1};", xtn.KeyToStr(), xtn.ValToStrOrEmpty());
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
return bfr.ToStrAndClear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import org.junit.*;
|
||||
package gplx.dbs;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.types.commons.KeyValHash;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
public class Db_conn_info_tst {
|
||||
@Before public void setup() {
|
||||
regy.Add(Db_conn_info_mock.Instance);
|
||||
@@ -24,23 +28,23 @@ public class Db_conn_info_tst {
|
||||
tst_Parse("gplx_key=mock;id=1;name=me;", kv_("id", "1"), kv_("name", "me")); // many
|
||||
tst_Parse("gplx_key=mock;id=1;name=me" , kv_("id", "1"), kv_("name", "me")); // no semi-colon at end
|
||||
}
|
||||
private Keyval kv_(String key, Object val) {return Keyval_.new_(key, val);}
|
||||
private void tst_Parse(String raw, Keyval... expd) {
|
||||
private KeyVal kv_(String key, Object val) {return KeyVal.NewStr(key, val);}
|
||||
private void tst_Parse(String raw, KeyVal... expd) {
|
||||
Db_conn_info_mock mock = (Db_conn_info_mock)regy.Parse(raw);
|
||||
Tfds.Eq_ary_str(expd, mock.Kvs());
|
||||
GfoTstr.EqAryObjAry(expd, mock.Kvs());
|
||||
}
|
||||
}
|
||||
class Db_conn_info_mock extends Db_conn_info__base {
|
||||
public Db_conn_info_mock(String raw, String db_api, String database) {super(raw, db_api, database);}
|
||||
public Keyval[] Kvs() {return kvs;} Keyval[] kvs;
|
||||
public KeyVal[] Kvs() {return kvs;} KeyVal[] kvs;
|
||||
@Override public String Key() {return Tid_const;} public static final String Tid_const = "mock";
|
||||
@Override public Db_conn_info New_self(String raw, Keyval_hash hash) {
|
||||
@Override public Db_conn_info New_self(String raw, KeyValHash hash) {
|
||||
Db_conn_info_mock rv = new Db_conn_info_mock("", "", "");
|
||||
int len = hash.Count();
|
||||
rv.kvs = new Keyval[len];
|
||||
int len = hash.Len();
|
||||
rv.kvs = new KeyVal[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.kvs[i] = hash.Get_at(i);
|
||||
rv.kvs[i] = hash.GetAt(i);
|
||||
return rv;
|
||||
}
|
||||
public static final Db_conn_info_mock Instance = new Db_conn_info_mock("", "", "");
|
||||
public static final Db_conn_info_mock Instance = new Db_conn_info_mock("", "", "");
|
||||
}
|
||||
|
||||
@@ -13,9 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.engines.*;
|
||||
import gplx.dbs.qrys.bats.*;
|
||||
package gplx.dbs;
|
||||
import gplx.types.basics.lists.Hash_adp;
|
||||
import gplx.types.basics.lists.Hash_adp_;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
import gplx.dbs.engines.Db_engine;
|
||||
import gplx.dbs.qrys.bats.Db_batch_mgr;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class Db_conn_pool { // PURPOSE: cache one connection per connection_string
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public Db_batch_mgr Batch_mgr() {return batch_mgr;} private final Db_batch_mgr batch_mgr = new Db_batch_mgr();
|
||||
@@ -24,7 +29,7 @@ public class Db_conn_pool { // PURPOSE: cache one connection per connection_stri
|
||||
public Db_conn Get_or_new(Db_conn_info url) {
|
||||
Db_conn rv = (Db_conn)hash.GetByOrNull(url.Db_api());
|
||||
if (rv == null) {
|
||||
Db_engine prime = (Db_engine)prime_hash.GetByOrNull(url.Key()); if (prime == null) Err_.new_wo_type("db engine prototype not found", "key", url.Key());
|
||||
Db_engine prime = (Db_engine)prime_hash.GetByOrNull(url.Key()); if (prime == null) ErrUtl.NewArgs("db engine prototype not found", "key", url.Key());
|
||||
Db_engine clone = prime.New_clone(url);
|
||||
rv = new Db_conn(clone);
|
||||
clone.Batch_mgr().Copy(clone.Tid(), batch_mgr);
|
||||
@@ -39,7 +44,7 @@ public class Db_conn_pool { // PURPOSE: cache one connection per connection_stri
|
||||
int len = hash.Len();
|
||||
Db_conn[] rls_ary = new Db_conn[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rls_ary[i] = (Db_conn)hash.Get_at(i);
|
||||
rls_ary[i] = (Db_conn)hash.GetAt(i);
|
||||
for (int i = 0; i < len; ++i)
|
||||
rls_ary[i].Rls_conn();
|
||||
hash.Clear();
|
||||
|
||||
@@ -14,17 +14,17 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.Bry_;
|
||||
import gplx.Byte_;
|
||||
import gplx.Double_;
|
||||
import gplx.Float_;
|
||||
import gplx.Int_;
|
||||
import gplx.Io_url_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.Long_;
|
||||
import gplx.String_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.types.basics.utls.BryUtl;
|
||||
import gplx.types.basics.utls.ByteUtl;
|
||||
import gplx.types.basics.utls.DoubleUtl;
|
||||
import gplx.types.basics.utls.FloatUtl;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.libs.files.Io_url_;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.basics.utls.LongUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
public class Db_conn_utl {
|
||||
public static Db_conn Conn__new(String url_rel) {
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
@@ -44,13 +44,13 @@ public class Db_conn_utl {
|
||||
Object val = row[j];
|
||||
switch (fld.Type().Tid()) {
|
||||
case DbmetaFldType.TidBool: stmt.Val_bool_as_byte (fld_name, BoolUtl.Cast(val)); break;
|
||||
case DbmetaFldType.TidByte: stmt.Val_byte (fld_name, Byte_.Cast(val)); break;
|
||||
case DbmetaFldType.TidInt: stmt.Val_int (fld_name, Int_.Cast(val)); break;
|
||||
case DbmetaFldType.TidLong: stmt.Val_long (fld_name, Long_.cast(val)); break;
|
||||
case DbmetaFldType.TidFloat: stmt.Val_float (fld_name, Float_.cast(val)); break;
|
||||
case DbmetaFldType.TidDouble: stmt.Val_double (fld_name, Double_.cast(val)); break;
|
||||
case DbmetaFldType.TidStr: stmt.Val_str (fld_name, String_.cast(val)); break;
|
||||
case DbmetaFldType.TidBry: stmt.Val_bry (fld_name, Bry_.cast(val)); break;
|
||||
case DbmetaFldType.TidByte: stmt.Val_byte (fld_name, ByteUtl.Cast(val)); break;
|
||||
case DbmetaFldType.TidInt: stmt.Val_int (fld_name, IntUtl.Cast(val)); break;
|
||||
case DbmetaFldType.TidLong: stmt.Val_long (fld_name, LongUtl.Cast(val)); break;
|
||||
case DbmetaFldType.TidFloat: stmt.Val_float (fld_name, FloatUtl.Cast(val)); break;
|
||||
case DbmetaFldType.TidDouble: stmt.Val_double (fld_name, DoubleUtl.Cast(val)); break;
|
||||
case DbmetaFldType.TidStr: stmt.Val_str (fld_name, StringUtl.Cast(val)); break;
|
||||
case DbmetaFldType.TidBry: stmt.Val_bry (fld_name, BryUtl.Cast(val)); break;
|
||||
}
|
||||
}
|
||||
stmt.Exec_insert();
|
||||
|
||||
@@ -13,8 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
package gplx.dbs;
|
||||
import gplx.core.criterias.*;
|
||||
import gplx.types.commons.KeyVal;
|
||||
public class Db_crt_ {
|
||||
public static final Criteria Wildcard = Criteria_.All;
|
||||
public static Criteria New_and (Criteria lhs, Criteria rhs) {return Criteria_.And(lhs, rhs);}
|
||||
@@ -52,11 +53,11 @@ public class Db_crt_ {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static Criteria eq_many_(Keyval... array) {
|
||||
public static Criteria eq_many_(KeyVal... array) {
|
||||
Criteria rv = null;
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Keyval pair = array[i];
|
||||
Criteria crt = Db_crt_.New_eq(pair.Key(), pair.Val());
|
||||
KeyVal pair = array[i];
|
||||
Criteria crt = Db_crt_.New_eq(pair.KeyToStr(), pair.Val());
|
||||
rv = (i == 0)? crt : Criteria_.And(rv, crt);
|
||||
}
|
||||
return rv;
|
||||
|
||||
@@ -13,11 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
package gplx.dbs;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.basics.utls.ObjectUtl;
|
||||
import org.junit.*; import gplx.core.criterias.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
public class Db_crt_tst {
|
||||
@Before public void setup() {
|
||||
row = GfoNde_.vals_(GfoFldList_.new_().Add("id", IntClassXtn.Instance).Add("name", StringClassXtn.Instance), Object_.Ary(1, "me"));
|
||||
row = GfoNde_.vals_(GfoFldList_.new_().Add("id", IntClassXtn.Instance).Add("name", StringClassXtn.Instance), ObjectUtl.Ary(1, "me"));
|
||||
}
|
||||
@Test public void EqualTest() {
|
||||
crt = Db_crt_.New_eq("id", 1);
|
||||
@@ -44,7 +46,7 @@ public class Db_crt_tst {
|
||||
|
||||
void tst_Match(boolean epxd, GfoNde row, Criteria crt) {
|
||||
boolean actl = crt.Matches(row);
|
||||
Tfds.Eq(epxd, actl);
|
||||
GfoTstr.EqObj(epxd, actl);
|
||||
}
|
||||
GfoNde row; Criteria crt;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.types.basics.utls.ArrayUtl;
|
||||
public class Db_mock_row {
|
||||
public int Idx() {return idx;} public Db_mock_row Idx_(int val) {idx = val; return this;} int idx = -1;
|
||||
public Db_mock_cell[] Dat() {return dat;} Db_mock_cell[] dat = null;
|
||||
|
||||
@@ -13,10 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_null implements gplx.core.brys.Bfr_arg {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_str_a7(Null_str);}
|
||||
@Override public String toString() {return Null_str;}
|
||||
public static final String Null_str = "NULL";
|
||||
public static final Db_null Instance = new Db_null(); Db_null() {}
|
||||
}
|
||||
package gplx.dbs;
|
||||
import gplx.types.custom.brys.wtrs.args.BryBfrArg;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
public class Db_null implements BryBfrArg {
|
||||
public void AddToBfr(BryWtr bfr) {bfr.AddStrA7(Null_str);}
|
||||
@Override public String toString() {return Null_str;}
|
||||
public static final String Null_str = "NULL";
|
||||
public static final Db_null Instance = new Db_null(); Db_null() {}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.Keyval;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.core.criterias.Criteria;
|
||||
import gplx.dbs.qrys.Db_qry__select_cmd;
|
||||
import gplx.dbs.qrys.Db_qry_delete;
|
||||
@@ -30,10 +30,10 @@ public class Db_qry_ {
|
||||
public static Db_qry_delete delete_(String tbl, Criteria crt) {return Db_qry_delete.new_(tbl, crt);}
|
||||
public static Db_qry_delete delete_tbl_(String tbl) {return Db_qry_delete.new_(tbl);}
|
||||
public static Db_qry_insert insert_(String tbl) {return new Db_qry_insert(tbl);}
|
||||
public static Db_qry_insert insert_common_(String tbl, Keyval... pairs) {
|
||||
public static Db_qry_insert insert_common_(String tbl, KeyVal... pairs) {
|
||||
Db_qry_insert cmd = new Db_qry_insert(tbl);
|
||||
for (Keyval pair : pairs)
|
||||
cmd.Val_obj(pair.Key(), pair.Val());
|
||||
for (KeyVal pair : pairs)
|
||||
cmd.Val_obj(pair.KeyToStr(), pair.Val());
|
||||
return cmd;
|
||||
}
|
||||
|
||||
@@ -46,11 +46,11 @@ public class Db_qry_ {
|
||||
update.Where_(crt);
|
||||
return update;
|
||||
}
|
||||
public static Db_qry_update update_common_(String tbl, Criteria crt, Keyval... pairs) {
|
||||
public static Db_qry_update update_common_(String tbl, Criteria crt, KeyVal... pairs) {
|
||||
Db_qry_update cmd = new Db_qry_update();
|
||||
cmd.From_(tbl); cmd.Where_(crt);
|
||||
for (Keyval pair : pairs)
|
||||
cmd.Val_obj(pair.Key(), pair.Val());
|
||||
for (KeyVal pair : pairs)
|
||||
cmd.Val_obj(pair.KeyToStr(), pair.Val());
|
||||
return cmd;
|
||||
}
|
||||
public static gplx.core.gfo_ndes.GfoNde Exec_as_nde(Db_conn conn, Db_qry qry) {return gplx.core.gfo_ndes.GfoNde_.rdr_(conn.Exec_qry_as_old_rdr(qry));}
|
||||
|
||||
@@ -13,16 +13,20 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
package gplx.dbs;
|
||||
import gplx.dbs.qrys.*; import gplx.core.gfo_ndes.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.basics.utls.ArrayUtl;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
import gplx.types.basics.constants.AsciiByte;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.types.commons.KeyValList;
|
||||
public class Db_qry_fxt {
|
||||
public static void Insert_kvo(Db_conn conn, String tblName, Keyval_list kvList) {
|
||||
public static void Insert_kvo(Db_conn conn, String tblName, KeyValList kvList) {
|
||||
Db_qry_insert qry = Db_qry_.insert_(tblName);
|
||||
for (int i = 0; i < kvList.Count(); i++) {
|
||||
Keyval kv = kvList.Get_at(i);
|
||||
qry.Val_obj(kv.Key(), kv.Val());
|
||||
for (int i = 0; i < kvList.Len(); i++) {
|
||||
KeyVal kv = kvList.GetAt(i);
|
||||
qry.Val_obj(kv.KeyToStr(), kv.Val());
|
||||
}
|
||||
qry.Exec_qry(conn);
|
||||
}
|
||||
@@ -48,20 +52,20 @@ public class Db_qry_fxt {
|
||||
for (int j = 0; j < fldLen; j++) {
|
||||
Db_mock_cell expdDat = expdRow.Dat()[j];
|
||||
Object actlVal = expdDat.Fld() == null ? actlNde.ReadAt(j) : actlNde.Read(expdDat.Fld());
|
||||
Tfds.Eq(expdDat.Val(), actlVal);
|
||||
GfoTstr.EqObj(expdDat.Val(), actlVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static String Db__print_tbl_as_str(Bry_bfr bfr, Db_conn conn, String tbl, String... cols) {
|
||||
public static String Db__print_tbl_as_str(BryWtr bfr, Db_conn conn, String tbl, String... cols) {
|
||||
int cols_len = cols.length;
|
||||
Db_rdr rdr = conn.Stmt_select(tbl, cols).Exec_select__rls_auto();
|
||||
while (rdr.Move_next()) {
|
||||
for (int i = 0; i < cols_len; ++i) {
|
||||
bfr.Add_obj(rdr.Read_at(i));
|
||||
bfr.Add_byte(i == cols_len - 1 ? AsciiByte.Nl : AsciiByte.Pipe);
|
||||
bfr.AddObj(rdr.Read_at(i));
|
||||
bfr.AddByte(i == cols_len - 1 ? AsciiByte.Nl : AsciiByte.Pipe);
|
||||
}
|
||||
}
|
||||
rdr.Rls();
|
||||
return bfr.To_str_and_clear();
|
||||
return bfr.ToStrAndClear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.types.commons.GfoDate;
|
||||
import gplx.libs.files.Io_url;
|
||||
public interface Db_rdr {
|
||||
boolean Move_next();
|
||||
byte[] Read_bry(String k);
|
||||
@@ -25,7 +27,7 @@ public interface Db_rdr {
|
||||
long Read_long(String k);
|
||||
float Read_float(String k);
|
||||
double Read_double(String k);
|
||||
DateAdp Read_date_by_str(String k);
|
||||
GfoDate Read_date_by_str(String k);
|
||||
boolean Read_bool_by_byte(String k);
|
||||
int Fld_len();
|
||||
Object Read_obj(String k);
|
||||
|
||||
@@ -1,34 +1,44 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.types.basics.utls.BryUtl;
|
||||
import gplx.types.basics.utls.ByteUtl;
|
||||
import gplx.types.basics.utls.DoubleUtl;
|
||||
import gplx.types.basics.utls.FloatUtl;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.basics.utls.LongUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.commons.GfoDate;
|
||||
import gplx.types.commons.GfoDateUtl;
|
||||
import gplx.libs.files.Io_url;
|
||||
public class Db_rdr_ {
|
||||
public static final Db_rdr Empty = new Db_rdr__empty();
|
||||
}
|
||||
class Db_rdr__empty implements Db_rdr {
|
||||
public boolean Move_next() {return false;}
|
||||
public byte[] Read_bry(String k) {return Bry_.Empty;}
|
||||
public byte[] Read_bry_by_str(String k) {return Bry_.Empty;}
|
||||
public byte[] Read_bry(String k) {return BryUtl.Empty;}
|
||||
public byte[] Read_bry_by_str(String k) {return BryUtl.Empty;}
|
||||
public void Save_bry_in_parts(Io_url url, String tbl, String fld, String crt_key, Object crt_val) {}
|
||||
public byte Read_byte(String k) {return Byte_.Max_value_127;}
|
||||
public String Read_str(String k) {return String_.Empty;}
|
||||
public DateAdp Read_date_by_str(String k) {return DateAdp_.MinValue;}
|
||||
public int Read_int(String k) {return Int_.Min_value;}
|
||||
public long Read_long(String k) {return Long_.Min_value;}
|
||||
public float Read_float(String k) {return Float_.NaN;}
|
||||
public double Read_double(String k) {return Double_.NaN;}
|
||||
public byte Read_byte(String k) {return ByteUtl.MaxValue127;}
|
||||
public String Read_str(String k) {return StringUtl.Empty;}
|
||||
public GfoDate Read_date_by_str(String k) {return GfoDateUtl.MinValue;}
|
||||
public int Read_int(String k) {return IntUtl.MinValue;}
|
||||
public long Read_long(String k) {return LongUtl.MinValue;}
|
||||
public float Read_float(String k) {return FloatUtl.NaN;}
|
||||
public double Read_double(String k) {return DoubleUtl.NaN;}
|
||||
public boolean Read_bool_by_byte(String k) {return false;}
|
||||
public int Fld_len() {return 0;}
|
||||
public Object Read_obj(String k) {return null;}
|
||||
|
||||
@@ -14,19 +14,19 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.Bry_;
|
||||
import gplx.Byte_;
|
||||
import gplx.DateAdp;
|
||||
import gplx.DateAdp_;
|
||||
import gplx.Double_;
|
||||
import gplx.Err_;
|
||||
import gplx.Float_;
|
||||
import gplx.Int_;
|
||||
import gplx.Io_url;
|
||||
import gplx.Long_;
|
||||
import gplx.Object_;
|
||||
import gplx.String_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.types.basics.utls.BryUtl;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.commons.GfoDate;
|
||||
import gplx.types.commons.GfoDateUtl;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.types.basics.utls.ObjectUtl;
|
||||
import gplx.types.basics.utls.FloatUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
import gplx.types.basics.utls.ByteUtl;
|
||||
import gplx.types.basics.utls.DoubleUtl;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.basics.utls.LongUtl;
|
||||
import java.sql.ResultSet;
|
||||
public class Db_rdr__basic implements Db_rdr {
|
||||
protected ResultSet rdr;
|
||||
@@ -35,25 +35,25 @@ public class Db_rdr__basic implements Db_rdr {
|
||||
public String Sql() {return sql;} private String sql;
|
||||
public boolean Move_next() {
|
||||
try {return rdr.next();}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "move_next failed; check column casting error in SQL", "sql", sql);}
|
||||
catch (Exception e) {throw ErrUtl.NewArgs(e, "move_next failed; check column casting error in SQL", "sql", sql);}
|
||||
}
|
||||
public byte[] Read_bry(String k) {try {return (byte[])rdr.getObject(k);} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Bry_.Cls_val_name);}}
|
||||
public byte[] Read_bry_by_str(String k) {try {return Bry_.new_u8((String)rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", String_.Cls_val_name);}}
|
||||
public void Save_bry_in_parts(Io_url url, String tbl, String fld, String crt_key, Object crt_val) {throw Err_.new_unimplemented();}
|
||||
public String Read_str(String k) {try {return (String)rdr.getObject(k);} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", String_.Cls_val_name);}}
|
||||
public DateAdp Read_date_by_str(String k) {return DateAdp_.parse_iso8561(Read_str(k));}
|
||||
public int Read_int(String k) {try {return Int_.Cast(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Int_.Cls_val_name);}}
|
||||
public long Read_long(String k) {try {return Long_.cast(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Long_.Cls_val_name);}}
|
||||
public float Read_float(String k) {try {return Float_.cast(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Float_.Cls_val_name);}}
|
||||
public double Read_double(String k) {try {return Double_.cast(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Double_.Cls_val_name);}}
|
||||
public byte Read_byte(String k) {try {return Byte_.Cast(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Byte_.Cls_val_name);}}
|
||||
public boolean Read_bool_by_byte(String k) {try {return Byte_.Cast(rdr.getObject(k)) == 1;} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", BoolUtl.ClsValName);}}
|
||||
public int Fld_len() {try {return rdr.getMetaData().getColumnCount();} catch (Exception e) {throw Err_.new_exc(e, "db", "field count failed", "sql", sql);}}
|
||||
public Object Read_obj(String k) {try {return rdr.getObject(k);} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Object_.Cls_val_name);}}
|
||||
public Object Read_at(int i) {try {return rdr.getObject(i + 1);} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "idx", i, "type", Object_.Cls_val_name);}}
|
||||
public byte[] Read_bry(String k) {try {return (byte[])rdr.getObject(k);} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "key", k, "type", BryUtl.ClsValName);}}
|
||||
public byte[] Read_bry_by_str(String k) {try {return BryUtl.NewU8((String)rdr.getObject(k));} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "key", k, "type", StringUtl.ClsValName);}}
|
||||
public void Save_bry_in_parts(Io_url url, String tbl, String fld, String crt_key, Object crt_val) {throw ErrUtl.NewUnimplemented();}
|
||||
public String Read_str(String k) {try {return (String)rdr.getObject(k);} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "key", k, "type", StringUtl.ClsValName);}}
|
||||
public GfoDate Read_date_by_str(String k) {return GfoDateUtl.ParseIso8561(Read_str(k));}
|
||||
public int Read_int(String k) {try {return IntUtl.Cast(rdr.getObject(k));} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "key", k, "type", IntUtl.ClsValName);}}
|
||||
public long Read_long(String k) {try {return LongUtl.Cast(rdr.getObject(k));} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "key", k, "type", LongUtl.ClsValName);}}
|
||||
public float Read_float(String k) {try {return FloatUtl.Cast(rdr.getObject(k));} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "key", k, "type", FloatUtl.ClsValName);}}
|
||||
public double Read_double(String k) {try {return DoubleUtl.Cast(rdr.getObject(k));} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "key", k, "type", DoubleUtl.ClsValName);}}
|
||||
public byte Read_byte(String k) {try {return ByteUtl.Cast(rdr.getObject(k));} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "key", k, "type", ByteUtl.ClsValName);}}
|
||||
public boolean Read_bool_by_byte(String k) {try {return ByteUtl.Cast(rdr.getObject(k)) == 1;} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "key", k, "type", BoolUtl.ClsValName);}}
|
||||
public int Fld_len() {try {return rdr.getMetaData().getColumnCount();} catch (Exception e) {throw ErrUtl.NewArgs(e, "field count failed", "sql", sql);}}
|
||||
public Object Read_obj(String k) {try {return rdr.getObject(k);} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "key", k, "type", ObjectUtl.ClsValName);}}
|
||||
public Object Read_at(int i) {try {return rdr.getObject(i + 1);} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "idx", i, "type", ObjectUtl.ClsValName);}}
|
||||
public void Rls() {
|
||||
try {rdr.close();}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "close failed");}
|
||||
catch (Exception e) {throw ErrUtl.NewArgs(e, "close failed");}
|
||||
if (stmt != null) {
|
||||
stmt.Rls();
|
||||
stmt = null; // NOTE: must null reference else will throw SQLException during statements DATE:2016-04-10
|
||||
|
||||
@@ -13,23 +13,25 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
package gplx.dbs;
|
||||
import gplx.types.basics.utls.ArrayUtl;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
import gplx.types.basics.constants.AsciiByte;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public class Db_sql_ {
|
||||
public static String Make_by_fmt(String[] lines, Object... args) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
BryWtr bfr = BryWtr.New();
|
||||
int len = lines.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (i != 0) bfr.Add_byte_nl();
|
||||
bfr.Add_str_u8(lines[i]);
|
||||
if (i != 0) bfr.AddByteNl();
|
||||
bfr.AddStrU8(lines[i]);
|
||||
}
|
||||
String fmt = bfr.To_str_and_clear();
|
||||
return String_.Format(fmt, args);
|
||||
String fmt = bfr.ToStrAndClear();
|
||||
return StringUtl.Format(fmt, args);
|
||||
}
|
||||
public static byte[] Escape_arg(byte[] raw) {
|
||||
int len = raw.length;
|
||||
Bry_bfr bfr = null;
|
||||
BryWtr bfr = null;
|
||||
boolean dirty = false;
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
@@ -37,26 +39,26 @@ public class Db_sql_ {
|
||||
if (b == AsciiByte.Apos) {
|
||||
if (bfr == null) {
|
||||
dirty = true;
|
||||
bfr = Bry_bfr_.New();
|
||||
bfr.Add_mid(raw, 0, i);
|
||||
bfr = BryWtr.New();
|
||||
bfr.AddMid(raw, 0, i);
|
||||
}
|
||||
bfr.Add_byte_apos().Add_byte_apos();
|
||||
bfr.AddByteApos().AddByteApos();
|
||||
}
|
||||
else {
|
||||
if (dirty) {
|
||||
bfr.Add_byte(b);
|
||||
bfr.AddByte(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
return dirty ? bfr.To_bry_and_clear() : raw;
|
||||
return dirty ? bfr.ToBryAndClear() : raw;
|
||||
}
|
||||
public static String Prep_in_from_ary(Object ary) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
BryWtr bfr = BryWtr.New();
|
||||
int len = ArrayUtl.Len(ary);
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (i != 0) bfr.Add_byte(AsciiByte.Comma);
|
||||
bfr.Add_byte(AsciiByte.Question);
|
||||
if (i != 0) bfr.AddByte(AsciiByte.Comma);
|
||||
bfr.AddByte(AsciiByte.Question);
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
return bfr.ToStrAndClear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
interface Db_sql_qry {
|
||||
String Tbl_main();
|
||||
}
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.dbs.engines.*; import gplx.core.stores.*;
|
||||
import gplx.frameworks.objects.Rls_able;
|
||||
import gplx.types.commons.GfoDate;
|
||||
import gplx.types.commons.GfoDecimal;
|
||||
public interface Db_stmt extends Rls_able {
|
||||
Db_stmt Crt_bool_as_byte(String k, boolean v);
|
||||
Db_stmt Val_bool_as_byte(String k, boolean v);
|
||||
@@ -35,9 +38,9 @@ public interface Db_stmt extends Rls_able {
|
||||
Db_stmt Crt_double(String k, double v);
|
||||
Db_stmt Val_double(String k, double v);
|
||||
Db_stmt Val_double(double v);
|
||||
Db_stmt Crt_decimal(String k, Decimal_adp v);
|
||||
Db_stmt Val_decimal(String k, Decimal_adp v);
|
||||
Db_stmt Val_decimal(Decimal_adp v);
|
||||
Db_stmt Crt_decimal(String k, GfoDecimal v);
|
||||
Db_stmt Val_decimal(String k, GfoDecimal v);
|
||||
Db_stmt Val_decimal(GfoDecimal v);
|
||||
Db_stmt Crt_bry(String k, byte[] v);
|
||||
Db_stmt Val_bry(String k, byte[] v);
|
||||
Db_stmt Val_bry(byte[] v);
|
||||
@@ -48,8 +51,8 @@ public interface Db_stmt extends Rls_able {
|
||||
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.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_date(String k, GfoDate v);
|
||||
Db_stmt Val_date(String k, GfoDate v);
|
||||
Db_stmt Crt_text(String k, String v);
|
||||
Db_stmt Val_text(String k, String v);
|
||||
boolean Exec_insert();
|
||||
|
||||
@@ -14,16 +14,6 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.Bry_;
|
||||
import gplx.Byte_;
|
||||
import gplx.Double_;
|
||||
import gplx.Err;
|
||||
import gplx.Err_;
|
||||
import gplx.Float_;
|
||||
import gplx.Int_;
|
||||
import gplx.Long_;
|
||||
import gplx.String_;
|
||||
import gplx.Type_ids_;
|
||||
import gplx.dbs.qrys.Db_qry__select_cmd;
|
||||
import gplx.dbs.qrys.Db_qry__select_in_tbl;
|
||||
import gplx.dbs.qrys.Db_qry_delete;
|
||||
@@ -31,7 +21,17 @@ import gplx.dbs.qrys.Db_qry_insert;
|
||||
import gplx.dbs.qrys.Db_qry_sql;
|
||||
import gplx.dbs.qrys.Db_qry_update;
|
||||
import gplx.dbs.qrys.Db_stmt_sql;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.types.basics.utls.BryUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
import gplx.types.basics.utls.ByteUtl;
|
||||
import gplx.types.basics.utls.DoubleUtl;
|
||||
import gplx.types.basics.utls.FloatUtl;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.basics.utls.LongUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.basics.utls.TypeIds;
|
||||
import gplx.types.errs.Err;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class Db_stmt_ {
|
||||
public static final Db_stmt Null = new Db_stmt_sql();
|
||||
public static Db_stmt new_insert_(Db_conn conn, String tbl, String... flds) {
|
||||
@@ -64,28 +64,26 @@ public class Db_stmt_ {
|
||||
return conn.Stmt_new(Db_qry_sql.rdr_(sql));
|
||||
}
|
||||
public static Db_stmt New_sql_lines(Db_conn conn, String... lines) {
|
||||
Db_qry qry = Db_qry_sql.sql_(String_.Concat_with_str("\n", lines));
|
||||
Db_qry qry = Db_qry_sql.sql_(StringUtl.ConcatWith("\n", lines));
|
||||
return conn.Stmt_new(qry);
|
||||
}
|
||||
public static Err err_(Exception e, Db_stmt stmt, String proc) {
|
||||
throw Err_.new_exc(e, "db", "db stmt failed", "proc", proc);
|
||||
}
|
||||
public static Err err_(Exception e, Db_stmt stmt, String proc) {throw ErrUtl.NewArgs(e, "db stmt failed", "proc", proc).FrameIgnoreAdd1();}
|
||||
public static Err err_(Exception e, String tbl, String proc) {
|
||||
throw Err_.new_exc(e, "core", "db call failed", "tbl", tbl, "proc", proc);
|
||||
throw ErrUtl.NewArgs(e, "db call failed", "tbl", tbl, "proc", proc).FrameIgnoreAdd1();
|
||||
}
|
||||
public static Db_stmt Rls(Db_stmt v) {if (v != null) v.Rls(); return null;}
|
||||
public static void Val_by_obj(Db_stmt stmt, String key, Object val) {
|
||||
int tid = Type_ids_.To_id_by_obj(val);
|
||||
int tid = TypeIds.ToIdByObj(val);
|
||||
switch (tid) {
|
||||
case Type_ids_.Id__bool: stmt.Val_bool_as_byte (key, BoolUtl.Cast(val)); break;
|
||||
case Type_ids_.Id__byte: stmt.Val_byte (key, Byte_.Cast(val)); break;
|
||||
case Type_ids_.Id__int: stmt.Val_int (key, Int_.Cast(val)); break;
|
||||
case Type_ids_.Id__long: stmt.Val_long (key, Long_.cast(val)); break;
|
||||
case Type_ids_.Id__float: stmt.Val_float (key, Float_.cast(val)); break;
|
||||
case Type_ids_.Id__double: stmt.Val_double (key, Double_.cast(val)); break;
|
||||
case Type_ids_.Id__str: stmt.Val_str (key, String_.cast(val)); break;
|
||||
case Type_ids_.Id__bry: stmt.Val_bry (key, Bry_.cast(val)); break;
|
||||
default: throw Err_.new_unhandled_default(tid);
|
||||
case TypeIds.IdBool: stmt.Val_bool_as_byte (key, BoolUtl.Cast(val)); break;
|
||||
case TypeIds.IdByte: stmt.Val_byte (key, ByteUtl.Cast(val)); break;
|
||||
case TypeIds.IdInt: stmt.Val_int (key, IntUtl.Cast(val)); break;
|
||||
case TypeIds.IdLong: stmt.Val_long (key, LongUtl.Cast(val)); break;
|
||||
case TypeIds.IdFloat: stmt.Val_float (key, FloatUtl.Cast(val)); break;
|
||||
case TypeIds.IdDouble: stmt.Val_double (key, DoubleUtl.Cast(val)); break;
|
||||
case TypeIds.IdStr: stmt.Val_str (key, StringUtl.Cast(val)); break;
|
||||
case TypeIds.IdBry: stmt.Val_bry (key, BryUtl.Cast(val)); break;
|
||||
default: throw ErrUtl.NewUnhandled(tid);
|
||||
}
|
||||
}
|
||||
public static void Insert_by_rdr(DbmetaFldList flds, Db_rdr rdr, Db_stmt stmt) {
|
||||
@@ -109,7 +107,7 @@ public class Db_stmt_ {
|
||||
case DbmetaFldType.TidDouble: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case DbmetaFldType.TidStr: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case DbmetaFldType.TidBry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled_default_w_msg(fld_tid, fld_name);
|
||||
default: throw ErrUtl.NewUnhandled(fld_tid, fld_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
package gplx.dbs;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class Db_stmt_bldr {
|
||||
private Db_conn conn; private Db_stmt create, update, delete;
|
||||
private String tbl_name; private String[] flds_keys, flds_vals, flds_all;
|
||||
@@ -21,7 +23,7 @@ public class Db_stmt_bldr {
|
||||
Conn_(v, tbl_name, flds.ToStrAry(), flds.ToStrAryExclude(flds_keys), flds_keys);
|
||||
}
|
||||
public void Conn_(Db_conn v, String tbl_name, String[] flds_vals, String... flds_keys) {
|
||||
Conn_(v, tbl_name, String_.Ary_add(flds_keys, flds_vals), flds_vals, flds_keys);
|
||||
Conn_(v, tbl_name, StringUtl.AryAdd(flds_keys, flds_vals), flds_vals, flds_keys);
|
||||
}
|
||||
private void Conn_(Db_conn v, String tbl_name, String[] flds_all, String[] flds_vals, String... flds_keys) {
|
||||
this.conn = v; this.tbl_name = tbl_name;
|
||||
@@ -33,7 +35,7 @@ public class Db_stmt_bldr {
|
||||
case Db_cmd_mode.Tid_update: if (update == null) update = conn.Stmt_update(tbl_name, flds_keys, flds_vals); return update;
|
||||
case Db_cmd_mode.Tid_delete: if (delete == null) delete = conn.Stmt_delete(tbl_name, flds_keys); return delete;
|
||||
case Db_cmd_mode.Tid_ignore: return Db_stmt_.Null;
|
||||
default: throw Err_.new_unhandled(cmd_mode);
|
||||
default: throw ErrUtl.NewUnhandled(cmd_mode);
|
||||
}
|
||||
}
|
||||
public void Batch_bgn() {conn.Txn_bgn(tbl_name);}
|
||||
|
||||
@@ -13,8 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public interface Db_tbl extends Rls_able {
|
||||
String Tbl_name();
|
||||
void Create_tbl();
|
||||
}
|
||||
package gplx.dbs;
|
||||
import gplx.frameworks.objects.Rls_able;
|
||||
public interface Db_tbl extends Rls_able {
|
||||
String Tbl_name();
|
||||
void Create_tbl();
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.Int_;
|
||||
import gplx.Object_;
|
||||
import gplx.String_;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.basics.utls.ObjectUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public class DbmetaFldItm {
|
||||
public DbmetaFldItm(String name, DbmetaFldType type) {
|
||||
this.name = name;
|
||||
@@ -33,12 +33,12 @@ public class DbmetaFldItm {
|
||||
public boolean Autonum() {return autonum;} public DbmetaFldItm AutonumSetY() {autonum = true; return this;} private boolean autonum;
|
||||
public Object DefaultVal() {return defaultVal;} public DbmetaFldItm DefaultValSet(Object v) {defaultVal = v; return this;} private Object defaultVal;
|
||||
public boolean Eq(DbmetaFldItm comp) {
|
||||
return String_.Eq(name, comp.name)
|
||||
return StringUtl.Eq(name, comp.name)
|
||||
&& type.Eq(comp.type)
|
||||
&& nullable == comp.nullable
|
||||
&& primary == comp.primary
|
||||
&& autonum == comp.autonum
|
||||
&& Object_.Eq(defaultVal, comp.defaultVal);
|
||||
&& ObjectUtl.Eq(defaultVal, comp.defaultVal);
|
||||
}
|
||||
public static final int NullableUnspecified = 0, NullableNull = 1, NullableNotNull = 2;
|
||||
public static final Object DefaultValNull = null;
|
||||
@@ -63,7 +63,7 @@ public class DbmetaFldItm {
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static final String[] StrAryEmpty = String_.Ary_empty; // marker constant; should add overrides
|
||||
public static final String[] StrAryEmpty = StringUtl.AryEmpty; // marker constant; should add overrides
|
||||
public static String Make_or_null(Db_conn conn, DbmetaFldList flds, String tbl_name, int fld_type, Object fld_dflt, String fld_name) {
|
||||
boolean tbl_exists = conn.Meta_tbl_exists(tbl_name);
|
||||
boolean fld_exists = true;
|
||||
@@ -79,5 +79,5 @@ public class DbmetaFldItm {
|
||||
flds.Add(fld);
|
||||
return fld.name;
|
||||
}
|
||||
public static String ToDoubleStrByInt(int v) {return Int_.To_str(v) + ".0";} // move
|
||||
public static String ToDoubleStrByInt(int v) {return IntUtl.ToStr(v) + ".0";} // move
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.Hash_adp;
|
||||
import gplx.Hash_adp_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.objects.lists.GfoIndexedList;
|
||||
import gplx.types.basics.lists.Hash_adp;
|
||||
import gplx.types.basics.lists.Hash_adp_;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.commons.lists.GfoIndexedList;
|
||||
public class DbmetaFldList {
|
||||
private final GfoIndexedList<String, DbmetaFldItm> flds = new GfoIndexedList<>();
|
||||
public void Clear() {flds.Clear();}
|
||||
|
||||
@@ -14,9 +14,9 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.Err_;
|
||||
import gplx.Type_ids_;
|
||||
import gplx.objects.strings.StringUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.basics.utls.TypeIds;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class DbmetaFldType {
|
||||
public DbmetaFldType(int tid, String name, int len1, int len2) {
|
||||
this.tid = tid;
|
||||
@@ -74,24 +74,24 @@ public class DbmetaFldType {
|
||||
case DbmetaFldType.TidBry: return ItmBry;
|
||||
case DbmetaFldType.TidDate: return ItmDate;
|
||||
case DbmetaFldType.TidDecimal: // return Itm__decimal(len1);
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
default: throw ErrUtl.NewUnhandled(tid);
|
||||
}
|
||||
}
|
||||
public static int GetTypeIdByObj(Object o) {
|
||||
int type_id = Type_ids_.To_id_by_obj(o);
|
||||
int type_id = TypeIds.ToIdByObj(o);
|
||||
switch (type_id) {
|
||||
case Type_ids_.Id__bool: return DbmetaFldType.TidBool;
|
||||
case Type_ids_.Id__byte: return DbmetaFldType.TidByte;
|
||||
case Type_ids_.Id__short: return DbmetaFldType.TidShort;
|
||||
case Type_ids_.Id__int: return DbmetaFldType.TidInt;
|
||||
case Type_ids_.Id__long: return DbmetaFldType.TidLong;
|
||||
case Type_ids_.Id__float: return DbmetaFldType.TidFloat;
|
||||
case Type_ids_.Id__double: return DbmetaFldType.TidDouble;
|
||||
case Type_ids_.Id__str: return DbmetaFldType.TidStr;
|
||||
case Type_ids_.Id__bry: return DbmetaFldType.TidBry;
|
||||
case Type_ids_.Id__date: return DbmetaFldType.TidDate;
|
||||
case Type_ids_.Id__decimal: return DbmetaFldType.TidDecimal;
|
||||
default: throw Err_.new_unhandled_default(type_id);
|
||||
case TypeIds.IdBool: return DbmetaFldType.TidBool;
|
||||
case TypeIds.IdByte: return DbmetaFldType.TidByte;
|
||||
case TypeIds.IdShort: return DbmetaFldType.TidShort;
|
||||
case TypeIds.IdInt: return DbmetaFldType.TidInt;
|
||||
case TypeIds.IdLong: return DbmetaFldType.TidLong;
|
||||
case TypeIds.IdFloat: return DbmetaFldType.TidFloat;
|
||||
case TypeIds.IdDouble: return DbmetaFldType.TidDouble;
|
||||
case TypeIds.IdStr: return DbmetaFldType.TidStr;
|
||||
case TypeIds.IdBry: return DbmetaFldType.TidBry;
|
||||
case TypeIds.IdDate: return DbmetaFldType.TidDate;
|
||||
case TypeIds.IdDecimal: return DbmetaFldType.TidDecimal;
|
||||
default: throw ErrUtl.NewUnhandled(type_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
import gplx.String_;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.dbs.metas.Dbmeta_idx_fld;
|
||||
import gplx.dbs.sqls.SqlQryWtr;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
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;
|
||||
@@ -28,7 +28,7 @@ public class Dbmeta_idx_itm {
|
||||
public final Dbmeta_idx_fld[] Flds;
|
||||
public String To_sql_create(SqlQryWtr sql_wtr) {return sql_wtr.Schema_wtr().Bld_create_idx(this);}
|
||||
public boolean Eq(Dbmeta_idx_itm comp) {
|
||||
return String_.Eq(name, comp.name)
|
||||
return StringUtl.Eq(name, comp.name)
|
||||
&& unique == comp.unique
|
||||
&& tbl == comp.tbl
|
||||
&& Dbmeta_idx_fld.Ary_eq(Flds, comp.Flds);
|
||||
@@ -41,7 +41,7 @@ public class Dbmeta_idx_itm {
|
||||
public static Dbmeta_idx_itm new_normal_by_tbl (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(BoolUtl.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(BoolUtl.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(BoolUtl.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 String Bld_idx_name(String tbl, String suffix) {return StringUtl.Concat(tbl, "__", suffix);}
|
||||
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;
|
||||
|
||||
@@ -13,13 +13,16 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.conn_props; import gplx.*;
|
||||
package gplx.dbs.conn_props;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public class Db_conn_props_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public boolean Has(String key) {return hash.Has(key);}
|
||||
public boolean Match(String key, String expd_val) {
|
||||
String actl_val = (String)hash.GetByOrNull(key);
|
||||
return actl_val == null ? false : String_.Eq(expd_val,actl_val);
|
||||
return actl_val == null ? false : StringUtl.Eq(expd_val,actl_val);
|
||||
}
|
||||
public void Add(String key, String val) {hash.Add(key, val);}
|
||||
public void Del(String key) {hash.Del(key);}
|
||||
|
||||
@@ -13,9 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.diffs; import gplx.dbs.*;
|
||||
import gplx.dbs.diffs.itms.*;
|
||||
import gplx.dbs.diffs.builds.*;
|
||||
import gplx.types.commons.GfoDateNow;
|
||||
public class Gdif_core {
|
||||
private final Db_conn conn;
|
||||
private final Gdif_job_tbl job_tbl;
|
||||
@@ -31,7 +32,7 @@ public class Gdif_core {
|
||||
public Gdif_db Db() {return db;} private final Gdif_db db;
|
||||
public Gdif_job_itm New_job(String name, String made_by) {
|
||||
int job_id = conn.Sys_mgr().Autonum_next(job_tbl.Tbl_name(), job_tbl.Fld_job_id());
|
||||
return job_tbl.Insert(job_id, name, made_by, Datetime_now.Get().XtoUtc(), "");
|
||||
return job_tbl.Insert(job_id, name, made_by, GfoDateNow.Get().ToUtc(), "");
|
||||
}
|
||||
public Gdif_cmd_itm New_cmd(Gdif_bldr_ctx ctx, int tid) {
|
||||
ctx.Cur_cmd_count++;
|
||||
|
||||
@@ -13,8 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.diffs; import gplx.dbs.*;
|
||||
import gplx.dbs.metas.*;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
public class Gfdb_diff_tbl {
|
||||
public Gfdb_diff_tbl(String name, DbmetaFldItm[] flds, DbmetaFldItm[] keys, DbmetaFldItm[] vals) {
|
||||
this.Name = name; this.Flds = flds; this.Keys = keys; this.Vals = vals;
|
||||
@@ -47,7 +48,7 @@ public class Gfdb_diff_tbl {
|
||||
}
|
||||
}
|
||||
// try to find shortest unique index
|
||||
Dbmeta_idx_itm unique_idx = null; int unique_idx_len = Int_.Max_value;
|
||||
Dbmeta_idx_itm unique_idx = null; int unique_idx_len = IntUtl.MaxValue;
|
||||
Dbmeta_idx_mgr idxs = tbl.Idxs();
|
||||
int idxs_len = idxs.Len();
|
||||
for (int i = 0; i < idxs_len; ++i) {
|
||||
|
||||
@@ -13,11 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.diffs; import gplx.dbs.*;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
class Gfdb_diff_tbl_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Len();}
|
||||
public Gfdb_diff_tbl Get_at(int idx) {return (Gfdb_diff_tbl)hash.Get_at(idx);}
|
||||
public Gfdb_diff_tbl Get_at(int idx) {return (Gfdb_diff_tbl)hash.GetAt(idx);}
|
||||
public Gfdb_diff_tbl Get_by(String key) {return (Gfdb_diff_tbl)hash.GetByOrNull(key);}
|
||||
}
|
||||
class Gfdb_diff_tbl_mgr__sqlite {
|
||||
|
||||
@@ -13,9 +13,22 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
package gplx.dbs.diffs;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.DbmetaFldList;
|
||||
import gplx.dbs.DbmetaFldType;
|
||||
import gplx.types.basics.utls.BryUtl;
|
||||
import gplx.types.commons.lists.CompareAbleUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
import gplx.types.basics.utls.ByteUtl;
|
||||
import gplx.types.basics.utls.DoubleUtl;
|
||||
import gplx.types.basics.utls.FloatUtl;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.basics.utls.LongUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class Gfdb_rdr_utl_ {
|
||||
public static int Compare(DbmetaFldItm[] flds, int len, Db_rdr lhs_rdr, Db_rdr rhs_rdr) {
|
||||
int comp = CompareAbleUtl.Same;
|
||||
@@ -25,14 +38,14 @@ public class Gfdb_rdr_utl_ {
|
||||
int tid = fld.Type().Tid();
|
||||
switch (tid) {
|
||||
case DbmetaFldType.TidBool: comp = BoolUtl.Compare (lhs_rdr.Read_bool_by_byte(fld_name), rhs_rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case DbmetaFldType.TidByte: comp = Byte_.Compare (lhs_rdr.Read_byte(fld_name) , rhs_rdr.Read_byte(fld_name)); break;
|
||||
case DbmetaFldType.TidInt: comp = Int_.Compare (lhs_rdr.Read_int(fld_name) , rhs_rdr.Read_int(fld_name)); break;
|
||||
case DbmetaFldType.TidLong: comp = Long_.Compare (lhs_rdr.Read_long(fld_name) , rhs_rdr.Read_long(fld_name)); break;
|
||||
case DbmetaFldType.TidFloat: comp = Float_.Compare (lhs_rdr.Read_float(fld_name) , rhs_rdr.Read_float(fld_name)); break;
|
||||
case DbmetaFldType.TidDouble: comp = Double_.Compare (lhs_rdr.Read_double(fld_name) , rhs_rdr.Read_double(fld_name)); break;
|
||||
case DbmetaFldType.TidStr: comp = String_.Compare (lhs_rdr.Read_str(fld_name) , rhs_rdr.Read_str(fld_name)); break;
|
||||
case DbmetaFldType.TidBry: comp = Bry_.Compare (lhs_rdr.Read_bry(fld_name) , rhs_rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
case DbmetaFldType.TidByte: comp = ByteUtl.Compare (lhs_rdr.Read_byte(fld_name) , rhs_rdr.Read_byte(fld_name)); break;
|
||||
case DbmetaFldType.TidInt: comp = IntUtl.Compare (lhs_rdr.Read_int(fld_name) , rhs_rdr.Read_int(fld_name)); break;
|
||||
case DbmetaFldType.TidLong: comp = LongUtl.Compare (lhs_rdr.Read_long(fld_name) , rhs_rdr.Read_long(fld_name)); break;
|
||||
case DbmetaFldType.TidFloat: comp = FloatUtl.Compare (lhs_rdr.Read_float(fld_name) , rhs_rdr.Read_float(fld_name)); break;
|
||||
case DbmetaFldType.TidDouble: comp = DoubleUtl.Compare (lhs_rdr.Read_double(fld_name) , rhs_rdr.Read_double(fld_name)); break;
|
||||
case DbmetaFldType.TidStr: comp = StringUtl.Compare (lhs_rdr.Read_str(fld_name) , rhs_rdr.Read_str(fld_name)); break;
|
||||
case DbmetaFldType.TidBry: comp = BryUtl.Compare (lhs_rdr.Read_bry(fld_name) , rhs_rdr.Read_bry(fld_name)); break;
|
||||
default: throw ErrUtl.NewUnhandled(tid);
|
||||
}
|
||||
if (comp != CompareAbleUtl.Same) return comp;
|
||||
}
|
||||
@@ -52,7 +65,7 @@ public class Gfdb_rdr_utl_ {
|
||||
case DbmetaFldType.TidDouble: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case DbmetaFldType.TidStr: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case DbmetaFldType.TidBry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
default: throw ErrUtl.NewUnhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +83,7 @@ public class Gfdb_rdr_utl_ {
|
||||
case DbmetaFldType.TidDouble: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case DbmetaFldType.TidStr: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case DbmetaFldType.TidBry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
default: throw ErrUtl.NewUnhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,41 +13,47 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
package gplx.dbs.diffs.builds; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.basics.utls.ObjectUtl;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import org.junit.*;
|
||||
public class Gfdb_diff_bldr_tst {
|
||||
private final Gfdb_diff_bldr_fxt fxt = new Gfdb_diff_bldr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Same() {
|
||||
fxt.Init__tbl__old(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__cur(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
@Test public void Same() {
|
||||
fxt.Init__tbl__old(ObjectUtl.Ary(1, "A") , ObjectUtl.Ary(2, "B"));
|
||||
fxt.Init__tbl__cur(ObjectUtl.Ary(1, "A") , ObjectUtl.Ary(2, "B"));
|
||||
fxt.Test__bld();
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt.Init__tbl__old(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__cur(Object_.Ary(1, "A1") , Object_.Ary(2, "B1"));
|
||||
@Test public void Update() {
|
||||
fxt.Init__tbl__old(ObjectUtl.Ary(1, "A") , ObjectUtl.Ary(2, "B"));
|
||||
fxt.Init__tbl__cur(ObjectUtl.Ary(1, "A1") , ObjectUtl.Ary(2, "B1"));
|
||||
fxt.Test__bld("U|1|A1", "U|2|B1");
|
||||
}
|
||||
@Test public void Insert() {
|
||||
fxt.Init__tbl__old(Object_.Ary(1, "A"));
|
||||
fxt.Init__tbl__cur(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
@Test public void Insert() {
|
||||
fxt.Init__tbl__old(ObjectUtl.Ary(1, "A"));
|
||||
fxt.Init__tbl__cur(ObjectUtl.Ary(1, "A") , ObjectUtl.Ary(2, "B"));
|
||||
fxt.Test__bld("I|2|B");
|
||||
}
|
||||
@Test public void Delete() {
|
||||
fxt.Init__tbl__old(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__cur(Object_.Ary(1, "A"));
|
||||
@Test public void Delete() {
|
||||
fxt.Init__tbl__old(ObjectUtl.Ary(1, "A") , ObjectUtl.Ary(2, "B"));
|
||||
fxt.Init__tbl__cur(ObjectUtl.Ary(1, "A"));
|
||||
fxt.Test__bld("D|2");
|
||||
}
|
||||
@Test public void Basic() {
|
||||
@Test public void Basic() {
|
||||
fxt.Init__tbl__old
|
||||
( Object_.Ary(1, "A")
|
||||
, Object_.Ary(2, "B")
|
||||
, Object_.Ary(3, "C")
|
||||
( ObjectUtl.Ary(1, "A")
|
||||
, ObjectUtl.Ary(2, "B")
|
||||
, ObjectUtl.Ary(3, "C")
|
||||
);
|
||||
fxt.Init__tbl__cur
|
||||
( Object_.Ary(1, "A")
|
||||
, Object_.Ary(2, "B1")
|
||||
, Object_.Ary(4, "D")
|
||||
( ObjectUtl.Ary(1, "A")
|
||||
, ObjectUtl.Ary(2, "B1")
|
||||
, ObjectUtl.Ary(4, "D")
|
||||
);
|
||||
fxt.Test__bld("U|2|B1", "D|3", "I|4|D");
|
||||
}
|
||||
@@ -76,12 +82,12 @@ class Gfdb_diff_bldr_fxt {
|
||||
public void Init__tbl__cur(Object[]... rows) {Db_conn_utl.Tbl__new(new_conn, "tbl", flds_ary, rows);}
|
||||
public void Test__bld(String... expd) {
|
||||
bldr.Compare(ctx, tbl, old_conn, new_conn);
|
||||
Tfds.Eq_ary_str(expd, wkr.To_str_ary());
|
||||
GfoTstr.EqLines(expd, wkr.To_str_ary());
|
||||
}
|
||||
}
|
||||
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 BryWtr bfr = BryWtr.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;
|
||||
@@ -90,15 +96,15 @@ class Gfdb_diff_wkr__test implements Gfdb_diff_wkr {
|
||||
public void Handle_same() {
|
||||
String old_val = old_rdr.Read_str("val");
|
||||
String new_val = new_rdr.Read_str("val");
|
||||
if (!String_.Eq(old_val, new_val))
|
||||
list.Add(bfr.Add_str_a7("U").Add_byte_pipe().Add_obj(old_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(new_val).To_str_and_clear());
|
||||
if (!StringUtl.Eq(old_val, new_val))
|
||||
list.Add(bfr.AddStrA7("U").AddBytePipe().AddObj(old_rdr.Read_obj("id")).AddBytePipe().AddStrA7(new_val).ToStrAndClear());
|
||||
}
|
||||
public void Handle_old_missing() {
|
||||
String new_val = new_rdr.Read_str("val");
|
||||
list.Add(bfr.Add_str_a7("I").Add_byte_pipe().Add_obj(new_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(new_val).To_str_and_clear());
|
||||
list.Add(bfr.AddStrA7("I").AddBytePipe().AddObj(new_rdr.Read_obj("id")).AddBytePipe().AddStrA7(new_val).ToStrAndClear());
|
||||
}
|
||||
public void Handle_new_missing() {
|
||||
list.Add(bfr.Add_str_a7("D").Add_byte_pipe().Add_obj(old_rdr.Read_obj("id")).To_str_and_clear());
|
||||
list.Add(bfr.AddStrA7("D").AddBytePipe().AddObj(old_rdr.Read_obj("id")).ToStrAndClear());
|
||||
}
|
||||
public String[] To_str_ary() {return list.ToStrAryAndClear();}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,13 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.builds;
|
||||
import gplx.Err_;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.diffs.Gfdb_diff_tbl;
|
||||
import gplx.dbs.diffs.Gfdb_rdr_utl_;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.types.commons.lists.CompareAbleUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
class Gfdb_diff_rdr_comparer {
|
||||
private Db_rdr old_rdr, new_rdr;
|
||||
private boolean old_rdr_move, new_rdr_move;
|
||||
@@ -58,7 +58,7 @@ class Gfdb_diff_rdr_comparer {
|
||||
old_rdr_move = false;
|
||||
new_rdr_move = true;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__old_missing;
|
||||
default: throw Err_.new_unhandled(comp);
|
||||
default: throw ErrUtl.NewUnhandled(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.builds; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.dbs.diffs.itms.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.types.commons.lists.CompareAbleUtl;
|
||||
public class Gfdb_diff_wkr__db implements Gfdb_diff_wkr {
|
||||
private DbmetaFldItm[] val_flds; private int val_flds_len;
|
||||
private Gfdb_diff_tbl tbl; private Db_rdr old_rdr, new_rdr;
|
||||
|
||||
@@ -13,9 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.cmds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.core.srls.*; import gplx.core.brys.fmtrs.*;
|
||||
package gplx.dbs.diffs.cmds; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.core.srls.*; import gplx.types.custom.brys.fmts.fmtrs.*;
|
||||
import gplx.dbs.metas.*;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.basics.utls.ObjectUtl;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
interface Gfdb_diff_cmd {
|
||||
void Merge_undo();
|
||||
void Merge_exec();
|
||||
@@ -42,7 +48,7 @@ class Gfo_srl_mgr_rdr__db {
|
||||
for (int i = 0; i < crt_len; ++i) {
|
||||
Dbmeta_dat_itm crt = crt_mgr.Get_at(i);
|
||||
switch (crt.Tid) {
|
||||
case DbmetaFldType.TidInt: select.Crt_int(crt.Key, Int_.Cast(crt.Val)); break;
|
||||
case DbmetaFldType.TidInt: select.Crt_int(crt.Key, IntUtl.Cast(crt.Val)); break;
|
||||
}
|
||||
}
|
||||
Db_rdr rdr = select.Exec_select__rls_manual();
|
||||
@@ -63,7 +69,7 @@ class Gfo_srl_mgr_rdr__db {
|
||||
for (int i = 0; i < crt_len; ++i) {
|
||||
Dbmeta_dat_itm crt = crt_mgr.Get_at(i);
|
||||
switch (crt.Tid) {
|
||||
case DbmetaFldType.TidInt: delete.Crt_int(crt.Key, Int_.Cast(crt.Val)); break;
|
||||
case DbmetaFldType.TidInt: delete.Crt_int(crt.Key, IntUtl.Cast(crt.Val)); break;
|
||||
}
|
||||
}
|
||||
delete.Exec_delete();
|
||||
@@ -99,7 +105,7 @@ class Gfdb_diff_cmd__fld__create {
|
||||
wtr.Set_int ("type_len_2" , cur.Type().Len2());
|
||||
wtr.Set_bool ("primary" , cur.Primary());
|
||||
wtr.Set_int ("nullable" , cur.Nullable());
|
||||
wtr.Set_str ("dflt" , Object_.Xto_str_or(cur.DefaultVal(), null));
|
||||
wtr.Set_str ("dflt" , ObjectUtl.ToStrOr(cur.DefaultVal(), null));
|
||||
wtr.Itm_end();
|
||||
}
|
||||
public void Load(Gfo_srl_ctx ctx, Gfo_srl_itm owner) {
|
||||
@@ -232,47 +238,47 @@ 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();
|
||||
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);
|
||||
private final BryFmtr fmtr = BryFmtr.New();
|
||||
private final BryWtr tmp_bfr = BryWtr.New();
|
||||
public void Bld_insert(BryWtr bfr, String tbl_name, String[] keys, String[] vals, int rng_bgn, int rng_end) {
|
||||
fmtr.FmtSet(Insert__fmt).KeysSet(Insert__keys);
|
||||
fmtr.BldToBfrMany(bfr, tbl_name, Bld_flds(tmp_bfr, ", ", "d.", keys, vals), Bld_join(keys), rng_bgn, rng_end);
|
||||
}
|
||||
public void Bld_update(Bry_bfr bfr, String tbl_name, String[] keys, String[] vals, int rng_bgn, int rng_end) {
|
||||
fmtr.Fmt_(Update__fmt).Keys_(Update__keys);
|
||||
fmtr.Bld_bfr_many(bfr, tbl_name, Bld_flds(tmp_bfr, ", ", "d.", keys, vals), Bld_join(keys), rng_bgn, rng_end);
|
||||
public void Bld_update(BryWtr bfr, String tbl_name, String[] keys, String[] vals, int rng_bgn, int rng_end) {
|
||||
fmtr.FmtSet(Update__fmt).KeysSet(Update__keys);
|
||||
fmtr.BldToBfrMany(bfr, tbl_name, Bld_flds(tmp_bfr, ", ", "d.", keys, vals), Bld_join(keys), rng_bgn, rng_end);
|
||||
}
|
||||
public void Bld_delete(Bry_bfr bfr, String tbl_name, String[] keys, int rng_bgn, int rng_end) {
|
||||
fmtr.Fmt_(Delete__fmt).Keys_(Delete__keys);
|
||||
fmtr.Bld_bfr_many(bfr, tbl_name, Bld_flds(tmp_bfr, " || '|' || ", "", keys, String_.Ary_empty), Bld_flds(tmp_bfr, " || '|' || ", "k.", keys, String_.Ary_empty), Bld_join(keys), rng_bgn, rng_end);
|
||||
public void Bld_delete(BryWtr bfr, String tbl_name, String[] keys, int rng_bgn, int rng_end) {
|
||||
fmtr.FmtSet(Delete__fmt).KeysSet(Delete__keys);
|
||||
fmtr.BldToBfrMany(bfr, tbl_name, Bld_flds(tmp_bfr, " || '|' || ", "", keys, StringUtl.AryEmpty), Bld_flds(tmp_bfr, " || '|' || ", "k.", keys, StringUtl.AryEmpty), Bld_join(keys), rng_bgn, rng_end);
|
||||
}
|
||||
private static String Bld_flds(Bry_bfr tmp_bfr, String dlm, String alias, String[] keys, String[] vals) {
|
||||
private static String Bld_flds(BryWtr tmp_bfr, String dlm, String alias, String[] keys, String[] vals) {
|
||||
int keys_len = keys.length;
|
||||
for (int i = 0; i < keys_len; ++i) {
|
||||
String key = keys[i];
|
||||
if (i != 0) tmp_bfr.Add_str_a7(dlm);
|
||||
tmp_bfr.Add_str_a7(alias).Add_str_a7(key);
|
||||
if (i != 0) tmp_bfr.AddStrA7(dlm);
|
||||
tmp_bfr.AddStrA7(alias).AddStrA7(key);
|
||||
}
|
||||
int flds_len = vals.length;
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
String val = vals[i];
|
||||
tmp_bfr.Add_str_a7(dlm);
|
||||
tmp_bfr.Add_str_a7(alias).Add_str_a7(val);
|
||||
tmp_bfr.AddStrA7(dlm);
|
||||
tmp_bfr.AddStrA7(alias).AddStrA7(val);
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
return tmp_bfr.ToStrAndClear();
|
||||
}
|
||||
private String Bld_join(String[] keys) {
|
||||
int len = keys.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String key = keys[i];
|
||||
tmp_bfr.Add_str_a7(i == 0 ? " ON " : " AND ");
|
||||
tmp_bfr.Add_str_a7("k.").Add_str_a7(key).Add_str_a7(" = ");
|
||||
tmp_bfr.Add_str_a7("d.").Add_str_a7(key);
|
||||
tmp_bfr.AddStrA7(i == 0 ? " ON " : " AND ");
|
||||
tmp_bfr.AddStrA7("k.").AddStrA7(key).AddStrA7(" = ");
|
||||
tmp_bfr.AddStrA7("d.").AddStrA7(key);
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
return tmp_bfr.ToStrAndClear();
|
||||
}
|
||||
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 = StringUtl.Ary("tbl", "flds", "join", "rng_bgn", "rng_end");
|
||||
private static final String Insert__fmt = StringUtl.ConcatLinesNlSkipLast
|
||||
( "INSERT INTO db_curr.~{tbl}"
|
||||
, "SELECT ~{flds}"
|
||||
, "FROM db_temp.~{tbl}_pkey k"
|
||||
@@ -280,8 +286,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 = StringUtl.Ary("tbl", "flds", "join", "rng_bgn", "rng_end");
|
||||
private static final String Update__fmt = StringUtl.ConcatLinesNlSkipLast
|
||||
( "REPLACE INTO db_curr.~{tbl}"
|
||||
, "SELECT ~{flds}"
|
||||
, "FROM db_temp.~{tbl}_pkey k"
|
||||
@@ -289,8 +295,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 = StringUtl.Ary("tbl", "pkey_where", "pkey_select", "join", "rng_bgn", "rng_end");
|
||||
private static final String Delete__fmt = StringUtl.ConcatLinesNlSkipLast
|
||||
( "DELETE db_curr.~{tbl}"
|
||||
, "WHERE ~{pkey_where} IN"
|
||||
, "( SELECT ~{pkey_select}"
|
||||
|
||||
@@ -89,7 +89,7 @@ class Gfdb_diff_cmd__idx__fld implements Gfo_srl_itm {
|
||||
// wtr.Set_int ("fld_nullable" , cur.Nullable_tid());
|
||||
// wtr.Set_bool ("fld_primary" , cur.Primary());
|
||||
// wtr.Set_bool ("fld_autonum" , cur.Autonum());
|
||||
// wtr.Set_str ("fld_dflt" , Object_.Xto_str_or(cur.Default(), null));
|
||||
// wtr.Set_str ("fld_dflt" , ObjectUtl.Xto_str_or(cur.Default(), null));
|
||||
//// wtr.Set_int ("fld_asc" , cur.Sort_tid);
|
||||
// wtr.Itm_end();
|
||||
// }
|
||||
|
||||
@@ -13,13 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.cmds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
package gplx.dbs.diffs.cmds;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
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();
|
||||
@Test public void Insert() {
|
||||
fxt.Test__insert("tbl1", String_.Ary("key1", "key2"), String_.Ary("fld1", "fld2"), 0, 99, String_.Concat_lines_nl_skip_last
|
||||
@Test public void Insert() {
|
||||
fxt.Test__insert("tbl1", StringUtl.Ary("key1", "key2"), StringUtl.Ary("fld1", "fld2"), 0, 99, StringUtl.ConcatLinesNlSkipLast
|
||||
( "INSERT INTO db_curr.tbl1"
|
||||
, "SELECT d.key1, d.key2, d.fld1, d.fld2"
|
||||
, "FROM db_temp.tbl1_pkey k"
|
||||
@@ -28,8 +30,8 @@ public class Gfdb_diff_cmd_sql_bldr_tst {
|
||||
, "AND k.diff_uid BETWEEN 0 AND 99;"
|
||||
));
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt.Test__update("tbl1", String_.Ary("key1", "key2"), String_.Ary("fld1", "fld2"), 0, 99, String_.Concat_lines_nl_skip_last
|
||||
@Test public void Update() {
|
||||
fxt.Test__update("tbl1", StringUtl.Ary("key1", "key2"), StringUtl.Ary("fld1", "fld2"), 0, 99, StringUtl.ConcatLinesNlSkipLast
|
||||
( "REPLACE INTO db_curr.tbl1"
|
||||
, "SELECT d.key1, d.key2, d.fld1, d.fld2"
|
||||
, "FROM db_temp.tbl1_pkey k"
|
||||
@@ -38,8 +40,8 @@ public class Gfdb_diff_cmd_sql_bldr_tst {
|
||||
, "AND k.diff_uid BETWEEN 0 AND 99;"
|
||||
));
|
||||
}
|
||||
@Test public void Delete() {
|
||||
fxt.Test__delete("tbl1", String_.Ary("key1", "key2"), 0, 99, String_.Concat_lines_nl_skip_last
|
||||
@Test public void Delete() {
|
||||
fxt.Test__delete("tbl1", StringUtl.Ary("key1", "key2"), 0, 99, StringUtl.ConcatLinesNlSkipLast
|
||||
( "DELETE db_curr.tbl1"
|
||||
, "WHERE key1 || '|' || key2 IN"
|
||||
, "( SELECT k.key1 || '|' || k.key2"
|
||||
@@ -53,17 +55,17 @@ 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 BryWtr bfr = BryWtr.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());
|
||||
GfoTstr.EqLines(expd, bfr.ToStrAndClear());
|
||||
}
|
||||
public void Test__update(String tbl_name, String[] keys, String[] flds, int rng_bgn, int rng_end, String expd) {
|
||||
bldr.Bld_update(bfr, tbl_name, keys, flds, 0, 99);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
GfoTstr.EqLines(expd, bfr.ToStrAndClear());
|
||||
}
|
||||
public void Test__delete(String tbl_name, String[] keys, int rng_bgn, int rng_end, String expd) {
|
||||
bldr.Bld_delete(bfr, tbl_name, keys, 0, 99);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
GfoTstr.EqLines(expd, bfr.ToStrAndClear());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.diffs.itms; import gplx.dbs.*;
|
||||
import gplx.frameworks.objects.Rls_able;
|
||||
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;
|
||||
|
||||
@@ -13,14 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
public class Gdif_job_itm {
|
||||
public Gdif_job_itm(int id, String name, String made_by, DateAdp made_on) {
|
||||
this.Id = id; this.Name = name; this.Made_by = made_by; this.Made_on = made_on;
|
||||
}
|
||||
public final int Id;
|
||||
public final String Name;
|
||||
public final String Made_by;
|
||||
public final DateAdp Made_on;
|
||||
public String Data;
|
||||
}
|
||||
package gplx.dbs.diffs.itms;
|
||||
import gplx.types.commons.GfoDate;
|
||||
public class Gdif_job_itm {
|
||||
public Gdif_job_itm(int id, String name, String made_by, GfoDate made_on) {
|
||||
this.Id = id; this.Name = name; this.Made_by = made_by; this.Made_on = made_on;
|
||||
}
|
||||
public final int Id;
|
||||
public final String Name;
|
||||
public final String Made_by;
|
||||
public final GfoDate Made_on;
|
||||
public String Data;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.diffs.itms; import gplx.dbs.*;
|
||||
import gplx.frameworks.objects.Rls_able;
|
||||
import gplx.types.commons.GfoDate;
|
||||
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;
|
||||
@@ -27,7 +29,7 @@ public class Gdif_job_tbl implements Rls_able {
|
||||
public String Tbl_name() {return tbl_name;}
|
||||
public String Fld_job_id() {return fld_job_id;}
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public Gdif_job_itm Insert(int id, String name, String made_by, DateAdp made_on, String data) {
|
||||
public Gdif_job_itm Insert(int id, String name, String made_by, GfoDate made_on, String data) {
|
||||
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_job_id , id)
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.diffs.itms; import gplx.dbs.*;
|
||||
import gplx.frameworks.objects.Rls_able;
|
||||
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;
|
||||
|
||||
@@ -15,8 +15,8 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines;
|
||||
|
||||
import gplx.Gfo_usr_dlg;
|
||||
import gplx.Io_url;
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.core.stores.DataRdr;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_conn_info;
|
||||
|
||||
@@ -13,11 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines; import gplx.Err_;
|
||||
import gplx.Gfo_usr_dlg;
|
||||
import gplx.Gfo_usr_dlg_;
|
||||
import gplx.Io_url;
|
||||
import gplx.Keyval;
|
||||
package gplx.dbs.engines;
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg;
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg_;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.core.stores.DataRdr;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_conn_info;
|
||||
@@ -42,7 +43,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
public abstract class Db_engine_sql_base implements Db_engine {
|
||||
@gplx.Internal protected void Ctor(Db_conn_info conn_info) {this.conn_info = conn_info;}
|
||||
public void Ctor(Db_conn_info conn_info) {this.conn_info = conn_info;}
|
||||
public abstract String Tid();
|
||||
public Db_conn_info Conn_info() {return conn_info;} protected Db_conn_info conn_info;
|
||||
public Db_conn_props_mgr Props() {return props;} private final Db_conn_props_mgr props = new Db_conn_props_mgr();
|
||||
@@ -72,7 +73,7 @@ public abstract class Db_engine_sql_base implements Db_engine {
|
||||
Statement cmd = New_stmt_exec(sql);
|
||||
return cmd.executeUpdate(sql);
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "db.engine:exec failed", "url", conn_info.Db_api(), "sql", sql);}
|
||||
catch (Exception e) {throw ErrUtl.NewArgs(e, "db.engine:exec failed", "url", conn_info.Db_api(), "sql", sql);}
|
||||
}
|
||||
private DataRdr Exec_as_rdr(String sql) {
|
||||
try {
|
||||
@@ -81,7 +82,7 @@ public abstract class Db_engine_sql_base implements Db_engine {
|
||||
ResultSet rdr = cmd.getResultSet();
|
||||
return New_rdr(rdr, sql);
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "db.engine:rdr failed", "url", conn_info.Db_api(), "sql", sql);}
|
||||
catch (Exception e) {throw ErrUtl.NewArgs(e, "db.engine:rdr failed", "url", conn_info.Db_api(), "sql", sql);}
|
||||
}
|
||||
public void Meta_tbl_create(Dbmeta_tbl_itm tbl) {Exec_as_int(tbl.To_sql_create(this.Sql_wtr())); this.Meta_mgr().Load_all();}
|
||||
public void Meta_tbl_delete(String tbl) {Exec_as_int(this.Sql_wtr().Schema_wtr().Bld_drop_tbl(tbl)); this.Meta_mgr().Load_all();}
|
||||
@@ -104,7 +105,7 @@ public abstract class Db_engine_sql_base implements Db_engine {
|
||||
Gfo_usr_dlg_.Instance.Plog_many("", "", "column added to table: db=~{0} tbl=~{1} fld=~{2}", conn_info.Database(), tbl, fld.Name());
|
||||
}
|
||||
catch (Exception e) { // catch error if column already added to table
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "column not added to table: db=~{0} tbl=~{1} fld=~{2} err=~{3}", conn_info.Database(), tbl, fld.Name(), Err_.Message_gplx_full(e));
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "column not added to table: db=~{0} tbl=~{1} fld=~{2} err=~{3}", conn_info.Database(), tbl, fld.Name(), ErrUtl.ToStrFull(e));
|
||||
}
|
||||
this.Meta_mgr().Load_all();
|
||||
}
|
||||
@@ -121,7 +122,7 @@ public abstract class Db_engine_sql_base implements Db_engine {
|
||||
rv.Ctor(stmt, (ResultSet)rdr, sql);
|
||||
return rv;
|
||||
}
|
||||
@gplx.Internal protected abstract Connection Conn_make();
|
||||
public abstract Connection Conn_make();
|
||||
private void Batch_mgr__conn_bgn() {batch_mgr.Conn_bgn().Run(this);}
|
||||
private void Batch_mgr__conn_end() {batch_mgr.Conn_end().Run(this);}
|
||||
private void Conn_assert() {
|
||||
@@ -134,32 +135,32 @@ public abstract class Db_engine_sql_base implements Db_engine {
|
||||
if (connection == null) return; // connection never opened; just exit
|
||||
this.Batch_mgr__conn_end();
|
||||
try {connection.close();}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "Conn_term failed", "url", conn_info.Raw());}
|
||||
catch (Exception e) {throw ErrUtl.NewArgs(e, "Conn_term failed", "url", conn_info.Raw());}
|
||||
connection = null;
|
||||
}
|
||||
@Override public Object Stmt_by_sql(String sql) {
|
||||
if (connection == null) Conn_assert();
|
||||
try {return connection.prepareStatement(sql);}
|
||||
catch (Exception e) {
|
||||
throw Err_.new_exc(e, "db", "New_stmt_prep failed", "sql", sql);
|
||||
throw ErrUtl.NewArgs(e, "New_stmt_prep failed", "sql", sql);
|
||||
}
|
||||
}
|
||||
private Statement New_stmt_exec(String sql) {
|
||||
if (connection == null) Conn_assert();
|
||||
try {return connection.createStatement();}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "New_stmt_exec failed", "sql", sql);}
|
||||
catch (Exception e) {throw ErrUtl.NewArgs(e, "New_stmt_exec failed", "sql", sql);}
|
||||
}
|
||||
protected Connection Conn_make_by_url(String url, String uid, String pwd) {
|
||||
try {return DriverManager.getConnection(url, uid, pwd);}
|
||||
catch (SQLException e) {throw Err_.new_exc(e, "db", "connection open failed", "info", Conn_info().Raw());}
|
||||
catch (SQLException e) {throw ErrUtl.NewArgs(e, "connection open failed", "info", Conn_info().Raw());}
|
||||
}
|
||||
protected Connection Conn__new_by_url_and_props(String url, Keyval... props) {
|
||||
protected Connection Conn__new_by_url_and_props(String url, KeyVal... props) {
|
||||
try {
|
||||
java.util.Properties properties = new java.util.Properties();
|
||||
for (Keyval prop : props)
|
||||
properties.setProperty(prop.Key(), prop.Val_to_str_or_empty());
|
||||
for (KeyVal prop : props)
|
||||
properties.setProperty(prop.KeyToStr(), prop.ValToStrOrEmpty());
|
||||
return DriverManager.getConnection(url, properties);
|
||||
}
|
||||
catch (SQLException e) {throw Err_.new_exc(e, "db", "connection open failed", "info", Conn_info().Raw());}
|
||||
catch (SQLException e) {throw ErrUtl.NewArgs(e, "connection open failed", "info", Conn_info().Raw());}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,18 +13,19 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class Mem_conn_info extends Db_conn_info__base {
|
||||
public Mem_conn_info(String raw, String db_api, String database) {super(raw, db_api, database);}
|
||||
@Override public String Key() {return Tid_const;} public static final String Tid_const = "mem";
|
||||
@Override public Db_conn_info New_self(String raw, Keyval_hash hash) {
|
||||
return new Mem_conn_info(raw, raw, hash.Get_val_as_str_or_fail("database"));
|
||||
}
|
||||
public static Db_conn_info new_(String database) {
|
||||
return Db_conn_info_.parse(Bld_raw
|
||||
( "gplx_key", Tid_const
|
||||
, "database", database
|
||||
));
|
||||
}
|
||||
public static final Mem_conn_info Instance = new Mem_conn_info("", "", "");
|
||||
}
|
||||
package gplx.dbs.engines.mems; import gplx.dbs.*;
|
||||
import gplx.types.commons.KeyValHash;
|
||||
public class Mem_conn_info extends Db_conn_info__base {
|
||||
public Mem_conn_info(String raw, String db_api, String database) {super(raw, db_api, database);}
|
||||
@Override public String Key() {return Tid_const;} public static final String Tid_const = "mem";
|
||||
@Override public Db_conn_info New_self(String raw, KeyValHash hash) {
|
||||
return new Mem_conn_info(raw, raw, hash.GetByValAsStrOrFail("database"));
|
||||
}
|
||||
public static Db_conn_info new_(String database) {
|
||||
return Db_conn_info_.parse(Bld_raw
|
||||
( "gplx_key", Tid_const
|
||||
, "database", database
|
||||
));
|
||||
}
|
||||
public static final Mem_conn_info Instance = new Mem_conn_info("", "", "");
|
||||
}
|
||||
|
||||
@@ -14,13 +14,12 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Io_mgr;
|
||||
import gplx.Io_url_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.Tfds;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
import gplx.libs.files.Io_mgr;
|
||||
import gplx.libs.files.Io_url_;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_conn_bldr;
|
||||
import gplx.dbs.Db_qry;
|
||||
@@ -28,7 +27,7 @@ import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.DbmetaFldList;
|
||||
import gplx.dbs.Dbmeta_tbl_itm;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
class Mem_db_fxt {
|
||||
public Mem_db_fxt() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
@@ -63,25 +62,25 @@ class Mem_db_fxt {
|
||||
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();
|
||||
BryWtr tmp_bfr = BryWtr.New();
|
||||
int expd_len = expd.length;
|
||||
String[] expd_rows = new String[expd_len];
|
||||
for (int i = 0; i < expd_len; ++i) {
|
||||
String[] expd_row = expd[i];
|
||||
for (int j = 0; j < expd_row.length; ++j) {
|
||||
if (j != 0) tmp_bfr.Add_byte_pipe();
|
||||
tmp_bfr.Add_str_u8(expd_row[j]);
|
||||
if (j != 0) tmp_bfr.AddBytePipe();
|
||||
tmp_bfr.AddStrU8(expd_row[j]);
|
||||
}
|
||||
expd_rows[i] = tmp_bfr.To_str_and_clear();
|
||||
expd_rows[i] = tmp_bfr.ToStrAndClear();
|
||||
}
|
||||
while (rdr.Move_next()) {
|
||||
int fld_len = rdr.Fld_len();
|
||||
for (int i = 0; i < fld_len; ++i) {
|
||||
if (i != 0) tmp_bfr.Add_byte_pipe();
|
||||
tmp_bfr.Add_obj_strict(rdr.Read_at(i));
|
||||
if (i != 0) tmp_bfr.AddBytePipe();
|
||||
tmp_bfr.AddObjStrict(rdr.Read_at(i));
|
||||
}
|
||||
actl_list.Add(tmp_bfr.To_str_and_clear());
|
||||
actl_list.Add(tmp_bfr.ToStrAndClear());
|
||||
}
|
||||
Tfds.Eq_ary(expd_rows, (String[])actl_list.ToAryAndClear(String.class));
|
||||
GfoTstr.EqLines(expd_rows, (String[])actl_list.ToAryAndClear(String.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.mems; 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.*;
|
||||
import gplx.dbs.wkrs.SqlWkrMgr;
|
||||
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.types.basics.lists.Hash_adp;
|
||||
import gplx.types.basics.lists.Hash_adp_;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class Mem_engine implements Db_engine {
|
||||
private final Hash_adp tbl_hash = Hash_adp_.New();
|
||||
Mem_engine(Db_conn_info conn_info) {
|
||||
@@ -38,15 +42,15 @@ public class Mem_engine implements Db_engine {
|
||||
public String Txn_end() {return "";}// --txn_count; return "";}
|
||||
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 Err_.new_unimplemented();}
|
||||
public Object Exec_as_obj(Db_qry qry) {throw ErrUtl.NewUnimplemented();}
|
||||
public void Conn_open() {}
|
||||
public void Conn_term() {
|
||||
// if (txn_count != 0) throw Err_.new_wo_type("Conn_term.txns still open", "txn_count", txn_count); // IGNORE: causing test to fails; DATE:2016-03-30
|
||||
// if (txn_count != 0) throw ErrUtl.NewArgs("Conn_term.txns still open", "txn_count", txn_count); // IGNORE: causing test to fails; DATE:2016-03-30
|
||||
}
|
||||
public Db_rdr Exec_as_rdr__rls_manual(Object rdr_obj, String sql) {throw Err_.new_unimplemented();}
|
||||
public Db_rdr Exec_as_rdr__rls_auto(Db_stmt stmt, Object rdr_obj, String sql) {throw Err_.new_unimplemented();}
|
||||
public DataRdr New_rdr(java.sql.ResultSet rdr, String sql) {throw Err_.new_unimplemented();}
|
||||
public Object Stmt_by_sql(String sql) {throw Err_.new_unimplemented();}
|
||||
public Db_rdr Exec_as_rdr__rls_manual(Object rdr_obj, String sql) {throw ErrUtl.NewUnimplemented();}
|
||||
public Db_rdr Exec_as_rdr__rls_auto(Db_stmt stmt, Object rdr_obj, String sql) {throw ErrUtl.NewUnimplemented();}
|
||||
public DataRdr New_rdr(java.sql.ResultSet rdr, String sql) {throw ErrUtl.NewUnimplemented();}
|
||||
public Object Stmt_by_sql(String sql) {throw ErrUtl.NewUnimplemented();}
|
||||
public void Meta_tbl_create(Dbmeta_tbl_itm meta) {
|
||||
Mem_tbl mem_tbl = new Mem_tbl(meta);
|
||||
tbl_hash.AddIfDupeUseNth(meta.Name(), mem_tbl);
|
||||
|
||||
@@ -13,14 +13,7 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Err_;
|
||||
import gplx.Hash_adp_bry;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.String_;
|
||||
package gplx.dbs.engines.mems;
|
||||
import gplx.core.criterias.Criteria;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_rdr;
|
||||
@@ -32,9 +25,16 @@ import gplx.dbs.sqls.itms.Sql_select_clause;
|
||||
import gplx.dbs.sqls.itms.Sql_select_fld;
|
||||
import gplx.dbs.sqls.itms.Sql_select_fld_list;
|
||||
import gplx.dbs.sqls.itms.Sql_tbl_itm;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
import gplx.types.basics.utls.ArrayUtl;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
import gplx.types.commons.lists.CompareAbleUtl;
|
||||
import gplx.types.commons.lists.ComparerAble;
|
||||
import gplx.types.basics.lists.Hash_adp_bry;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class Mem_exec_select {
|
||||
private final Mem_engine engine;
|
||||
private final List_adp tmp_where_rows = List_adp_.New();
|
||||
@@ -61,7 +61,7 @@ public class Mem_exec_select {
|
||||
List_adp join_tbls = qry2.From().Tbls;
|
||||
int join_tbls_len = join_tbls.Len();
|
||||
for (int i = 1; i < join_tbls_len; ++i) {
|
||||
Sql_tbl_itm join_tbl = (Sql_tbl_itm)join_tbls.Get_at(i);
|
||||
Sql_tbl_itm join_tbl = (Sql_tbl_itm)join_tbls.GetAt(i);
|
||||
Mem_row[] join_rows = (Mem_row[])engine.Tbls__get(join_tbl.Name).rows.ToAry(Mem_row.class);
|
||||
join_rows = Mem_exec_.Rows__alias(join_rows, join_tbl.Alias);
|
||||
tbl_rows = Mem_exec_.Rows__join(join_tbl.Join_tid, tbl_rows, join_rows, join_tbl.Alias, join_tbl.Join_flds);
|
||||
@@ -111,7 +111,7 @@ class Mem_sorter implements 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();
|
||||
BryWtr bfr = BryWtr.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) {
|
||||
@@ -134,12 +134,12 @@ class Mem_exec_ {
|
||||
switch (join_tid) {
|
||||
case Sql_tbl_itm.Tid__inner: continue;
|
||||
case Sql_tbl_itm.Tid__left: break;
|
||||
default: throw Err_.new_unhandled_default(join_tid);
|
||||
default: throw ErrUtl.NewUnhandled(join_tid);
|
||||
}
|
||||
}
|
||||
int rhs_list_len = rhs_list == null ? 1 : rhs_list.Len();
|
||||
for (int j = 0; j < rhs_list_len; ++j) {
|
||||
Mem_row rhs_row = rhs_list == null ? Mem_row.Null_row : (Mem_row)rhs_list.Get_at(j);
|
||||
Mem_row rhs_row = rhs_list == null ? Mem_row.Null_row : (Mem_row)rhs_list.GetAt(j);
|
||||
Mem_row merged = Rows__merge(lhs_row, rhs_row);
|
||||
rv.Add(merged);
|
||||
}
|
||||
@@ -161,14 +161,14 @@ class Mem_exec_ {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static byte[] Rows__bld_key(Bry_bfr bfr, boolean join_is_src, String trg_tbl, Mem_row row, Sql_join_fld[] join_flds, int join_flds_len) {
|
||||
private static byte[] Rows__bld_key(BryWtr bfr, boolean join_is_src, String trg_tbl, Mem_row row, Sql_join_fld[] join_flds, int join_flds_len) {
|
||||
for (int i = 0; i < join_flds_len; ++i) {
|
||||
if (i != 0) bfr.Add_byte_pipe();
|
||||
if (i != 0) bfr.AddBytePipe();
|
||||
Sql_join_fld join_fld = join_flds[i];
|
||||
Object val = row.Get_by(join_fld.To_fld_sql(join_is_src, trg_tbl));
|
||||
bfr.Add_obj(val);
|
||||
bfr.AddObj(val);
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
return bfr.ToBryAndClear();
|
||||
}
|
||||
private static Mem_row Rows__merge(Mem_row lhs, Mem_row rhs) {
|
||||
Mem_row rv = new Mem_row();
|
||||
@@ -193,7 +193,7 @@ class Mem_exec_ {
|
||||
Mem_row trg_row = new Mem_row(); rv[i] = trg_row;
|
||||
for (int j = 0; j < select_flds_len; ++j) { // loop over each fld
|
||||
Sql_select_fld fld = select_flds.Get_at(j);
|
||||
if (String_.Eq(fld.Alias, Sql_select_fld.Fld__wildcard)) { // wildcard; add all cols
|
||||
if (StringUtl.Eq(fld.Alias, Sql_select_fld.Fld__wildcard)) { // wildcard; add all cols
|
||||
for (int k = 0; k < src_row.Len(); ++k) {
|
||||
String key = src_row.Fld_at(k);
|
||||
Object val = src_row.Get_by_or_dbnull(key);
|
||||
|
||||
@@ -14,61 +14,61 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems;
|
||||
import gplx.String_;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_null;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_qry_;
|
||||
import gplx.dbs.sqls.itms.Sql_tbl_itm;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
import org.junit.Test;
|
||||
public class Mem_exec_select_tst {
|
||||
private final Mem_db_fxt__single fxt = new Mem_db_fxt__single();
|
||||
@Test public void Basic() {
|
||||
@Test public void Basic() {
|
||||
fxt.Exec__create_tbl("tbl_1", "fld_1");
|
||||
fxt.Exec__insert("tbl_1"
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_0")
|
||||
, StringUtl.Ary("a_1")
|
||||
, StringUtl.Ary("a_2")
|
||||
, StringUtl.Ary("a_0")
|
||||
);
|
||||
|
||||
// select all
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_()
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_0")
|
||||
, StringUtl.Ary("a_1")
|
||||
, StringUtl.Ary("a_2")
|
||||
, StringUtl.Ary("a_0")
|
||||
);
|
||||
|
||||
// order by
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Order_("fld_1", BoolUtl.N)
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_0")
|
||||
, StringUtl.Ary("a_2")
|
||||
, StringUtl.Ary("a_1")
|
||||
, StringUtl.Ary("a_0")
|
||||
);
|
||||
|
||||
// offset
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Offset_(1)
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_0")
|
||||
, StringUtl.Ary("a_2")
|
||||
, StringUtl.Ary("a_0")
|
||||
);
|
||||
|
||||
// limit
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Limit_(2)
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_2")
|
||||
, StringUtl.Ary("a_1")
|
||||
, StringUtl.Ary("a_2")
|
||||
);
|
||||
}
|
||||
@Test public void Join__single() {
|
||||
@Test public void Join__single() {
|
||||
fxt.Exec__create_tbl("tbl_1", "fld_a", "fld_1a");
|
||||
fxt.Exec__create_tbl("tbl_2", "fld_a", "fld_2a");
|
||||
fxt.Exec__insert("tbl_1"
|
||||
, String_.Ary("a_0", "1a_0")
|
||||
, String_.Ary("a_1", "1a_1")
|
||||
, String_.Ary("a_2", "1a_2")
|
||||
, StringUtl.Ary("a_0", "1a_0")
|
||||
, StringUtl.Ary("a_1", "1a_1")
|
||||
, StringUtl.Ary("a_2", "1a_2")
|
||||
);
|
||||
fxt.Exec__insert("tbl_2"
|
||||
, String_.Ary("a_0", "2a_0")
|
||||
, String_.Ary("a_2", "2a_2")
|
||||
, StringUtl.Ary("a_0", "2a_0")
|
||||
, StringUtl.Ary("a_2", "2a_2")
|
||||
);
|
||||
|
||||
// inner join
|
||||
@@ -76,8 +76,8 @@ public class Mem_exec_select_tst {
|
||||
.Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a")
|
||||
.From_("tbl_1", "t1")
|
||||
. Join_("tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a"))
|
||||
, String_.Ary("a_0", "1a_0", "2a_0")
|
||||
, String_.Ary("a_2", "1a_2", "2a_2")
|
||||
, StringUtl.Ary("a_0", "1a_0", "2a_0")
|
||||
, StringUtl.Ary("a_2", "1a_2", "2a_2")
|
||||
);
|
||||
|
||||
// left join
|
||||
@@ -85,21 +85,21 @@ public class Mem_exec_select_tst {
|
||||
.Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a")
|
||||
.From_("tbl_1", "t1")
|
||||
. Join_(Sql_tbl_itm.Tid__left, Sql_tbl_itm.Db__null, "tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a"))
|
||||
, String_.Ary("a_0", "1a_0", "2a_0")
|
||||
, String_.Ary("a_1", "1a_1", Db_null.Null_str)
|
||||
, String_.Ary("a_2", "1a_2", "2a_2")
|
||||
, StringUtl.Ary("a_0", "1a_0", "2a_0")
|
||||
, StringUtl.Ary("a_1", "1a_1", Db_null.Null_str)
|
||||
, StringUtl.Ary("a_2", "1a_2", "2a_2")
|
||||
);
|
||||
}
|
||||
@Test public void Join__many() {
|
||||
@Test public void Join__many() {
|
||||
fxt.Exec__create_tbl("tbl_1", "fld_a", "fld_1a");
|
||||
fxt.Exec__create_tbl("tbl_2", "fld_a", "fld_2a");
|
||||
fxt.Exec__insert("tbl_1"
|
||||
, String_.Ary("a_0", "1a_0")
|
||||
, String_.Ary("a_1", "1a_1")
|
||||
, StringUtl.Ary("a_0", "1a_0")
|
||||
, StringUtl.Ary("a_1", "1a_1")
|
||||
);
|
||||
fxt.Exec__insert("tbl_2"
|
||||
, String_.Ary("a_0", "2a_0")
|
||||
, String_.Ary("a_0", "2a_1")
|
||||
, StringUtl.Ary("a_0", "2a_0")
|
||||
, StringUtl.Ary("a_0", "2a_1")
|
||||
);
|
||||
|
||||
// inner join
|
||||
@@ -107,8 +107,8 @@ public class Mem_exec_select_tst {
|
||||
.Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a")
|
||||
.From_("tbl_1", "t1")
|
||||
. Join_("tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a"))
|
||||
, String_.Ary("a_0", "1a_0", "2a_0")
|
||||
, String_.Ary("a_0", "1a_0", "2a_1")
|
||||
, StringUtl.Ary("a_0", "1a_0", "2a_0")
|
||||
, StringUtl.Ary("a_0", "1a_0", "2a_1")
|
||||
);
|
||||
|
||||
// left join
|
||||
@@ -116,9 +116,9 @@ public class Mem_exec_select_tst {
|
||||
.Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a")
|
||||
.From_("tbl_1", "t1")
|
||||
. Join_(Sql_tbl_itm.Tid__left, Sql_tbl_itm.Db__null, "tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a"))
|
||||
, String_.Ary("a_0", "1a_0", "2a_0")
|
||||
, String_.Ary("a_0", "1a_0", "2a_1")
|
||||
, String_.Ary("a_1", "1a_1", Db_null.Null_str)
|
||||
, StringUtl.Ary("a_0", "1a_0", "2a_0")
|
||||
, StringUtl.Ary("a_0", "1a_0", "2a_1")
|
||||
, StringUtl.Ary("a_1", "1a_1", Db_null.Null_str)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*;
|
||||
package gplx.dbs.engines.mems;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
public class Mem_qry_set {
|
||||
private final List_adp rows = List_adp_.New();
|
||||
public int Len() {return rows.Len();}
|
||||
public Mem_row Get_at(int i) {return (Mem_row)rows.Get_at(i);}
|
||||
public Mem_row Get_at(int i) {return (Mem_row)rows.GetAt(i);}
|
||||
public void Add(Mem_row row) {rows.Add(row);}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,17 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.mems; import gplx.dbs.Db_rdr;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.types.basics.utls.BryUtl;
|
||||
import gplx.types.basics.utls.ByteUtl;
|
||||
import gplx.types.basics.utls.DoubleUtl;
|
||||
import gplx.types.basics.utls.FloatUtl;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.basics.utls.LongUtl;
|
||||
import gplx.types.commons.GfoDate;
|
||||
import gplx.types.commons.GfoDateUtl;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class Mem_rdr implements Db_rdr {
|
||||
private final Mem_row[] rows; private int row_idx = -1; private final int rows_len;
|
||||
private Mem_row row;
|
||||
@@ -28,15 +38,15 @@ public class Mem_rdr implements Db_rdr {
|
||||
}
|
||||
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
|
||||
public void Save_bry_in_parts(Io_url url, String tbl, String fld, String crt_key, Object crt_val) {throw Err_.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 byte[] Read_bry_by_str(String k) {return BryUtl.NewU8Safe((String)row.Get_by(k));} // NOTE: null b/c db can have NULL
|
||||
public void Save_bry_in_parts(Io_url url, String tbl, String fld, String crt_key, Object crt_val) {throw ErrUtl.NewUnimplemented();}
|
||||
public GfoDate Read_date_by_str(String k) {return GfoDateUtl.ParseIso8561((String)row.Get_by(k));}
|
||||
public byte Read_byte(String k) {return ByteUtl.Cast(row.Get_by(k));}
|
||||
public int Read_int(String k) {return IntUtl.Cast(row.Get_by(k));}
|
||||
public long Read_long(String k) {return LongUtl.Cast(row.Get_by(k));}
|
||||
public float Read_float(String k) {return FloatUtl.Cast(row.Get_by(k));}
|
||||
public double Read_double(String k) {return DoubleUtl.Cast(row.Get_by(k));}
|
||||
public boolean Read_bool_by_byte(String k) {return ByteUtl.Cast(row.Get_by(k)) == 1;}
|
||||
public int Fld_len() {return row.Len();}
|
||||
public Object Read_obj(String k) {return row.Get_by(k);}
|
||||
public Object Read_at(int i) {return row.Get_at(i);}
|
||||
|
||||
@@ -13,13 +13,19 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.engines.mems; import gplx.dbs.*;
|
||||
import gplx.frameworks.invks.GfoMsg;
|
||||
import gplx.frameworks.invks.Gfo_invk;
|
||||
import gplx.frameworks.invks.Gfo_invk_;
|
||||
import gplx.frameworks.invks.GfsCtx;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
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);}
|
||||
public String Fld_at(int i) {return (String)flds.GetAt(i);}
|
||||
public Object Get_at(int i) {return hash.GetAt(i);}
|
||||
public Object Get_by(String key) {return hash.GetByOrNull(key);}
|
||||
public Object Get_by_or_dbnull(String key) {
|
||||
Object rv = hash.GetByOrNull(key);
|
||||
|
||||
@@ -14,21 +14,20 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.DateAdp;
|
||||
import gplx.Decimal_adp;
|
||||
import gplx.Err_;
|
||||
import gplx.Ordered_hash;
|
||||
import gplx.Ordered_hash_;
|
||||
import gplx.String_;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
import gplx.core.stores.DataRdr;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.engines.Db_engine;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.commons.GfoDate;
|
||||
import gplx.types.commons.GfoDecimal;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
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();
|
||||
@@ -36,7 +35,7 @@ public class Mem_stmt implements Db_stmt {
|
||||
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 int Args_len() {return val_list.Len();}
|
||||
public Object Args_get_at(int i) {return val_list.Get_at(i);}
|
||||
public Object Args_get_at(int i) {return val_list.GetAt(i);}
|
||||
public Object Args_get_by(String k) {return val_list.GetByOrNull(k);}
|
||||
public Db_qry Qry() {return qry;} private Db_qry qry;
|
||||
public Db_stmt Reset_stmt() {return this;}
|
||||
@@ -54,7 +53,7 @@ public class Mem_stmt implements Db_stmt {
|
||||
public Db_stmt Val_byte(String k, byte v) {return Add_byte(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_byte(byte v) {return Add_byte(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_byte(boolean where, String k, byte v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to add value", "type", "byte", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_int(String k, int v) {return Add_int(BoolUtl.Y, k, v);}
|
||||
@@ -62,78 +61,78 @@ public class Mem_stmt implements Db_stmt {
|
||||
public Db_stmt Val_int(String k, int v) {return Add_int(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_int(int v) {return Add_int(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_int(boolean where, String k, int v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "int", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to add value", "type", "int", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_long(String k, long v) {return Add_long(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_long(String k, long v) {return Add_long(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_long(long v) {return Add_long(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_long(boolean where, String k, long v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "long", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to add value", "type", "long", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_float(String k, float v) {return Add_float(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_float(String k, float v) {return Add_float(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_float(float v) {return Add_float(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_float(boolean where, String k, float v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "float", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to add value", "type", "float", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_double(String k, double v) {return Add_double(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_double(String k, double v) {return Add_double(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_double(double v) {return Add_double(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_double(boolean where, String k, double v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to add value", "type", "double", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_decimal(String k, Decimal_adp v) {return Add_decimal(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_decimal(String k, Decimal_adp v) {return Add_decimal(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_decimal(Decimal_adp v) {return Add_decimal(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_decimal(boolean where, String k, Decimal_adp v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
|
||||
public Db_stmt Crt_decimal(String k, GfoDecimal v) {return Add_decimal(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_decimal(String k, GfoDecimal v) {return Add_decimal(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_decimal(GfoDecimal v) {return Add_decimal(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_decimal(boolean where, String k, GfoDecimal v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to add value", "type", "decimal", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_bry(String k, byte[] v) {return Add_bry(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_bry(byte[] v) {return Add_bry(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_bry(boolean where, String k, byte[] v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "byte[]", "val", v.length);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw ErrUtl.NewArgs(e, "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(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_bry_as_str(String k, byte[] v) {return Add_bry_as_str(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_bry_as_str(byte[] v) {return Add_bry_as_str(BoolUtl.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));}
|
||||
private Db_stmt Add_bry_as_str(boolean where, String k, byte[] v) {return Add_str(where, k, StringUtl.NewU8(v));}
|
||||
public Db_stmt Crt_str(String k, String v) {return Add_str(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_str(String k, String v) {return Add_str(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_str(String v) {return Add_str(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_str(boolean where, String k, String v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "String", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to add value", "type", "String", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_date(String k, DateAdp v) {return Add_date(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_date(String k, DateAdp v) {return Add_date(BoolUtl.N, k, v);}
|
||||
private Db_stmt Add_date(boolean where, String k, DateAdp v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "date", "val", v);}
|
||||
public Db_stmt Crt_date(String k, GfoDate v) {return Add_date(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_date(String k, GfoDate v) {return Add_date(BoolUtl.N, k, v);}
|
||||
private Db_stmt Add_date(boolean where, String k, GfoDate v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to add value", "type", "date", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_text(String k, String v) {return Add_text(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_text(String k, String v) {return Add_text(BoolUtl.N, k, v);}
|
||||
private Db_stmt Add_text(boolean where, String k, String v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "text", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to add value", "type", "text", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_rdr_(gplx.core.ios.streams.Io_stream_rdr v, long rdr_len) {
|
||||
try {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
BryWtr bfr = BryWtr.New();
|
||||
gplx.core.ios.streams.Io_stream_rdr_.Load_all_to_bfr(bfr, v);
|
||||
Add("", BoolUtl.N, bfr.To_str_and_clear());
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
|
||||
Add("", BoolUtl.N, bfr.ToStrAndClear());
|
||||
} catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to add value", "type", "rdr", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public boolean Exec_insert() {
|
||||
Mem_tbl tbl = engine.Tbls__get(qry.BaseTable());
|
||||
if (tbl == null) throw Err_.new_wo_type("must call Create_tbl", "tbl", qry.BaseTable());
|
||||
if (tbl == null) throw ErrUtl.NewArgs("must call Create_tbl", "tbl", qry.BaseTable());
|
||||
return tbl.Insert(this) == 1;
|
||||
}
|
||||
public int Exec_update() {
|
||||
@@ -144,14 +143,14 @@ public class Mem_stmt implements Db_stmt {
|
||||
Mem_tbl tbl = engine.Tbls__get(qry.BaseTable());
|
||||
return tbl.Delete(this);
|
||||
}
|
||||
public DataRdr Exec_select() {throw Err_.new_unimplemented();}
|
||||
public DataRdr Exec_select() {throw ErrUtl.NewUnimplemented();}
|
||||
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);
|
||||
return engine.Qry_runner().Select(this);
|
||||
}
|
||||
public Object Exec_select_val() {throw Err_.new_unimplemented();}
|
||||
public Object Exec_select_val() {throw ErrUtl.NewUnimplemented();}
|
||||
private void Add(String k, boolean where, Object v) {
|
||||
if (k == DbmetaFldItm.KeyNull) return; // key is explicitly null; ignore; allows schema_2+ type definitions
|
||||
val_list.AddIfDupeUse1st(k, v); // NOTE: only add if new; WHERE with IN will call Add many times; fld_ttl IN ('A.png', 'B.png');
|
||||
|
||||
@@ -13,16 +13,27 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*;
|
||||
import gplx.core.criterias.*;
|
||||
package gplx.dbs.engines.mems;
|
||||
import gplx.core.criterias.Criteria;
|
||||
import gplx.core.criterias.Criteria_;
|
||||
import gplx.core.criterias.Criteria_between;
|
||||
import gplx.core.criterias.Criteria_bool_base;
|
||||
import gplx.core.criterias.Criteria_fld;
|
||||
import gplx.core.criterias.Criteria_in;
|
||||
import gplx.core.criterias.Criteria_not;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class Mem_stmt_args {
|
||||
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));}
|
||||
public Keyval Get_next() {
|
||||
public void Add(String k, Object v) {list.Add(KeyVal.NewStr(k, v));}
|
||||
public KeyVal Get_next() {
|
||||
int idx = ++cur_idx;
|
||||
return idx == list.Len() ? null: (Keyval)list.Get_at(idx);
|
||||
return idx == list.Len() ? null: (KeyVal)list.GetAt(idx);
|
||||
}
|
||||
}
|
||||
class Mem_stmt_args_ {
|
||||
@@ -37,8 +48,8 @@ class Mem_stmt_args_ {
|
||||
case Criteria_.Tid_comp:
|
||||
case Criteria_.Tid_like:
|
||||
case Criteria_.Tid_iomatch:
|
||||
Keyval kvp = args.Get_next();
|
||||
if (!String_.Eq(kvp.Key(), fld.Key())) throw Err_.new_("db", "fld_crt.key mismatch", "fld.key", fld_key, "kvp.key", kvp.Key());
|
||||
KeyVal kvp = args.Get_next();
|
||||
if (!StringUtl.Eq(kvp.KeyToStr(), fld.Key())) throw ErrUtl.NewArgs("fld_crt.key mismatch", "fld.key", fld_key, "kvp.key", kvp.KeyToStr());
|
||||
sub.Val_as_obj_(kvp.Val());
|
||||
break;
|
||||
case Criteria_.Tid_in:
|
||||
@@ -52,7 +63,7 @@ class Mem_stmt_args_ {
|
||||
crt_between.Lo_((Comparable)(args.Get_next()).Val());
|
||||
crt_between.Hi_((Comparable)(args.Get_next()).Val());
|
||||
break;
|
||||
default: throw Err_.new_unhandled(sub.Tid());
|
||||
default: throw ErrUtl.NewUnhandled(sub.Tid());
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -68,7 +79,7 @@ class Mem_stmt_args_ {
|
||||
Criteria_not crt_not = (Criteria_not)crt;
|
||||
Fill(args, crt_not.Crt());
|
||||
break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
default: throw ErrUtl.NewUnhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.criterias.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.itms.*;
|
||||
package gplx.dbs.engines.mems; import gplx.dbs.*;
|
||||
import gplx.core.criterias.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.itms.*;
|
||||
import gplx.dbs.metas.*;
|
||||
import gplx.types.basics.lists.Hash_adp;
|
||||
import gplx.types.basics.lists.Hash_adp_;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.basics.wrappers.IntRef;
|
||||
public class Mem_tbl {
|
||||
private final List_adp where_rows = List_adp_.New();
|
||||
private final Hash_adp autonum_hash = Hash_adp_.New();
|
||||
@@ -37,12 +42,12 @@ public class Mem_tbl {
|
||||
return 1;
|
||||
}
|
||||
private int Autonum_calc(String name) {
|
||||
Int_obj_ref autonum_itm = (Int_obj_ref)autonum_hash.GetByOrNull(name);
|
||||
IntRef autonum_itm = (IntRef)autonum_hash.GetByOrNull(name);
|
||||
if (autonum_itm == null) {
|
||||
autonum_itm = Int_obj_ref.New(0);
|
||||
autonum_itm = IntRef.New(0);
|
||||
autonum_hash.Add(name, autonum_itm);
|
||||
}
|
||||
return autonum_itm.Val_add();
|
||||
return autonum_itm.ValAddOne();
|
||||
}
|
||||
public int Update(Mem_stmt stmt) {
|
||||
Db_qry_update qry = (Db_qry_update)stmt.Qry();
|
||||
@@ -52,7 +57,7 @@ public class Mem_tbl {
|
||||
int where_rows_len = where_rows.Len();
|
||||
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);
|
||||
Mem_row itm = (Mem_row)where_rows.GetAt(i);
|
||||
for (int j = 0; j < update_cols_len; ++j)
|
||||
itm.Set_by(update_cols[j], stmt.Args_get_at(j));
|
||||
}
|
||||
@@ -64,7 +69,7 @@ public class Mem_tbl {
|
||||
Select_rows_where(where_rows, stmt, qry.Where());
|
||||
int where_rows_len = where_rows.Len();
|
||||
for (int i = 0; i < where_rows_len; ++i) {
|
||||
Mem_row itm = (Mem_row)where_rows.Get_at(i);
|
||||
Mem_row itm = (Mem_row)where_rows.GetAt(i);
|
||||
rows.Del(itm);
|
||||
}
|
||||
return where_rows_len;
|
||||
@@ -96,7 +101,7 @@ public class Mem_tbl {
|
||||
rv.Clear();
|
||||
int rows_len = rows.Len();
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
Mem_row itm = (Mem_row)rows.Get_at(i);
|
||||
Mem_row itm = (Mem_row)rows.GetAt(i);
|
||||
if (crt.Matches(itm))
|
||||
rv.Add(itm);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mysql; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mysql; import gplx.dbs.*;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.types.commons.KeyValHash;
|
||||
public class Mysql_conn_info extends Db_conn_info__base {
|
||||
public Mysql_conn_info(String raw, String db_api, String database, String server, String uid, String pwd) {super(raw, db_api, database);
|
||||
this.server = server;
|
||||
@@ -34,10 +36,10 @@ public class Mysql_conn_info extends Db_conn_info__base {
|
||||
, "charset", "utf8"
|
||||
));
|
||||
}
|
||||
@Override public Db_conn_info New_self(String raw, Keyval_hash hash) {
|
||||
@Override public Db_conn_info New_self(String raw, KeyValHash hash) {
|
||||
return new Mysql_conn_info
|
||||
( raw, Bld_api(hash, Keyval_.new_("charset", "utf8")), hash.Get_val_as_str_or_fail("database")
|
||||
, hash.Get_val_as_str_or_fail("server"), hash.Get_val_as_str_or_fail("uid"), hash.Get_val_as_str_or_fail("pwd"));
|
||||
( raw, Bld_api(hash, KeyVal.NewStr("charset", "utf8")), hash.GetByValAsStrOrFail("database")
|
||||
, hash.GetByValAsStrOrFail("server"), hash.GetByValAsStrOrFail("uid"), hash.GetByValAsStrOrFail("pwd"));
|
||||
}
|
||||
public static final Mysql_conn_info Instance = new Mysql_conn_info("", "", "", "", "", "");
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mysql;
|
||||
import gplx.Err_;
|
||||
import gplx.core.stores.DataRdr;
|
||||
import gplx.core.stores.Db_data_rdr;
|
||||
import gplx.dbs.Db_conn_info;
|
||||
@@ -24,7 +23,7 @@ import gplx.dbs.metas.Dbmeta_tbl_mgr;
|
||||
import gplx.dbs.sqls.SqlQryWtr;
|
||||
import gplx.dbs.sqls.SqlQryWtrUtl;
|
||||
import gplx.dbs.wkrs.SqlWkrMgr;
|
||||
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
public class Mysql_engine extends Db_engine_sql_base {
|
||||
@@ -39,8 +38,8 @@ public class Mysql_engine extends Db_engine_sql_base {
|
||||
return rv;
|
||||
}
|
||||
@Override public DataRdr New_rdr(ResultSet rdr, String commandText) {return Mysql_rdr.new_(rdr, commandText);}
|
||||
@Override public Dbmeta_tbl_mgr Meta_mgr() {throw Err_.new_unimplemented();}
|
||||
@gplx.Internal @Override protected Connection Conn_make() {
|
||||
@Override public Dbmeta_tbl_mgr Meta_mgr() {throw ErrUtl.NewUnimplemented();}
|
||||
@Override public Connection Conn_make() {
|
||||
Mysql_conn_info conn_info_as_mysql = (Mysql_conn_info)conn_info;
|
||||
Connection rv = Conn_make_by_url("jdbc:mysql://localhost/" + conn_info_as_mysql.Database() + "?characterEncoding=UTF8&useSSL=false", conn_info_as_mysql.Uid(), conn_info_as_mysql.Pwd());
|
||||
return rv;
|
||||
|
||||
@@ -13,10 +13,11 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.noops; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.noops; import gplx.dbs.*;
|
||||
import gplx.types.commons.KeyValHash;
|
||||
public class Noop_conn_info extends Db_conn_info__base {
|
||||
public Noop_conn_info(String raw, String db_api, String database) {super(raw, db_api, database);}
|
||||
@Override public String Key() {return Tid_const;} public static final String Tid_const = "null_db";
|
||||
@Override public Db_conn_info New_self(String raw, Keyval_hash hash) {return this;}
|
||||
@Override public Db_conn_info New_self(String raw, KeyValHash hash) {return this;}
|
||||
public static final Noop_conn_info Instance = new Noop_conn_info("gplx_key=null_db", "", "");
|
||||
}
|
||||
|
||||
@@ -13,10 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.noops; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.noops; 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.*;
|
||||
import gplx.dbs.wkrs.SqlWkrMgr;
|
||||
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class Noop_engine implements Db_engine {
|
||||
public String Tid() {return Noop_conn_info.Tid_const;}
|
||||
public Db_conn_info Conn_info() {return Db_conn_info_.Null;}
|
||||
@@ -30,7 +32,7 @@ public class Noop_engine implements Db_engine {
|
||||
public Db_rdr Exec_as_rdr__rls_manual (Object rdr_obj, String sql) {return Db_rdr_.Empty;}
|
||||
public Db_rdr Exec_as_rdr__rls_auto (Db_stmt stmt, Object rdr_obj, String sql) {return Db_rdr_.Empty;}
|
||||
public Db_stmt Stmt_by_qry(Db_qry qry) {return Db_stmt_.Null;}
|
||||
public Object Stmt_by_sql(String sql) {throw Err_.new_unimplemented();}
|
||||
public Object Stmt_by_sql(String sql) {throw ErrUtl.NewUnimplemented();}
|
||||
public DataRdr New_rdr(java.sql.ResultSet rdr, String sql) {return DataRdr_.Null;}
|
||||
public void Txn_bgn(String name) {}
|
||||
public String Txn_end() {return "";}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.postgres; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.postgres; import gplx.dbs.*;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.types.commons.KeyValHash;
|
||||
public class Postgres_conn_info extends Db_conn_info__base {
|
||||
public Postgres_conn_info(String raw, String db_api, String database, String server, String uid, String pwd) {super(raw, db_api, database);
|
||||
this.server = server;
|
||||
@@ -35,10 +37,10 @@ public class Postgres_conn_info extends Db_conn_info__base {
|
||||
, "encoding", "unicode" // needed for 1.1 conn; otherwise, ascii
|
||||
));
|
||||
}
|
||||
@Override public Db_conn_info New_self(String raw, Keyval_hash hash) {
|
||||
@Override public Db_conn_info New_self(String raw, KeyValHash hash) {
|
||||
return new Postgres_conn_info
|
||||
( raw, Bld_api(hash, Keyval_.new_("encoding", "unicode")), hash.Get_val_as_str_or_fail("database")
|
||||
, hash.Get_val_as_str_or_fail("server"), hash.Get_val_as_str_or_fail("user id"), hash.Get_val_as_str_or_fail("password"));
|
||||
( raw, Bld_api(hash, KeyVal.NewStr("encoding", "unicode")), hash.GetByValAsStrOrFail("database")
|
||||
, hash.GetByValAsStrOrFail("server"), hash.GetByValAsStrOrFail("user id"), hash.GetByValAsStrOrFail("password"));
|
||||
}
|
||||
public static final Postgres_conn_info Instance = new Postgres_conn_info("", "", "", "", "", "");
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.postgres; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.postgres; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.core.stores.*;
|
||||
import gplx.dbs.sqls.*; import gplx.dbs.metas.*;
|
||||
import gplx.dbs.wkrs.SqlWkrMgr;
|
||||
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
@@ -31,8 +31,8 @@ public class Postgres_engine extends Db_engine_sql_base {
|
||||
return rv;
|
||||
}
|
||||
@Override public DataRdr New_rdr(ResultSet rdr, String commandText) {return Db_data_rdr_.new_(rdr, commandText);}
|
||||
@Override public Dbmeta_tbl_mgr Meta_mgr() {throw Err_.new_unimplemented();}
|
||||
@gplx.Internal @Override protected Connection Conn_make() {
|
||||
@Override public Dbmeta_tbl_mgr Meta_mgr() {throw ErrUtl.NewUnimplemented();}
|
||||
@Override public Connection Conn_make() {
|
||||
Postgres_conn_info conn_info_as_postgres = (Postgres_conn_info)conn_info;
|
||||
return Conn_make_by_url("jdbc:" + conn_info_as_postgres.Key() + "://localhost/" + conn_info_as_postgres.Database(), conn_info_as_postgres.Uid(), conn_info_as_postgres.Pwd());
|
||||
}
|
||||
|
||||
@@ -1,27 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.sqlite; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.sqlite; import gplx.dbs.*;
|
||||
import gplx.libs.files.Io_mgr;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.libs.files.Io_url_;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.types.commons.KeyValHash;
|
||||
public class Sqlite_conn_info extends Db_conn_info__base {
|
||||
public Sqlite_conn_info(String raw, String db_api, String database, Io_url url) {super(raw, db_api, database);this.url = url;}
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "sqlite";
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
@Override public Db_conn_info New_self(String raw, Keyval_hash hash) {
|
||||
Io_url url = Io_url_.new_any_(hash.Get_val_as_str_or_fail("data source"));
|
||||
@Override public Db_conn_info New_self(String raw, KeyValHash hash) {
|
||||
Io_url url = Io_url_.new_any_(hash.GetByValAsStrOrFail("data source"));
|
||||
String db = url.NameOnly();
|
||||
String api = Bld_api(hash, Keyval_.new_("version", "3"));
|
||||
String api = Bld_api(hash, KeyVal.NewStr("version", "3"));
|
||||
return new Sqlite_conn_info(raw, api, db, url);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,23 +13,24 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.sqlite; import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Byte_;
|
||||
import gplx.DateAdp;
|
||||
import gplx.DateAdp_;
|
||||
import gplx.Decimal_adp;
|
||||
import gplx.Decimal_adp_;
|
||||
import gplx.Err_;
|
||||
import gplx.Float_;
|
||||
import gplx.Gfo_usr_dlg_;
|
||||
import gplx.Int_;
|
||||
import gplx.Io_mgr;
|
||||
import gplx.Io_url;
|
||||
import gplx.Keyval;
|
||||
import gplx.Keyval_;
|
||||
import gplx.Long_;
|
||||
import gplx.String_;
|
||||
import gplx.Type_;
|
||||
package gplx.dbs.engines.sqlite;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
import gplx.types.basics.utls.ByteUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.basics.utls.ClassUtl;
|
||||
import gplx.types.commons.GfoDate;
|
||||
import gplx.types.commons.GfoDateUtl;
|
||||
import gplx.types.commons.GfoDecimal;
|
||||
import gplx.types.commons.GfoDecimalUtl;
|
||||
import gplx.types.basics.utls.FloatUtl;
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg_;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.libs.files.Io_mgr;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.types.commons.KeyValUtl;
|
||||
import gplx.types.basics.utls.LongUtl;
|
||||
import gplx.core.ios.IoItmFil;
|
||||
import gplx.core.stores.DataRdr;
|
||||
import gplx.core.stores.Db_data_rdr;
|
||||
@@ -72,12 +73,12 @@ public class Sqlite_engine extends Db_engine_sql_base {
|
||||
@Override public DataRdr New_rdr(ResultSet rdr, String commandText) {return Sqlite_rdr.new_(rdr, commandText);}
|
||||
@Override public Db_rdr New_rdr_clone() {return new Db_rdr__sqlite();}
|
||||
@Override public void Env_db_attach(String alias, Db_conn conn) {
|
||||
Db_conn_info cs_obj = conn.Conn_info(); if (!String_.Eq(cs_obj.Key(), Sqlite_conn_info.Key_const)) throw Err_.new_("dbs", "must attach to sqlite databases", "conn", cs_obj.Raw());
|
||||
Db_conn_info cs_obj = conn.Conn_info(); if (!StringUtl.Eq(cs_obj.Key(), Sqlite_conn_info.Key_const)) throw ErrUtl.NewArgs("must attach to sqlite databases", "conn", cs_obj.Raw());
|
||||
Sqlite_conn_info cs = (Sqlite_conn_info)cs_obj;
|
||||
Env_db_attach(alias, cs.Url());
|
||||
}
|
||||
@Override public void Env_db_attach(String alias, Io_url db_url) {Exec_as_int(String_.Format("ATTACH '{0}' AS {1};", db_url.Raw(), alias));}
|
||||
@Override public void Env_db_detach(String alias) {Exec_as_int(String_.Format("DETACH {0};", alias));}
|
||||
@Override public void Env_db_attach(String alias, Io_url db_url) {Exec_as_int(StringUtl.Format("ATTACH '{0}' AS {1};", db_url.Raw(), alias));}
|
||||
@Override public void Env_db_detach(String alias) {Exec_as_int(StringUtl.Format("DETACH {0};", alias));}
|
||||
@Override public void Txn_bgn(String name) {txn_mgr.Txn_bgn(name);}
|
||||
@Override public String Txn_end() {return txn_mgr.Txn_end();}
|
||||
@Override public void Txn_cxl() {txn_mgr.Txn_cxl();}
|
||||
@@ -88,28 +89,28 @@ public class Sqlite_engine extends Db_engine_sql_base {
|
||||
@Override public boolean Meta_idx_exists(String idx) {return schema_mgr.Idx_exists(idx);}
|
||||
@Override public Db_stmt Stmt_by_qry(Db_qry qry) {return new Sqlite_stmt(this, qry);}
|
||||
private static boolean loaded = false;
|
||||
protected void Meta_tbl_gather_hook() {throw Err_.new_unimplemented();}
|
||||
@gplx.Internal @Override protected Connection Conn_make() {
|
||||
protected void Meta_tbl_gather_hook() {throw ErrUtl.NewUnimplemented();}
|
||||
@Override public Connection Conn_make() {
|
||||
if (!loaded) {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
}
|
||||
catch (ClassNotFoundException e) {throw Err_.new_exc(e, "db", "could not load sqlite jdbc driver");}
|
||||
catch (ClassNotFoundException e) {throw ErrUtl.NewArgs(e, "could not load sqlite jdbc driver");}
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
// init vars for opening connection
|
||||
Sqlite_conn_info conn_info_as_sqlite = (Sqlite_conn_info)conn_info;
|
||||
Io_url sqlite_fs_url = conn_info_as_sqlite.Url();
|
||||
String sqlite_db_url = "jdbc:sqlite://" + String_.Replace(sqlite_fs_url.Raw(), "\\", "/");
|
||||
String sqlite_db_url = "jdbc:sqlite://" + StringUtl.Replace(sqlite_fs_url.Raw(), "\\", "/");
|
||||
|
||||
// set open_mode flag if conn is read-only; needed else all SELECT queries will be very slow; DATE:2016-09-03
|
||||
IoItmFil sqlite_fs_itm = Io_mgr.Instance.QueryFil(sqlite_fs_url);
|
||||
boolean read_only = sqlite_fs_itm.Exists() // NOTE: must check if it exists; else missing-file will be marked as readonly connection, and missing-file will sometimes be dynamically created as read-write; DATE:2016-09-04
|
||||
&& Io_mgr.Instance.Query_read_only(sqlite_fs_url, Sqlite_engine_.Read_only_detection);
|
||||
Keyval[] props = read_only
|
||||
? Keyval_.Ary(Keyval_.new_("open_mode", "1"))
|
||||
: Keyval_.Ary_empty;
|
||||
KeyVal[] props = read_only
|
||||
? KeyValUtl.Ary(KeyVal.NewStr("open_mode", "1"))
|
||||
: KeyValUtl.AryEmpty;
|
||||
if (read_only) {
|
||||
Gfo_usr_dlg_.Instance.Note_many("", "", "Sqlite db opened as read-only: url=~{0}", sqlite_fs_url.Xto_api());
|
||||
}
|
||||
@@ -120,36 +121,36 @@ public class Sqlite_engine extends Db_engine_sql_base {
|
||||
// set busyTimeout; needed else multiple processes accessing same db can cause "database is locked" error; DATE:2016-09-03
|
||||
SQLiteConnection rv_as_sqlite = (org.sqlite.SQLiteConnection)rv;
|
||||
try {rv_as_sqlite.setBusyTimeout(10000);}
|
||||
catch (SQLException e) {Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to set busy timeout; err=~{0}", Err_.Message_gplx_log(e));}
|
||||
catch (SQLException e) {Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to set busy timeout; err=~{0}", ErrUtl.ToStrLog(e));}
|
||||
return rv;
|
||||
}
|
||||
public static final Sqlite_engine Instance = new Sqlite_engine();
|
||||
}
|
||||
class Db_rdr__sqlite extends Db_rdr__basic { @Override public byte Read_byte(String k) {try {return (byte)Int_.Cast(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "k", k, "type", Byte_.Cls_val_name);}}
|
||||
class Db_rdr__sqlite extends Db_rdr__basic { @Override public byte Read_byte(String k) {try {return (byte)IntUtl.Cast(rdr.getObject(k));} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "k", k, "type", ByteUtl.ClsValName);}}
|
||||
@Override public boolean Read_bool_by_byte(String k) {
|
||||
try {
|
||||
int val = rdr.getInt(k);
|
||||
return val == 1;
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "i", k, "type", BoolUtl.ClsValName);}
|
||||
} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "i", k, "type", BoolUtl.ClsValName);}
|
||||
}
|
||||
@Override public long Read_long(String k) {
|
||||
try {
|
||||
long val = rdr.getLong(k);
|
||||
Number n = (Number)val;
|
||||
return n.longValue();
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "i", k, "type", Long_.Cls_val_name);}
|
||||
} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "i", k, "type", LongUtl.ClsValName);}
|
||||
}
|
||||
@Override public float Read_float(String k) {
|
||||
try {
|
||||
Double val = (Double)rdr.getDouble(k);
|
||||
return val == null ? Float.NaN : val.floatValue();
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed:", "i", k, "type", Float_.Cls_val_name);}
|
||||
} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed:", "i", k, "type", FloatUtl.ClsValName);}
|
||||
}
|
||||
@Override public DateAdp Read_date_by_str(String k) {
|
||||
@Override public GfoDate Read_date_by_str(String k) {
|
||||
try {
|
||||
String val = rdr.getString(k);
|
||||
return val == null ? null : DateAdp_.parse_fmt(val, "yyyyMMdd_HHmmss");
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "i", k, "type", DateAdp_.Cls_ref_type);}
|
||||
return val == null ? null : GfoDateUtl.ParseFmt(val, "yyyyMMdd_HHmmss");
|
||||
} catch (Exception e) {throw ErrUtl.NewArgs(e, "read failed", "i", k, "type", GfoDateUtl.ClsRefType);}
|
||||
}
|
||||
// @Override public DecimalAdp ReadDecimalOr(String key, DecimalAdp or) {
|
||||
// Object val = Read(key);
|
||||
@@ -163,43 +164,43 @@ class Sqlite_rdr extends Db_data_rdr { @Override public float ReadFloat(String
|
||||
Double d = ((Double)val);
|
||||
return val == null ? or : d.floatValue();
|
||||
}
|
||||
@Override public Decimal_adp ReadDecimal(String key) {return ReadDecimalOr(key, null);}
|
||||
@Override public Decimal_adp ReadDecimalOr(String key, Decimal_adp or) {
|
||||
@Override public GfoDecimal ReadDecimal(String key) {return ReadDecimalOr(key, null);}
|
||||
@Override public GfoDecimal ReadDecimalOr(String key, GfoDecimal or) {
|
||||
Object val = Read(key);
|
||||
if (val == null) return or;
|
||||
if (Type_.Eq_by_obj(val, Double.class)) {
|
||||
return Decimal_adp_.double_((Double)val);
|
||||
if (ClassUtl.EqByObj(Double.class, val)) {
|
||||
return GfoDecimalUtl.NewByDouble((Double)val);
|
||||
}
|
||||
else if (Type_.Eq_by_obj(val, Integer.class)) { // 2021-09-16|needed for gfds
|
||||
return Decimal_adp_.int_((Integer)val);
|
||||
else if (ClassUtl.EqByObj(Integer.class, val)) { // 2021-09-16|needed for gfds
|
||||
return GfoDecimalUtl.NewByInt((Integer)val);
|
||||
}
|
||||
else {
|
||||
throw Err_.New("sqlite decimal must be either double or int; val={0}", val);
|
||||
throw ErrUtl.NewFmt("sqlite decimal must be either double or int; val={0}", val);
|
||||
}
|
||||
}
|
||||
@Override public DateAdp ReadDate(String key) {return ReadDateOr(key, null);}
|
||||
@Override public DateAdp ReadDateOr(String key, DateAdp or) {
|
||||
@Override public GfoDate ReadDate(String key) {return ReadDateOr(key, null);}
|
||||
@Override public GfoDate ReadDateOr(String key, GfoDate or) {
|
||||
Object val = Read(key);
|
||||
if (val == null) return or;
|
||||
String valStr = (String)val;
|
||||
try {
|
||||
return DateAdp_.parse_fmt(valStr, "M/dd/yyyy hh:mm tt");
|
||||
return GfoDateUtl.ParseFmt(valStr, "M/dd/yyyy hh:mm tt");
|
||||
}
|
||||
catch (Exception exc) { // 2021-09-16|needed for gfds
|
||||
return DateAdp_.parse_fmt(valStr, "yyyy-MM-dd hh:mm:ss");
|
||||
return GfoDateUtl.ParseFmt(valStr, "yyyy-MM-dd hh:mm:ss");
|
||||
}
|
||||
}
|
||||
@Override public boolean ReadBool(String key) {return ReadBoolOr(key, false);}
|
||||
@Override public boolean ReadBoolOr(String key, boolean or) {
|
||||
Object val = Read(key);
|
||||
return val == null ? or : Int_.Cast(val) == 1;
|
||||
return val == null ? or : IntUtl.Cast(val) == 1;
|
||||
}
|
||||
@Override public byte ReadByte(String key) {return ReadByteOr(key, Byte_.Zero);}
|
||||
@Override public byte ReadByte(String key) {return ReadByteOr(key, ByteUtl.Zero);}
|
||||
@Override public byte ReadByteOr(String key, byte or) {
|
||||
Object val = Read(key);
|
||||
return val == null ? or : (byte)Int_.Cast(val);
|
||||
return val == null ? or : (byte)IntUtl.Cast(val);
|
||||
}
|
||||
@Override public long ReadLong(String key) {return ReadLongOr(key, Long_.Min_value);}
|
||||
@Override public long ReadLong(String key) {return ReadLongOr(key, LongUtl.MinValue);}
|
||||
@Override public long ReadLongOr(String key, long or) {
|
||||
Object val = Read(key);
|
||||
if (val == null) return or;
|
||||
@@ -213,8 +214,8 @@ class Sqlite_rdr extends Db_data_rdr { @Override public float ReadFloat(String
|
||||
} Sqlite_rdr() {}
|
||||
}
|
||||
class Sqlite_stmt extends gplx.dbs.qrys.Db_stmt_cmd { public Sqlite_stmt(Db_engine engine, Db_qry qry) {super(engine, qry);}
|
||||
@Override protected Db_stmt Add_date(boolean where, String k, DateAdp v) {
|
||||
@Override protected Db_stmt Add_date(boolean where, String k, GfoDate v) {
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
return super.Add_str(where, k, v.XtoStr_fmt_iso_8561());
|
||||
return super.Add_str(where, k, v.ToStrFmtIso8561());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,17 +13,22 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.sqlite; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.engines.sqlite; import gplx.dbs.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg;
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg_;
|
||||
import gplx.libs.files.Io_mgr;
|
||||
import gplx.types.basics.constants.AsciiByte;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.commons.GfoDate;
|
||||
public class Sqlite_engine_ {
|
||||
public static void Db_attach(Db_conn p, String alias, String url) {
|
||||
String s = String_.Format("ATTACH '{0}' AS {1};", url, alias);
|
||||
String s = StringUtl.Format("ATTACH '{0}' AS {1};", url, alias);
|
||||
Db_qry qry = Db_qry_sql.xtn_(s);
|
||||
p.Exec_qry(qry);
|
||||
}
|
||||
public static void Db_detach(Db_conn p, String alias) {
|
||||
String s = String_.Format("DETACH '{0}';", alias);
|
||||
String s = StringUtl.Format("DETACH '{0}';", alias);
|
||||
Db_qry qry = Db_qry_sql.xtn_(s);
|
||||
p.Exec_qry(qry);
|
||||
}
|
||||
@@ -46,7 +51,7 @@ public class Sqlite_engine_ {
|
||||
p.Exec_qry(qry);
|
||||
}
|
||||
public static void Tbl_rename(Db_conn p, String src, String trg) {
|
||||
Db_qry qry = Db_qry_sql.ddl_(String_.Format("ALTER TABLE {0} RENAME TO {1};", src, trg));
|
||||
Db_qry qry = Db_qry_sql.ddl_(StringUtl.Format("ALTER TABLE {0} RENAME TO {1};", src, trg));
|
||||
p.Exec_qry(qry);
|
||||
}
|
||||
public static void Idx_create(Gfo_usr_dlg usr_dlg, Db_conn conn, String tbl, Dbmeta_idx_itm[] idx_ary) {
|
||||
@@ -72,8 +77,8 @@ public class Sqlite_engine_ {
|
||||
public static final int Stmt_arg_max = 999; // 999 is max number of variables allowed by sqlite
|
||||
public static final boolean Supports_read_binary_stream = false;
|
||||
public static final boolean Supports_indexed_by = true;
|
||||
public static String X_date_to_str(DateAdp v) {return v == Date_null ? "" : v.XtoStr_fmt_iso_8561();}
|
||||
public static final DateAdp Date_null = null;
|
||||
public static String X_date_to_str(GfoDate v) {return v == Date_null ? "" : v.ToStrFmtIso8561();}
|
||||
public static final GfoDate Date_null = null;
|
||||
public static final byte Wildcard_byte = AsciiByte.Hash;
|
||||
public static final String Wildcard_str = "%";
|
||||
public static int Read_only_detection = Io_mgr.Read_only__basic__file;
|
||||
|
||||
@@ -14,17 +14,17 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.sqlite;
|
||||
import gplx.Int_;
|
||||
import gplx.String_;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_qry_;
|
||||
import gplx.dbs.sqls.SqlQryWtr;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
public class Sqlite_pragma implements Db_qry {
|
||||
private final String sql;
|
||||
public Sqlite_pragma(boolean parens, String key, String val) {
|
||||
String fmt = parens ? "PRAGMA {0}({1});" : "PRAGMA {0} = {1};";
|
||||
this.sql = String_.Format(fmt, key, val);
|
||||
this.sql = StringUtl.Format(fmt, key, val);
|
||||
}
|
||||
public int Tid() {return Db_qry_.Tid_pragma;}
|
||||
public boolean ReturnsRdr() {return false;}
|
||||
@@ -42,12 +42,12 @@ public class Sqlite_pragma implements Db_qry {
|
||||
public static Sqlite_pragma New__synchronous__normal() {return new Sqlite_pragma(BoolUtl.N, "synchronous" , "normal");} // default if WAL
|
||||
public static Sqlite_pragma New__synchronous__full() {return new Sqlite_pragma(BoolUtl.N, "synchronous" , "full");} // default otherwise
|
||||
public static Sqlite_pragma New__synchronous__extra() {return new Sqlite_pragma(BoolUtl.N, "synchronous" , "extra");}
|
||||
public static Sqlite_pragma New__wal_autocheckpoint(int v) {return new Sqlite_pragma(BoolUtl.N, "wal_auto_checkpoint", Int_.To_str(v));} // default is 1000
|
||||
public static Sqlite_pragma New__wal_autocheckpoint(int v) {return new Sqlite_pragma(BoolUtl.N, "wal_auto_checkpoint", IntUtl.ToStr(v));} // default is 1000
|
||||
public static Sqlite_pragma New__wal_checkpoint__passive() {return new Sqlite_pragma(BoolUtl.Y, "wal_checkpoint" , "passive");}
|
||||
public static Sqlite_pragma New__wal_checkpoint__full() {return new Sqlite_pragma(BoolUtl.Y, "wal_checkpoint" , "full");}
|
||||
public static Sqlite_pragma New__wal_checkpoint__restart() {return new Sqlite_pragma(BoolUtl.Y, "wal_checkpoint" , "restart");}
|
||||
public static Sqlite_pragma New__wal_checkpoint__truncate() {return new Sqlite_pragma(BoolUtl.Y, "wal_checkpoint" , "truncate");}
|
||||
public static Sqlite_pragma New__locking_mode__normal() {return new Sqlite_pragma(BoolUtl.N, "locking_mode" , "normal");} // default
|
||||
public static Sqlite_pragma New__locking_mode__exclusive() {return new Sqlite_pragma(BoolUtl.N, "locking_mode" , "exclusive");}
|
||||
public static Sqlite_pragma New__page_size(int v) {return new Sqlite_pragma(BoolUtl.N, "page_size" , Int_.To_str(v));} // default is 1024
|
||||
public static Sqlite_pragma New__page_size(int v) {return new Sqlite_pragma(BoolUtl.N, "page_size" , IntUtl.ToStr(v));} // default is 1024
|
||||
}
|
||||
|
||||
@@ -13,9 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.sqlite; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.sqlite; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
import gplx.dbs.metas.*; import gplx.dbs.metas.parsers.*;
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg_;
|
||||
import gplx.types.basics.utls.BryUtl;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public class Sqlite_schema_mgr implements Dbmeta_reload_cmd {
|
||||
private final Db_engine engine; private boolean init = true;
|
||||
private final Dbmeta_idx_mgr idx_mgr = new Dbmeta_idx_mgr();
|
||||
@@ -48,7 +52,7 @@ public class Sqlite_schema_mgr implements Dbmeta_reload_cmd {
|
||||
tbl_mgr.Clear(); idx_mgr.Clear();
|
||||
Dbmeta_parser__tbl tbl_parser = new Dbmeta_parser__tbl();
|
||||
Dbmeta_parser__idx idx_parser = new Dbmeta_parser__idx();
|
||||
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.new_("sqlite_master", String_.Ary_empty, String_.Ary("type", "name", "sql"), Db_qry__select_in_tbl.Order_by_null);
|
||||
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.new_("sqlite_master", StringUtl.AryEmpty, StringUtl.Ary("type", "name", "sql"), Db_qry__select_in_tbl.Order_by_null);
|
||||
Db_rdr rdr = engine.Stmt_by_qry(qry).Exec_select__rls_auto();
|
||||
try {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.schema.load.bgn: conn=~{0}", engine.Conn_info().Db_api());
|
||||
@@ -60,19 +64,19 @@ public class Sqlite_schema_mgr implements Dbmeta_reload_cmd {
|
||||
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)));
|
||||
if (StringUtl.HasAtBgn(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(BryUtl.NewU8(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)));
|
||||
idx_mgr.Add(idx_parser.Parse(BryUtl.NewU8(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));
|
||||
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, ErrUtl.ToStrLog(e));
|
||||
}
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
|
||||
@@ -14,19 +14,19 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.sqlite;
|
||||
import gplx.Gfo_usr_dlg_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.String_;
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg_;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.dbs.engines.Db_engine;
|
||||
import gplx.dbs.qrys.Db_qry_sql;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
public class Sqlite_txn_mgr {
|
||||
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 = BoolUtl.Y, txn_started = BoolUtl.N; // NOTE: txns only support 1 level; SQLite fails when nesting transactions; DATE:2015-03-11
|
||||
public void Txn_bgn(String name) {
|
||||
if (String_.Len_eq_0(name)) name = "unnamed";
|
||||
if (StringUtl.IsNullOrEmpty(name)) name = "unnamed";
|
||||
if (pragma_needed) {
|
||||
pragma_needed = false;
|
||||
engine.Exec_as_obj(Db_qry_sql.xtn_("PRAGMA synchronous = OFF;"));
|
||||
@@ -38,7 +38,7 @@ public class Sqlite_txn_mgr {
|
||||
// Execute(Db_qry_sql.xtn_("PRAGMA locking_mode = EXCLUSIVE;"));
|
||||
// Execute(Db_qry_sql.xtn_("PRAGMA cache_size=4000;")); // too many will also cause out of memory
|
||||
if (txn_started) {
|
||||
engine.Exec_as_obj(Db_qry_sql.xtn_(String_.Format("SAVEPOINT {0};", name)));
|
||||
engine.Exec_as_obj(Db_qry_sql.xtn_(StringUtl.Format("SAVEPOINT {0};", name)));
|
||||
}
|
||||
else {
|
||||
txn_started = true;
|
||||
@@ -48,28 +48,28 @@ public class Sqlite_txn_mgr {
|
||||
}
|
||||
public String Txn_end() {
|
||||
if (txn_list.Len() == 0) {Gfo_usr_dlg_.Instance.Warn_many("", "", "no txns in stack;"); return "";}
|
||||
String txn_last = (String)List_adp_.Pop_last(txn_list);
|
||||
String txn_last = (String)List_adp_.PopLast(txn_list);
|
||||
if (txn_list.Len() == 0) {// no txns left; commit it
|
||||
engine.Exec_as_obj(Db_qry_sql.xtn_("COMMIT TRANSACTION;"));
|
||||
txn_started = false;
|
||||
}
|
||||
else
|
||||
engine.Exec_as_obj(Db_qry_sql.xtn_(String_.Format("RELEASE SAVEPOINT {0};", txn_last)));
|
||||
engine.Exec_as_obj(Db_qry_sql.xtn_(StringUtl.Format("RELEASE SAVEPOINT {0};", txn_last)));
|
||||
return txn_last;
|
||||
}
|
||||
public void Txn_cxl() {
|
||||
if (txn_list.Len() == 0) {Gfo_usr_dlg_.Instance.Warn_many("", "", "no txns in stack;"); return;}
|
||||
String txn_last = (String)List_adp_.Pop_last(txn_list);
|
||||
String txn_last = (String)List_adp_.PopLast(txn_list);
|
||||
if (txn_list.Len() == 0) {// no txns left; rollback
|
||||
engine.Exec_as_obj(Db_qry_sql.xtn_("ROLLBACK TRANSACTION;"));
|
||||
txn_started = false;
|
||||
}
|
||||
else
|
||||
engine.Exec_as_obj(Db_qry_sql.xtn_(String_.Format("ROLBACK TRANSACTION TO SAVEPOINT {0};", txn_last)));
|
||||
engine.Exec_as_obj(Db_qry_sql.xtn_(StringUtl.Format("ROLBACK TRANSACTION TO SAVEPOINT {0};", txn_last)));
|
||||
}
|
||||
public void Txn_sav() {
|
||||
if (txn_list.Len() == 0) {Gfo_usr_dlg_.Instance.Warn_many("", "", "no txns in stack;"); return;}
|
||||
String name = (String)txn_list.Get_at(txn_list.Len() - 1);
|
||||
String name = (String)txn_list.GetAt(txn_list.Len() - 1);
|
||||
this.Txn_end(); this.Txn_bgn(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.tdbs; import gplx.dbs.*;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.libs.files.Io_url_;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import org.junit.*;
|
||||
public class TdbConnectInfo_tst {
|
||||
@Test public void Full() {
|
||||
@@ -25,6 +28,6 @@ public class TdbConnectInfo_tst {
|
||||
tst_Parse(connectInfo, Io_url_.new_any_("C:\\dir\\xmpl.tdb"), "dsv");
|
||||
}
|
||||
void tst_Parse(Db_conn_info connectInfo, Io_url url, String format) {
|
||||
Tfds.Eq(((Tdb_conn_info)connectInfo).Url(), url);
|
||||
GfoTstr.EqObj(((Tdb_conn_info)connectInfo).Url(), url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs;
|
||||
import gplx.libs.files.Io_url;
|
||||
public class TdbDatabase {
|
||||
public String Name() {return name;} public void Name_set(String v) {name = v;} private String name = "xmpl";
|
||||
public Io_url DbUrl() {return dbInfo;} Io_url dbInfo;
|
||||
public TdbFileList Files() {return files;} TdbFileList files;
|
||||
public TdbTableList Tables() {return tables;} TdbTableList tables;
|
||||
@gplx.Internal protected boolean IsNew() {return isNew;} @gplx.Internal protected void IsNew_set(boolean v) {isNew = v;} private boolean isNew;
|
||||
@gplx.Internal protected TdbFile MakeFile(Io_url url) {
|
||||
public boolean IsNew() {return isNew;} public void IsNew_set(boolean v) {isNew = v;} private boolean isNew;
|
||||
public TdbFile MakeFile(Io_url url) {
|
||||
TdbFile rv = TdbFile.new_(FileId_next++, url);
|
||||
files.Add(rv);
|
||||
return rv;
|
||||
}
|
||||
@gplx.Internal protected TdbTable MakeTbl(String name, int fileId) {
|
||||
public TdbTable MakeTbl(String name, int fileId) {
|
||||
TdbFile file = files.Get_by_or_fail(fileId);
|
||||
TdbTable rv = TdbTable.new_(TableId_next++, name, file);
|
||||
tables.Add(rv);
|
||||
|
||||
@@ -13,8 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*;
|
||||
import gplx.core.stores.*;
|
||||
package gplx.dbs.engines.tdbs;
|
||||
import gplx.libs.files.Io_mgr;
|
||||
import gplx.core.stores.DataRdr;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
class TdbDbLoadMgr {
|
||||
public TdbDatabase LoadTbls(Io_url dbInfo) {
|
||||
TdbDatabase db = TdbDatabase.new_(dbInfo);
|
||||
@@ -34,11 +38,11 @@ class TdbDbLoadMgr {
|
||||
DataRdr rdr = rootRdr.Subs();
|
||||
while (rdr.MoveNextPeer()) {
|
||||
String name = rdr.NameOfNode();
|
||||
if (String_.Eq(name, TdbFileList.StoreTblName)) db.Files().DataObj_Rdr(rdr);
|
||||
else if (String_.Eq(name, TdbTableList.StoreTableName)) db.Tables().DataObj_Rdr(rdr, db.Files());
|
||||
if (StringUtl.Eq(name, TdbFileList.StoreTblName)) db.Files().DataObj_Rdr(rdr);
|
||||
else if (StringUtl.Eq(name, TdbTableList.StoreTableName)) db.Tables().DataObj_Rdr(rdr, db.Files());
|
||||
else db.Tables().Get_by_or_fail(rdr.NameOfNode()).DataObj_Rdr(rdr);
|
||||
}
|
||||
if (db.Files().Len() == 0) throw Err_.new_wo_type("fatal error: db has no files", "connectInfo", db.DbUrl());
|
||||
if (db.Files().Len() == 0) throw ErrUtl.NewArgs("fatal error: db has no files", "connectInfo", db.DbUrl());
|
||||
}
|
||||
DataRdr MakeDataRdr(Io_url fil) {
|
||||
String text = Io_mgr.Instance.LoadFilStr(fil);
|
||||
|
||||
@@ -13,7 +13,11 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*;
|
||||
package gplx.dbs.engines.tdbs;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.libs.files.Io_url_;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
import gplx.core.stores.*; /*DsvDataRdr*/ import gplx.langs.dsvs.*; /*DsvDataWtr*/
|
||||
public class TdbDbLoadMgr_tst {
|
||||
@@ -25,7 +29,7 @@ public class TdbDbLoadMgr_tst {
|
||||
TdbDatabase db; TdbDbLoadMgr loadMgr = TdbDbLoadMgr.new_(); TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_();
|
||||
DataRdr rdr; DataWtr wtr;
|
||||
@Test public void ReadDbFiles() {
|
||||
String raw = String_.Concat_lines_crlf
|
||||
String raw = StringUtl.ConcatLinesCrlf
|
||||
( "=======DIF======================, ,\" \",//"
|
||||
, "_files, ,\" \",#"
|
||||
, "==DEF==DIF======================, ,\" \",//"
|
||||
@@ -38,15 +42,15 @@ public class TdbDbLoadMgr_tst {
|
||||
rdr = rdr_(raw);
|
||||
|
||||
db.Files().DataObj_Rdr(rdr);
|
||||
Tfds.Eq(db.Files().Len(), 2);
|
||||
GfoTstr.EqObj(db.Files().Len(), 2);
|
||||
TdbFile file2 = db.Files().Get_by_or_fail(2);
|
||||
Tfds.Eq(file2.Path().Raw(), "C:\\file.dsv");
|
||||
GfoTstr.EqObj(file2.Path().Raw(), "C:\\file.dsv");
|
||||
|
||||
db.Files().DataObj_Wtr(wtr);
|
||||
Tfds.Eq(wtr.To_str(), raw);
|
||||
GfoTstr.EqObj(wtr.To_str(), raw);
|
||||
}
|
||||
@Test public void ReadDbTbls() {
|
||||
String raw = String_.Concat_lines_crlf
|
||||
String raw = StringUtl.ConcatLinesCrlf
|
||||
( "=======DIF======================, ,\" \",//"
|
||||
, "_tables, ,\" \",#"
|
||||
, "==DEF==DIF======================, ,\" \",//"
|
||||
@@ -58,16 +62,16 @@ public class TdbDbLoadMgr_tst {
|
||||
rdr = rdr_(raw);
|
||||
|
||||
db.Tables().DataObj_Rdr(rdr, db.Files());
|
||||
Tfds.Eq(db.Tables().Len(), 1);
|
||||
GfoTstr.EqObj(db.Tables().Len(), 1);
|
||||
TdbTable table = db.Tables().Get_by_or_fail("tbl1");
|
||||
Tfds.Eq(table.Name(), "tbl1");
|
||||
Tfds.Eq(table.File().Id(), 1);
|
||||
GfoTstr.EqObj(table.Name(), "tbl1");
|
||||
GfoTstr.EqObj(table.File().Id(), 1);
|
||||
|
||||
db.Tables().DataObj_Wtr(wtr);
|
||||
Tfds.Eq(wtr.To_str(), raw);
|
||||
GfoTstr.EqObj(wtr.To_str(), raw);
|
||||
}
|
||||
@Test public void ReadTbl() {
|
||||
String raw = String_.Concat_lines_crlf
|
||||
String raw = StringUtl.ConcatLinesCrlf
|
||||
( "=======DIF======================, ,\" \",//"
|
||||
, "tbl0, ,\" \",#"
|
||||
, "==DEF==DIF======================, ,\" \",//"
|
||||
@@ -80,16 +84,16 @@ public class TdbDbLoadMgr_tst {
|
||||
|
||||
db.MakeTbl("tbl0", TdbFile.MainFileId);
|
||||
db.Tables().Get_by_or_fail(rdr.NameOfNode()).DataObj_Rdr(rdr);
|
||||
Tfds.Eq(db.Tables().Len(), 1);
|
||||
GfoTstr.EqObj(db.Tables().Len(), 1);
|
||||
TdbTable tbl = db.Tables().Get_by_or_fail("tbl0");
|
||||
Tfds.Eq(tbl.Rows().Count(), 1);
|
||||
GfoTstr.EqObj(tbl.Rows().Count(), 1);
|
||||
|
||||
GfoNde row = tbl.Rows().FetchAt_asGfoNde(0);
|
||||
Tfds.Eq(row.Read("id"), 0);
|
||||
Tfds.Eq(row.Read("name"), "me");
|
||||
GfoTstr.EqObj(row.Read("id"), 0);
|
||||
GfoTstr.EqObj(row.Read("name"), "me");
|
||||
|
||||
tbl.DataObj_Wtr(wtr);
|
||||
Tfds.Eq(wtr.To_str(), raw);
|
||||
GfoTstr.EqObj(wtr.To_str(), raw);
|
||||
}
|
||||
DataRdr rdr_(String raw) {
|
||||
DataRdr rdr = DsvDataRdr_.dsv_(raw);
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs;
|
||||
import gplx.core.stores.*;
|
||||
import gplx.libs.files.Io_mgr;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
class TdbDbSaveMgr {
|
||||
public void SaveDb(TdbDatabase db) {
|
||||
for (Object filObj : db.Files()) {
|
||||
|
||||
@@ -13,7 +13,11 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.tdbs;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.libs.files.Io_url_;
|
||||
import org.junit.*; import gplx.core.stores.*;
|
||||
import gplx.langs.dsvs.*; import gplx.core.type_xtns.*;
|
||||
public class TdbDbSaveMgr_tst {
|
||||
@@ -23,7 +27,7 @@ public class TdbDbSaveMgr_tst {
|
||||
wtr.Clear();
|
||||
} TdbDatabase db; TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_(); DataWtr wtr = DsvDataWtr_.new_();
|
||||
@Test public void WriteDbFils() {
|
||||
String expd = String_.Concat_lines_crlf
|
||||
String expd = StringUtl.ConcatLinesCrlf
|
||||
( ""
|
||||
, ""
|
||||
, "================================, ,\" \",//"
|
||||
@@ -36,10 +40,10 @@ public class TdbDbSaveMgr_tst {
|
||||
);
|
||||
db.Files().DataObj_Wtr(wtr);
|
||||
String actl = wtr.To_str();
|
||||
Tfds.Eq(expd, actl);
|
||||
GfoTstr.EqObj(expd, actl);
|
||||
}
|
||||
@Test public void WriteDbTbls() {
|
||||
String expd = String_.Concat_lines_crlf
|
||||
String expd = StringUtl.ConcatLinesCrlf
|
||||
( ""
|
||||
, ""
|
||||
, "================================, ,\" \",//"
|
||||
@@ -51,10 +55,10 @@ public class TdbDbSaveMgr_tst {
|
||||
);
|
||||
db.Tables().DataObj_Wtr(wtr);
|
||||
String actl = wtr.To_str();
|
||||
Tfds.Eq(expd, actl);
|
||||
GfoTstr.EqObj(expd, actl);
|
||||
}
|
||||
@Test public void WriteTbl() {
|
||||
String expd = String_.Concat_lines_crlf
|
||||
String expd = StringUtl.ConcatLinesCrlf
|
||||
( ""
|
||||
, ""
|
||||
, "================================, ,\" \",//"
|
||||
@@ -70,6 +74,6 @@ public class TdbDbSaveMgr_tst {
|
||||
|
||||
tbl.DataObj_Wtr(wtr);
|
||||
String actl = wtr.To_str();
|
||||
Tfds.Eq(expd, actl);
|
||||
GfoTstr.EqObj(expd, actl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,11 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.tdbs; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.core.criterias.*;
|
||||
import gplx.dbs.qrys.*; import gplx.core.gfo_ndes.*;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
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;
|
||||
@@ -34,7 +36,7 @@ class TdbDeleteWkr implements Db_qryWkr {
|
||||
deleted.Add(row);
|
||||
}
|
||||
for (int i = 0; i < deleted.Len(); i++) {
|
||||
GfoNde row = (GfoNde)deleted.Get_at(i);
|
||||
GfoNde row = (GfoNde)deleted.GetAt(i);
|
||||
tbl.Rows().Del(row);
|
||||
rv++;
|
||||
}
|
||||
|
||||
@@ -13,10 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.tdbs; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.core.stores.*; import gplx.dbs.metas.*; import gplx.dbs.conn_props.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.*; import gplx.dbs.qrys.bats.*;
|
||||
import gplx.dbs.wkrs.SqlWkrMgr;
|
||||
|
||||
import gplx.libs.dlgs.Gfo_usr_dlg;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.libs.files.Io_url_;
|
||||
import gplx.types.basics.lists.Hash_adp;
|
||||
import gplx.types.basics.lists.Hash_adp_;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class TdbEngine implements Db_engine {
|
||||
public String Tid() {return Tdb_conn_info.Tid_const;}
|
||||
public Db_conn_info Conn_info() {return conn_info;} private Db_conn_info conn_info;
|
||||
@@ -46,7 +51,7 @@ public class TdbEngine implements Db_engine {
|
||||
return wkr.Exec(this, qry);
|
||||
}
|
||||
public Db_stmt Stmt_by_qry(Db_qry qry) {return new Db_stmt_sql().Parse(qry, sql_wtr.ToSqlStr(qry, true));}
|
||||
public Object Stmt_by_sql(String sql) {throw Err_.new_unimplemented();}
|
||||
public Object Stmt_by_sql(String sql) {throw ErrUtl.NewUnimplemented();}
|
||||
public Db_rdr Exec_as_rdr__rls_manual(Object rdr_obj, String sql) {return Db_rdr_.Empty;}
|
||||
public Db_rdr Exec_as_rdr__rls_auto(Db_stmt stmt, Object rdr_obj, String sql) {return Db_rdr_.Empty;}
|
||||
public DataRdr New_rdr(java.sql.ResultSet rdr, String sql) {return DataRdr_.Null;}
|
||||
@@ -61,10 +66,10 @@ public class TdbEngine implements Db_engine {
|
||||
public void FlushTbl(TdbTable tbl) {
|
||||
saveMgr.SaveFile(db, tbl.File());
|
||||
}
|
||||
public void Meta_tbl_create(Dbmeta_tbl_itm meta) {throw Err_.new_unimplemented();}
|
||||
public void Meta_idx_create(Gfo_usr_dlg usr_dlg, Dbmeta_idx_itm... ary) {throw Err_.new_unimplemented();}
|
||||
public void Meta_idx_delete(String idx) {throw Err_.new_unimplemented();}
|
||||
public void Meta_fld_append(String tbl, DbmetaFldItm fld) {throw Err_.new_unimplemented();}
|
||||
public void Meta_tbl_create(Dbmeta_tbl_itm meta) {throw ErrUtl.NewUnimplemented();}
|
||||
public void Meta_idx_create(Gfo_usr_dlg usr_dlg, Dbmeta_idx_itm... ary) {throw ErrUtl.NewUnimplemented();}
|
||||
public void Meta_idx_delete(String idx) {throw ErrUtl.NewUnimplemented();}
|
||||
public void Meta_fld_append(String tbl, DbmetaFldItm fld) {throw ErrUtl.NewUnimplemented();}
|
||||
public void Meta_tbl_delete(String tbl) {}
|
||||
public boolean Meta_tbl_exists(String name) {return false;}
|
||||
public boolean Meta_fld_exists(String tbl, String fld) {return false;}
|
||||
@@ -85,7 +90,7 @@ public class TdbEngine implements Db_engine {
|
||||
wkrs.Add(Db_qry_.Tid_flush, TdbFlushWkr.new_());
|
||||
}
|
||||
public static TdbEngine as_(Object obj) {return obj instanceof TdbEngine ? (TdbEngine)obj : null;}
|
||||
public static TdbEngine cast(Object obj) {try {return (TdbEngine)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, TdbEngine.class, obj);}}
|
||||
public static TdbEngine cast(Object obj) {try {return (TdbEngine)obj;} catch(Exception exc) {throw ErrUtl.NewCast(exc, TdbEngine.class, obj);}}
|
||||
}
|
||||
interface Db_qryWkr {
|
||||
Object Exec(Db_engine engine, Db_qry cmd);
|
||||
|
||||
@@ -13,17 +13,19 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class TdbFile {
|
||||
public int Id() {return id;} int id;
|
||||
public Io_url Path() {return url;} Io_url url;
|
||||
|
||||
public static TdbFile new_(int id, Io_url url) {
|
||||
TdbFile rv = new TdbFile();
|
||||
rv.id = id; rv.url = url;
|
||||
return rv;
|
||||
}
|
||||
public static final int MainFileId = 1;
|
||||
public static TdbFile as_(Object obj) {return obj instanceof TdbFile ? (TdbFile)obj : null;}
|
||||
public static TdbFile cast(Object obj) {try {return (TdbFile)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, TdbFile.class, obj);}}
|
||||
}
|
||||
package gplx.dbs.engines.tdbs;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class TdbFile {
|
||||
public int Id() {return id;} int id;
|
||||
public Io_url Path() {return url;} Io_url url;
|
||||
|
||||
public static TdbFile new_(int id, Io_url url) {
|
||||
TdbFile rv = new TdbFile();
|
||||
rv.id = id; rv.url = url;
|
||||
return rv;
|
||||
}
|
||||
public static final int MainFileId = 1;
|
||||
public static TdbFile as_(Object obj) {return obj instanceof TdbFile ? (TdbFile)obj : null;}
|
||||
public static TdbFile cast(Object obj) {try {return (TdbFile)obj;} catch(Exception exc) {throw ErrUtl.NewCast(exc, TdbFile.class, obj);}}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs;
|
||||
import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*; import gplx.core.stores.*;
|
||||
import gplx.core.lists.*; /*Ordered_hash_base*/ import gplx.langs.dsvs.*; /*DsvStoreLayout*/
|
||||
import gplx.langs.dsvs.*; /*DsvStoreLayout*/
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.libs.files.Io_url_;
|
||||
import gplx.types.basics.lists.Ordered_hash_base;
|
||||
public class TdbFileList extends Ordered_hash_base {
|
||||
public TdbFile Get_by_or_fail(int id) {return TdbFile.as_(Get_by_or_fail_base(id));}
|
||||
public void Add(TdbFile src) {Add_base(src.Id(), src);}
|
||||
@@ -29,7 +32,7 @@ public class TdbFileList extends Ordered_hash_base {
|
||||
return rv;
|
||||
} TdbFileList() {}
|
||||
|
||||
@gplx.Internal protected void DataObj_Wtr(DataWtr wtr) {
|
||||
public void DataObj_Wtr(DataWtr wtr) {
|
||||
wtr.InitWtr(DsvStoreLayout.Key_const, layout);
|
||||
wtr.WriteTableBgn(StoreTblName, FldList);
|
||||
for (Object filObj : this) {
|
||||
@@ -42,7 +45,7 @@ public class TdbFileList extends Ordered_hash_base {
|
||||
}
|
||||
wtr.WriteNodeEnd();
|
||||
}
|
||||
@gplx.Internal protected void DataObj_Rdr(DataRdr rdr) {
|
||||
public void DataObj_Rdr(DataRdr rdr) {
|
||||
layout = TdbStores.FetchLayout(rdr);
|
||||
this.Clear();
|
||||
DataRdr subRdr = rdr.Subs();
|
||||
|
||||
@@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.types.basics.utls.ArrayUtl;
|
||||
class TdbFlushWkr implements Db_qryWkr {
|
||||
public Object Exec(Db_engine engineObj, Db_qry cmdObj) {
|
||||
TdbEngine engine = TdbEngine.cast(engineObj); Db_qry_flush cmd = Db_qry_flush.cast(cmdObj);
|
||||
|
||||
@@ -13,7 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.engines.tdbs; import gplx.dbs.*;
|
||||
import gplx.libs.files.Io_mgr;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.basics.utls.ObjectUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.commons.GfoDate;
|
||||
import gplx.types.commons.GfoDateUtl;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.libs.files.Io_url_;
|
||||
import org.junit.*;
|
||||
import gplx.core.ios.*; /*IoMgrFxt*/ import gplx.dbs.qrys.*; import gplx.core.type_xtns.*;
|
||||
public class TdbFlush_tst {
|
||||
@@ -21,7 +29,7 @@ public class TdbFlush_tst {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
engine = fx_engine.run_MakeEngine(dbPath);
|
||||
}
|
||||
TdbEngine engine; Io_url dbPath = Io_url_.mem_fil_("mem/dir/db0.dsv"); DateAdp time = DateAdp_.parse_gplx("2001-01-01");
|
||||
TdbEngine engine; Io_url dbPath = Io_url_.mem_fil_("mem/dir/db0.dsv"); GfoDate time = GfoDateUtl.ParseGplx("2001-01-01");
|
||||
TdbEngineFxt fx_engine = TdbEngineFxt.new_(); IoMgrFxt fx_io = IoMgrFxt.new_();
|
||||
@Test public void FlushNewDb() {
|
||||
fx_engine.tst_FilesCount(engine, 1);
|
||||
@@ -66,7 +74,7 @@ public class TdbFlush_tst {
|
||||
}
|
||||
@Test public void FlushDirtyFilOnly() {
|
||||
Io_url dbPathOther = Io_url_.mem_fil_("mem/dir/db1.dsv");
|
||||
TdbFile filOther = fx_engine.run_MakeFile(engine, dbPathOther); Tfds.Eq(false, Object_.Eq(filOther.Id(), TdbFile.MainFileId));
|
||||
TdbFile filOther = fx_engine.run_MakeFile(engine, dbPathOther); GfoTstr.EqObj(false, ObjectUtl.Eq(filOther.Id(), TdbFile.MainFileId));
|
||||
fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId); fx_engine.run_MakeTbl(engine, "tbl1", filOther.Id());
|
||||
engine.FlushAll();
|
||||
fx_io.run_UpdateFilModifiedTime(dbPath, time); fx_io.run_UpdateFilModifiedTime(dbPathOther, time);
|
||||
@@ -96,22 +104,22 @@ class TdbEngineFxt {
|
||||
engine.Exec_as_obj(cmd);
|
||||
}
|
||||
|
||||
public void tst_FilesCount(TdbEngine engine, int count) {Tfds.Eq(engine.Db().Files().Len(), count);}
|
||||
public void tst_FilesCount(TdbEngine engine, int count) {GfoTstr.EqObj(engine.Db().Files().Len(), count);}
|
||||
public void tst_File(TdbEngine engine, int index, int id, Io_url url, String format) {
|
||||
TdbFile src = engine.Db().Files().Get_by_or_fail(id);
|
||||
Tfds.Eq(src.Path().Raw(), url.Raw());
|
||||
GfoTstr.EqObj(src.Path().Raw(), url.Raw());
|
||||
}
|
||||
public static TdbEngineFxt new_() {return new TdbEngineFxt();} TdbEngineFxt() {}
|
||||
}
|
||||
class IoMgrFxt {
|
||||
public void run_UpdateFilModifiedTime(Io_url url, DateAdp val) {Io_mgr.Instance.UpdateFilModifiedTime(url, val);}
|
||||
public void tst_QueryFilModified(boolean expdMatch, Io_url url, DateAdp expt) {
|
||||
public void run_UpdateFilModifiedTime(Io_url url, GfoDate val) {Io_mgr.Instance.UpdateFilModifiedTime(url, val);}
|
||||
public void tst_QueryFilModified(boolean expdMatch, Io_url url, GfoDate expt) {
|
||||
IoItmFil filItem = Io_mgr.Instance.QueryFil(url);
|
||||
DateAdp actl = filItem.ModifiedTime();
|
||||
boolean actlMatch = String_.Eq(expt.XtoStr_gplx(), actl.XtoStr_gplx());
|
||||
Tfds.Eq(expdMatch, actlMatch, expt.XtoStr_gplx() + (expdMatch ? "!=" : "==") + actl.XtoStr_gplx());
|
||||
GfoDate actl = filItem.ModifiedTime();
|
||||
boolean actlMatch = StringUtl.Eq(expt.ToStrGplx(), actl.ToStrGplx());
|
||||
GfoTstr.EqObj(expdMatch, actlMatch, expt.ToStrGplx() + (expdMatch ? "!=" : "==") + actl.ToStrGplx());
|
||||
}
|
||||
public void tst_Exists(boolean expd, Io_url url) {Tfds.Eq(expd, Io_mgr.Instance.ExistsFil(url));}
|
||||
public void tst_Exists(boolean expd, Io_url url) {GfoTstr.EqObj(expd, Io_mgr.Instance.ExistsFil(url));}
|
||||
|
||||
public static IoMgrFxt new_() {return new IoMgrFxt();} IoMgrFxt() {}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,21 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.core.gfo_ndes.*; import gplx.core.stores.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
import gplx.dbs.sqls.itms.*;
|
||||
package gplx.dbs.engines.tdbs;
|
||||
import gplx.core.gfo_ndes.GfoFldList;
|
||||
import gplx.core.gfo_ndes.GfoNde;
|
||||
import gplx.core.gfo_ndes.GfoNde_;
|
||||
import gplx.core.stores.DataRdr;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.engines.Db_engine;
|
||||
import gplx.dbs.qrys.Db_arg;
|
||||
import gplx.dbs.qrys.Db_qry_insert;
|
||||
import gplx.dbs.sqls.itms.Sql_select_fld;
|
||||
import gplx.dbs.sqls.itms.Sql_select_fld_list;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
class TdbInsertWkr implements Db_qryWkr {
|
||||
public Object Exec(Db_engine engineObj, Db_qry cmdObj) {
|
||||
TdbEngine engine = TdbEngine.cast(engineObj); Db_qry_insert cmd = (Db_qry_insert)cmdObj;
|
||||
@@ -33,8 +44,8 @@ class TdbInsertWkr implements Db_qryWkr {
|
||||
Sql_select_fld_list insertFlds = insert.Cols(); int insertFldsCount = insertFlds.Len();
|
||||
GfoFldList selectFldsForNewRow = null;
|
||||
try {selectFldsForNewRow = TdbSelectWkr.To_GfoFldLst(tbl, insertFlds);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "failed to generate flds for new row");}
|
||||
if (insertFldsCount > selectFldsForNewRow.Count()) throw Err_.new_wo_type("insert flds cannot exceed selectFlds", "insertFlds", To_str(insertFlds), "selectFlds", selectFldsForNewRow.To_str());
|
||||
catch (Exception e) {throw ErrUtl.NewArgs(e, "failed to generate flds for new row");}
|
||||
if (insertFldsCount > selectFldsForNewRow.Count()) throw ErrUtl.NewArgs("insert flds cannot exceed selectFlds", "insertFlds", To_str(insertFlds), "selectFlds", selectFldsForNewRow.To_str());
|
||||
while (rdr.MoveNextPeer()) {
|
||||
count++;
|
||||
GfoNde row = GfoNde_.vals_(selectFldsForNewRow, new Object[insertFldsCount]);
|
||||
@@ -47,21 +58,21 @@ class TdbInsertWkr implements Db_qryWkr {
|
||||
}
|
||||
int InsertRowsByVals(TdbEngine engine, TdbTable tbl, Db_qry_insert insert) {
|
||||
GfoNde row = GfoNde_.vals_(tbl.Flds(), new Object[tbl.Flds().Count()]);
|
||||
for (int i = 0; i < insert.Args().Count(); i++) {
|
||||
Keyval kv = insert.Args().Get_at(i);
|
||||
for (int i = 0; i < insert.Args().Len(); i++) {
|
||||
KeyVal kv = insert.Args().GetAt(i);
|
||||
Db_arg arg = (Db_arg)kv.Val();
|
||||
row.Write(kv.Key(), arg.Val);
|
||||
row.Write(kv.KeyToStr(), arg.Val);
|
||||
}
|
||||
tbl.Rows().Add(row);
|
||||
return 1;
|
||||
}
|
||||
private String To_str(Sql_select_fld_list flds) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
BryWtr bfr = BryWtr.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));
|
||||
bfr.AddStrU8(StringUtl.Format("{0},{1}|", fld.Fld, fld.Alias));
|
||||
}
|
||||
return bfr.To_str();
|
||||
return bfr.ToStr();
|
||||
}
|
||||
public static TdbInsertWkr new_() {TdbInsertWkr rv = new TdbInsertWkr(); return rv;}
|
||||
}
|
||||
|
||||
@@ -13,15 +13,32 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.core.criterias.*; import gplx.core.gfo_ndes.*; import gplx.dbs.qrys.*;
|
||||
import gplx.dbs.sqls.itms.*;
|
||||
import gplx.core.stores.*; /*GfoNdeRdr*/
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
package gplx.dbs.engines.tdbs;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
import gplx.core.criterias.Criteria;
|
||||
import gplx.core.gfo_ndes.GfoFld;
|
||||
import gplx.core.gfo_ndes.GfoFldList;
|
||||
import gplx.core.gfo_ndes.GfoFldList_;
|
||||
import gplx.core.gfo_ndes.GfoNde;
|
||||
import gplx.core.gfo_ndes.GfoNdeList;
|
||||
import gplx.core.gfo_ndes.GfoNdeList_;
|
||||
import gplx.core.gfo_ndes.GfoNde_;
|
||||
import gplx.core.stores.GfoNdeRdr_;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.engines.Db_engine;
|
||||
import gplx.dbs.qrys.Db_qry__select_cmd;
|
||||
import gplx.dbs.sqls.itms.Sql_order_fld_sorter;
|
||||
import gplx.dbs.sqls.itms.Sql_select_fld;
|
||||
import gplx.dbs.sqls.itms.Sql_select_fld_list;
|
||||
import gplx.dbs.sqls.itms.Sql_where_clause;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.commons.lists.ComparerAble;
|
||||
class TdbSelectWkr implements Db_qryWkr {
|
||||
public Object Exec(Db_engine engineObj, Db_qry cmdObj) {
|
||||
TdbEngine engine = TdbEngine.cast(engineObj); Db_qry__select_cmd cmd = (Db_qry__select_cmd)cmdObj;
|
||||
if (cmd.From().Tbls.Len() > 1) throw Err_.new_("gplx.tdbs", "joins not supported for tdbs", "sql", cmd.ToSqlExec(engineObj.Sql_wtr()));
|
||||
if (cmd.From().Tbls.Len() > 1) throw ErrUtl.NewArgs("joins not supported for tdbs", "sql", cmd.ToSqlExec(engineObj.Sql_wtr()));
|
||||
|
||||
TdbTable tbl = engine.FetchTbl(cmd.From().Base_tbl.Name);
|
||||
GfoNdeList rv = (cmd.Where_itm() == Sql_where_clause.Where__null && cmd.Limit() == Db_qry__select_cmd.Limit__disabled) ? rv = tbl.Rows() : FilterRecords(tbl, cmd.Where_itm().Root, cmd.Limit());
|
||||
@@ -50,8 +67,8 @@ class TdbSelectWkr implements Db_qryWkr {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Sql_select_fld selectFld = flds.Get_at(i);
|
||||
GfoFld fld = tbl.Flds().FetchOrNull(selectFld.Fld);
|
||||
if (fld == null) throw Err_.new_wo_type("fld not found in tbl", "fldName", selectFld.Fld, "tblName", tbl.Name(), "tblFlds", tbl.Flds().To_str());
|
||||
if (rv.Has(selectFld.Alias)) throw Err_.new_wo_type("alias is not unique", "fldName", selectFld.Fld, "flds", rv.To_str());
|
||||
if (fld == null) throw ErrUtl.NewArgs("fld not found in tbl", "fldName", selectFld.Fld, "tblName", tbl.Name(), "tblFlds", tbl.Flds().To_str());
|
||||
if (rv.Has(selectFld.Alias)) throw ErrUtl.NewArgs("alias is not unique", "fldName", selectFld.Fld, "flds", rv.To_str());
|
||||
selectFld.GroupBy_type(fld.Type());
|
||||
rv.Add(selectFld.Alias, selectFld.Val_type());
|
||||
}
|
||||
@@ -83,7 +100,7 @@ class TdbGroupByWkr {
|
||||
Ordered_hash curHash = groupByRows;
|
||||
GfoNde rv = null;
|
||||
for (int i = 0; i < len; i++) {
|
||||
String fld = (String)groupByFlds.Get_at(i);
|
||||
String fld = (String)groupByFlds.GetAt(i);
|
||||
boolean last = i == len - 1;
|
||||
Object val = selectRow.Read(fld);
|
||||
Object o = curHash.GetByOrNull(val);
|
||||
|
||||
@@ -21,7 +21,7 @@ class TdbStores {
|
||||
public static final String Xml = "xml";
|
||||
public static DataRdr rdr_(String text) {return DsvDataRdr_.dsv_(text);}
|
||||
public static DataWtr wtr_() {return DsvDataWtr_.new_();}
|
||||
@gplx.Internal protected static DsvStoreLayout FetchLayout(DataRdr rdr) {
|
||||
public static DsvStoreLayout FetchLayout(DataRdr rdr) {
|
||||
GfoNdeRdr ndeRdr = GfoNdeRdr_.as_(rdr); if (ndeRdr == null) return null; // can happen for non-Dsv Rdrs (ex: Xml)
|
||||
return DsvStoreLayout.as_(ndeRdr.UnderNde().EnvVars().GetByOrNull(DsvStoreLayout.Key_const));
|
||||
}
|
||||
|
||||
@@ -1,28 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.*; /*GfoNdeList*/ import gplx.core.stores.*; import gplx.langs.dsvs.*; /*DsvStoreLayout*/ import gplx.core.gfo_ndes.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs;
|
||||
import gplx.types.basics.utls.ClassUtl;
|
||||
import gplx.core.gfo_ndes.GfoFldList;
|
||||
import gplx.core.gfo_ndes.GfoFldList_;
|
||||
import gplx.core.gfo_ndes.GfoNde;
|
||||
import gplx.core.gfo_ndes.GfoNdeList;
|
||||
import gplx.core.gfo_ndes.GfoNdeList_;
|
||||
import gplx.core.stores.DataRdr;
|
||||
import gplx.core.stores.DataWtr;
|
||||
import gplx.core.stores.GfoNdeRdr;
|
||||
import gplx.core.stores.GfoNdeRdr_;
|
||||
import gplx.langs.dsvs.DsvStoreLayout;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class TdbTable {
|
||||
public int Id() {return id;} int id;
|
||||
public String Name() {return name;} private String name;
|
||||
public GfoFldList Flds() {return flds;} GfoFldList flds = GfoFldList_.new_();
|
||||
public GfoNdeList Rows() {return rows;} GfoNdeList rows = GfoNdeList_.new_();
|
||||
@gplx.Internal protected TdbFile File() {return file;} TdbFile file;
|
||||
@gplx.Internal protected boolean IsLoaded() {return isLoaded;} private boolean isLoaded = true;
|
||||
@gplx.Internal protected boolean IsDirty() {return isDirty;} public void IsDirty_set(boolean v) {isDirty = v;} private boolean isDirty = false;
|
||||
public TdbFile File() {return file;} TdbFile file;
|
||||
public boolean IsLoaded() {return isLoaded;} private boolean isLoaded = true;
|
||||
public boolean IsDirty() {return isDirty;} public void IsDirty_set(boolean v) {isDirty = v;} private boolean isDirty = false;
|
||||
|
||||
public static TdbTable new_(int id, String name, TdbFile file) {TdbTable rv = new TdbTable(); rv.ctor(id, name, file); rv.isDirty = true; return rv;} TdbTable() {}
|
||||
public static TdbTable load_(int id, String name, TdbFile file) {TdbTable rv = new TdbTable(); rv.ctor(id, name, file); rv.isLoaded = false; return rv;}
|
||||
@@ -31,7 +42,7 @@ public class TdbTable {
|
||||
layout = DsvStoreLayout.dsv_full_();
|
||||
}
|
||||
|
||||
@gplx.Internal protected void DataObj_Wtr(DataWtr wtr) {
|
||||
public void DataObj_Wtr(DataWtr wtr) {
|
||||
wtr.InitWtr(DsvStoreLayout.Key_const, layout);
|
||||
wtr.WriteTableBgn(name, flds);
|
||||
for (int rowIdx = 0; rowIdx < rows.Count(); rowIdx++) {
|
||||
@@ -44,20 +55,20 @@ public class TdbTable {
|
||||
wtr.WriteNodeEnd();
|
||||
isDirty = false;
|
||||
}
|
||||
@gplx.Internal protected void DataObj_Rdr(DataRdr rdr) {
|
||||
public void DataObj_Rdr(DataRdr rdr) {
|
||||
layout = TdbStores.FetchLayout(rdr);
|
||||
GfoNdeRdr ndeRdr = GfoNdeRdr_.as_(rdr );
|
||||
if (ndeRdr != null) {
|
||||
if (ndeRdr.UnderNde() == null) throw Err_.new_wo_type("ndeRdr.UnderNde is null", "name", rdr.NameOfNode());
|
||||
if (ndeRdr.UnderNde() == null) throw ErrUtl.NewArgs("ndeRdr.UnderNde is null", "name", rdr.NameOfNode());
|
||||
rows = ndeRdr.UnderNde().Subs();
|
||||
flds = ndeRdr.UnderNde().SubFlds();
|
||||
}
|
||||
else { // XmlRdr needs to load each row again...
|
||||
throw Err_.new_invalid_op("TableLoad not implemented").Args_add("rdrType", Type_.Name_by_obj(rdr), "rdrName", rdr.NameOfNode());
|
||||
throw ErrUtl.NewInvalidOp("TableLoad not implemented").ArgsAdd("rdrType", ClassUtl.NameByObj(rdr)).ArgsAdd("rdrName", rdr.NameOfNode());
|
||||
}
|
||||
isLoaded = true;
|
||||
}
|
||||
DsvStoreLayout layout;
|
||||
public static TdbTable as_(Object obj) {return obj instanceof TdbTable ? (TdbTable)obj : null;}
|
||||
public static TdbTable cast(Object obj) {try {return (TdbTable)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, TdbTable.class, obj);}}
|
||||
public static TdbTable cast(Object obj) {try {return (TdbTable)obj;} catch(Exception exc) {throw ErrUtl.NewCast(exc, TdbTable.class, obj);}}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.core.lists.*; /*Ordered_hash_base*/ import gplx.langs.dsvs.*; /*DsvStoreLayout*/ import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*; import gplx.core.stores.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs;
|
||||
import gplx.types.basics.lists.Ordered_hash_base;
|
||||
import gplx.core.gfo_ndes.GfoFldList;
|
||||
import gplx.core.gfo_ndes.GfoFldList_;
|
||||
import gplx.core.stores.DataRdr;
|
||||
import gplx.core.stores.DataWtr;
|
||||
import gplx.core.type_xtns.IntClassXtn;
|
||||
import gplx.core.type_xtns.StringClassXtn;
|
||||
import gplx.langs.dsvs.DsvStoreLayout;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.libs.files.Io_url;
|
||||
public class TdbTableList extends Ordered_hash_base {
|
||||
public TdbTable Get_by(String name) {return TdbTable.as_(Fetch_base(name));}
|
||||
public TdbTable Get_by_or_fail(String name) {
|
||||
TdbTable rv = TdbTable.as_(Get_by(name)); if (rv == null) throw Err_.new_wo_type("could not find table; database file may not exist", "table", name);
|
||||
TdbTable rv = TdbTable.as_(Get_by(name)); if (rv == null) throw ErrUtl.NewArgs("could not find table; database file may not exist", "table", name);
|
||||
return rv;
|
||||
}
|
||||
public void Add(TdbTable dataTable) {Add_base(dataTable.Name(), dataTable);}
|
||||
@@ -28,7 +37,7 @@ public class TdbTableList extends Ordered_hash_base {
|
||||
rv.layout = DsvStoreLayout.dsv_full_();
|
||||
return rv;
|
||||
}
|
||||
@gplx.Internal protected void DataObj_Wtr(DataWtr wtr) {
|
||||
public void DataObj_Wtr(DataWtr wtr) {
|
||||
wtr.InitWtr(DsvStoreLayout.Key_const, layout);
|
||||
wtr.WriteTableBgn(StoreTableName, FldList);
|
||||
for (Object tblObj : this) {
|
||||
@@ -41,7 +50,7 @@ public class TdbTableList extends Ordered_hash_base {
|
||||
}
|
||||
wtr.WriteNodeEnd();
|
||||
}
|
||||
@gplx.Internal protected void DataObj_Rdr(DataRdr rdr, TdbFileList files) {
|
||||
public void DataObj_Rdr(DataRdr rdr, TdbFileList files) {
|
||||
layout = TdbStores.FetchLayout(rdr);
|
||||
DataRdr subRdr = rdr.Subs();
|
||||
this.Clear();
|
||||
|
||||
@@ -13,10 +13,11 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.tdbs; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.core.criterias.*;
|
||||
import gplx.core.gfo_ndes.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
import gplx.types.commons.KeyVal;
|
||||
class TdbUpdateWkr implements Db_qryWkr {
|
||||
public Object Exec(Db_engine engineObj, Db_qry cmdObj) {
|
||||
TdbEngine engine = TdbEngine.cast(engineObj); Db_qry_update cmd = (Db_qry_update)cmdObj;
|
||||
@@ -35,10 +36,10 @@ class TdbUpdateWkr implements Db_qryWkr {
|
||||
return rv;
|
||||
}
|
||||
void UpdateRow(Db_qry_update cmd, GfoNde row) {
|
||||
for (int i = 0; i < cmd.Args().Count(); i++) {
|
||||
Keyval p = (Keyval)cmd.Args().Get_at(i);
|
||||
for (int i = 0; i < cmd.Args().Len(); i++) {
|
||||
KeyVal p = (KeyVal)cmd.Args().GetAt(i);
|
||||
Db_arg prm = (Db_arg)p.Val();
|
||||
row.Write(p.Key(), prm.Val);
|
||||
row.Write(p.KeyToStr(), prm.Val);
|
||||
}
|
||||
}
|
||||
public static TdbUpdateWkr new_() {TdbUpdateWkr rv = new TdbUpdateWkr(); return rv;}
|
||||
|
||||
@@ -1,28 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class Tdb_conn_info extends Db_conn_info__base {
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.dbs.*;
|
||||
import gplx.libs.files.Io_url;
|
||||
import gplx.libs.files.Io_url_;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.types.commons.KeyValHash;
|
||||
public class Tdb_conn_info extends Db_conn_info__base {
|
||||
public Tdb_conn_info(String raw, String db_api, String database, Io_url url) {super(raw, db_api, database);this.url = url; this.server = url.Raw(); }
|
||||
@Override public String Key() {return Tid_const;} public static final String Tid_const = "tdb";
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
public String Server() {return server;} private final String server;
|
||||
@Override public Db_conn_info New_self(String raw, Keyval_hash hash) {
|
||||
Io_url url = Io_url_.new_any_(hash.Get_val_as_str_or_fail("url"));
|
||||
@Override public Db_conn_info New_self(String raw, KeyValHash hash) {
|
||||
Io_url url = Io_url_.new_any_(hash.GetByValAsStrOrFail("url"));
|
||||
String db = url.NameOnly();
|
||||
String api = Bld_api(hash, Keyval_.new_("version", "3"));
|
||||
String api = Bld_api(hash, KeyVal.NewStr("version", "3"));
|
||||
return new Tdb_conn_info(raw, api, db, url);
|
||||
}
|
||||
public static Db_conn_info new_(Io_url url) {
|
||||
|
||||
@@ -13,16 +13,18 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.metas; import gplx.dbs.*;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
public class Dbmeta_fld_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Len();}
|
||||
public void Clear() {hash.Clear();}
|
||||
public void Add(DbmetaFldItm itm) {hash.Add(itm.Name(), itm);}
|
||||
public boolean Has(String name) {return hash.Has(name);}
|
||||
public DbmetaFldItm Get_at(int idx) {return (DbmetaFldItm)hash.Get_at(idx);}
|
||||
public DbmetaFldItm Get_at(int idx) {return (DbmetaFldItm)hash.GetAt(idx);}
|
||||
public DbmetaFldItm Get_by(String name) {return (DbmetaFldItm)hash.GetByOrNull(name);}
|
||||
public DbmetaFldItm[] To_ary() {return hash.Len() == 0 ? DbmetaFldItm.AryEmpty : (DbmetaFldItm[])hash.To_ary(DbmetaFldItm.class);}
|
||||
public DbmetaFldItm[] To_ary() {return hash.Len() == 0 ? DbmetaFldItm.AryEmpty : (DbmetaFldItm[])hash.ToAry(DbmetaFldItm.class);}
|
||||
public DbmetaFldList To_fld_list() {
|
||||
DbmetaFldList rv = new DbmetaFldList();
|
||||
int len = hash.Len();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user