mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
v1.9.2.1
This commit is contained in:
parent
be63adc5af
commit
a022d7f26c
@ -49,7 +49,7 @@ public class ErrMsgWtr {
|
||||
String msg = err.Hdr();
|
||||
String typ = String_.Eq(err.Key(), "") ? "" : String_.Concat(" <", err.Key(), ">");
|
||||
boolean onlyOne = errAry.length == 1;
|
||||
String idxStr = onlyOne ? "" : Int_.XtoStr(i);
|
||||
String idxStr = onlyOne ? "" : Int_.Xto_str(i);
|
||||
sb.Add(idxStr).Add("\t").Add(msg).Add(typ).Add_char_crlf(); // ex: " @count must be > 0 <gplx.arg>"
|
||||
WriteKeyValAry(sb, err.Args());
|
||||
sb.Add("\t").Add(err.Proc().SignatureRaw()).Add_char_crlf();
|
||||
@ -87,7 +87,7 @@ public class ErrMsgWtr {
|
||||
ErrProcData comp = errAry[j].Proc();
|
||||
if (String_.Eq(proc.Raw(), comp.Raw())) {idx = j; break;}
|
||||
}
|
||||
String idxStr = onlyOne ? "" : Int_.XtoStr(idx);
|
||||
String idxStr = onlyOne ? "" : Int_.Xto_str(idx);
|
||||
String hdr = idx == -1 ? "\t" : idxStr + "\t";
|
||||
String ideAddressSpr = String_.CrLf + "\t\t";
|
||||
String ideAddress = String_.Eq(proc.IdeAddress(), "") ? "" : ideAddressSpr + proc.IdeAddress(); // NOTE: ideAddress will be blank in compiled mode
|
||||
|
@ -59,7 +59,7 @@ class ErrProcData {
|
||||
int linEnd = String_.FindFwd(raw, ")", linBgn); if (linEnd == String_.Find_none) return rv;
|
||||
String linRaw = String_.Mid(raw, linBgn, linEnd);
|
||||
rv.sourceLine = Int_.parse_(linRaw);
|
||||
rv.ideAddress = String_.Concat("(", rv.sourceFileRaw, ":", Int_.XtoStr(rv.sourceLine), ")");
|
||||
rv.ideAddress = String_.Concat("(", rv.sourceFileRaw, ":", Int_.Xto_str(rv.sourceLine), ")");
|
||||
return rv;
|
||||
}
|
||||
public static ErrProcData new_() {return new ErrProcData();} ErrProcData() {}
|
||||
|
@ -19,8 +19,8 @@ package gplx;
|
||||
public class Bool_ implements GfoInvkAble {
|
||||
public static final boolean[] Ary_empty = new boolean[0];
|
||||
public static final Class<?> ClassOf = Boolean.class;
|
||||
public static int XtoInt(boolean v) {return v ? 1 : 0;}
|
||||
public static String XtoStr_lower(boolean v) {return v ? "true" : "false";}
|
||||
public static int Xto_int(boolean v) {return v ? 1 : 0;}
|
||||
public static String Xto_str_lower(boolean v) {return v ? "true" : "false";}
|
||||
public static byte Xto_byte(boolean v) {return v ? Y_byte : N_byte;}
|
||||
public static boolean cast_(Object obj) {try {return (Boolean)obj;} catch (Exception e) {throw Err_.type_mismatch_exc_(e, boolean.class, obj);}}
|
||||
public static boolean cast_or_(Object obj, boolean v) {try {return (Boolean)obj;} catch (Exception e) {Err_.Noop(e); return v;}}
|
||||
|
@ -22,7 +22,7 @@ public class Bool_obj_ref {
|
||||
public Bool_obj_ref Val_n_() {val = false; return this;}
|
||||
public Bool_obj_ref Val_(boolean v) {val = v; return this;}
|
||||
public Bool_obj_ref Val_toggle_() {val = !val; return this;}
|
||||
@Override public String toString() {return Bool_.XtoStr_lower(val);}
|
||||
@Override public String toString() {return Bool_.Xto_str_lower(val);}
|
||||
public static Bool_obj_ref n_() {return new_(false);}
|
||||
public static Bool_obj_ref y_() {return new_(true);}
|
||||
public static Bool_obj_ref new_(boolean val) {
|
||||
|
@ -19,6 +19,7 @@ package gplx;
|
||||
import java.lang.*;
|
||||
import gplx.ios.*;
|
||||
public class Bry_ {
|
||||
public static final String Cls_name = "byte[]";
|
||||
public static final int NotFound = -1;
|
||||
public static final byte[] Empty = new byte[0];
|
||||
public static final byte[][] Ary_empty = new byte[0][];
|
||||
|
@ -248,8 +248,8 @@ public class Bry_bfr {
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr Add_str(String v) {return Add(Bry_.new_utf8_(v));}
|
||||
public Bry_bfr Add_float(float f) {Add_str(Float_.XtoStr(f)); return this;}
|
||||
public Bry_bfr Add_double(double v) {Add_str(Double_.XtoStr(v)); return this;}
|
||||
public Bry_bfr Add_float(float f) {Add_str(Float_.Xto_str(f)); return this;}
|
||||
public Bry_bfr Add_double(double v) {Add_str(Double_.Xto_str(v)); return this;}
|
||||
public Bry_bfr Add_dte(DateAdp val) {return Add_dte_segs(val.Year(), val.Month(),val.Day(), val.Hour(), val.Minute(), val.Second(), val.Frac());}
|
||||
public Bry_bfr Add_dte_segs(int y, int M, int d, int H, int m, int s, int f) { // yyyyMMdd HHmmss.fff
|
||||
if (bfr_len + 19 > bfr_max) Resize((bfr_len + 19) * 2);
|
||||
|
@ -63,7 +63,7 @@ class Bry_bfr_mkr_mgr {
|
||||
for (int i = 0; i < ary_max; i++) {
|
||||
Bry_bfr itm = ary[i];
|
||||
if (itm != null) {
|
||||
if (itm.Mkr_mgr() != null) throw Err_.new_("failed to clear bfr: " + Int_.XtoStr(i));
|
||||
if (itm.Mkr_mgr() != null) throw Err_.new_("failed to clear bfr: " + Int_.Xto_str(i));
|
||||
itm.Clear();
|
||||
}
|
||||
ary[i] = null;
|
||||
|
@ -259,4 +259,5 @@ public class Bry_fmtr {
|
||||
byte[] bry = bfr.XtoAryAndClear();
|
||||
this.Fmt_(bry).Compile();
|
||||
}
|
||||
public static String Escape_tilde(String v) {return String_.Replace(v, "~", "~~");}
|
||||
}
|
||||
|
@ -53,6 +53,9 @@ public class Bry_fmtr_tst {
|
||||
Bry_fmtr_fxt fxt = new Bry_fmtr_fxt().Clear();
|
||||
fxt.Bld_bfr_many_and_set_fmt("a~{0}c", Object_.Ary("b"), "abc");
|
||||
}
|
||||
@Test public void Escape_tilde() {
|
||||
Tfds.Eq("~~~~~~", Bry_fmtr.Escape_tilde("~~~"));
|
||||
}
|
||||
}
|
||||
class Bry_fmtr_tst_mok implements Bry_fmtr_eval_mgr {
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
|
||||
|
@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
public class Byte_ {
|
||||
public static final byte MinValue = Byte.MIN_VALUE;
|
||||
public static final String Cls_name = "byte";
|
||||
public static byte[] Ary(byte... ary) {return ary;}
|
||||
public static byte[] Ary_by_ints(int... ary) {
|
||||
int ary_len = ary.length;
|
||||
@ -26,8 +27,8 @@ public class Byte_ {
|
||||
rv[i] = int_(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
public static String XtoStr(byte v) {return new Byte(v).toString();}
|
||||
public static int XtoInt(byte v) {return v < 0 ? (int)v + 256 : v;}
|
||||
public static String Xto_str(byte v) {return new Byte(v).toString();}
|
||||
public static int Xto_int(byte v) {return v < 0 ? (int)v + 256 : v;}
|
||||
public static boolean In(byte v, byte... ary) {
|
||||
for (byte itm : ary)
|
||||
if (v == itm) return true;
|
||||
|
@ -31,5 +31,5 @@ public class Byte__tst {
|
||||
tst_XtoInt( 128, 128);
|
||||
tst_XtoInt( 255, 255);
|
||||
tst_XtoInt( 256, 0);
|
||||
} void tst_XtoInt(int v, int expd) {Tfds.Eq(expd, Byte_.XtoInt((byte)v));} // WORKAROUND/JAVA: v is of type int b/c java promotes numbers to ints
|
||||
} void tst_XtoInt(int v, int expd) {Tfds.Eq(expd, Byte_.Xto_int((byte)v));} // WORKAROUND/JAVA: v is of type int b/c java promotes numbers to ints
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class Byte_obj_ref {
|
||||
public Byte_obj_ref Val_(byte v) {val = v; return this;}
|
||||
@Override public int hashCode() {return val;}
|
||||
@Override public boolean equals(Object obj) {return obj == null ? false : val == ((Byte_obj_ref)obj).Val();}
|
||||
@Override public String toString() {return Int_.XtoStr(val);}
|
||||
@Override public String toString() {return Int_.Xto_str(val);}
|
||||
public static Byte_obj_ref zero_() {return new_(Byte_.Zero);}
|
||||
public static Byte_obj_ref new_(byte val) {
|
||||
Byte_obj_ref rv = new Byte_obj_ref();
|
||||
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
public class Byte_obj_val {
|
||||
public byte Val() {return val;} private byte val;
|
||||
@Override public String toString() {return Int_.XtoStr(val);}
|
||||
@Override public String toString() {return Int_.Xto_str(val);}
|
||||
@Override public int hashCode() {return val;}
|
||||
@Override public boolean equals(Object obj) {return obj == null ? false : val == ((Byte_obj_val)obj).Val();}
|
||||
public static Byte_obj_val new_(byte val) {
|
||||
|
@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
public class Double_ {
|
||||
public static final Class<?> ClassOf = Double.class;
|
||||
public static final String Cls_name = "double";
|
||||
public static final double Inf_pos = Double.POSITIVE_INFINITY;;
|
||||
public static final double NaN = Double.NaN;;
|
||||
public static final byte[] NaN_bry = Bry_.new_ascii_("NaN");
|
||||
@ -31,15 +32,15 @@ public class Double_ {
|
||||
try {String s = String_.as_(v); return s == null ? Double_.cast_(v) : Double_.parse_(s);}
|
||||
catch (Exception e) {throw Err_.cast_(e, double.class, v);}
|
||||
}
|
||||
public static String XtoStr(double v) {
|
||||
public static String Xto_str(double v) {
|
||||
int v_int = (int)v;
|
||||
return v - v_int == 0 ? Int_.XtoStr(v_int) : Double.toString(v);
|
||||
return v - v_int == 0 ? Int_.Xto_str(v_int) : Double.toString(v);
|
||||
}
|
||||
public static String Xto_str_loose(double v) {
|
||||
int v_as_int = (int)v;
|
||||
return v == v_as_int
|
||||
? Int_.XtoStr(v_as_int) // convert to int, and call print String to eliminate any trailing decimal places
|
||||
: Float_.XtoStr((float)v); // calling ((float)v).toString is better at removing trailing 0s than String.format("%g", v). note that .net .toString() handles it better; EX:2449.600000000000d; DATE:2014-07-29
|
||||
? Int_.Xto_str(v_as_int) // convert to int, and call print String to eliminate any trailing decimal places
|
||||
: Float_.Xto_str((float)v); // calling ((float)v).toString is better at removing trailing 0s than String.format("%g", v). note that .net .toString() handles it better; EX:2449.600000000000d; DATE:2014-07-29
|
||||
}
|
||||
public static double cast_(Object o) {try {return (Double)o;} catch(Exception e) {throw Err_.type_mismatch_exc_(e, double.class, o);}}
|
||||
public static double parse_(String raw) {try {return Double.parseDouble(raw);} catch(Exception e) {throw Err_.parse_type_exc_(e, double.class, raw);}}
|
||||
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
public class Double_obj_val implements CompareAble {
|
||||
public double Val() {return val;} double val;
|
||||
@Override public String toString() {return Double_.XtoStr(val);}
|
||||
@Override public String toString() {return Double_.Xto_str(val);}
|
||||
@Override public int hashCode() {return (int)val;}
|
||||
@Override public boolean equals(Object obj) {return obj == null ? false : val == ((Double_obj_val)obj).Val();}
|
||||
public int compareTo(Object obj) {Double_obj_val comp = (Double_obj_val)obj; return Double_.Compare(val, comp.val);}
|
||||
|
@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
public class Float_ {
|
||||
public static final String Cls_name = "float";
|
||||
public static final float NaN = Float.NaN;;
|
||||
public static boolean IsNaN(float v) {return Float.isNaN(v);}
|
||||
public static int RoundUp(float val) {
|
||||
@ -25,9 +26,9 @@ public class Float_ {
|
||||
}
|
||||
public static float Div(int val, int divisor) {return (float)val / (float)divisor;}
|
||||
public static float Div(long val, long divisor) {return (float)val / (float)divisor;}
|
||||
public static String XtoStr(float v) {
|
||||
public static String Xto_str(float v) {
|
||||
int v_int = (int)v;
|
||||
return v - v_int == 0 ? Int_.XtoStr(v_int) : Float.toString(v);
|
||||
return v - v_int == 0 ? Int_.Xto_str(v_int) : Float.toString(v);
|
||||
}
|
||||
public static float cast_double_(double v) {return (float)v;}
|
||||
public static float cast_(Object obj) {try {return (Float)obj;} catch(Exception exc) {throw Err_.type_mismatch_exc_(exc, float.class, obj);}}
|
||||
|
@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
public class Int_ implements GfoInvkAble {
|
||||
public static final Class<?> ClassOf = Integer.class;
|
||||
public static final String Cls_name = "int";
|
||||
public static final int Base1 = 1;
|
||||
public static final int Const_dlm_len = 1;
|
||||
public static final int Const_position_after_char = 1;
|
||||
@ -132,11 +133,11 @@ public class Int_ implements GfoInvkAble {
|
||||
if (val < 0) throw Err_.new_("key must be >= 0").Add("key", key).Add("val", val);
|
||||
return this;
|
||||
}
|
||||
public static String XtoStr_PadBgn_space(int v, int reqdPlaces) {return Xto_str_pad_bgn(v, reqdPlaces, Byte_ascii.Space, true);} // EX: 1, 3 returns " 1"
|
||||
public static String XtoStr_PadBgn(int v, int reqdPlaces) {return Xto_str_pad_bgn(v, reqdPlaces, Byte_ascii.Num_0, true);} // EX: 1, 3 returns "001"
|
||||
public static String Xto_str_pad_bgn_space(int v, int reqdPlaces) {return Xto_str_pad_bgn(v, reqdPlaces, Byte_ascii.Space, true);} // EX: 1, 3 returns " 1"
|
||||
public static String Xto_str_pad_bgn(int v, int reqdPlaces) {return Xto_str_pad_bgn(v, reqdPlaces, Byte_ascii.Num_0, true);} // EX: 1, 3 returns "001"
|
||||
static String Xto_str_pad_bgn(int val, int places, byte pad_chr, boolean bgn) {
|
||||
int len = DigitCount(val);
|
||||
int pad_len = places - len; if (pad_len < 0) return Int_.XtoStr(val);
|
||||
int pad_len = places - len; if (pad_len < 0) return Int_.Xto_str(val);
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
boolean neg = val < 0;
|
||||
if (bgn) { // special logic to handle negative numbers; EX: -1 -> "-001", not "00-1"
|
||||
@ -157,13 +158,13 @@ public class Int_ implements GfoInvkAble {
|
||||
public static int cast_(Object obj) {try {return (Integer)obj;} catch(Exception exc) {throw Err_.type_mismatch_exc_(exc, int.class, obj);}}
|
||||
public static int cast_or_(Object obj, int or) {try {return (Integer)obj;} catch(Exception e) {Err_.Noop(e); return or;}}
|
||||
public static int Xby_double_(double v) {return (int)v;}
|
||||
public static String XtoStr(int v) {return new Integer(v).toString();}
|
||||
public static String XtoStr_fmt(int v, String fmt) {return new java.text.DecimalFormat(fmt).format(v);}
|
||||
public static String Xto_str(int v) {return new Integer(v).toString();}
|
||||
public static String Xto_str_fmt(int v, String fmt) {return new java.text.DecimalFormat(fmt).format(v);}
|
||||
public static boolean TypeMatch(Class<?> type) {return type == int.class || type == Integer.class;}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_XtoStr_PadBgn)) {
|
||||
int v = m.ReadInt(GfsCore_.Arg_primitive), pad = m.ReadInt("pad");
|
||||
return ctx.Deny() ? (Object)this : XtoStr_PadBgn(v, pad);
|
||||
return ctx.Deny() ? (Object)this : Xto_str_pad_bgn(v, pad);
|
||||
}
|
||||
else if (ctx.Match(k, "Add")) {
|
||||
int v = m.ReadInt(GfsCore_.Arg_primitive), operand = m.ReadInt("operand");
|
||||
@ -196,16 +197,16 @@ public class Int_ implements GfoInvkAble {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
public static String XtoStr_hex(int v) {
|
||||
public static String Xto_str_hex(int v) {
|
||||
String rv = Integer.toHexString(v);
|
||||
int rvLen = String_.Len(rv);
|
||||
if (rvLen < 8) rv = String_.Repeat("0", 8 - rvLen) + rv;
|
||||
return String_.Upper(rv);
|
||||
}
|
||||
public static String XtoStr(int[] ary) {
|
||||
public static String Xto_str(int[] ary) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int i = 0; i < ary.length; i++)
|
||||
sb.Add_spr_unless_first(Int_.XtoStr(ary[i]), " ", i);
|
||||
sb.Add_spr_unless_first(Int_.Xto_str(ary[i]), " ", i);
|
||||
return sb.XtoStr();
|
||||
}
|
||||
public static int[] Ary_parse(String raw_str, int reqd_len, int[] or) {
|
||||
|
@ -26,7 +26,7 @@ public class Int__tst {
|
||||
tst_XtoStr_PadLeft_Zeroes(-12 , 3, "-12"); // negative
|
||||
tst_XtoStr_PadLeft_Zeroes(-123 , 3, "-123"); // negative
|
||||
tst_XtoStr_PadLeft_Zeroes(-1234 , 3, "-1234"); // negative
|
||||
} void tst_XtoStr_PadLeft_Zeroes(int val, int zeros, String expd) {Tfds.Eq(expd, Int_.XtoStr_PadBgn(val, zeros));}
|
||||
} void tst_XtoStr_PadLeft_Zeroes(int val, int zeros, String expd) {Tfds.Eq(expd, Int_.Xto_str_pad_bgn(val, zeros));}
|
||||
@Test public void parseOr_() {
|
||||
tst_ParseOr("", -1); // empty
|
||||
tst_ParseOr("123", 123); // single
|
||||
@ -41,7 +41,7 @@ public class Int__tst {
|
||||
@Test public void Xto_fmt() {
|
||||
tst_XtoStr_fmt(1, "1");
|
||||
tst_XtoStr_fmt(1000, "1,000");
|
||||
} void tst_XtoStr_fmt(int v, String expd) {Tfds.Eq(expd, Int_.XtoStr_fmt(v, "#,###"));}
|
||||
} void tst_XtoStr_fmt(int v, String expd) {Tfds.Eq(expd, Int_.Xto_str_fmt(v, "#,###"));}
|
||||
@Test public void AryRng() {
|
||||
tst_AryRng(1, 3, Int_.Ary(1, 2, 3));
|
||||
} void tst_AryRng(int bgn, int end, int[] expd) {Tfds.Eq_ary(expd, Int_.AryRng(bgn, end));}
|
||||
@ -71,7 +71,7 @@ public class Int__tst {
|
||||
tst_DigitCount(100, 3);
|
||||
tst_DigitCount(-1, 2);
|
||||
tst_DigitCount(-100, 4);
|
||||
} void tst_DigitCount(int val, int expd) {Tfds.Eq(expd, Int_.DigitCount(val), Int_.XtoStr(val));}
|
||||
} void tst_DigitCount(int val, int expd) {Tfds.Eq(expd, Int_.DigitCount(val), Int_.Xto_str(val));}
|
||||
@Test public void Log10() {
|
||||
tst_Log10( 0, 0);
|
||||
tst_Log10( 1, 0);
|
||||
@ -104,8 +104,8 @@ public class Int__tst {
|
||||
Ary_parse__tst("123,321,213" , 3, Int_.Ary_empty, 123, 321, 213);
|
||||
Ary_parse__tst(" 1, 2,3" , 3, Int_.Ary_empty, 1, 2, 3);
|
||||
Ary_parse__tst("-1,+2,-3" , 3, Int_.Ary_empty, -1, 2, -3);
|
||||
Ary_parse__tst(Int_.XtoStr(Int_.MinValue) , 1, Int_.Ary_empty, Int_.MinValue);
|
||||
Ary_parse__tst(Int_.XtoStr(Int_.MaxValue) , 1, Int_.Ary_empty, Int_.MaxValue);
|
||||
Ary_parse__tst(Int_.Xto_str(Int_.MinValue) , 1, Int_.Ary_empty, Int_.MinValue);
|
||||
Ary_parse__tst(Int_.Xto_str(Int_.MaxValue) , 1, Int_.Ary_empty, Int_.MaxValue);
|
||||
Ary_parse__tst("1,2" , 1, Int_.Ary_empty);
|
||||
Ary_parse__tst("1" , 2, Int_.Ary_empty);
|
||||
Ary_parse__tst("a" , 1, Int_.Ary_empty);
|
||||
|
@ -23,7 +23,7 @@ public class Int_obj_ref {
|
||||
public int Val_add(int v) {val += v; return val;}
|
||||
public Int_obj_ref Val_zero_() {val = 0; return this;}
|
||||
public Int_obj_ref Val_neg1_() {val = -1; return this;}
|
||||
@Override public String toString() {return Int_.XtoStr(val);}
|
||||
@Override public String toString() {return Int_.Xto_str(val);}
|
||||
@Override public int hashCode() {return val;}
|
||||
@Override public boolean equals(Object obj) {return val == ((Int_obj_ref)obj).Val();}
|
||||
public static Int_obj_ref neg1_() {return new_(-1);}
|
||||
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
public class Int_obj_val implements CompareAble {
|
||||
public int Val() {return val;} int val;
|
||||
@Override public String toString() {return Int_.XtoStr(val);}
|
||||
@Override public String toString() {return Int_.Xto_str(val);}
|
||||
@Override public int hashCode() {return val;}
|
||||
@Override public boolean equals(Object obj) {return obj == null ? false : val == ((Int_obj_val)obj).Val();}
|
||||
public int compareTo(Object obj) {Int_obj_val comp = (Int_obj_val)obj; return Int_.Compare(val, comp.val);}
|
||||
|
@ -19,6 +19,7 @@ package gplx;
|
||||
public class Long_ {
|
||||
public static final long MinValue = Long.MIN_VALUE;
|
||||
public static final long MaxValue = Long.MAX_VALUE;
|
||||
public static final String Cls_name = "long";
|
||||
public static final long Neg1 = -1;
|
||||
public static final int Log10Ary_len = 21;
|
||||
public static long[] Log10Ary = new long[]
|
||||
@ -28,8 +29,8 @@ public class Long_ {
|
||||
, Long_.Pow(10, 15), Long_.Pow(10, 16), Long_.Pow(10, 17), Long_.Pow(10, 18), Long_.Pow(10, 19)
|
||||
, Long_.MaxValue
|
||||
};
|
||||
public static String XtoStr(long v) {return Long.toString(v);}
|
||||
public static String XtoStr_PadBgn(long v, int reqdPlaces) {return String_.Pad(XtoStr(v), reqdPlaces, "0", true);} // ex: 1, 3 returns 001
|
||||
public static String Xto_str(long v) {return Long.toString(v);}
|
||||
public static String Xto_str_PadBgn(long v, int reqdPlaces) {return String_.Pad(Xto_str(v), reqdPlaces, "0", true);} // ex: 1, 3 returns 001
|
||||
public static long parse_or_(String raw, int or) {
|
||||
if (raw == null) return or;
|
||||
try {
|
||||
|
@ -19,6 +19,7 @@ package gplx;
|
||||
import java.lang.*;
|
||||
public class String_ implements GfoInvkAble {
|
||||
public static final Class<?> ClassOf = String.class;
|
||||
public static final String Cls_name = "str" + "ing";
|
||||
public static final int Find_none = -1, Pos_neg1 = -1;
|
||||
public static final String Null = null, Empty = "", Null_mark = "<<NULL>>", Tab = "\t", Lf = "\n", CrLf = "\r\n";
|
||||
public static String cast_(Object v) {return (String)v;}
|
||||
|
@ -25,21 +25,21 @@ public class DecimalAdp implements CompareAble {
|
||||
|
||||
protected DecimalAdp(BigDecimal v) {this.under = v;} BigDecimal under;
|
||||
protected DecimalAdp(int v) {this.under = new BigDecimal(v);}
|
||||
public String XtoStr() {
|
||||
public String Xto_str() {
|
||||
BigDecimal tmp = under;
|
||||
if (tmp.scale() > 14) tmp = tmp.setScale(14, RoundingMode.DOWN); // NOTE: setting to 14 to match PHP/C# values more closely; RoundingMode.Down for same reason; see E, Pi tests
|
||||
return tmp .stripTrailingZeros() // NOTE: stripTrailingZeros for exp tests; EX: 120.0 -> 120; 0.01200000000000 -> .012
|
||||
.toPlainString(); // NOTE: toPlainString b/c stripTrailingZeros now converts 120 to 1.2E+2 (and any other value that is a multiple of 10)
|
||||
}
|
||||
public String XtoStr(String fmt) {return new DecimalFormat(fmt).format(under);}
|
||||
public String Xto_str(String fmt) {return new DecimalFormat(fmt).format(under);}
|
||||
@Override public String toString() {return under.toString();}
|
||||
public boolean Eq(DecimalAdp v) {return v.under.doubleValue() == under.doubleValue();}
|
||||
public BigDecimal XtoDecimal() {return under;}
|
||||
public long XtoLong_Mult1000() {return under.movePointRight(3).longValue();}
|
||||
public BigDecimal Xto_decimal() {return under;}
|
||||
public long Xto_long_mult_1000() {return under.movePointRight(3).longValue();}
|
||||
public int Fraction1000() {return (int)(under.movePointRight(3).floatValue() % 1000);}
|
||||
public double XtoDouble() {return under.doubleValue();}
|
||||
public int XtoInt() {return (int)under.doubleValue();}
|
||||
public long XtoLong() {return (long)under.doubleValue();}
|
||||
public double Xto_double() {return under.doubleValue();}
|
||||
public int Xto_int() {return (int)under.doubleValue();}
|
||||
public long Xto_long() {return (long)under.doubleValue();}
|
||||
public DecimalAdp Op_add(DecimalAdp v) {return new DecimalAdp(under.add(v.under, DecimalAdp_.Gplx_rounding_context));}
|
||||
public DecimalAdp Op_subtract(DecimalAdp v) {return new DecimalAdp(under.subtract(v.under, DecimalAdp_.Gplx_rounding_context));}
|
||||
public DecimalAdp Op_mult(DecimalAdp v) {return new DecimalAdp(under.multiply(v.under));}
|
||||
|
@ -46,7 +46,7 @@ import java.math.BigDecimal;
import java.math.MathContext;
import java.math.Roun
|
||||
}
|
||||
public static String CalcPctStr(long dividend, long divisor, String fmt) {
|
||||
if (divisor == 0) return "%ERR";
|
||||
return DecimalAdp_.float_(Float_.Div(dividend, divisor) * 100).XtoStr(fmt) + "%";
|
||||
return DecimalAdp_.float_(Float_.Div(dividend, divisor) * 100).Xto_str(fmt) + "%";
|
||||
}
|
||||
public static DecimalAdp divide_safe_(long lhs, long rhs) {return rhs == 0 ? Zero : divide_(lhs, rhs);}
|
||||
public static DecimalAdp divide_(long lhs, long rhs) {
return new DecimalAdp(new BigDecimal(lhs).divide(new BigDecimal(rhs), Gplx_rounding_context));
}
public static DecimalAdp int_(int v) {return new DecimalAdp(new BigDecimal(v));}
public static DecimalAdp long_(long v) {return new DecimalAdp(new BigDecimal(v));}
|
||||
|
@ -22,28 +22,28 @@ public class DecimalAdp__tst {
|
||||
tst_divide_(1, 1000, "0.001");
|
||||
tst_divide_(1, 3, "0.33333333333333");
|
||||
tst_divide_(1, 7, "0.14285714285714");
|
||||
} void tst_divide_(int lhs, int rhs, String expd) {Tfds.Eq(expd, DecimalAdp_.divide_(lhs, rhs).XtoStr());}
|
||||
} void tst_divide_(int lhs, int rhs, String expd) {Tfds.Eq(expd, DecimalAdp_.divide_(lhs, rhs).Xto_str());}
|
||||
@Test public void base1000_() {
|
||||
tst_base1000_(1000, "1");
|
||||
tst_base1000_(1234, "1.234");
|
||||
tst_base1000_(123, "0.123");
|
||||
} void tst_base1000_(int val, String expd) {Tfds.Eq(expd, DecimalAdp_.base1000_(val).XtoStr());}
|
||||
} void tst_base1000_(int val, String expd) {Tfds.Eq(expd, DecimalAdp_.base1000_(val).Xto_str());}
|
||||
@Test public void parts_() {
|
||||
tst_parts_(1, 0, "1");
|
||||
tst_parts_(1, 2, "1.2");
|
||||
tst_parts_(1, 23, "1.23");
|
||||
tst_parts_(123, 4567, "123.4567");
|
||||
} void tst_parts_(int num, int fracs, String expd) {Tfds.Eq(expd, DecimalAdp_.parts_(num, fracs).XtoStr());}
|
||||
} void tst_parts_(int num, int fracs, String expd) {Tfds.Eq(expd, DecimalAdp_.parts_(num, fracs).Xto_str());}
|
||||
@Test public void parse_() {
|
||||
tst_parse_("1", "1");
|
||||
tst_parse_("1.2", "1.2");
|
||||
tst_parse_("0.1", "0.1");
|
||||
} void tst_parse_(String raw, String expd) {Tfds.Eq(expd, DecimalAdp_.parse_(raw).XtoStr());}
|
||||
} void tst_parse_(String raw, String expd) {Tfds.Eq(expd, DecimalAdp_.parse_(raw).Xto_str());}
|
||||
@Test public void Truncate_decimal() {
|
||||
tst_Truncate_decimal("1", "1");
|
||||
tst_Truncate_decimal("1.1", "1");
|
||||
tst_Truncate_decimal("1.9", "1");
|
||||
} void tst_Truncate_decimal(String raw, String expd) {Tfds.Eq(DecimalAdp_.parse_(expd).XtoStr(), DecimalAdp_.parse_(raw).Op_truncate_decimal().XtoStr());}
|
||||
} void tst_Truncate_decimal(String raw, String expd) {Tfds.Eq(DecimalAdp_.parse_(expd).Xto_str(), DecimalAdp_.parse_(raw).Op_truncate_decimal().Xto_str());}
|
||||
@Test public void Fraction1000() {
|
||||
tst_Fraction1000(1, 1000, 1); // 0.001
|
||||
tst_Fraction1000(1, 3, 333); // 0.33333333
|
||||
@ -58,5 +58,5 @@ public class DecimalAdp__tst {
|
||||
tst_XtoStr_fmt(1, 2, "0.0", "0.5");
|
||||
tst_XtoStr_fmt(1, 3, "0.0", "0.3");
|
||||
tst_XtoStr_fmt(10000, 7, "0,000.000", "1,428.571");
|
||||
} void tst_XtoStr_fmt(int l, int r, String fmt, String expd) {Tfds.Eq(expd, DecimalAdp_.divide_(l, r).XtoStr(fmt));}
|
||||
} void tst_XtoStr_fmt(int l, int r, String fmt, String expd) {Tfds.Eq(expd, DecimalAdp_.divide_(l, r).Xto_str(fmt));}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class TimeSpanAdp implements CompareAble, EqAble {
|
||||
case 1: return "s";
|
||||
case 2: return "m";
|
||||
case 3: return "h";
|
||||
default: return "unknown:<" + Int_.XtoStr(i) + ">";
|
||||
default: return "unknown:<" + Int_.Xto_str(i) + ">";
|
||||
}
|
||||
}
|
||||
@gplx.Internal protected TimeSpanAdp(long fracs) {this.fracs = fracs;}
|
||||
|
@ -25,7 +25,7 @@ public class TimeSpanAdp_ {
|
||||
return new TimeSpanAdp(fracs);
|
||||
}
|
||||
public static TimeSpanAdp decimal_(DecimalAdp seconds) {
|
||||
return new TimeSpanAdp(seconds.XtoLong_Mult1000());
|
||||
return new TimeSpanAdp(seconds.Xto_long_mult_1000());
|
||||
}
|
||||
public static TimeSpanAdp units_(int frc, int sec, int min, int hour) {
|
||||
int[] units = new int[] {frc, sec, min, hour};
|
||||
@ -92,7 +92,7 @@ public class TimeSpanAdp_ {
|
||||
sb.Add(Sprs[i]);
|
||||
if (val < 10) // zeroPad
|
||||
sb.Add("0");
|
||||
sb.Add(Int_.XtoStr(val));
|
||||
sb.Add(Int_.Xto_str(val));
|
||||
}
|
||||
return sb.XtoStrAndClear();
|
||||
}
|
||||
@ -115,7 +115,7 @@ public class TimeSpanAdp_ {
|
||||
zeros = first && !fmt_padZeros ? 1 : padZerosAry[i]; // if first, don't zero pad (avoid "01")
|
||||
dlm = first ? "" : Sprs[i]; // if first, don't use dlm (avoid ":01")
|
||||
sb.Add(dlm);
|
||||
sb.Add(Int_.XtoStr_PadBgn(val, zeros));
|
||||
sb.Add(Int_.Xto_str_pad_bgn(val, zeros));
|
||||
first = false;
|
||||
}
|
||||
return sb.XtoStr();
|
||||
|
@ -39,7 +39,7 @@ class Criteria_or extends Criteria_bool_base {
|
||||
class Criteria_const implements Criteria {
|
||||
public byte Crt_tid() {return Criteria_.Tid_const;}
|
||||
public boolean Matches(Object comp) {return val;} private boolean val;
|
||||
public String XtoStr() {return String_.Concat(" IS ", Bool_.XtoStr_lower(val));}
|
||||
public String XtoStr() {return String_.Concat(" IS ", Bool_.Xto_str_lower(val));}
|
||||
public Criteria_const(boolean val) {this.val = val;}
|
||||
}
|
||||
class Criteria_not implements Criteria {
|
||||
|
@ -118,7 +118,7 @@ public class ListAdp_tst {
|
||||
list_AddMany("0", "1", "2");
|
||||
for (Object valObj : list) {
|
||||
String val = (String)valObj;
|
||||
Tfds.Eq(Int_.XtoStr(pos++), val);
|
||||
Tfds.Eq(Int_.Xto_str(pos++), val);
|
||||
tst_Enumerator("0", "1", "2");
|
||||
}
|
||||
}
|
||||
|
@ -62,9 +62,9 @@ public class OrderedHash_base extends HashAdp_base implements OrderedHash, GfoIn
|
||||
public String XtoStr_ui() {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
int count = ordered.Count();
|
||||
int pad = String_.Len(Int_.XtoStr(count));
|
||||
int pad = String_.Len(Int_.Xto_str(count));
|
||||
for (int i = 0; i < count; i++) {
|
||||
sb .Add(Int_.XtoStr_PadBgn(i, pad))
|
||||
sb .Add(Int_.Xto_str_pad_bgn(i, pad))
|
||||
.Add(":").Add(ordered.FetchAt(i).toString())
|
||||
.Add(Op_sys.Cur().Nl_str());
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public class HexDecUtl {
|
||||
case 0: return '0'; case 1: return '1'; case 2: return '2'; case 3: return '3'; case 4: return '4';
|
||||
case 5: return '5'; case 6: return '6'; case 7: return '7'; case 8: return '8'; case 9: return '9';
|
||||
case 10: return 'A'; case 11: return 'B'; case 12: return 'C'; case 13: return 'D'; case 14: return 'E'; case 15: return 'F';
|
||||
default: throw Err_.parse_("hexstring", Int_.XtoStr(val));
|
||||
default: throw Err_.parse_("hexstring", Int_.Xto_str(val));
|
||||
}
|
||||
}
|
||||
static byte Xto_byte(int v) {
|
||||
@ -82,7 +82,7 @@ public class HexDecUtl {
|
||||
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3; case 4: return Byte_ascii.Num_4;
|
||||
case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7; case 8: return Byte_ascii.Num_8; case 9: return Byte_ascii.Num_9;
|
||||
case 10: return Byte_ascii.Ltr_A; case 11: return Byte_ascii.Ltr_B; case 12: return Byte_ascii.Ltr_C; case 13: return Byte_ascii.Ltr_D; case 14: return Byte_ascii.Ltr_E; case 15: return Byte_ascii.Ltr_F;
|
||||
default: throw Err_.parse_("hexstring", Int_.XtoStr(v));
|
||||
default: throw Err_.parse_("hexstring", Int_.Xto_str(v));
|
||||
}
|
||||
}
|
||||
public static void Write(byte[] bry, int bgn, int end, int val) {
|
||||
|
@ -52,7 +52,11 @@ public class RegxAdp {
|
||||
if (match.Rslt_none()) break;
|
||||
rv.Add(match);
|
||||
int find_bgn = match.Find_bgn();
|
||||
idx = find_bgn + match.Find_len();
|
||||
int find_len = match.Find_len();
|
||||
idx = find_len == 0 // find_bgn == find_end
|
||||
? find_bgn + 1 // add 1 to resume search from next char; DATE:2014-09-02
|
||||
: find_bgn + find_len // otherwise search after find_end
|
||||
;
|
||||
}
|
||||
return (RegxMatch[])rv.XtoAry(RegxMatch.class);
|
||||
}
|
||||
|
@ -26,7 +26,8 @@ public class RegxAdp__tst implements TfdsEqListItmStr {
|
||||
tst_Match("[^a]", "b", true); // charSet_negate
|
||||
} void tst_Match(String find, String input, boolean expd) {Tfds.Eq(expd, RegxAdp_.Match(input, find));}
|
||||
@Test public void Match_all() {
|
||||
tst_Match_all("#REDIRECT [[Template:Error]]", "^\\p{Nd}*", 0); // handle match = true but len = 0 DATE:2013-04-10
|
||||
tst_Match_all("#REDIRECT [[Template:Error]]", "^\\p{Nd}*", 1); // handle match = true but len = 0; DATE:2013-04-11
|
||||
tst_Match_all("a", "$", 1); // $ should match once, not zero; DATE:2014-09-02
|
||||
} void tst_Match_all(String input, String regx, int expd) {Tfds.Eq(expd, RegxAdp_.new_(regx).Match_all(input, 0).length);}
|
||||
@Test public void Replace() {
|
||||
tst_Replace("ab", "a", "b", "bb"); // basic
|
||||
|
@ -19,7 +19,7 @@ package gplx.texts; import gplx.*;
|
||||
public class RegxMatch {
|
||||
public RegxMatch(boolean rslt, int find_bgn, int find_end, RegxGroup[] groups) {this.rslt = rslt; this.find_bgn = find_bgn; this.find_end = find_end; this.groups = groups;}
|
||||
public boolean Rslt() {return rslt;} private boolean rslt;
|
||||
public boolean Rslt_none() {return !rslt || (find_end - find_bgn) == 0;} // NOTE: find_end - find_bgn == 0 means find.length == 0; treating these as failed match, even thought matcher.find = true; DATE:2013-04-10
|
||||
public boolean Rslt_none() {return !rslt;} // NOTE: was "|| find_end - find_bgn == 0"; DATE:2013-04-11; DATE:2014-09-02
|
||||
public int Find_bgn() {return find_bgn;} int find_bgn;
|
||||
public int Find_end() {return find_end;} int find_end;
|
||||
public int Find_len() {return find_end - find_bgn;}
|
||||
|
@ -159,7 +159,7 @@ class HashDlgWtrDefault implements HashDlgWtr {
|
||||
current += increment;
|
||||
int percentage = (current * 100) / total;
|
||||
if (percentage <= lastPercentage) return;
|
||||
dialog.WriteTempText(String_.LimitToFirst(p, dialog.CharsPerLineMax()) + Int_.XtoStr(percentage) + "%");
|
||||
dialog.WriteTempText(String_.LimitToFirst(p, dialog.CharsPerLineMax()) + Int_.Xto_str(percentage) + "%");
|
||||
lastPercentage = percentage;
|
||||
}
|
||||
public void End() {}
|
||||
|
@ -26,7 +26,7 @@ public class Io_size_ {
|
||||
long div = (long)Math_.Pow((long)1024, (long)pow);
|
||||
DecimalAdp valDecimal = DecimalAdp_.divide_(val, div);
|
||||
String[] unit = Io_size_.Units[pow];
|
||||
return valDecimal.XtoStr("#,###.000") + " " + String_.PadBgn(unit[0], 2, " ");
|
||||
return valDecimal.Xto_str("#,###.000") + " " + String_.PadBgn(unit[0], 2, " ");
|
||||
}
|
||||
public static long parse_or_(String raw, long or) {
|
||||
if (raw == null || raw == String_.Empty) return or;
|
||||
@ -48,7 +48,7 @@ public class Io_size_ {
|
||||
}
|
||||
DecimalAdp comp = val.Op_truncate_decimal();
|
||||
if (!val.Eq(comp)) return or;
|
||||
return val.XtoLong();
|
||||
return val.Xto_long();
|
||||
}
|
||||
static int parse_unitPow_(String unitStr) {
|
||||
int unitLen = Array_.Len(Units);
|
||||
@ -104,7 +104,7 @@ class Io_size_fmtr_arg implements Bry_fmtr_arg {
|
||||
}
|
||||
long div = (long)Math_.Pow((long)1024, (long)pow);
|
||||
DecimalAdp val_decimal = DecimalAdp_.divide_(val, div);
|
||||
bfr.Add_str(val_decimal.XtoStr("#,###.000")).Add_byte(Byte_ascii.Space).Add(gplx.ios.Io_size_.Units_bry[pow]);
|
||||
bfr.Add_str(val_decimal.Xto_str("#,###.000")).Add_byte(Byte_ascii.Space).Add(gplx.ios.Io_size_.Units_bry[pow]);
|
||||
if (suffix != null)
|
||||
bfr.Add(suffix);
|
||||
}
|
||||
|
@ -22,6 +22,6 @@ public class DecimalAdpClassXtn extends ClassXtn_base implements ClassXtn {
|
||||
public Object DefaultValue() {return 0;}
|
||||
public boolean Eq(Object lhs, Object rhs) {try {return DecimalAdp_.cast_(lhs).Eq(DecimalAdp_.cast_(rhs));} catch (Exception e) {Err_.Noop(e); return false;}}
|
||||
@Override public Object ParseOrNull(String raw) {return DecimalAdp_.parse_(raw);}
|
||||
@Override public String XtoUi(Object obj, String fmt) {return DecimalAdp_.cast_(obj).XtoStr();}
|
||||
@Override public String XtoUi(Object obj, String fmt) {return DecimalAdp_.cast_(obj).Xto_str();}
|
||||
public static final DecimalAdpClassXtn _ = new DecimalAdpClassXtn(); DecimalAdpClassXtn() {} // added to ClassXtnPool by default
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class GfoNdeFxt {
|
||||
static GfoFldList GfoFldList_by_count_(int count) {
|
||||
GfoFldList rv = GfoFldList_.new_();
|
||||
for (int i = 0; i < count; i++)
|
||||
rv.Add("fld" + Int_.XtoStr(i), StringClassXtn._);
|
||||
rv.Add("fld" + Int_.Xto_str(i), StringClassXtn._);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ class XtoStrWkr_gplx implements XtoStrWkr {
|
||||
Class<?> type = ClassAdp_.ClassOf_obj(o);
|
||||
String rv = null;
|
||||
if (type == String.class) rv = String_.cast_(o);
|
||||
else if (Int_.TypeMatch(type)) return Int_.XtoStr(Int_.cast_(o));
|
||||
else if (Int_.TypeMatch(type)) return Int_.Xto_str(Int_.cast_(o));
|
||||
else if (Bool_.TypeMatch(type)) return Yn.Xto_str(Bool_.cast_(o));
|
||||
else if (type == DateAdp.class) return DateAdp_.cast_(o).XtoStr_gplx();
|
||||
else rv = Object_.Xto_str_strict_or_empty(o);
|
||||
|
@ -44,7 +44,7 @@ public abstract class DataWtr_base implements SrlMgr {
|
||||
public long SrlLongOr(String key, long or) {WriteData(key, or); return or;}
|
||||
public String SrlStrOr(String key, String or) {WriteData(key, or); return or;}
|
||||
public DateAdp SrlDateOr(String key, DateAdp or) {WriteData(key, or.XtoStr_gplx()); return or;}
|
||||
public DecimalAdp SrlDecimalOr(String key, DecimalAdp or) {WriteData(key, or.XtoDecimal()); return or;}
|
||||
public DecimalAdp SrlDecimalOr(String key, DecimalAdp or) {WriteData(key, or.Xto_decimal()); return or;}
|
||||
public double SrlDoubleOr(String key, double or) {WriteData(key, or); return or;}
|
||||
public Object SrlObjOr(String key, Object or) {throw Err_.not_implemented_();}
|
||||
public void TypeKey_(String v) {}
|
||||
|
@ -24,7 +24,7 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
|
||||
public static void Eq_byte(byte expd, byte actl) {Eq_wkr(expd, actl, true, EmptyStr);}
|
||||
public static void Eq_long(long expd, long actl) {Eq_wkr(expd, actl, true, EmptyStr);}
|
||||
public static void Eq_float(float expd, float actl) {Eq_wkr(expd, actl, true, EmptyStr);}
|
||||
public static void Eq_decimal(DecimalAdp expd, DecimalAdp actl) {Eq_wkr(expd.XtoDouble(), actl.XtoDouble(), true, EmptyStr);}
|
||||
public static void Eq_decimal(DecimalAdp expd, DecimalAdp actl) {Eq_wkr(expd.Xto_double(), actl.Xto_double(), true, EmptyStr);}
|
||||
public static void Eq_date(DateAdp expd, DateAdp actl) {Eq_wkr(expd.XtoStr_gplx(), actl.XtoStr_gplx(), true, EmptyStr);}
|
||||
public static void Eq_date(DateAdp expd, DateAdp actl, String fmt, Object... args){Eq_wkr(expd.XtoStr_gplx(), actl.XtoStr_gplx(), true, String_.Format(fmt, args));}
|
||||
public static void Eq_url(Io_url expd, Io_url actl) {Eq_wkr(expd.Raw(), actl.Raw(), true, EmptyStr);}
|
||||
@ -206,14 +206,14 @@ class TfdsMsgBldr {
|
||||
for (int i = 0; i < list.Count(); i++) {
|
||||
TfdsEqAryItm itm = (TfdsEqAryItm)list.FetchAt(i);
|
||||
sb.Add_fmt_line("{0}: {1} {2} {3}"
|
||||
, Int_.XtoStr_PadBgn(itm.Idx(), 4)
|
||||
, Int_.Xto_str_pad_bgn(itm.Idx(), 4)
|
||||
, String_.PadBgn(itm.Lhs(), lhsLenMax, " ")
|
||||
, itm.Eq() ? "==" : "!="
|
||||
, String_.PadBgn(itm.Rhs(), rhsLenMax, " ")
|
||||
);
|
||||
}
|
||||
// String compSym = isEq ? " " : "!=";
|
||||
// String result = String_.Format("{0}: {1}{2} {3} {4}", Int_.XtoStr_PadBgn(i, 4), lhsString, String_.CrLf + "\t\t", compSym, rhsString);
|
||||
// String result = String_.Format("{0}: {1}{2} {3} {4}", Int_.Xto_str_pad_bgn(i, 4), lhsString, String_.CrLf + "\t\t", compSym, rhsString);
|
||||
// foreach (Object obj in list) {
|
||||
// String itmComparison = (String)obj;
|
||||
// sb.Add_fmt_line("{0}{1}", "\t\t", itmComparison);
|
||||
|
@ -41,8 +41,8 @@ public class HierStrBldr {
|
||||
multipleAry[i] = (idx / multiple) * multiple; // NOTE: rounds down to multiple; EX: 11 -> 10
|
||||
}
|
||||
for (int i = 0; i < multipleAry.length; i++)
|
||||
sb.Add_fmt(dirFmt, Int_.XtoStr_fmt(multipleAry[i], numFmt));
|
||||
sb.Add_fmt(filFmt, Int_.XtoStr_fmt(idx, numFmt));
|
||||
sb.Add_fmt(dirFmt, Int_.Xto_str_fmt(multipleAry[i], numFmt));
|
||||
sb.Add_fmt(filFmt, Int_.Xto_str_fmt(idx, numFmt));
|
||||
return sb.XtoStr();
|
||||
}
|
||||
public HierStrBldr Ctor_io(Io_url root, String dirFmt, String filFmt, String numFmt, int... filCountMaxs) {
|
||||
|
@ -39,7 +39,7 @@ class GfmlUsrMsgs {
|
||||
Err rv = Err_.new_("gfml parse error");
|
||||
for (int i = 0; i < bldr.Doc().UsrMsgs().Count(); i++) {
|
||||
UsrMsg um = (UsrMsg)bldr.Doc().UsrMsgs().FetchAt(i);
|
||||
rv.Add("err" + Int_.XtoStr(i), um.XtoStr());
|
||||
rv.Add("err" + Int_.Xto_str(i), um.XtoStr());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
@ -66,12 +66,12 @@ class GfmlStringHighlighter {
|
||||
int gap = nxtMarkBgn - endPos;
|
||||
if (gap > 0) {
|
||||
int gapDigits = Int_.DigitCount(gap);
|
||||
posBfr.Add_fmt("[{0}]", Int_.XtoStr_PadBgn(gap, gapDigits));
|
||||
posBfr.Add_fmt("[{0}]", Int_.Xto_str_pad_bgn(gap, gapDigits));
|
||||
rawBfr.Add_fmt("[{0}]", String_.Repeat(".", gapDigits));
|
||||
symBfr.Add_fmt(" {0} ", String_.Repeat(" ", gapDigits));
|
||||
}
|
||||
if (curMark.Sym() != ' ')
|
||||
symList.Add(String_.Format("[{0}] {1} {2}", Int_.XtoStr_PadBgn(curMark.Pos(), rawLenDigits), curMark.Sym(), curMark.Msg()));
|
||||
symList.Add(String_.Format("[{0}] {1} {2}", Int_.Xto_str_pad_bgn(curMark.Pos(), rawLenDigits), curMark.Sym(), curMark.Msg()));
|
||||
}
|
||||
if (rawBfrBgn == 0) {
|
||||
posBfr.Add_at(0, "<");
|
||||
|
@ -82,7 +82,7 @@ class SqlCmd_quote_end implements GfmlBldrCmd {
|
||||
GfmlTkn pnd = (GfmlTkn)list.FetchAt(i);
|
||||
sb.Add(pnd.Val());
|
||||
}
|
||||
//Int_.XtoStr(bldr.CurNdeFrame().Nde().SubTkns().length)
|
||||
//Int_.Xto_str(bldr.CurNdeFrame().Nde().SubTkns().length)
|
||||
GfmlAtr atr = GfmlAtr.new_(GfmlTkn_.raw_("word"), GfmlTkn_.raw_(sb.XtoStr()), GfmlType_.String);
|
||||
bldr.CurNdeFrame().CurNde().SubObjs_Add(atr);
|
||||
bldr.Frames_end();
|
||||
|
@ -57,7 +57,7 @@ class GfmlTypeCompiler_fxt {
|
||||
for (int i = 0; i < max; i++) {
|
||||
GfmlFld_mok expdFld = (GfmlFld_mok)tstr.List_FetchAtOrNull(expd.Subs(), i);
|
||||
GfmlFld_mok actlFld = (GfmlFld_mok)tstr.List_FetchAtOrNull(actl.Subs(), i);
|
||||
tstr.SubName_push(Int_.XtoStr(i) + " fld");
|
||||
tstr.SubName_push(Int_.Xto_str(i) + " fld");
|
||||
tst(tstr, expdFld, actlFld);
|
||||
tstr.SubName_pop();
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class GfmlNde_mok implements GfmlItm_mok {
|
||||
public ListAdp Subs() {return subs;}
|
||||
public String XtoStrStub() {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
sb.Add_kv("key=", key).Add_kv("hnd=", hnd).Add_kv("typ=", typ).Add_kv("subs=", Int_.XtoStr(subs.Count()));
|
||||
sb.Add_kv("key=", key).Add_kv("hnd=", hnd).Add_kv("typ=", typ).Add_kv("subs=", Int_.Xto_str(subs.Count()));
|
||||
return sb.XtoStr();
|
||||
}
|
||||
public GfmlNde_mok Subs_(GfmlItm_mok... ary) {
|
||||
@ -141,7 +141,7 @@ class GfmlTypeResolver_fxt {
|
||||
for (int i = 0; i < max; i++) {
|
||||
GfmlItm_mok expdSub = (GfmlItm_mok)tstr.List_FetchAtOrNull(expd.Subs(), i);
|
||||
GfmlItm_mok actlSub = (GfmlItm_mok)tstr.List_FetchAtOrNull(actl.Subs(), i);
|
||||
tstr.SubName_push(Int_.XtoStr(i));
|
||||
tstr.SubName_push(Int_.Xto_str(i));
|
||||
if (expdSub == null) {
|
||||
GfmlNde_mok mm = GfmlNde_mok.as_(actlSub);
|
||||
String actlSubStr = mm == null ? "sub:null" : mm.XtoStrStub();
|
||||
|
@ -68,7 +68,7 @@ class GfmlTkn_mok {
|
||||
for (int i = 0; i < max; i++) {
|
||||
GfmlTkn_mok expdSub = (GfmlTkn_mok)tstr.List_FetchAtOrNull(expd.Subs(), i);
|
||||
GfmlTkn_mok actlSub = (GfmlTkn_mok)tstr.List_FetchAtOrNull(actl.Subs(), i);
|
||||
tstr.SubName_push(Int_.XtoStr(i));
|
||||
tstr.SubName_push(Int_.Xto_str(i));
|
||||
tst(tstr, expdSub, actlSub);
|
||||
tstr.SubName_pop();
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ class TimerWatch {
|
||||
this.End();
|
||||
Tfds.Write(XtoStr_ms() + " " + text);
|
||||
}
|
||||
public String XtoStr_ms() {return Long_.XtoStr(duration);}
|
||||
public String XtoStr_ms() {return Long_.Xto_str(duration);}
|
||||
public static TimerWatch new_() {
|
||||
TimerWatch rv = new TimerWatch();
|
||||
rv.Bgn();
|
||||
|
97
140_dbs/src_100_core/gplx/dbs/Db_conn_info.java
Normal file
97
140_dbs/src_100_core/gplx/dbs/Db_conn_info.java
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public interface Db_conn_info {
|
||||
String Key();
|
||||
String Server();
|
||||
String Database();
|
||||
String Str_raw();
|
||||
String Str_api();
|
||||
Db_conn_info Make_new(String raw, GfoMsg m);
|
||||
}
|
||||
class Db_conn_info__null extends Db_conn_info__base {
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "null_db";
|
||||
@Override public Db_conn_info Make_new(String raw, GfoMsg m) {return this;}
|
||||
public static final Db_conn_info__null _ = new Db_conn_info__null(); Db_conn_info__null() {this.Ctor_of_db_connect("", "", "gplx_key=null_db", "");}
|
||||
}
|
||||
class Db_conn_info__mysql extends Db_conn_info__base {
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "mysql";
|
||||
public String Uid() {return uid;} private String uid;
|
||||
public String Pwd() {return pwd;} private String pwd;
|
||||
public static Db_conn_info new_(String server, String database, String uid, String pwd) {
|
||||
return Db_conn_info_.parse_(BldRaw(GfoMsg_.new_cast_("Db_conn_info")
|
||||
.Add("gplx_key", Key_const)
|
||||
.Add("server", server)
|
||||
.Add("database", database)
|
||||
.Add("uid", uid)
|
||||
.Add("pwd", pwd)
|
||||
.Add("charset", "utf8")
|
||||
));
|
||||
}
|
||||
@Override public Db_conn_info Make_new(String raw, GfoMsg m) {
|
||||
Db_conn_info__mysql rv = new Db_conn_info__mysql();
|
||||
rv.Ctor_of_db_connect(m.ReadStr("server"), m.ReadStr("database"), raw, BldApi(m, KeyVal_.new_("charset", "utf8")));
|
||||
rv.uid = m.ReadStr("uid");
|
||||
rv.pwd = m.ReadStr("pwd");
|
||||
return rv;
|
||||
}
|
||||
public static final Db_conn_info__mysql _ = new Db_conn_info__mysql(); Db_conn_info__mysql() {}
|
||||
}
|
||||
class Db_conn_info__postgres extends Db_conn_info__base {
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "postgresql";
|
||||
public String Uid() {return uid;} private String uid;
|
||||
public String Pwd() {return pwd;} private String pwd;
|
||||
public static Db_conn_info new_(String server, String database, String uid, String pwd) {
|
||||
return Db_conn_info_.parse_(BldRaw(GfoMsg_.new_cast_("Db_conn_info")
|
||||
.Add("gplx_key", Key_const)
|
||||
.Add("server", server)
|
||||
.Add("database", database)
|
||||
.Add("port", 5432)
|
||||
.Add("user id", uid)
|
||||
.Add("password", pwd)
|
||||
.Add("encoding", "unicode") // needed for 1.1 provider; otherwise, ascii
|
||||
));
|
||||
}
|
||||
@Override public Db_conn_info Make_new(String raw, GfoMsg m) {
|
||||
Db_conn_info__postgres rv = new Db_conn_info__postgres();
|
||||
rv.Ctor_of_db_connect(m.ReadStr("server"), m.ReadStr("database"), raw, BldApi(m, KeyVal_.new_("encoding", "unicode")));
|
||||
rv.uid = m.ReadStr("user id");
|
||||
rv.pwd = m.ReadStr("password");
|
||||
return rv;
|
||||
}
|
||||
public static final Db_conn_info__postgres _ = new Db_conn_info__postgres(); Db_conn_info__postgres() {}
|
||||
}
|
||||
class Db_conn_info__tdb extends Db_conn_info__base {
|
||||
public Io_url Url() {return url;} Io_url url;
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "tdb";
|
||||
public static Db_conn_info new_(Io_url url) {
|
||||
return Db_conn_info_.parse_(BldRaw(GfoMsg_.new_cast_("Db_conn_info")
|
||||
.Add("gplx_key", Key_const)
|
||||
.Add("url", url.Raw())
|
||||
));
|
||||
} Db_conn_info__tdb() {}
|
||||
@Override public Db_conn_info Make_new(String raw, GfoMsg m) {
|
||||
Db_conn_info__tdb rv = new Db_conn_info__tdb();
|
||||
String urlStr = m.ReadStr("url");
|
||||
Io_url url = Io_url_.new_any_(urlStr);
|
||||
rv.Ctor_of_db_connect(urlStr, url.NameOnly(), raw, BldApi(m));
|
||||
rv.url = url;
|
||||
return rv;
|
||||
}
|
||||
public static final Db_conn_info__tdb _ = new Db_conn_info__tdb();
|
||||
}
|
52
140_dbs/src_100_core/gplx/dbs/Db_conn_info_.java
Normal file
52
140_dbs/src_100_core/gplx/dbs/Db_conn_info_.java
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_conn_info_ {
|
||||
public static final Db_conn_info Null = Db_conn_info__null._;
|
||||
public static final Db_conn_info Test = Db_conn_info__mysql.new_("127.0.0.1", "unit_tests", "root", "mysql7760");
|
||||
public static Db_conn_info parse_(String raw) {return Db_conn_info_pool._.Parse(raw);}
|
||||
public static Db_conn_info sqlite_(Io_url url) {return Db_conn_info__sqlite.load_(url);}
|
||||
public static Db_conn_info tdb_(Io_url url) {return Db_conn_info__tdb.new_(url);}
|
||||
public static final String Key_tdb = TdbEngine.KeyDef;
|
||||
}
|
||||
class Db_conn_info_pool {
|
||||
private OrderedHash regy = OrderedHash_.new_();
|
||||
public Db_conn_info_pool() {
|
||||
this.Add(Db_conn_info__null._).Add(Db_conn_info__tdb._).Add(Db_conn_info__mysql._).Add(Db_conn_info__postgres._).Add(Db_conn_info__sqlite._);
|
||||
}
|
||||
public Db_conn_info_pool Add(Db_conn_info itm) {regy.AddReplace(itm.Key(), itm); return this;}
|
||||
public Db_conn_info Parse(String raw) {// assume each pair has format of: name=val;
|
||||
try {
|
||||
GfoMsg m = GfoMsg_.new_parse_("db_conn_info");
|
||||
String[] terms = String_.Split(raw, ";");
|
||||
String conn_info_key = "";
|
||||
for (String term : terms) {
|
||||
if (String_.Len(term) == 0) continue;
|
||||
String[] kv = String_.Split(term, "=");
|
||||
if (String_.Eq(kv[0], "gplx_key"))
|
||||
conn_info_key = kv[1]; // NOTE: do not add to GfoMsg; will not be part of ApiStr
|
||||
else
|
||||
m.Add(kv[0], kv[1]);
|
||||
}
|
||||
Db_conn_info prototype = (Db_conn_info)regy.Fetch(conn_info_key);
|
||||
return prototype.Make_new(raw, m);
|
||||
}
|
||||
catch(Exception exc) {throw Err_.parse_type_exc_(exc, Db_conn_info.class, raw);}
|
||||
}
|
||||
public static final Db_conn_info_pool _ = new Db_conn_info_pool();
|
||||
}
|
@ -16,14 +16,15 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public abstract class Db_connect_base implements Db_connect {
|
||||
public abstract String Key_of_db_connect();
|
||||
public String Database() {return database;} public Db_connect_base Database_(String v) {database = v; return this;} private String database = "";
|
||||
public String Server() {return server;} public Db_connect_base Server_(String v) {server = v; return this;} private String server = "";
|
||||
public String Raw_of_db_connect() {return raw;} public Db_connect XtoStr_raw_(String v) {raw = v; return this;} private String raw = "";
|
||||
public String Api_of_db_connect() {return api;} public Db_connect XtoStr_std_(String v) {api = v; return this;} private String api = "";
|
||||
public abstract Db_connect Clone_of_db_connect(String raw, GfoMsg m);
|
||||
public abstract class Db_conn_info__base implements Db_conn_info {
|
||||
public abstract String Key();
|
||||
public String Database() {return database;} public Db_conn_info__base Database_(String v) {database = v; return this;} private String database = "";
|
||||
public String Server() {return server;} public Db_conn_info__base Server_(String v) {server = v; return this;} private String server = "";
|
||||
public String Str_raw() {return raw;} public Db_conn_info XtoStr_raw_(String v) {raw = v; return this;} private String raw = "";
|
||||
public String Str_api() {return api;} public Db_conn_info XtoStr_std_(String v) {api = v; return this;} private String api = "";
|
||||
public abstract Db_conn_info Make_new(String raw, GfoMsg m);
|
||||
protected void Ctor_of_db_connect(String server, String database, String raw, String api) {this.server = server; this.database = database; this.raw = raw; this.api = api;}
|
||||
|
||||
protected static String BldApi(GfoMsg m, KeyVal... xtnAry) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
HashAdp hash = HashAdp_.new_();
|
@ -16,30 +16,30 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_connect_sqlite extends Db_connect_base {
|
||||
@Override public String Key_of_db_connect() {return KeyDef;} public static final String KeyDef = "sqlite";
|
||||
public Io_url Url() {return url;} Io_url url;
|
||||
public static Db_connect load_(Io_url url) {
|
||||
return Db_connect_.parse_(BldRaw(GfoMsg_.new_cast_("Db_connect")
|
||||
.Add("gplx_key", KeyDef)
|
||||
public class Db_conn_info__sqlite extends Db_conn_info__base {
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "sqlite";
|
||||
public Io_url Url() {return url;} private Io_url url;
|
||||
public static Db_conn_info load_(Io_url url) {
|
||||
return Db_conn_info_.parse_(BldRaw(GfoMsg_.new_cast_("Db_conn_info")
|
||||
.Add("gplx_key", Key_const)
|
||||
.Add("data source", url.Xto_api())
|
||||
.Add("version", 3)
|
||||
));
|
||||
}
|
||||
public static Db_connect make_(Io_url url) {
|
||||
public static Db_conn_info make_(Io_url url) {
|
||||
Io_mgr._.CreateDirIfAbsent(url.OwnerDir());
|
||||
return Db_connect_.parse_(BldRaw(GfoMsg_.new_cast_("Db_connect")
|
||||
.Add("gplx_key", KeyDef)
|
||||
return Db_conn_info_.parse_(BldRaw(GfoMsg_.new_cast_("Db_conn_info")
|
||||
.Add("gplx_key", Key_const)
|
||||
.Add("data source", url.Xto_api())
|
||||
.Add("version", 3)
|
||||
));
|
||||
}
|
||||
@Override public Db_connect Clone_of_db_connect(String raw, GfoMsg m) {
|
||||
Db_connect_sqlite rv = new Db_connect_sqlite();
|
||||
String dataSourceUrl = m.ReadStr("data source");
|
||||
rv.url = Io_url_.new_any_(dataSourceUrl);
|
||||
rv.Ctor_of_db_connect("", dataSourceUrl, raw, BldApi(m, KeyVal_.new_("version", "3")));
|
||||
@Override public Db_conn_info Make_new(String raw, GfoMsg m) {
|
||||
Db_conn_info__sqlite rv = new Db_conn_info__sqlite();
|
||||
String url = m.ReadStr("data source");
|
||||
rv.url = Io_url_.new_any_(url);
|
||||
rv.Ctor_of_db_connect("", url, raw, BldApi(m, KeyVal_.new_("version", "3")));
|
||||
return rv;
|
||||
}
|
||||
public static final Db_connect_sqlite _ = new Db_connect_sqlite(); Db_connect_sqlite() {}
|
||||
public static final Db_conn_info__sqlite _ = new Db_conn_info__sqlite(); Db_conn_info__sqlite() {}
|
||||
}
|
@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class Db_connect_tst {
|
||||
public class Db_conn_info_tst {
|
||||
@Before public void setup() {
|
||||
regy = new Db_connect_pool();
|
||||
regy.Add(Db_connect_mock._);
|
||||
} Db_connect_pool regy;
|
||||
regy = new Db_conn_info_pool();
|
||||
regy.Add(Db_conn_info_mock._);
|
||||
} Db_conn_info_pool regy;
|
||||
@Test public void Parse() {
|
||||
tst_Parse("gplx_key=mock;id=1;", kv_("id", "1")); // one; gplx_key removed
|
||||
tst_Parse("gplx_key=mock;id=1;name=me;", kv_("id", "1"), kv_("name", "me")); // many
|
||||
@ -29,19 +29,19 @@ public class Db_connect_tst {
|
||||
}
|
||||
KeyVal kv_(String key, Object val) {return KeyVal_.new_(key, val);}
|
||||
void tst_Parse(String raw, KeyVal... expd) {
|
||||
Db_connect_mock mock = (Db_connect_mock)regy.Parse(raw);
|
||||
Db_conn_info_mock mock = (Db_conn_info_mock)regy.Parse(raw);
|
||||
Tfds.Eq_ary_str(expd, mock.Kvs());
|
||||
}
|
||||
}
|
||||
class Db_connect_mock extends Db_connect_base {
|
||||
class Db_conn_info_mock extends Db_conn_info__base {
|
||||
public KeyVal[] Kvs() {return kvs;} KeyVal[] kvs;
|
||||
@Override public String Key_of_db_connect() {return KeyDef;} public static final String KeyDef = "mock";
|
||||
@Override public Db_connect Clone_of_db_connect(String raw, GfoMsg m) {
|
||||
Db_connect_mock rv = new Db_connect_mock();
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "mock";
|
||||
@Override public Db_conn_info Make_new(String raw, GfoMsg m) {
|
||||
Db_conn_info_mock rv = new Db_conn_info_mock();
|
||||
rv.kvs = new KeyVal[m.Args_count()];
|
||||
for (int i = 0; i < m.Args_count(); i++)
|
||||
rv.kvs[i] = m.Args_getAt(i);
|
||||
return rv;
|
||||
}
|
||||
public static final Db_connect_mock _ = new Db_connect_mock(); Db_connect_mock() {}
|
||||
public static final Db_conn_info_mock _ = new Db_conn_info_mock(); Db_conn_info_mock() {}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public interface Db_connect {
|
||||
String Key_of_db_connect();
|
||||
String Server();
|
||||
String Database();
|
||||
String Raw_of_db_connect();
|
||||
String Api_of_db_connect();
|
||||
Db_connect Clone_of_db_connect(String raw, GfoMsg m);
|
||||
}
|
||||
class Db_connect_null extends Db_connect_base {
|
||||
@Override public String Key_of_db_connect() {return KeyDef;} public static final String KeyDef = "null_db";
|
||||
@Override public Db_connect Clone_of_db_connect(String raw, GfoMsg m) {return this;}
|
||||
public static final Db_connect_null _ = new Db_connect_null(); Db_connect_null() {this.Ctor_of_db_connect("", "", "gplx_key=null_db", "");}
|
||||
}
|
||||
class Db_connect_mysql extends Db_connect_base {
|
||||
public String Uid() {return uid;} private String uid;
|
||||
public String Pwd() {return pwd;} private String pwd;
|
||||
@Override public String Key_of_db_connect() {return KeyDef;} public static final String KeyDef = "mysql";
|
||||
public static Db_connect new_(String server, String database, String uid, String pwd) {
|
||||
return Db_connect_.parse_(BldRaw(GfoMsg_.new_cast_("Db_connect")
|
||||
.Add("gplx_key", KeyDef)
|
||||
.Add("server", server)
|
||||
.Add("database", database)
|
||||
.Add("uid", uid)
|
||||
.Add("pwd", pwd)
|
||||
.Add("charset", "utf8")
|
||||
));
|
||||
}
|
||||
@Override public Db_connect Clone_of_db_connect(String raw, GfoMsg m) {
|
||||
Db_connect_mysql rv = new Db_connect_mysql();
|
||||
rv.Ctor_of_db_connect(m.ReadStr("server"), m.ReadStr("database"), raw, BldApi(m, KeyVal_.new_("charset", "utf8")));
|
||||
rv.uid = m.ReadStr("uid");
|
||||
rv.pwd = m.ReadStr("pwd");
|
||||
return rv;
|
||||
}
|
||||
public static final Db_connect_mysql _ = new Db_connect_mysql(); Db_connect_mysql() {}
|
||||
}
|
||||
class Db_connect_postgres extends Db_connect_base {
|
||||
public String Uid() {return uid;} private String uid;
|
||||
public String Pwd() {return pwd;} private String pwd;
|
||||
@Override public String Key_of_db_connect() {return KeyDef;} public static final String KeyDef = "postgresql";
|
||||
public static Db_connect new_(String server, String database, String uid, String pwd) {
|
||||
return Db_connect_.parse_(BldRaw(GfoMsg_.new_cast_("Db_connect")
|
||||
.Add("gplx_key", KeyDef)
|
||||
.Add("server", server)
|
||||
.Add("database", database)
|
||||
.Add("port", 5432)
|
||||
.Add("user id", uid)
|
||||
.Add("password", pwd)
|
||||
.Add("encoding", "unicode") // needed for 1.1 provider; otherwise, ascii
|
||||
));
|
||||
}
|
||||
@Override public Db_connect Clone_of_db_connect(String raw, GfoMsg m) {
|
||||
Db_connect_postgres rv = new Db_connect_postgres();
|
||||
rv.Ctor_of_db_connect(m.ReadStr("server"), m.ReadStr("database"), raw, BldApi(m, KeyVal_.new_("encoding", "unicode")));
|
||||
rv.uid = m.ReadStr("user id");
|
||||
rv.pwd = m.ReadStr("password");
|
||||
return rv;
|
||||
}
|
||||
public static final Db_connect_postgres _ = new Db_connect_postgres(); Db_connect_postgres() {}
|
||||
}
|
||||
class Db_connect_tdb extends Db_connect_base {
|
||||
public Io_url Url() {return url;} Io_url url;
|
||||
@Override public String Key_of_db_connect() {return KeyDef;} public static final String KeyDef = "tdb";
|
||||
public static Db_connect new_(Io_url url) {
|
||||
return Db_connect_.parse_(BldRaw(GfoMsg_.new_cast_("Db_connect")
|
||||
.Add("gplx_key", KeyDef)
|
||||
.Add("url", url.Raw())
|
||||
));
|
||||
} Db_connect_tdb() {}
|
||||
@Override public Db_connect Clone_of_db_connect(String raw, GfoMsg m) {
|
||||
Db_connect_tdb rv = new Db_connect_tdb();
|
||||
String urlStr = m.ReadStr("url");
|
||||
Io_url url = Io_url_.new_any_(urlStr);
|
||||
rv.Ctor_of_db_connect(urlStr, url.NameOnly(), raw, BldApi(m));
|
||||
rv.url = url;
|
||||
return rv;
|
||||
}
|
||||
public static final Db_connect_tdb _ = new Db_connect_tdb();
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_connect_ {
|
||||
public static final Db_connect Null = Db_connect_null._;
|
||||
public static final Db_connect Test = Db_connect_mysql.new_("127.0.0.1", "unit_tests", "root", "mysql7760");
|
||||
public static Db_connect parse_(String raw) {return Db_connect_pool._.Parse(raw);}
|
||||
public static Db_connect tdb_(Io_url url) {return Db_connect_tdb.new_(url);}
|
||||
public static Db_connect sqlite_(Io_url url) {return Db_connect_sqlite.load_(url);}
|
||||
public static final String TdbKey = TdbEngine.KeyDef;
|
||||
}
|
||||
class Db_connect_pool {
|
||||
public Db_connect_pool() {
|
||||
this.Add(Db_connect_null._).Add(Db_connect_tdb._).Add(Db_connect_mysql._).Add(Db_connect_postgres._).Add(Db_connect_sqlite._);
|
||||
}
|
||||
public Db_connect_pool Add(Db_connect prototype) {regy.AddReplace(prototype.Key_of_db_connect(), prototype); return this;}
|
||||
public Db_connect Parse(String raw) {// assume each pair has format of: name=val;
|
||||
try {
|
||||
GfoMsg m = GfoMsg_.new_parse_("dbConnectionString");
|
||||
String[] terms = String_.Split(raw, ";");
|
||||
String gplxKey = "";
|
||||
for (String term : terms) {
|
||||
if (String_.Len(term) == 0) continue;
|
||||
String[] kv = String_.Split(term, "=");
|
||||
if (String_.Eq(kv[0], "gplx_key"))
|
||||
gplxKey = kv[1]; // NOTE: do not add to GfoMsg; will not be part of ApiStr
|
||||
else
|
||||
m.Add(kv[0], kv[1]);
|
||||
}
|
||||
Db_connect prototype = (Db_connect)regy.Fetch(gplxKey);
|
||||
return prototype.Clone_of_db_connect(raw, m);
|
||||
}
|
||||
catch(Exception exc) {throw Err_.parse_type_exc_(exc, Db_connect.class, raw);}
|
||||
}
|
||||
OrderedHash regy = OrderedHash_.new_();
|
||||
public static final Db_connect_pool _ = new Db_connect_pool();
|
||||
}
|
@ -16,21 +16,22 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_provider implements RlsAble {
|
||||
public class Db_provider {
|
||||
@gplx.Internal protected Db_provider(Db_engine engine) {
|
||||
this.engine = engine;
|
||||
txn_mgr = new Db_txn_mgr_base(engine);
|
||||
this.txn_mgr = new Db_txn_mgr_base(engine);
|
||||
}
|
||||
@gplx.Internal protected Db_engine Engine() {return engine;} private Db_engine engine;
|
||||
public Db_connect ConnectInfo() {return engine.ConnectInfo();}
|
||||
public Db_stmt Prepare(Db_qry qry) {return engine.New_db_stmt(this, qry);}
|
||||
public int Exec_qry(Db_qry qry) {txn_mgr.Txn_count_(txn_mgr.Txn_count() + 1); return Int_.cast_(engine.Execute(qry));}
|
||||
public DataRdr Exec_qry_as_rdr(Db_qry qry) {return DataRdr_.cast_(engine.Execute(qry));}
|
||||
public int Exec_sql(String sql) {return this.Exec_qry(Db_qry_sql.dml_(sql));}
|
||||
public DataRdr Exec_sql_as_rdr(String sql) {return this.Exec_qry_as_rdr(Db_qry_sql.rdr_(sql));}
|
||||
public Db_txn_mgr Txn_mgr() {return txn_mgr;} Db_txn_mgr txn_mgr;
|
||||
public void Rls() {
|
||||
engine.Rls();
|
||||
Db_provider_pool._.Del(this.ConnectInfo()); // remove from pool, else rls'd instance will be cached and fail upon next use
|
||||
public Db_conn_info Conn_info() {return engine.Conn_info();}
|
||||
public Db_engine Engine() {return engine;} private final Db_engine engine;
|
||||
public Db_txn_mgr Txn_mgr() {return txn_mgr;} private final Db_txn_mgr txn_mgr;
|
||||
|
||||
public Db_stmt Prepare(Db_qry qry) {return engine.New_db_stmt(this, qry);}
|
||||
public int Exec_qry(Db_qry qry) {txn_mgr.Txn_count_(txn_mgr.Txn_count() + 1); return Int_.cast_(engine.Execute(qry));}
|
||||
public DataRdr Exec_qry_as_rdr(Db_qry qry) {return DataRdr_.cast_(engine.Execute(qry));}
|
||||
public int Exec_sql(String sql) {return this.Exec_qry(Db_qry_sql.dml_(sql));}
|
||||
public DataRdr Exec_sql_as_rdr(String sql) {return this.Exec_qry_as_rdr(Db_qry_sql.rdr_(sql));}
|
||||
public void Conn_term() {
|
||||
engine.Conn_term();
|
||||
Db_provider_pool._.Del(this.Conn_info()); // remove from pool, else rls'd instance will be cached and fail upon next use
|
||||
}
|
||||
}
|
||||
|
@ -16,15 +16,13 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_provider_ {
|
||||
public static final Db_provider Null = new_(Db_connect_.Null);
|
||||
public static Db_provider new_(Db_connect dbInfo) {
|
||||
Db_engine prototype = Db_engineRegy._.Get(dbInfo.Key_of_db_connect());
|
||||
Db_engine engine = prototype.MakeEngine(dbInfo);
|
||||
engine.Connect();
|
||||
Db_provider rv = new Db_provider(engine);
|
||||
// Env_.Dispose_reg(rv); // NOTE: need to dispose or else mysql error: Unable to release semaphore
|
||||
return rv;
|
||||
public class Db_provider_ {
|
||||
public static final Db_provider Null = new_and_open_(Db_conn_info_.Null);
|
||||
public static Db_provider new_and_open_(Db_conn_info conn_info) {
|
||||
Db_engine prototype = Db_engine_regy._.Get(conn_info.Key());
|
||||
Db_engine engine = prototype.Make_new(conn_info);
|
||||
engine.Conn_open(); // auto-open
|
||||
return new Db_provider(engine);
|
||||
}
|
||||
public static int Select_fld0_as_int_or(Db_provider p, String sql, int or) {
|
||||
DataRdr rdr = DataRdr_.Null;
|
||||
@ -43,10 +41,3 @@ public class Db_provider_ {
|
||||
}
|
||||
}
|
||||
}
|
||||
class Db_engineRegy {
|
||||
public Db_engine Get(String key) {return (Db_engine)hash.FetchOrFail(key);}
|
||||
HashAdp hash = HashAdp_.new_();
|
||||
Db_engineRegy Add(Db_engine engine) {hash.Add(engine.Key(), engine); return this;}
|
||||
Db_engineRegy() {this.Add(Db_engine_null._).Add(TdbEngine._).Add(Mysql_engine._).Add(Postgres_engine._).Add(Sqlite_engine._);}
|
||||
public static final Db_engineRegy _ = new Db_engineRegy();
|
||||
}
|
||||
|
@ -16,25 +16,25 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_provider_pool {
|
||||
public void Del(Db_connect connectInfo) {hash.Del(connectInfo.Raw_of_db_connect());}
|
||||
public Db_provider FetchOrNew(Db_connect connectInfo) {return FetchOrNew(connectInfo.Raw_of_db_connect());}
|
||||
public Db_provider FetchOrNew(String raw) {
|
||||
public class Db_provider_pool {
|
||||
private final OrderedHash hash = OrderedHash_.new_();
|
||||
public Db_provider Get_or_new(Db_conn_info connectInfo) {return Get_or_new(connectInfo.Str_raw());}
|
||||
public Db_provider Get_or_new(String raw) {
|
||||
Db_provider rv = (Db_provider)hash.Fetch(raw);
|
||||
if (rv == null) {
|
||||
rv = Db_provider_.new_(Db_connect_.parse_(raw));
|
||||
rv = Db_provider_.new_and_open_(Db_conn_info_.parse_(raw));
|
||||
hash.Add(raw, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Del(Db_conn_info connectInfo) {hash.Del(connectInfo.Str_raw());}
|
||||
public void Clear() {
|
||||
for (int i = 0; i < hash.Count(); i++) {
|
||||
Db_provider provider = (Db_provider)hash.FetchAt(i);
|
||||
provider.Rls();
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Db_provider provider = (Db_provider)hash.FetchAt(0);
|
||||
provider.Conn_term();
|
||||
}
|
||||
hash.Clear();
|
||||
}
|
||||
OrderedHash hash = OrderedHash_.new_();
|
||||
@gplx.Internal protected static Db_provider_pool new_() {return new Db_provider_pool();} Db_provider_pool() {}
|
||||
public static final Db_provider_pool _ = new Db_provider_pool();
|
||||
}
|
||||
public static final Db_provider_pool _ = new Db_provider_pool(); Db_provider_pool() {}
|
||||
}
|
||||
|
30
140_dbs/src_100_core/gplx/dbs/Db_rdr.java
Normal file
30
140_dbs/src_100_core/gplx/dbs/Db_rdr.java
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public interface Db_rdr {
|
||||
boolean Move_next();
|
||||
byte[] Read_bry(int i);
|
||||
byte[] Read_bry_by_str(int i);
|
||||
String Read_str(int i);
|
||||
byte Read_byte(int i);
|
||||
int Read_int(int i);
|
||||
long Read_long(int i);
|
||||
float Read_float(int i);
|
||||
double Read_double(int i);
|
||||
void Close();
|
||||
}
|
33
140_dbs/src_100_core/gplx/dbs/Db_rdr_.java
Normal file
33
140_dbs/src_100_core/gplx/dbs/Db_rdr_.java
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_rdr_ {
|
||||
public static final Db_rdr Null = new Db_rdr__null();
|
||||
}
|
||||
class Db_rdr__null implements Db_rdr {
|
||||
public boolean Move_next() {return false;}
|
||||
public byte[] Read_bry(int i) {return Bry_.Empty;}
|
||||
public byte[] Read_bry_by_str(int i) {return Bry_.Empty;}
|
||||
public byte Read_byte(int i) {return Byte_.MaxValue_127;}
|
||||
public String Read_str(int i) {return String_.Empty;}
|
||||
public int Read_int(int i) {return Int_.MinValue;}
|
||||
public long Read_long(int i) {return Long_.MinValue;}
|
||||
public float Read_float(int i) {return Float_.NaN;}
|
||||
public double Read_double(int i) {return Double_.NaN;}
|
||||
public void Close() {}
|
||||
}
|
37
140_dbs/src_100_core/gplx/dbs/Db_rdr__basic.java
Normal file
37
140_dbs/src_100_core/gplx/dbs/Db_rdr__basic.java
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import java.sql.ResultSet;
|
||||
class Db_rdr__basic implements Db_rdr {
|
||||
private final ResultSet rdr;
|
||||
public Db_rdr__basic(ResultSet rdr, String sql) {this.rdr = rdr; this.sql = sql;}
|
||||
public String Sql() {return sql;} private final String sql;
|
||||
public boolean Move_next() {
|
||||
try {return rdr.next();}
|
||||
catch (Exception e) {throw Err_.new_fmt_("move_next failed; check column casting error in SQL: err={0} sql={1}", Err_.Message_lang(e), sql);}
|
||||
}
|
||||
public byte[] Read_bry(int i) {try {return rdr.getBytes(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Bry_.Cls_name, Err_.Message_lang(e));}}
|
||||
public byte[] Read_bry_by_str(int i) {try {return Bry_.new_utf8_(rdr.getString(i));} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, String_.Cls_name, Err_.Message_lang(e));}}
|
||||
public String Read_str(int i) {try {return rdr.getString(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, String_.Cls_name, Err_.Message_lang(e));}}
|
||||
public int Read_int(int i) {try {return rdr.getInt(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Int_.Cls_name, Err_.Message_lang(e));}}
|
||||
public long Read_long(int i) {try {return rdr.getLong(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Long_.Cls_name, Err_.Message_lang(e));}}
|
||||
public float Read_float(int i) {try {return rdr.getFloat(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Float_.Cls_name, Err_.Message_lang(e));}}
|
||||
public double Read_double(int i) {try {return rdr.getDouble(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Double_.Cls_name, Err_.Message_lang(e));}}
|
||||
public byte Read_byte(int i) {try {return rdr.getByte(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Byte_.Cls_name, Err_.Message_lang(e));}}
|
||||
public void Close() {try {rdr.close();} catch (Exception e) {throw Err_.new_("close failed: err={0}", Err_.Message_lang(e));}}
|
||||
}
|
@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public interface Db_qry {
|
||||
int Tid();
|
||||
String KeyOfDb_qry();
|
||||
boolean ExecRdrAble();
|
||||
String XtoSql();
|
||||
|
@ -47,6 +47,7 @@ public class Db_qry_ {
|
||||
}
|
||||
public static final Object WhereAll = null;
|
||||
public static Db_qry as_(Object obj) {return obj instanceof Db_qry ? (Db_qry)obj : null;}
|
||||
public static final int Tid_basic = 0, Tid_select_in_tbl = 1;
|
||||
}
|
||||
interface Db_qryWkr {
|
||||
Object Exec(Db_engine engine, Db_qry cmd);
|
||||
|
60
140_dbs/src_110_dbQry/gplx/dbs/Db_qry__select_in_tbl.java
Normal file
60
140_dbs/src_110_dbQry/gplx/dbs/Db_qry__select_in_tbl.java
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_qry__select_in_tbl implements Db_qry {
|
||||
public Db_qry__select_in_tbl(String tbl_name, String[] select_flds, String[] where_flds, String group_by_sql, String having_sql, String order_by_sql, String limit_sql) {
|
||||
this.tbl_name = tbl_name; this.select_flds = select_flds; this.where_flds = where_flds; this.group_by_sql = group_by_sql; this.having_sql = having_sql; this.order_by_sql = order_by_sql; this.limit_sql = limit_sql;
|
||||
}
|
||||
public int Tid() {return Db_qry_.Tid_select_in_tbl;}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public String[] Select_flds() {return select_flds;} private final String[] select_flds;
|
||||
public String[] Where_flds() {return where_flds;} private final String[] where_flds;
|
||||
public void Where_sql(String_bldr sb) {
|
||||
if (where_flds == null) return;
|
||||
int where_flds_len = where_flds.length;
|
||||
if (where_flds_len == 0) return;
|
||||
for (int i = 0; i < where_flds_len; ++i) {
|
||||
if (i != 0) sb.Add("AND ");
|
||||
sb.Add(where_flds[i]).Add(" = ? ");
|
||||
}
|
||||
}
|
||||
public String Group_by_sql() {return group_by_sql;} private final String group_by_sql;
|
||||
public String Having_sql() {return having_sql;} private final String having_sql;
|
||||
public String Order_by_sql() {return order_by_sql;} private final String order_by_sql;
|
||||
public String Limit_sql() {return limit_sql;} private final String limit_sql;
|
||||
public static Db_qry__select_in_tbl new_(String tbl_name, String[] where_flds, String[] select_flds) {return new Db_qry__select_in_tbl(tbl_name, select_flds, where_flds, null, null, null, null);}
|
||||
public String KeyOfDb_qry() {return "select_in_tbl";}
|
||||
public boolean ExecRdrAble() {return true;}
|
||||
public String XtoSql() {return Xto_sql();}
|
||||
public String Xto_sql() {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
sb.Add("SELECT ");
|
||||
int select_flds_len = select_flds.length;
|
||||
for (int i = 0; i < select_flds_len; ++i) {
|
||||
if (i != 0) sb.Add(",");
|
||||
sb.Add(select_flds[i]);
|
||||
}
|
||||
sb.Add(" FROM ").Add(tbl_name).Add(" ");
|
||||
if (where_flds != null) {sb.Add("WHERE "); Where_sql(sb);}
|
||||
if (group_by_sql != null) sb.Add(group_by_sql);
|
||||
if (having_sql != null) sb.Add(having_sql);
|
||||
if (order_by_sql != null) sb.Add(order_by_sql);
|
||||
if (limit_sql != null) sb.Add(limit_sql);
|
||||
return sb.XtoStr();
|
||||
}
|
||||
}
|
@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.criterias.*;
|
||||
public class Db_qry_delete implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_basic;}
|
||||
public String KeyOfDb_qry() {return KeyConst;} public static final String KeyConst = "DELETE";
|
||||
public boolean ExecRdrAble() {return false;}
|
||||
public String XtoSql() {return Sql_cmd_wtr_.Ansi.XtoSqlQry(this, false);}
|
||||
public int Exec_qry(Db_provider provider) {return provider.Exec_qry(this);}
|
||||
|
||||
public Db_qry_delete Where_add_(String key, int val) {
|
||||
Criteria crt = Db_crt_.eq_(key, val);
|
||||
where = Sql_where.merge_or_new_(where, crt);
|
||||
|
@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_qry_flush implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_basic;}
|
||||
public String KeyOfDb_qry() {return KeyConst;} public static final String KeyConst = "FLUSH";
|
||||
public boolean ExecRdrAble() {return false;}
|
||||
public int Exec_qry(Db_provider provider) {return provider.Exec_qry(this);}
|
||||
|
@ -17,12 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_qry_insert implements Db_qry_arg_owner {
|
||||
public int Tid() {return Db_qry_.Tid_basic;}
|
||||
public String KeyOfDb_qry() {return KeyConst;} public static final String KeyConst = "INSERT";
|
||||
public boolean ExecRdrAble() {return false;}
|
||||
public String XtoSql() {return Sql_cmd_wtr_.Ansi.XtoSqlQry(this, false);}
|
||||
public int Exec_qry(Db_provider provider) {return provider.Exec_qry(this);}
|
||||
public Db_qry_arg_owner From_(String tbl) {baseTable = tbl; return this;}
|
||||
public Db_qry_arg_owner Arg_(String k, DecimalAdp v) {return Arg_obj_type_(k, v.XtoDecimal(), Db_val_type.Tid_decimal);}
|
||||
public Db_qry_arg_owner Arg_(String k, DecimalAdp v) {return Arg_obj_type_(k, v.Xto_decimal(), Db_val_type.Tid_decimal);}
|
||||
public Db_qry_arg_owner Arg_(String k, DateAdp v) {return Arg_obj_type_(k, v, Db_val_type.Tid_date);}
|
||||
public Db_qry_arg_owner Arg_byte_(String k, byte v) {return Arg_obj_type_(k, v, Db_val_type.Tid_byte);}
|
||||
public Db_qry_arg_owner Arg_(String k, int v) {return Arg_obj_type_(k, v, Db_val_type.Tid_int32);}
|
||||
|
@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.criterias.*;
|
||||
public class Db_qry_select implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_basic;}
|
||||
public String KeyOfDb_qry() {return KeyConst;} public static final String KeyConst = "SELECT";
|
||||
public boolean ExecRdrAble() {return true;}
|
||||
public DataRdr Exec_qry_as_rdr(Db_provider provider) {return provider.Exec_qry_as_rdr(this);}
|
||||
|
@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_qry_sql implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_basic;}
|
||||
public String KeyOfDb_qry() {return KeyConst;} public static final String KeyConst = "SQL";
|
||||
public boolean ExecRdrAble() {return isReader;} private boolean isReader;
|
||||
public int Exec_qry(Db_provider provider) {return provider.Exec_qry(this);}
|
||||
|
@ -18,13 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.criterias.*;
|
||||
public class Db_qry_update implements Db_qry_arg_owner {
|
||||
public int Tid() {return Db_qry_.Tid_basic;}
|
||||
public String KeyOfDb_qry() {return KeyConst;} public static final String KeyConst = "UPDATE";
|
||||
public boolean ExecRdrAble() {return false;}
|
||||
public int Exec_qry(Db_provider provider) {return provider.Exec_qry(this);}
|
||||
public String XtoSql() {return Sql_cmd_wtr_.Ansi.XtoSqlQry(this, false);}
|
||||
|
||||
public Db_qry_arg_owner From_(String tbl) {baseTable = tbl; return this;}
|
||||
public Db_qry_arg_owner Arg_(String k, DecimalAdp v) {return Arg_obj_type_(k, v.XtoDecimal(), Db_val_type.Tid_decimal);}
|
||||
public Db_qry_arg_owner Arg_(String k, DecimalAdp v) {return Arg_obj_type_(k, v.Xto_decimal(), Db_val_type.Tid_decimal);}
|
||||
public Db_qry_arg_owner Arg_(String k, DateAdp v) {return Arg_obj_type_(k, v, Db_val_type.Tid_date);}
|
||||
public Db_qry_arg_owner Arg_byte_(String k, byte v) {return Arg_obj_type_(k, v, Db_val_type.Tid_byte);}
|
||||
public Db_qry_arg_owner Arg_(String k, int v) {return Arg_obj_type_(k, v, Db_val_type.Tid_int32);}
|
||||
|
@ -35,6 +35,7 @@ public interface Db_stmt extends RlsAble {
|
||||
int Exec_update();
|
||||
int Exec_delete();
|
||||
DataRdr Exec_select();
|
||||
Db_rdr Exec_select_as_rdr();
|
||||
Object Exec_select_val();
|
||||
Db_stmt Clear();
|
||||
Db_stmt New();
|
||||
|
@ -47,4 +47,7 @@ public class Db_stmt_ {
|
||||
public static Db_stmt new_select_all_(Db_provider provider, String tbl) {
|
||||
return provider.Prepare(Db_qry_.select_tbl_(tbl));
|
||||
}
|
||||
public static Db_stmt new_select_as_rdr(Db_provider provider, Db_qry__select_in_tbl qry) {
|
||||
return provider.Prepare(qry);
|
||||
}
|
||||
}
|
||||
|
@ -18,13 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs; import gplx.*;
|
||||
import java.sql.*;
|
||||
class Db_stmt_cmd implements Db_stmt {
|
||||
Db_engine engine;
|
||||
PreparedStatement stmt = null;
|
||||
String sql;
|
||||
int val_idx = 0;
|
||||
private Db_engine engine;
|
||||
private PreparedStatement stmt = null;
|
||||
private String sql;
|
||||
private int val_idx = 0;
|
||||
public Db_stmt_cmd(Db_provider provider, Db_qry qry) {
|
||||
this.provider = provider; this.engine = provider.Engine();
|
||||
sql = Sql_cmd_wtr_.Ansi.XtoSqlQry(qry, true);
|
||||
sql = qry.Tid() == Db_qry_.Tid_select_in_tbl ? ((Db_qry__select_in_tbl)qry).Xto_sql() : Sql_cmd_wtr_.Ansi.XtoSqlQry(qry, true);
|
||||
New();
|
||||
}
|
||||
public Db_stmt New() {
|
||||
@ -58,7 +58,7 @@ class Db_stmt_cmd implements Db_stmt {
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_decimal_(DecimalAdp v) {
|
||||
try {stmt.setBigDecimal(++val_idx, v.XtoDecimal());} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "decimal", v);}
|
||||
try {stmt.setBigDecimal(++val_idx, v.Xto_decimal());} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "decimal", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_bry_by_str_(String v) {return Val_bry_(Bry_.new_utf8_(v));}
|
||||
@ -87,6 +87,9 @@ class Db_stmt_cmd implements Db_stmt {
|
||||
public DataRdr Exec_select() {
|
||||
try {DataRdr rv = engine.NewDataRdr(stmt.executeQuery(), sql); return rv;} catch (Exception e) {throw Err_.err_(e, "failed to exec prepared statement: sql={0}", sql);}
|
||||
}
|
||||
public Db_rdr Exec_select_as_rdr() {
|
||||
try {return engine.New_db_rdr(stmt.executeQuery(), sql);} catch (Exception e) {throw Err_.err_(e, "select failed: sql={0}", sql);}
|
||||
}
|
||||
public Object Exec_select_val() {
|
||||
try {Object rv = Db_qry_select.Rdr_to_val(engine.NewDataRdr(stmt.executeQuery(), sql)); return rv;} catch (Exception e) {throw Err_.err_(e, "failed to exec prepared statement: sql={0}", sql);}
|
||||
}
|
||||
|
@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
class Db_stmt_sql implements Db_stmt {
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
Bry_fmtr tmp_fmtr = Bry_fmtr.new_();
|
||||
int val_idx = 0;
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
private Bry_fmtr tmp_fmtr = Bry_fmtr.new_();
|
||||
private int val_idx = 0;
|
||||
public Db_provider Provider() {return provider;} public void Provider_(Db_provider v) {this.provider = v;} Db_provider provider;
|
||||
public Db_stmt New() {return this;}
|
||||
public Db_stmt Val_bool_(boolean v) {
|
||||
@ -28,27 +28,27 @@ class Db_stmt_sql implements Db_stmt {
|
||||
}
|
||||
public Db_stmt Val_byte_by_bool_(boolean v) {return Val_byte_(v ? Bool_.Y_byte : Bool_.N_byte);}
|
||||
public Db_stmt Val_byte_(byte v) {
|
||||
try {Add(++val_idx, Byte_.XtoStr(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "byte", v);}
|
||||
try {Add(++val_idx, Byte_.Xto_str(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "byte", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_int_(int v) {
|
||||
try {Add(++val_idx, Int_.XtoStr(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "int", v);}
|
||||
try {Add(++val_idx, Int_.Xto_str(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "int", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_long_(long v) {
|
||||
try {Add(++val_idx, Long_.XtoStr(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "long", v);}
|
||||
try {Add(++val_idx, Long_.Xto_str(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "long", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_float_(float v) {
|
||||
try {Add(++val_idx, Float_.XtoStr(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "float", v);}
|
||||
try {Add(++val_idx, Float_.Xto_str(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "float", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_double_(double v) {
|
||||
try {Add(++val_idx, Double_.XtoStr(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "double", v);}
|
||||
try {Add(++val_idx, Double_.Xto_str(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "double", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_decimal_(DecimalAdp v) {
|
||||
try {Add(++val_idx, v.XtoStr());} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "decimal", v);}
|
||||
try {Add(++val_idx, v.Xto_str());} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "decimal", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_bry_by_str_(String v) {return Val_bry_(Bry_.new_utf8_(v));}
|
||||
@ -84,6 +84,7 @@ class Db_stmt_sql implements Db_stmt {
|
||||
public DataRdr Exec_select() {
|
||||
try {DataRdr rv = provider.Exec_qry_as_rdr(Db_qry_sql.rdr_(this.Xto_sql())); return rv;} catch (Exception e) {throw Err_.err_(e, "failed to exec prepared statement: sql={0}", sql_orig);}
|
||||
}
|
||||
public Db_rdr Exec_select_as_rdr() {throw Err_.not_implemented_();}
|
||||
public Object Exec_select_val() {
|
||||
try {Object rv = Db_qry_select.Rdr_to_val(this.Exec_select()); return rv;} catch (Exception e) {throw Err_.err_(e, "failed to exec prepared statement: sql={0}", sql_orig);}
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ class Sql_cmd_wtr_ansi implements Sql_cmd_wtr {
|
||||
}
|
||||
Class<?> valType = val.getClass();
|
||||
if (valType == Boolean.class)
|
||||
sb.Add_obj(Bool_.XtoInt(Bool_.cast_(val))); // NOTE!: save boolean to 0 or 1, b/c (a) db may not support bit datatype (sqllite) and (b) avoid i18n issues with "true"/"false"
|
||||
sb.Add_obj(Bool_.Xto_int(Bool_.cast_(val))); // NOTE!: save boolean to 0 or 1, b/c (a) db may not support bit datatype (sqllite) and (b) avoid i18n issues with "true"/"false"
|
||||
else if
|
||||
( valType == Byte.class || valType == Short.class
|
||||
|| valType == Integer.class || valType == Long.class
|
||||
@ -162,7 +162,7 @@ class Sql_cmd_wtr_ansi implements Sql_cmd_wtr {
|
||||
XtoSqlVal_DateAdp(sb, prm, (DateAdp)val);
|
||||
else if (valType == DecimalAdp.class) {
|
||||
DecimalAdp valDecimal = (DecimalAdp)val;
|
||||
sb.Add(valDecimal.XtoStr());
|
||||
sb.Add(valDecimal.Xto_str());
|
||||
}
|
||||
// else if (valType == System.Enum.class)
|
||||
// sb.Add_any(Enm_.XtoInt(val)); // save enum as 0 or 1, since (a) no db supports enum datatype; (b) names are fungible; (c) int is less space than name
|
||||
|
@ -31,7 +31,7 @@ public class PoolIds {
|
||||
return rv;
|
||||
}
|
||||
public int FetchNextAndCommit(String dbInfo, String url) {
|
||||
Db_provider provider = Db_provider_pool._.FetchOrNew(dbInfo);
|
||||
Db_provider provider = Db_provider_pool._.Get_or_new(dbInfo);
|
||||
int rv = PoolIds._.FetchNext(provider, url);
|
||||
PoolIds._.Commit(provider, url, rv + 1);
|
||||
return rv;
|
||||
@ -41,7 +41,7 @@ public class PoolIds {
|
||||
if (rv == 0) {
|
||||
rv = provider.Exec_qry(Db_qry_.insert_(Tbl_Name).Arg_(Fld_id_path, url).Arg_(Fld_id_next_id, val));
|
||||
}
|
||||
if (rv != 1) throw Err_.new_("failed to update nextId").Add("provider", provider.ConnectInfo().Raw_of_db_connect()).Add("url", url).Add("nextId", val);
|
||||
if (rv != 1) throw Err_.new_("failed to update nextId").Add("provider", provider.Conn_info().Str_raw()).Add("url", url).Add("nextId", val);
|
||||
}
|
||||
public static final String Tbl_Name = "pool_ids";
|
||||
@gplx.Internal protected static final String Fld_id_path = "id_path";
|
||||
|
@ -16,30 +16,35 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
interface Db_engine extends RlsAble {
|
||||
String Key();
|
||||
Db_connect ConnectInfo();
|
||||
void Connect();
|
||||
Object Execute(Db_qry cmd);
|
||||
DataRdr NewDataRdr(java.sql.ResultSet rdr, String sql);
|
||||
Db_stmt New_db_stmt(Db_provider provider, Db_qry sql);
|
||||
Object New_db_cmd(String sql);
|
||||
void Txn_bgn();
|
||||
void Txn_end();
|
||||
Db_engine MakeEngine(Db_connect connectInfo);
|
||||
public interface Db_engine {
|
||||
String Key();
|
||||
Db_conn_info Conn_info();
|
||||
void Conn_open();
|
||||
void Conn_term();
|
||||
void Txn_bgn();
|
||||
void Txn_end();
|
||||
Db_engine Make_new(Db_conn_info conn_info);
|
||||
|
||||
Db_rdr New_db_rdr(Object o, String sql); // ResultSet if desktop; Cursor if android
|
||||
Db_stmt New_db_stmt(Db_provider provider, Db_qry sql);
|
||||
Object Execute(Db_qry cmd);
|
||||
DataRdr NewDataRdr(java.sql.ResultSet rdr, String sql);
|
||||
Object New_db_cmd(String sql);
|
||||
}
|
||||
class Db_engine_null implements Db_engine {
|
||||
public String Key() {return Db_connect_.Null.Key_of_db_connect();}
|
||||
public Db_connect ConnectInfo() {return Db_connect_.Null;}
|
||||
public void Connect() {}
|
||||
public String Key() {return Db_conn_info_.Null.Key();}
|
||||
public Db_conn_info Conn_info() {return Db_conn_info_.Null;}
|
||||
public void Conn_open() {}
|
||||
public void Conn_term() {}
|
||||
public void Txn_bgn() {}
|
||||
public void Txn_end() {}
|
||||
public Db_engine Make_new(Db_conn_info conn_info) {return this;}
|
||||
|
||||
public Object Execute(Db_qry cmd) {return cmd.ExecRdrAble() ? (Object)DataRdr_.Null : -1;}
|
||||
public Object New_db_cmd(String sql) {throw Err_.not_implemented_();}
|
||||
public DataRdr NewDataRdr(java.sql.ResultSet rdr, String sql) {return DataRdr_.Null;}
|
||||
public Db_stmt New_db_stmt(Db_provider provider, Db_qry qry) {return Db_stmt_.Null;}
|
||||
public void Txn_bgn() {}
|
||||
public void Txn_end() {}
|
||||
public void Rls() {}
|
||||
public Db_engine MakeEngine(Db_connect connectInfo) {return this;}
|
||||
public Object New_db_cmd(String sql) {throw Err_.not_implemented_();}
|
||||
public DataRdr NewDataRdr(java.sql.ResultSet rdr, String sql) {return DataRdr_.Null;}
|
||||
public Db_rdr New_db_rdr(Object o, String sql) {return Db_rdr_.Null;}
|
||||
public Db_stmt New_db_stmt(Db_provider provider, Db_qry qry) {return Db_stmt_.Null;}
|
||||
public static final Db_engine_null _ = new Db_engine_null(); Db_engine_null() {}
|
||||
}
|
||||
class ExecSqlWkr implements Db_qryWkr {
|
||||
|
32
140_dbs/src_200_engine/gplx/dbs/Db_engine_regy.java
Normal file
32
140_dbs/src_200_engine/gplx/dbs/Db_engine_regy.java
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_engine_regy {
|
||||
private final HashAdp hash = HashAdp_.new_();
|
||||
Db_engine_regy() {
|
||||
this.Add(Db_engine_null._)
|
||||
.Add(TdbEngine._)
|
||||
.Add(Mysql_engine._)
|
||||
.Add(Postgres_engine._)
|
||||
.Add(Sqlite_engine._)
|
||||
;
|
||||
}
|
||||
public Db_engine_regy Add(Db_engine engine) {hash.Add(engine.Key(), engine); return this;}
|
||||
public Db_engine Get(String key) {return (Db_engine)hash.FetchOrFail(key);}
|
||||
public static final Db_engine_regy _ = new Db_engine_regy();
|
||||
}
|
@ -17,19 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import java.sql.*;
|
||||
abstract class Db_engine_sql_base implements Db_engine, RlsAble {
|
||||
abstract class Db_engine_sql_base implements Db_engine {
|
||||
public abstract String Key();
|
||||
public Db_connect ConnectInfo() {return dbInfo;} protected Db_connect dbInfo;
|
||||
public abstract Db_engine MakeEngine(Db_connect dbInfo);
|
||||
public Db_conn_info Conn_info() {return conn_info;} protected Db_conn_info conn_info;
|
||||
@gplx.Virtual public void Txn_bgn() {Execute(Db_qry_sql.xtn_("BEGIN TRANSACTION;"));}
|
||||
@gplx.Virtual public void Txn_end() {Execute(Db_qry_sql.xtn_("COMMIT TRANSACTION;"));}
|
||||
public abstract Db_engine Make_new(Db_conn_info conn_info);
|
||||
@gplx.Virtual public Sql_cmd_wtr SqlWtr() {return Sql_cmd_wtr_.Ansi;}
|
||||
public Object Execute(Db_qry cmd) {
|
||||
Db_qryWkr wkr = (Db_qryWkr)wkrs.FetchOrFail(cmd.KeyOfDb_qry());
|
||||
return wkr.Exec(this, cmd);
|
||||
}
|
||||
@gplx.Virtual public void Txn_bgn() {Execute(Db_qry_sql.xtn_("BEGIN TRANSACTION;"));}
|
||||
@gplx.Virtual public void Txn_end() {Execute(Db_qry_sql.xtn_("COMMIT TRANSACTION;"));}
|
||||
@gplx.Internal protected void ctor_SqlEngineBase(Db_connect dbInfo) {
|
||||
this.dbInfo = dbInfo;
|
||||
@gplx.Internal protected void ctor_SqlEngineBase(Db_conn_info conn_info) {
|
||||
this.conn_info = conn_info;
|
||||
wkrs.Add(Db_qry_select.KeyConst, new ExecSqlWkr());
|
||||
wkrs.Add(Db_qry_insert.KeyConst, new ExecSqlWkr());
|
||||
wkrs.Add(Db_qry_update.KeyConst, new ExecSqlWkr());
|
||||
@ -53,21 +53,22 @@ abstract class Db_engine_sql_base implements Db_engine, RlsAble {
|
||||
}
|
||||
catch (Exception exc) {throw Err_.err_(exc, "exec reader failed").Add("sql", sql).Add("err", Err_.Message_gplx_brief(exc));}
|
||||
}
|
||||
@gplx.Internal protected abstract Connection NewDbCon();
|
||||
@gplx.Internal protected abstract Connection Conn_new();
|
||||
@gplx.Virtual public DataRdr NewDataRdr(ResultSet rdr, String sql) {return gplx.stores.Db_data_rdr_.new_(rdr, sql);}
|
||||
public Db_stmt New_db_stmt(Db_provider provider, Db_qry qry) {return new Db_stmt_cmd(provider, qry);}
|
||||
public Db_rdr New_db_rdr(Object rdr, String sql) {return new Db_rdr__basic((ResultSet)rdr, sql);}
|
||||
public Db_stmt New_db_stmt(Db_provider provider, Db_qry qry) {return new Db_stmt_cmd(provider, qry);}
|
||||
public Object New_db_cmd(String sql) {
|
||||
try {return connection.prepareStatement(sql);}
|
||||
catch (Exception e) {
|
||||
throw Err_.err_(e, "failed to prepare sql; sql={0}", sql);}
|
||||
}
|
||||
public void Connect() {
|
||||
connection = NewDbCon();
|
||||
public void Conn_open() {
|
||||
connection = Conn_new();
|
||||
} private Connection connection;
|
||||
public void Rls() {
|
||||
public void Conn_term() {
|
||||
// if (Env_.Mode_testing()) return; // WORKAROUND:MYSQL:else errors randomly when running all tests. possible connection pooling issue (?); // commented out 2013-08-22
|
||||
try {connection.close();}
|
||||
catch (SQLException e) {throw Err_.err_(e, "close connection failed").Add("ConnectInfo", dbInfo.Raw_of_db_connect());}
|
||||
catch (SQLException e) {throw Err_.err_(e, "close connection failed").Add("ConnectInfo", conn_info.Str_raw());}
|
||||
}
|
||||
Statement NewDbCmd(String commandText) {
|
||||
Statement cmd = null;
|
||||
@ -77,6 +78,6 @@ abstract class Db_engine_sql_base implements Db_engine, RlsAble {
|
||||
}
|
||||
protected Connection NewDbCon(String url, String uid, String pwd) {
|
||||
try {return DriverManager.getConnection(url, uid, pwd);}
|
||||
catch (SQLException e) {throw Err_.err_(e, "connection open failed").Add("ConnectInfo", ConnectInfo().Raw_of_db_connect());}
|
||||
catch (SQLException e) {throw Err_.err_(e, "connection open failed").Add("ConnectInfo", Conn_info().Str_raw());}
|
||||
}
|
||||
}
|
||||
|
@ -19,16 +19,16 @@ package gplx.dbs; import gplx.*;
|
||||
import gplx.stores.*;
|
||||
import java.sql.*;
|
||||
class Mysql_engine extends Db_engine_sql_base {
|
||||
@Override public String Key() {return Db_connect_mysql.KeyDef;}
|
||||
@Override public String Key() {return Db_conn_info__mysql.Key_const;}
|
||||
@Override public Sql_cmd_wtr SqlWtr() {return Sql_cmd_wtr_.BackslashSensitive;}
|
||||
@Override public Db_engine MakeEngine(Db_connect connectInfo) {
|
||||
@Override public Db_engine Make_new(Db_conn_info connectInfo) {
|
||||
Mysql_engine rv = new Mysql_engine();
|
||||
rv.ctor_SqlEngineBase(connectInfo);
|
||||
return rv;
|
||||
}
|
||||
@Override public DataRdr NewDataRdr(ResultSet rdr, String commandText) {return Mysql_rdr.new_(rdr, commandText);}
|
||||
@gplx.Internal @Override protected Connection NewDbCon() {
|
||||
Db_connect_mysql connUrl = (Db_connect_mysql)dbInfo;
|
||||
@gplx.Internal @Override protected Connection Conn_new() {
|
||||
Db_conn_info__mysql connUrl = (Db_conn_info__mysql)conn_info;
|
||||
return NewDbCon("jdbc:mysql://localhost/" + connUrl.Database() + "?characterEncoding=UTF8", connUrl.Uid(), connUrl.Pwd());
|
||||
}
|
||||
@gplx.Internal protected static final Mysql_engine _ = new Mysql_engine(); Mysql_engine() {}
|
||||
|
@ -19,17 +19,17 @@ package gplx.dbs; import gplx.*;
|
||||
import gplx.stores.*;
|
||||
import java.sql.*;
|
||||
class Postgres_engine extends Db_engine_sql_base {
|
||||
@Override public String Key() {return Db_connect_postgres.KeyDef;}
|
||||
@Override public String Key() {return Db_conn_info__postgres.Key_const;}
|
||||
@Override public Sql_cmd_wtr SqlWtr() {return Sql_cmd_wtr_.BackslashSensitive;}
|
||||
@Override public Db_engine MakeEngine(Db_connect connectInfo) {
|
||||
@Override public Db_engine Make_new(Db_conn_info connectInfo) {
|
||||
Postgres_engine rv = new Postgres_engine();
|
||||
rv.ctor_SqlEngineBase(connectInfo);
|
||||
return rv;
|
||||
}
|
||||
@Override public DataRdr NewDataRdr(ResultSet rdr, String commandText) {return Db_data_rdr_.new_(rdr, commandText);}
|
||||
@gplx.Internal @Override protected Connection NewDbCon() {
|
||||
Db_connect_postgres connUrl = (Db_connect_postgres)dbInfo;
|
||||
return NewDbCon("jdbc:" + connUrl.Key_of_db_connect() + "://localhost/" + connUrl.Database(), connUrl.Uid(), connUrl.Pwd());
|
||||
@gplx.Internal @Override protected Connection Conn_new() {
|
||||
Db_conn_info__postgres connUrl = (Db_conn_info__postgres)conn_info;
|
||||
return NewDbCon("jdbc:" + connUrl.Key() + "://localhost/" + connUrl.Database(), connUrl.Uid(), connUrl.Pwd());
|
||||
}
|
||||
@gplx.Internal protected static final Postgres_engine _ = new Postgres_engine(); Postgres_engine() {}
|
||||
}
|
||||
|
@ -19,15 +19,15 @@ package gplx.dbs; import gplx.*;
|
||||
import gplx.stores.*;
|
||||
import java.sql.*;
|
||||
class Sqlite_engine extends Db_engine_sql_base {
|
||||
@Override public String Key() {return Db_connect_sqlite.KeyDef;}
|
||||
@Override public Db_engine MakeEngine(Db_connect connectInfo) {
|
||||
@Override public String Key() {return Db_conn_info__sqlite.Key_const;}
|
||||
@Override public Db_engine Make_new(Db_conn_info connectInfo) {
|
||||
Sqlite_engine rv = new Sqlite_engine();
|
||||
rv.ctor_SqlEngineBase(connectInfo);
|
||||
return rv;
|
||||
}
|
||||
@Override public DataRdr NewDataRdr(ResultSet rdr, String commandText) {return Sqlite_rdr.new_(rdr, commandText);}
|
||||
static boolean loaded = false;
|
||||
@gplx.Internal @Override protected Connection NewDbCon() {
|
||||
@gplx.Internal @Override protected Connection Conn_new() {
|
||||
if (!loaded) {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
@ -35,7 +35,7 @@ class Sqlite_engine extends Db_engine_sql_base {
|
||||
catch (ClassNotFoundException e) {throw Err_.new_("could not load sqlite jdbc driver");}
|
||||
loaded = true;
|
||||
}
|
||||
Db_connect_sqlite connUrl = (Db_connect_sqlite)dbInfo;
|
||||
Db_conn_info__sqlite connUrl = (Db_conn_info__sqlite)conn_info;
|
||||
return NewDbCon("jdbc:sqlite://" + String_.Replace(connUrl.Database(), "\\", "/"), "", "");
|
||||
}
|
||||
private boolean pragma_needed = true;
|
||||
|
@ -51,7 +51,7 @@ public class Sqlite_engine_ {
|
||||
}
|
||||
public static void Pragma_page_size_4096(Db_provider p) {Pragma_page_size(p, 4096);}
|
||||
public static void Pragma_page_size(Db_provider p, int val) {
|
||||
Db_qry qry = Db_qry_sql.ddl_("PRAGMA page_size = " + Int_.XtoStr(val) + ";");
|
||||
Db_qry qry = Db_qry_sql.ddl_("PRAGMA page_size = " + Int_.Xto_str(val) + ";");
|
||||
p.Exec_qry(qry);
|
||||
}
|
||||
public static void Idx_create(Db_provider p, Db_idx_itm... idxs) {Idx_create(Gfo_usr_dlg_.Null, p, "", idxs);}
|
||||
@ -68,15 +68,15 @@ public class Sqlite_engine_ {
|
||||
public static Db_provider Provider_load_or_fail_(Io_url url) {
|
||||
boolean exists = Io_mgr._.ExistsFil(url);
|
||||
if (!exists) throw Err_.new_fmt_("db does not exist; url=~{0}", url.Raw());
|
||||
Db_connect connect = Db_connect_sqlite.load_(url);
|
||||
return Db_provider_.new_(connect);
|
||||
Db_conn_info connect = Db_conn_info__sqlite.load_(url);
|
||||
return Db_provider_.new_and_open_(connect);
|
||||
}
|
||||
public static Db_provider Provider_load_or_make_(Io_url url) {return Provider_load_or_make_(url, Bool_obj_ref.n_());}
|
||||
public static Db_provider Provider_load_or_make_(Io_url url, Bool_obj_ref created) {
|
||||
boolean exists = Io_mgr._.ExistsFil(url);
|
||||
created.Val_(!exists);
|
||||
Db_connect connect = exists ? Db_connect_sqlite.load_(url) : Db_connect_sqlite.make_(url);
|
||||
Db_provider p = Db_provider_.new_(connect);
|
||||
Db_conn_info connect = exists ? Db_conn_info__sqlite.load_(url) : Db_conn_info__sqlite.make_(url);
|
||||
Db_provider p = Db_provider_.new_and_open_(connect);
|
||||
if (!exists)
|
||||
Pragma_page_size(p, 4096);
|
||||
return p;
|
||||
|
@ -24,7 +24,7 @@ public class db_DataTypes_tst {
|
||||
fx.RunAll(Db_provider_fxt.Mysql());
|
||||
}
|
||||
@Test public void Tdb() {if (Tfds.SkipDb) return;
|
||||
fx.Select_FloatStr_(Float_.XtoStr(Float_.Div(1, 3)));
|
||||
fx.Select_FloatStr_(Float_.Xto_str(Float_.Div(1, 3)));
|
||||
fx.RunAll(Db_provider_fxt.Tdb("110_dbs_multiple_data_types.dsv"));
|
||||
}
|
||||
@Test public void Postgres() {if (Db_provider_fxt.SkipPostgres) return;
|
||||
@ -51,12 +51,12 @@ INSERT INTO dbs_multiple_data_types VALUES (1, 'John Doe', B'1', '3/30/2006 10:2
|
||||
class DataTypes_base_fxt {
|
||||
public Db_provider Provider() {return provider;} Db_provider provider;
|
||||
public DataTypes_base_fxt() {}
|
||||
public void Rls() {provider.Rls();}
|
||||
public void Rls() {provider.Conn_term();}
|
||||
public String Select_FloatStr() {return select_FloatStr;} public DataTypes_base_fxt Select_FloatStr_(String v) {select_FloatStr = v; return this;} private String select_FloatStr;
|
||||
public void RunAll(Db_provider provider) {
|
||||
this.provider = provider;
|
||||
this.Select_hook(select_FloatStr);
|
||||
provider.Rls();
|
||||
provider.Conn_term();
|
||||
}
|
||||
public void Select_hook(String floatStr) {
|
||||
DataRdr rdr = Db_qry_.select_tbl_("dbs_multiple_data_types").Exec_qry_as_rdr(provider);
|
||||
|
@ -19,14 +19,14 @@ package gplx.dbs; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class TdbConnectInfo_tst {
|
||||
@Test public void Full() {
|
||||
Db_connect connectInfo = Db_connect_.parse_("gplx_key=tdb;url=C:\\dir\\xmpl.tdb;format=dsv;");
|
||||
Db_conn_info connectInfo = Db_conn_info_.parse_("gplx_key=tdb;url=C:\\dir\\xmpl.tdb;format=dsv;");
|
||||
tst_Parse(connectInfo, Io_url_.new_any_("C:\\dir\\xmpl.tdb"), "dsv");
|
||||
}
|
||||
@Test public void DefaultFormat() {
|
||||
Db_connect connectInfo = Db_connect_.parse_("gplx_key=tdb;url=C:\\dir\\xmpl.tdb"); // dsv Format inferred
|
||||
Db_conn_info connectInfo = Db_conn_info_.parse_("gplx_key=tdb;url=C:\\dir\\xmpl.tdb"); // dsv Format inferred
|
||||
tst_Parse(connectInfo, Io_url_.new_any_("C:\\dir\\xmpl.tdb"), "dsv");
|
||||
}
|
||||
void tst_Parse(Db_connect connectInfo, Io_url url, String format) {
|
||||
Tfds.Eq(((Db_connect_tdb)connectInfo).Url(), url);
|
||||
void tst_Parse(Db_conn_info connectInfo, Io_url url, String format) {
|
||||
Tfds.Eq(((Db_conn_info__tdb)connectInfo).Url(), url);
|
||||
}
|
||||
}
|
||||
|
@ -43,5 +43,5 @@ public class TdbDatabase {
|
||||
}
|
||||
int FileId_next = TdbFile.MainFileId + 1;
|
||||
int TableId_next = 1;
|
||||
// public static Io_url UrlOf(Db_connect url) {return Io_url_.new_any_(url.ServerName());}
|
||||
// public static Io_url UrlOf(Db_conn_info url) {return Io_url_.new_any_(url.ServerName());}
|
||||
}
|
||||
|
@ -18,17 +18,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs; import gplx.*;
|
||||
class TdbEngine implements Db_engine {
|
||||
public String Key() {return KeyDef;} public static final String KeyDef = "tdb";
|
||||
public Db_connect ConnectInfo() {return connectInfo;} Db_connect connectInfo;
|
||||
public Db_conn_info Conn_info() {return conn_info;} Db_conn_info conn_info;
|
||||
public TdbDatabase Db() {return db;} TdbDatabase db;
|
||||
public Db_engine MakeEngine(Db_connect connectInfo) {
|
||||
TdbEngine rv = new TdbEngine();
|
||||
rv.CtorTdbEngine(connectInfo);
|
||||
return rv;
|
||||
}
|
||||
public void Connect() {
|
||||
String urlStr = (String)connectInfo.Server();
|
||||
public void Conn_open() {
|
||||
String urlStr = (String)conn_info.Server();
|
||||
db = loadMgr.LoadTbls(Io_url_.new_any_(urlStr));
|
||||
}
|
||||
public void Conn_term() {}
|
||||
public void Txn_bgn() {}
|
||||
public void Txn_end() {}
|
||||
public Db_engine Make_new(Db_conn_info conn_info) {
|
||||
TdbEngine rv = new TdbEngine();
|
||||
rv.CtorTdbEngine(conn_info);
|
||||
return rv;
|
||||
}
|
||||
public Object Execute(Db_qry cmd) {
|
||||
Db_qryWkr wkr = (Db_qryWkr)wkrs.FetchOrFail(cmd.KeyOfDb_qry());
|
||||
return wkr.Exec(this, cmd);
|
||||
@ -36,8 +39,7 @@ class TdbEngine implements Db_engine {
|
||||
public DataRdr NewDataRdr(java.sql.ResultSet rdr, String sql) {return DataRdr_.Null;}
|
||||
public Db_stmt New_db_stmt(Db_provider provider, Db_qry qry) {return new Db_stmt_sql().Parse(Sql_cmd_wtr_.Ansi.XtoSqlQry(qry, true));}
|
||||
public Object New_db_cmd(String sql) {throw Err_.not_implemented_();}
|
||||
public void Txn_bgn() {}
|
||||
public void Txn_end() {}
|
||||
public Db_rdr New_db_rdr(Object o, String sql) {return Db_rdr_.Null;}
|
||||
public TdbTable FetchTbl(String name) {
|
||||
TdbTable tbl = db.Tables().FetchOrFail(name);
|
||||
if (!tbl.IsLoaded()) loadMgr.LoadTbl(db, tbl);
|
||||
@ -49,13 +51,12 @@ class TdbEngine implements Db_engine {
|
||||
public void FlushTbl(TdbTable tbl) {
|
||||
saveMgr.SaveFile(db, tbl.File());
|
||||
}
|
||||
public void Rls() {}
|
||||
|
||||
HashAdp wkrs = HashAdp_.new_(); TdbDbLoadMgr loadMgr = TdbDbLoadMgr.new_(); TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_();
|
||||
@gplx.Internal protected static final TdbEngine _ = new TdbEngine();
|
||||
//TdbEngine() {this.connectInfo = TdbConnectUrl._;}
|
||||
void CtorTdbEngine(Db_connect connectInfo) {
|
||||
this.connectInfo = connectInfo;
|
||||
//TdbEngine() {this.conn_info = TdbConnectUrl._;}
|
||||
void CtorTdbEngine(Db_conn_info conn_info) {
|
||||
this.conn_info = conn_info;
|
||||
wkrs.Add(Db_qry_select.KeyConst, TdbSelectWkr._);
|
||||
wkrs.Add(Db_qry_insert.KeyConst, TdbInsertWkr.new_());
|
||||
wkrs.Add(Db_qry_update.KeyConst, TdbUpdateWkr.new_());
|
||||
|
@ -81,9 +81,9 @@ public class TdbFlush_tst {
|
||||
}
|
||||
class TdbEngineFxt {
|
||||
public TdbEngine run_MakeEngine(Io_url url) {
|
||||
Db_connect connectInfo = Db_connect_.tdb_(url);
|
||||
TdbEngine engine = (TdbEngine)TdbEngine._.MakeEngine(connectInfo);
|
||||
engine.Connect();
|
||||
Db_conn_info connectInfo = Db_conn_info_.tdb_(url);
|
||||
TdbEngine engine = (TdbEngine)TdbEngine._.Make_new(connectInfo);
|
||||
engine.Conn_open();
|
||||
return engine;
|
||||
}
|
||||
public TdbFile run_MakeFile(TdbEngine engine, Io_url url) {return engine.Db().MakeFile(url);}
|
||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.stores; import gplx.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; /*Db_connect*/
|
||||
import gplx.dbs.*; /*Db_conn_info*/
|
||||
public class DbMaprMgr_tst {
|
||||
@Before public void setup() {
|
||||
mgr = DbMaprMgr.new_().RootIndexFlds_(DbMaprArg.new_("id", "disc_id"))
|
||||
@ -37,9 +37,9 @@ public class DbMaprMgr_tst {
|
||||
. Flds_add(MockStream.id_idk, "stream_id").Flds_add(MockStream.name_idk, "stream_name")
|
||||
. ConstantFlds_add("stream_type", 1)
|
||||
)));
|
||||
wtr = DbMaprWtr.new_by_url_(Db_connect_.Test);
|
||||
wtr = DbMaprWtr.new_by_url_(Db_conn_info_.Test);
|
||||
wtr.EnvVars().Add(DbMaprWtr.Key_Mgr, mgr);
|
||||
provider = Db_provider_pool._.FetchOrNew(Db_connect_.Test);
|
||||
provider = Db_provider_pool._.Get_or_new(Db_conn_info_.Test);
|
||||
Db_qry_fxt.DeleteAll(provider, "mock_discs", "mock_titles", "mock_chapters", "mock_streams");
|
||||
} DbMaprMgr mgr; DbMaprWtr wtr; Db_provider provider; MockDisc disc; MockTitle title; MockChapter chapter; MockStream audio, subtitle; SrlMgr rdr;
|
||||
@Test public void PurgeObjTree() {
|
||||
@ -133,7 +133,7 @@ public class DbMaprMgr_tst {
|
||||
Tfds.Eq("subtitle1", ((MockStream)t.Subtitles().FetchAt(0)).Name());
|
||||
}
|
||||
DbMaprRdr rdr_() {
|
||||
DbMaprRdr rv = DbMaprRdr.new_(Db_connect_.Test, Db_crt_.eq_("disc_id", 1));
|
||||
DbMaprRdr rv = DbMaprRdr.new_(Db_conn_info_.Test, Db_crt_.eq_("disc_id", 1));
|
||||
rv.EnvVars().Add(DbMaprWtr.Key_Mgr, mgr);
|
||||
return rv;
|
||||
}
|
||||
|
@ -114,9 +114,9 @@ public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
HashAdp tables = HashAdp_.new_();
|
||||
Db_provider provider; Criteria rootCrt;
|
||||
DbMaprMgr mgr; ListAdp rowStack = ListAdp_.new_();
|
||||
public static DbMaprRdr new_(Db_connect dbInfo, Criteria rootCrt) {
|
||||
public static DbMaprRdr new_(Db_conn_info dbInfo, Criteria rootCrt) {
|
||||
DbMaprRdr rv = new DbMaprRdr();
|
||||
rv.provider = Db_provider_pool._.FetchOrNew(dbInfo); rv.rootCrt = rootCrt;
|
||||
rv.provider = Db_provider_pool._.Get_or_new(dbInfo); rv.rootCrt = rootCrt;
|
||||
return rv;
|
||||
} DbMaprRdr() {}
|
||||
}
|
@ -83,9 +83,9 @@ public class DbMaprWtr extends DataWtr_base implements DataWtr {
|
||||
public String XtoStr() {return "";}
|
||||
@Override public SrlMgr SrlMgr_new(Object o) {return new DbMaprWtr();}
|
||||
DbMaprMgr mgr; Db_provider provider; String curTableName; Db_qry_insert insertCmd;
|
||||
public static DbMaprWtr new_by_url_(Db_connect url) {
|
||||
public static DbMaprWtr new_by_url_(Db_conn_info url) {
|
||||
DbMaprWtr rv = new DbMaprWtr();
|
||||
rv.provider = Db_provider_pool._.FetchOrNew(url);
|
||||
rv.provider = Db_provider_pool._.Get_or_new(url);
|
||||
return rv;
|
||||
} DbMaprWtr() {}
|
||||
public static final String Key_Mgr = "DbMapr.mgr";
|
||||
|
@ -43,12 +43,12 @@ public class Db_provider_fxt implements RlsAble {
|
||||
Tfds.Eq_ary(actlValAry, expdValAry);
|
||||
return record;
|
||||
}
|
||||
public void Rls() {provider.Rls();}
|
||||
public void Rls() {provider.Conn_term();}
|
||||
|
||||
public static Db_provider Mysql() {return Db_provider_.new_(Db_connect_mysql.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_provider Tdb(String fileName) {return Db_provider_.new_(Db_connect_.tdb_(Tfds.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));}
|
||||
public static Db_provider Postgres() {return Db_provider_.new_(Db_connect_postgres.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_provider Sqlite() {return Db_provider_.new_(Db_connect_sqlite.load_(Tfds.RscDir.GenSubFil_nest("140_dbs", "sqlite", "unit_tests.db")));}
|
||||
public static Db_provider Mysql() {return Db_provider_.new_and_open_(Db_conn_info__mysql.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_provider Tdb(String fileName) {return Db_provider_.new_and_open_(Db_conn_info_.tdb_(Tfds.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));}
|
||||
public static Db_provider Postgres() {return Db_provider_.new_and_open_(Db_conn_info__postgres.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_provider Sqlite() {return Db_provider_.new_and_open_(Db_conn_info__sqlite.load_(Tfds.RscDir.GenSubFil_nest("140_dbs", "sqlite", "unit_tests.db")));}
|
||||
// public static Db_provider Mssql() {return MssqlConnectUrl.WindowsAuth(".", "unit_tests");
|
||||
public static final boolean SkipPostgres = Tfds.SkipDb || true;
|
||||
}
|
@ -19,7 +19,7 @@ package gplx.dbs; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class PoolIds_tst {
|
||||
@Before public void setup() {
|
||||
provider = Db_provider_pool._.FetchOrNew(Db_connect_.Test);
|
||||
provider = Db_provider_pool._.Get_or_new(Db_conn_info_.Test);
|
||||
Db_qry_fxt.DeleteAll(provider, PoolIds.Tbl_Name);
|
||||
mgr = PoolIds._;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public abstract class GroupBys_base_tst {
|
||||
Db_qry_.delete_tbl_("dbs_group_bys").Exec_qry(provider);
|
||||
}
|
||||
@After public void teardown() {
|
||||
provider.Rls();
|
||||
provider.Conn_term();
|
||||
}
|
||||
protected void GroupBy_1fld_hook() {
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 1));
|
||||
|
@ -26,7 +26,7 @@ public abstract class InsertIntos_base_tst {
|
||||
provider.Exec_qry(Db_qry_delete.new_().BaseTable_("dbs_insert_intos"));
|
||||
}
|
||||
@After public void teardown() {
|
||||
provider.Rls();
|
||||
provider.Conn_term();
|
||||
}
|
||||
protected void Select_hook() {
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 1));
|
||||
|
@ -25,7 +25,7 @@ public abstract class Joins_base_tst {
|
||||
Db_qry_delete.new_().BaseTable_("dbs_join1").Exec_qry(provider);
|
||||
}
|
||||
@After public void teardown() {
|
||||
provider.Rls();
|
||||
provider.Conn_term();
|
||||
}
|
||||
protected void InnerJoin_hook() {
|
||||
provider.Exec_qry(Db_qry_insert.new_().BaseTable_("dbs_crud_ops").Arg_("id", 0).Arg_("name", "me"));
|
||||
|
@ -23,7 +23,7 @@ public abstract class OrderBys_base_tst {
|
||||
fx.Provider_(provider);
|
||||
Db_qry_delete.new_().BaseTable_("dbs_crud_ops").Exec_qry(provider);
|
||||
} protected Db_provider_fxt fx = new Db_provider_fxt();
|
||||
@After public void teardown() {provider.Rls();}
|
||||
@After public void teardown() {provider.Conn_term();}
|
||||
protected abstract Db_provider provider_(); protected Db_provider provider;
|
||||
protected void Basic_hook() {
|
||||
fx.tst_ExecDml(1, Db_qry_insert.new_().BaseTable_("dbs_crud_ops").Arg_("id", 1).Arg_("name", "you"));
|
||||
|
@ -82,7 +82,7 @@ public class SqliteDbMain {
|
||||
}
|
||||
long time_elapsed = (Env_.TickCount() - time_bgn);
|
||||
// provider.Txn_mgr().Txn_end();
|
||||
provider.Rls();
|
||||
provider.Conn_term();
|
||||
Tfds.Write(time_elapsed, number / time_elapsed);
|
||||
// 250; 260
|
||||
Tfds.Write("");
|
||||
|
@ -41,7 +41,7 @@ public class IptBnd_upDownRange implements InjectAble, GfoInvkAble, GfoEvObj {
|
||||
public int Adj() {return adj;} public IptBnd_upDownRange Adj_(int v) {adj = v; return this;} int adj;
|
||||
void WhenEvt(GfsCtx ctx, GfoMsg m) {
|
||||
curVal = m.ReadInt(arg) + adj;
|
||||
txtBox.Text_(Int_.XtoStr(curVal));
|
||||
txtBox.Text_(Int_.Xto_str(curVal));
|
||||
}
|
||||
void ExecCmd(String c, int val) {
|
||||
GfoInvkAble_.InvkCmd_val(src, c, val - adj);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user