mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
v2.6.4.1
This commit is contained in:
parent
fe0ce6340d
commit
bf44bcf3c6
@ -16,14 +16,21 @@ 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.core.brys; import gplx.*; import gplx.core.*;
|
||||
public class Bry_rdr {
|
||||
private byte[] src; private int src_len;
|
||||
public Bry_rdr Src_(byte[] src, int src_len) {this.src = src; this.src_len = src_len; pos = 0; return this;} public Bry_rdr Src_(byte[] src) {return Src_(src, src.length);}
|
||||
public int Pos() {return pos;} public Bry_rdr Pos_(int v) {this.pos = v; return this;} private int pos;
|
||||
public class Bry_rdr {
|
||||
public byte[] Src() {return src;} protected byte[] src;
|
||||
public int Src_len() {return src_len;} protected int src_len;
|
||||
public void Init(byte[] src) {this.Init(src, 0);}
|
||||
public void Init(byte[] src, int pos) {
|
||||
this.src = src; this.src_len = src.length; this.pos = pos;
|
||||
}
|
||||
public int Pos() {return pos;} public Bry_rdr Pos_(int v) {this.pos = v; return this;} protected int pos;
|
||||
public void Pos_add(int v) {pos += v;}
|
||||
public boolean Pos_is_eos() {return pos == src_len;}
|
||||
public void Pos_add_one() {++pos;}
|
||||
public int Or_int() {return or_int;} public void Or_int_(int v) {or_int = v;} private int or_int = Int_.MinValue;
|
||||
public byte[] Or_bry() {return or_bry;} public void Or_bry_(byte[] v) {or_bry = v;} private byte[] or_bry;
|
||||
public int Find_fwd(byte find) {return Bry_finder.Find_fwd(src, find, pos);}
|
||||
public int Find_fwd_ws() {return Bry_finder.Find_fwd_until_ws(src, pos, src_len);}
|
||||
public int Find_fwd__pos_at_lhs(byte[] find_bry) {return Find_fwd__pos_at(find_bry, Bool_.N);}
|
||||
public int Find_fwd__pos_at_rhs(byte[] find_bry) {return Find_fwd__pos_at(find_bry, Bool_.Y);}
|
||||
public int Find_fwd__pos_at(byte[] find_bry, boolean pos_at_rhs) {
|
||||
@ -37,6 +44,7 @@ public class Bry_rdr {
|
||||
public int Read_int_to_pipe() {return Read_int_to(Byte_ascii.Pipe);}
|
||||
public int Read_int_to_nl() {return Read_int_to(Byte_ascii.NewLine);}
|
||||
public int Read_int_to_quote() {return Read_int_to(Byte_ascii.Quote);}
|
||||
public int Read_int_to_non_num(){return Read_int_to(Byte_ascii.Nil);}
|
||||
public int Read_int_to(byte to_char) {
|
||||
int bgn = pos;
|
||||
int rv = 0;
|
||||
@ -54,8 +62,14 @@ public class Bry_rdr {
|
||||
else // 1st negative
|
||||
negative = -1; // flag negative
|
||||
break;
|
||||
default:
|
||||
return b == to_char ? rv * negative : or_int;
|
||||
default: {
|
||||
boolean match = b == to_char;
|
||||
if (to_char == Byte_ascii.Nil) {// hack for Read_int_to_non_num
|
||||
--pos;
|
||||
match = true;
|
||||
}
|
||||
return match ? rv * negative : or_int;
|
||||
}
|
||||
}
|
||||
}
|
||||
return bgn == pos ? or_int : rv * negative;
|
||||
@ -87,4 +101,55 @@ public class Bry_rdr {
|
||||
byte[] double_bry = Read_bry_to(to_char);
|
||||
return Double_.parse_(String_.new_a7(double_bry)); // double will never have utf8
|
||||
}
|
||||
@gplx.Virtual public Bry_rdr Skip_ws() {
|
||||
while (pos < src_len) {
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Tab: case Byte_ascii.NewLine: case Byte_ascii.CarriageReturn: case Byte_ascii.Space:
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Bry_rdr Skip_alpha_num_under() {
|
||||
while (pos < src_len) {
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
case Byte_ascii.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E:
|
||||
case Byte_ascii.Ltr_F: case Byte_ascii.Ltr_G: case Byte_ascii.Ltr_H: case Byte_ascii.Ltr_I: case Byte_ascii.Ltr_J:
|
||||
case Byte_ascii.Ltr_K: case Byte_ascii.Ltr_L: case Byte_ascii.Ltr_M: case Byte_ascii.Ltr_N: case Byte_ascii.Ltr_O:
|
||||
case Byte_ascii.Ltr_P: case Byte_ascii.Ltr_Q: case Byte_ascii.Ltr_R: case Byte_ascii.Ltr_S: case Byte_ascii.Ltr_T:
|
||||
case Byte_ascii.Ltr_U: case Byte_ascii.Ltr_V: case Byte_ascii.Ltr_W: case Byte_ascii.Ltr_X: case Byte_ascii.Ltr_Y: case Byte_ascii.Ltr_Z:
|
||||
case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e:
|
||||
case Byte_ascii.Ltr_f: case Byte_ascii.Ltr_g: case Byte_ascii.Ltr_h: case Byte_ascii.Ltr_i: case Byte_ascii.Ltr_j:
|
||||
case Byte_ascii.Ltr_k: case Byte_ascii.Ltr_l: case Byte_ascii.Ltr_m: case Byte_ascii.Ltr_n: case Byte_ascii.Ltr_o:
|
||||
case Byte_ascii.Ltr_p: case Byte_ascii.Ltr_q: case Byte_ascii.Ltr_r: case Byte_ascii.Ltr_s: case Byte_ascii.Ltr_t:
|
||||
case Byte_ascii.Ltr_u: case Byte_ascii.Ltr_v: case Byte_ascii.Ltr_w: case Byte_ascii.Ltr_x: case Byte_ascii.Ltr_y: case Byte_ascii.Ltr_z:
|
||||
case Byte_ascii.Underline:
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public void Chk_bry_or_fail(byte[] bry) {
|
||||
int bry_len = bry.length;
|
||||
boolean match = Bry_.Match(src, pos, pos + bry_len, bry);
|
||||
if (match) pos += bry_len;
|
||||
else throw Err_.new_("bry.rdr:chk failed; bry={0} pos={1}", bry, pos);
|
||||
}
|
||||
public void Chk_byte_or_fail(byte b) {
|
||||
boolean match = pos < src_len ? src[pos] == b : false;
|
||||
if (match) ++pos;
|
||||
else throw Err_.new_("bry.rdr:chk failed; byte={0} pos={1}", b, pos);
|
||||
}
|
||||
public byte[] Mid_by_len_safe(int len) {
|
||||
int end = pos + len; if (end > src_len) end = src_len;
|
||||
return Bry_.Mid(src, pos, end);
|
||||
}
|
||||
}
|
@ -42,7 +42,7 @@ class ErrProcData {
|
||||
for (int i = 0; i < len; i++) {
|
||||
ErrProcData md = ErrProcData.parse_(lines[i]);
|
||||
if (md.SourceLine() == 0) break; // ASSUME: java code; not interested
|
||||
if (String_.HasAtBgn(md.signatureRaw, "gplx.Err_") || String_.HasAtBgn(md.signatureRaw, "gplx.Err.")) continue; // java includes entire stackTrace from point of creation; only care about point of throw
|
||||
if (String_.Has_at_bgn(md.signatureRaw, "gplx.Err_") || String_.Has_at_bgn(md.signatureRaw, "gplx.Err.")) continue; // java includes entire stackTrace from point of creation; only care about point of throw
|
||||
list.Add(md);
|
||||
}
|
||||
return (ErrProcData[])list.To_ary(ErrProcData.class);
|
||||
|
@ -414,8 +414,8 @@ public class Bry_ {
|
||||
if (src[i] == lkp) return true;
|
||||
return false;
|
||||
}
|
||||
public static boolean HasAtEnd(byte[] src, byte[] lkp) {int src_len = src.length; return HasAtEnd(src, lkp, src_len - lkp.length, src_len);}
|
||||
public static boolean HasAtEnd(byte[] src, byte[] lkp, int src_bgn, int src_end) {
|
||||
public static boolean Has_at_end(byte[] src, byte[] lkp) {int src_len = src.length; return Has_at_end(src, lkp, src_len - lkp.length, src_len);}
|
||||
public static boolean Has_at_end(byte[] src, byte[] lkp, int src_bgn, int src_end) {
|
||||
int lkp_len = lkp.length;
|
||||
if (src_bgn < 0) return false;
|
||||
int pos = src_end - lkp_len; if (pos < src_bgn) return false; // lkp is longer than src
|
||||
@ -424,11 +424,11 @@ public class Bry_ {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static boolean HasAtBgn(byte[] src, byte lkp, int src_bgn) {
|
||||
public static boolean Has_at_bgn(byte[] src, byte lkp, int src_bgn) {
|
||||
return src_bgn < src.length ? src[src_bgn] == lkp : false;
|
||||
}
|
||||
public static boolean HasAtBgn(byte[] src, byte[] lkp) {return HasAtBgn(src, lkp, 0, src.length);}
|
||||
public static boolean HasAtBgn(byte[] src, byte[] lkp, int src_bgn, int src_end) {
|
||||
public static boolean Has_at_bgn(byte[] src, byte[] lkp) {return Has_at_bgn(src, lkp, 0, src.length);}
|
||||
public static boolean Has_at_bgn(byte[] src, byte[] lkp, int src_bgn, int src_end) {
|
||||
int lkp_len = lkp.length;
|
||||
if (lkp_len + src_bgn > src_end) return false; // lkp is longer than src
|
||||
for (int i = 0; i < lkp_len; i++) {
|
||||
|
@ -47,7 +47,7 @@ public class Bry__tst {
|
||||
}
|
||||
Tfds.Eq_ary(expd, Bry_.XtoStrBytesByInt(val, Int_.DigitCount(val)));
|
||||
}
|
||||
@Test public void HasAtEnd() {
|
||||
@Test public void Has_at_end() {
|
||||
tst_HasAtEnd("a|bcd|e", "d" , 2, 5, true); // y_basic
|
||||
tst_HasAtEnd("a|bcd|e", "bcd" , 2, 5, true); // y_many
|
||||
tst_HasAtEnd("a|bcd|e", "|bcd" , 2, 5, false); // n_long
|
||||
@ -56,14 +56,14 @@ public class Bry__tst {
|
||||
tst_HasAtEnd("abc", "bd", false); // n
|
||||
tst_HasAtEnd("a", "ab", false); // exceeds_len
|
||||
}
|
||||
void tst_HasAtEnd(String src, String find, int bgn, int end, boolean expd) {Tfds.Eq(expd, Bry_.HasAtEnd(Bry_.new_u8(src), Bry_.new_u8(find), bgn, end));}
|
||||
void tst_HasAtEnd(String src, String find, boolean expd) {Tfds.Eq(expd, Bry_.HasAtEnd(Bry_.new_u8(src), Bry_.new_u8(find)));}
|
||||
@Test public void HasAtBgn() {
|
||||
void tst_HasAtEnd(String src, String find, int bgn, int end, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_end(Bry_.new_u8(src), Bry_.new_u8(find), bgn, end));}
|
||||
void tst_HasAtEnd(String src, String find, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_end(Bry_.new_u8(src), Bry_.new_u8(find)));}
|
||||
@Test public void Has_at_bgn() {
|
||||
tst_HasAtBgn("y_basic" , "a|bcd|e", "b" , 2, 5, true);
|
||||
tst_HasAtBgn("y_many" , "a|bcd|e", "bcd" , 2, 5, true);
|
||||
tst_HasAtBgn("n_long" , "a|bcd|e", "bcde" , 2, 5, false);
|
||||
tst_HasAtBgn("n_pos" , "a|bcd|e", "|bc" , 2, 5, false);
|
||||
} void tst_HasAtBgn(String tst, String src, String find, int bgn, int end, boolean expd) {Tfds.Eq(expd, Bry_.HasAtBgn(Bry_.new_u8(src), Bry_.new_u8(find), bgn, end), tst);}
|
||||
} void tst_HasAtBgn(String tst, String src, String find, int bgn, int end, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_bgn(Bry_.new_u8(src), Bry_.new_u8(find), bgn, end), tst);}
|
||||
@Test public void Match() {
|
||||
tst_Match("abc", 0, "abc", true);
|
||||
tst_Match("abc", 2, "c", true);
|
||||
|
@ -79,8 +79,8 @@ public class String_ implements GfoInvkAble {
|
||||
public static char CharAt(String s, int i) {return s.charAt(i);}
|
||||
public static int CodePointAt(String s, int i) {return s.codePointAt(i);}
|
||||
public static boolean Has(String s, String find) {return s.indexOf(find) != String_.Find_none;}
|
||||
public static boolean HasAtBgn(String s, String v) {return s.startsWith(v);}
|
||||
public static boolean HasAtEnd(String s, String v) {return s.endsWith(v);}
|
||||
public static boolean Has_at_bgn(String s, String v) {return s.startsWith(v);}
|
||||
public static boolean Has_at_end(String s, String v) {return s.endsWith(v);}
|
||||
public static int FindFwd(String s, String find) {return s.indexOf(find);}
|
||||
public static int FindFwd(String s, String find, int pos) {return s.indexOf(find, pos);}
|
||||
public static int FindBwd(String s, String find) {return s.lastIndexOf(find);}
|
||||
@ -204,7 +204,7 @@ public class String_ implements GfoInvkAble {
|
||||
}
|
||||
public static String DelBgnIf(String s, String find) {
|
||||
if (s == null) throw Err_arg.null_("s"); if (find == null) throw Err_arg.null_("find");
|
||||
return HasAtBgn(s, find) ? String_.Mid(s, Len(find)) : s;
|
||||
return Has_at_bgn(s, find) ? String_.Mid(s, Len(find)) : s;
|
||||
}
|
||||
public static String DelEnd(String s, int count) {
|
||||
if (count < 0) throw Err_arg.cannotBe_("< 0", "count", count);
|
||||
@ -214,7 +214,7 @@ public class String_ implements GfoInvkAble {
|
||||
}
|
||||
public static String DelEndIf(String s, String find) {
|
||||
if (s == null) throw Err_arg.null_("s"); if (find == null) throw Err_arg.null_("find");
|
||||
return HasAtEnd(s, find) ? Mid_lang(s, 0, Len(s) - Len(find)) : s;
|
||||
return Has_at_end(s, find) ? Mid_lang(s, 0, Len(s) - Len(find)) : s;
|
||||
}
|
||||
public static String LowerFirst(String s) {
|
||||
int len = Len(s); if (len == 0) return String_.Empty;
|
||||
|
@ -35,7 +35,7 @@ public class EnmMgr {
|
||||
String term = String_.Trim(ary[i]); // ex: key.ctrl + key.a
|
||||
if (prefix != null) term = String_.Replace(term, prefix, "");
|
||||
int cur = -1;
|
||||
if (String_.HasAtBgn(term, "#"))
|
||||
if (String_.Has_at_bgn(term, "#"))
|
||||
cur = Int_.parse_(String_.Mid(term, 1));
|
||||
else
|
||||
cur = Int_.cast_(rawRegy.Get_by(term));
|
||||
|
@ -57,7 +57,7 @@ public class Io_url implements CompareAble, EqAble, ParseAble, GfoInvkAble { //_
|
||||
}
|
||||
public String GenRelUrl_orEmpty(Io_url dir) {
|
||||
String dirRaw = dir.Raw();
|
||||
return String_.HasAtBgn(raw, dirRaw)
|
||||
return String_.Has_at_bgn(raw, dirRaw)
|
||||
? String_.DelBgn(raw, String_.Len(dirRaw))
|
||||
: String_.Empty;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class Io_url_ {
|
||||
private static String parse_http_file(String v, boolean wnt) {
|
||||
byte[] v_bry = Bry_.new_u8(v);
|
||||
int v_len = v_bry.length;
|
||||
if (Bry_.HasAtBgn(v_bry, Io_url.Http_file_bry, 0, v_len)) {
|
||||
if (Bry_.Has_at_bgn(v_bry, Io_url.Http_file_bry, 0, v_len)) {
|
||||
byte[] rv = new byte[v_len - Io_url.Http_file_len];
|
||||
for (int i = 0; i < rv.length; i++) {
|
||||
byte b = v_bry[i + Io_url.Http_file_len];
|
||||
@ -80,13 +80,13 @@ public class Io_url_ {
|
||||
return Io_url_.new_any_(val);
|
||||
}
|
||||
static String EndsWith_or_add(String raw, String endsWith) {
|
||||
if (String_.HasAtEnd(raw, endsWith)) return raw;
|
||||
if (String_.Has_at_end(raw, endsWith)) return raw;
|
||||
return raw += endsWith;
|
||||
}
|
||||
public static Io_url Rel_dir(String s) {return IsAbs(s) ? Io_url_.new_dir_(s) : Env_.AppUrl().OwnerDir().GenSubDir(s);}
|
||||
public static Io_url Rel_fil(String s) {return IsAbs(s) ? Io_url_.new_fil_(s) : Env_.AppUrl().OwnerDir().GenSubFil(s);}
|
||||
static boolean IsAbs(String s) {
|
||||
return String_.HasAtBgn(s, Op_sys.Lnx.Fsys_dir_spr_str())
|
||||
return String_.Has_at_bgn(s, Op_sys.Lnx.Fsys_dir_spr_str())
|
||||
|| (String_.Len(s) > 2
|
||||
&& ( (String_.CharAt(s, 1) == ':' && String_.CharAt(s, 2) == '\\')
|
||||
|| (String_.CharAt(s, 1) == '\\' && String_.CharAt(s, 2) == '\\')
|
||||
|
@ -55,7 +55,7 @@ public class Base64Converter {
|
||||
public static byte[] Decode(String s){
|
||||
if (toInt == null) Init();
|
||||
int sLen = String_.Len(s);
|
||||
int delta = String_.HasAtEnd(s, "==") ? 2 : String_.HasAtEnd(s, "=") ? 1 : 0;
|
||||
int delta = String_.Has_at_end(s, "==") ? 2 : String_.Has_at_end(s, "=") ? 1 : 0;
|
||||
byte[] buffer = new byte[sLen *3/4 - delta];
|
||||
int mask = 0xFF;
|
||||
int index = 0;
|
||||
|
@ -573,7 +573,7 @@ class Io_stream_rdr_http implements Io_stream_rdr {
|
||||
return this;
|
||||
}
|
||||
read_done = false;
|
||||
this.exists = src_conn.getResponseCode() == 200; // ASSUME: response code of 200 means that file exists; note that content_length seems to always be -1; DATE:2015-05-20
|
||||
this.exists = Int_.In(src_conn.getResponseCode(), 200, 301); // ASSUME: response code of 200 (OK) or 301 (Redirect) means that file exists; note that content_length seems to always be -1; DATE:2015-05-20
|
||||
src_stream = new java.io.BufferedInputStream(src_conn.getInputStream());
|
||||
xfer_fmt.Bgn(content_length);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class IoItmDir extends IoItm_base {
|
||||
String dirSpr = this.Url().Info().DirSpr(); int dirSprLen = String_.Len(dirSpr);
|
||||
String currDirStr = this.Url().Raw();
|
||||
String findDirStr = findDirUrl.Raw();
|
||||
if (!String_.HasAtBgn(findDirStr, currDirStr)) return null; // findUrl must start with currUrl;
|
||||
if (!String_.Has_at_bgn(findDirStr, currDirStr)) return null; // findUrl must start with currUrl;
|
||||
String findName = String_.DelEnd(currDirStr, dirSprLen); // seed findName for String_.MidByLen below;
|
||||
IoItmDir curDir = this;
|
||||
while (true) {
|
||||
|
@ -42,7 +42,7 @@ public class IoRecycleBin {
|
||||
String nameAndExt = url.NameAndExt_noDirSpr() + "|";
|
||||
for (int i = linesLen; i > 0; i--) {
|
||||
String line = lines[i - 1];
|
||||
if (String_.HasAtBgn(line, nameAndExt)) {
|
||||
if (String_.Has_at_bgn(line, nameAndExt)) {
|
||||
String[] terms = String_.Split(line, "|");
|
||||
Io_url origUrl = url.OwnerRoot().GenSubFil(terms[1]);
|
||||
list.Add(origUrl);
|
||||
|
@ -60,7 +60,7 @@ abstract class IoUrlInfo_base implements IoUrlInfo {
|
||||
public abstract boolean CaseSensitive();
|
||||
public abstract boolean Match(String raw);
|
||||
public abstract String EngineKey();
|
||||
public boolean IsDir(String raw) {return String_.HasAtEnd(raw, DirSpr());}
|
||||
public boolean IsDir(String raw) {return String_.Has_at_end(raw, DirSpr());}
|
||||
public abstract String XtoRootName(String raw, int rawLen);
|
||||
@gplx.Virtual public String Xto_api(String raw) {
|
||||
return IsDir(raw)
|
||||
@ -142,7 +142,7 @@ class IoUrlInfo_lnx extends IoUrlInfo_base {
|
||||
@Override public String DirSpr() {return DirSprStr;} static final String DirSprStr = Op_sys.Lnx.Fsys_dir_spr_str();
|
||||
@Override public byte DirSpr_byte() {return Byte_ascii.Slash;}
|
||||
@Override public boolean CaseSensitive() {return Op_sys.Lnx.Fsys_case_match();}
|
||||
@Override public boolean Match(String raw) {return String_.HasAtBgn(raw, DirSprStr);} // anything that starts with /
|
||||
@Override public boolean Match(String raw) {return String_.Has_at_bgn(raw, DirSprStr);} // anything that starts with /
|
||||
@Override public String XtoRootName(String raw, int rawLen) {
|
||||
return rawLen == 1 && String_.Eq(raw, DirSprStr)
|
||||
? "root"
|
||||
@ -180,7 +180,7 @@ class IoUrlInfo_mem extends IoUrlInfo_base {
|
||||
@Override public String XtoRootName(String raw, int rawLen) {
|
||||
return String_.Eq(raw, key) ? String_.DelEnd(key, 1) : null;
|
||||
}
|
||||
@Override public boolean Match(String raw) {return String_.HasAtBgn(raw, key);}
|
||||
@Override public boolean Match(String raw) {return String_.Has_at_bgn(raw, key);}
|
||||
public static IoUrlInfo_mem new_(String key, String engineKey) {
|
||||
IoUrlInfo_mem rv = new IoUrlInfo_mem();
|
||||
rv.key = key; rv.engineKey = engineKey;
|
||||
@ -196,7 +196,7 @@ class IoUrlInfo_alias extends IoUrlInfo_base {
|
||||
@Override public String XtoRootName(String raw, int rawLen) {
|
||||
return String_.Eq(raw, srcRootDir) ? srcRootName : null;
|
||||
}
|
||||
@Override public boolean Match(String raw) {return String_.HasAtBgn(raw, srcDir);}
|
||||
@Override public boolean Match(String raw) {return String_.Has_at_bgn(raw, srcDir);}
|
||||
@Override public String Xto_api(String raw) {
|
||||
String rv = String_.Replace(raw, srcDir, trgDir); // replace src with trg
|
||||
if (!String_.Eq(srcDirSpr, trgDirSpr)) rv = String_.Replace(rv, srcDirSpr, trgDirSpr); // replace dirSprs
|
||||
|
@ -66,7 +66,7 @@ public class Op_sys {
|
||||
else throw Err_mgr._.fmt_(GRP_KEY, "unknown_bitness", "unknown bitness; expecting 32 or 64; System.getProperty(\"bit.level\") yielded ~{0}", bitness_str);
|
||||
|
||||
os_name = System.getProperty("os.name").toLowerCase();
|
||||
if (String_.HasAtBgn(os_name, "win")) {
|
||||
if (String_.Has_at_bgn(os_name, "win")) {
|
||||
String os_version = System.getProperty("os.version").toLowerCase();// "Windows 7".equals(osName) && "6.1".equals(osVersion);
|
||||
byte sub_tid = Sub_tid_unknown;
|
||||
if (String_.Eq(os_name, "windows xp") && String_.Eq(os_version, "5.1")) sub_tid = Sub_tid_win_xp;
|
||||
@ -75,7 +75,7 @@ public class Op_sys {
|
||||
return new_wnt_(bitness_byte, sub_tid);
|
||||
}
|
||||
else if (String_.Eq(os_name, "linux")) return new_unx_flavor_(Tid_lnx, os_name, bitness_byte);
|
||||
else if (String_.HasAtBgn(os_name, "mac")) return new_unx_flavor_(Tid_osx, os_name, bitness_byte); // EX:Mac OS X
|
||||
else if (String_.Has_at_bgn(os_name, "mac")) return new_unx_flavor_(Tid_osx, os_name, bitness_byte); // EX:Mac OS X
|
||||
else throw Err_mgr._.fmt_(GRP_KEY, "unknown_os_name", "unknown os_name; expecting windows, linux, mac; System.getProperty(\"os.name\") yielded ~{0}", os_name);
|
||||
} catch (Exception exc) {Drd.os_name = os_name; return Drd;}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class Db_conn {
|
||||
public void Ddl_create_idx(Gfo_usr_dlg usr_dlg, Db_meta_idx... idxs) {engine.Ddl_create_idx(usr_dlg, idxs);}
|
||||
public void Ddl_append_fld(String tbl, Db_meta_fld fld) {engine.Ddl_append_fld(tbl, fld);}
|
||||
public void Ddl_delete_tbl(String tbl) {engine.Ddl_delete_tbl(tbl);}
|
||||
public boolean Schema_tbl_exists(String tbl) {return engine.Schema_tbl_exists(tbl);}
|
||||
public boolean Meta_tbl_exists(String tbl) {return engine.Meta_tbl_exists(tbl);}
|
||||
public void Rls_reg(RlsAble rls) {rls_list.Add(rls);}
|
||||
public void Rls_conn() {
|
||||
int len = rls_list.Count();
|
||||
|
@ -19,7 +19,7 @@ package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.engines.nulls.*; import gplx.dbs.engines.mems.*; import gplx.dbs.engines.sqlite.*; import gplx.dbs.engines.tdbs.*;
|
||||
import gplx.dbs.engines.mysql.*; import gplx.dbs.engines.postgres.*;
|
||||
public class Db_conn_info_ {
|
||||
public static final Db_conn_info Null = Null_conn_info._;
|
||||
public static final Db_conn_info Null = Noop_conn_info.I;
|
||||
public static final Db_conn_info Test = Mysql_conn_info.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 Sqlite_conn_info.load_(url);}
|
||||
@ -30,7 +30,7 @@ public class Db_conn_info_ {
|
||||
class Db_conn_info_pool {
|
||||
private Ordered_hash regy = Ordered_hash_.new_();
|
||||
public Db_conn_info_pool() {
|
||||
this.Add(Null_conn_info._).Add(Tdb_conn_info._).Add(Mysql_conn_info._).Add(Postgres_conn_info._).Add(Sqlite_conn_info._);
|
||||
this.Add(Noop_conn_info.I).Add(Tdb_conn_info._).Add(Mysql_conn_info._).Add(Postgres_conn_info._).Add(Sqlite_conn_info._);
|
||||
this.Add(Db_conn_info__mem.I);
|
||||
}
|
||||
public Db_conn_info_pool Add(Db_conn_info itm) {regy.Add_if_dupe_use_nth(itm.Tid(), itm); return this;}
|
||||
|
@ -41,6 +41,6 @@ public class Db_conn_pool {
|
||||
}
|
||||
public static final Db_conn_pool I = new Db_conn_pool(); Db_conn_pool() {this.Init();}
|
||||
private void Init() {
|
||||
this.Engines__add(Null_engine._, TdbEngine._, Mysql_engine._, Postgres_engine._, Sqlite_engine._, Db_engine__mem._);
|
||||
this.Engines__add(Noop_engine._, TdbEngine._, Mysql_engine._, Postgres_engine._, Sqlite_engine._, Db_engine__mem._);
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public class Db_meta_fld {
|
||||
public boolean Primary() {return primary;} private final boolean primary;
|
||||
public boolean Autonum() {return autonum;} private final boolean autonum;
|
||||
public Object Default_value() {return default_value;} private final Object default_value;
|
||||
public static final int Tid_bool = 0, Tid_byte = 1, Tid_short = 2, Tid_int = 3, Tid_long = 4, Tid_float = 5, Tid_double = 6, Tid_str = 7, Tid_text = 8, Tid_bry = 9;
|
||||
public static final int Tid_bool = 0, Tid_byte = 1, Tid_short = 2, Tid_int = 3, Tid_long = 4, Tid_float = 5, Tid_double = 6, Tid_str = 7, Tid_text = 8, Tid_bry = 9, Tid_decimal = 10, Tid_date = 11;
|
||||
public static final String Key_null = null;
|
||||
public static final int Len_null = -1;
|
||||
public static final String[] Ary_empy = String_.Ary_empty;
|
||||
|
@ -24,6 +24,17 @@ public class Db_meta_tbl {
|
||||
}
|
||||
public String Name() {return name;} private final String name;
|
||||
public Db_meta_fld[] Flds() {return flds;} private final Db_meta_fld[] flds;
|
||||
public boolean Flds_has(String fld) {
|
||||
if (flds_hash == null) {
|
||||
flds_hash = Ordered_hash_.new_();
|
||||
int len = flds.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_meta_fld fld_itm = flds[i];
|
||||
flds_hash.Add(fld_itm.Name(), fld_itm);
|
||||
}
|
||||
}
|
||||
return flds_hash.Has(fld);
|
||||
} private Ordered_hash flds_hash;
|
||||
public Db_meta_idx[] Idxs() {return idxs;} private final Db_meta_idx[] idxs;
|
||||
public String To_sql_create() {return Db_sqlbldr__sqlite.I.Bld_create_tbl(this);}
|
||||
public static Db_meta_tbl new_(String name, Db_meta_fld_list flds, Db_meta_idx... idxs) {return new Db_meta_tbl(name, flds.To_fld_ary(), idxs);}
|
||||
|
@ -18,25 +18,16 @@ 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(String k);
|
||||
byte[] Read_bry_by_str(int i);
|
||||
byte[] Read_bry_in_parts(String tbl, String fld, String crt_key, Object crt_val);
|
||||
byte[] Read_bry_by_str(String k);
|
||||
String Read_str(int i);
|
||||
String Read_str(String k);
|
||||
byte Read_byte(int i);
|
||||
byte Read_byte(String k);
|
||||
int Read_int(int i);
|
||||
int Read_int(String k);
|
||||
long Read_long(int i);
|
||||
long Read_long(String k);
|
||||
float Read_float(int i);
|
||||
float Read_float(String k);
|
||||
double Read_double(int i);
|
||||
double Read_double(String k);
|
||||
DateAdp Read_date_by_str(int i);
|
||||
DateAdp Read_date_by_str(String k);
|
||||
boolean Read_bool_by_byte(int i);
|
||||
boolean Read_bool_by_byte(String k);
|
||||
void Rls();
|
||||
}
|
||||
|
@ -21,25 +21,16 @@ public class Db_rdr_ {
|
||||
}
|
||||
class Db_rdr__empty implements Db_rdr {
|
||||
public boolean Move_next() {return false;}
|
||||
public byte[] Read_bry(int i) {return Bry_.Empty;}
|
||||
public byte[] Read_bry(String k) {return Bry_.Empty;}
|
||||
public byte[] Read_bry_by_str(int i) {return Bry_.Empty;}
|
||||
public byte[] Read_bry_by_str(String k) {return Bry_.Empty;}
|
||||
public byte Read_byte(int i) {return Byte_.Max_value_127;}
|
||||
public byte[] Read_bry_in_parts(String tbl, String fld, String crt_key, Object crt_val) {return Bry_.Empty;}
|
||||
public byte Read_byte(String k) {return Byte_.Max_value_127;}
|
||||
public String Read_str(int i) {return String_.Empty;}
|
||||
public String Read_str(String k) {return String_.Empty;}
|
||||
public DateAdp Read_date_by_str(int i) {return DateAdp_.MinValue;}
|
||||
public DateAdp Read_date_by_str(String k) {return DateAdp_.MinValue;}
|
||||
public int Read_int(int i) {return Int_.MinValue;}
|
||||
public int Read_int(String k) {return Int_.MinValue;}
|
||||
public long Read_long(int i) {return Long_.MinValue;}
|
||||
public long Read_long(String k) {return Long_.MinValue;}
|
||||
public float Read_float(int i) {return Float_.NaN;}
|
||||
public float Read_float(String k) {return Float_.NaN;}
|
||||
public double Read_double(int i) {return Double_.NaN;}
|
||||
public double Read_double(String k) {return Double_.NaN;}
|
||||
public boolean Read_bool_by_byte(int i) {return false;}
|
||||
public boolean Read_bool_by_byte(String k) {return false;}
|
||||
public void Rls() {}
|
||||
}
|
||||
|
@ -26,25 +26,16 @@ public class Db_rdr__basic implements Db_rdr {
|
||||
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);}
|
||||
}
|
||||
@gplx.Virtual public byte[] Read_bry(int i) {try {return rdr.getBytes(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Bry_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public byte[] Read_bry(String k) {try {return (byte[])rdr.getObject(k);} catch (Exception e) {throw Err_.new_("read failed: k={0} type={1} err={2}", k, Bry_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public byte[] Read_bry_by_str(int i) {try {return Bry_.new_u8(rdr.getString(i + 1));} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, String_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public byte[] Read_bry_by_str(String k) {try {return Bry_.new_u8((String)rdr.getObject(k));} catch (Exception e) {throw Err_.new_("read failed: k={0} type={1} err={2}", k, String_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public String Read_str(int i) {try {return rdr.getString(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, String_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public byte[] Read_bry_in_parts(String tbl, String fld, String crt_key, Object crt_val) {throw Err_.not_implemented_();}
|
||||
@gplx.Virtual public String Read_str(String k) {try {return (String)rdr.getObject(k);} catch (Exception e) {throw Err_.new_("read failed: k={0} type={1} err={2}", k, String_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public DateAdp Read_date_by_str(int i) {return DateAdp_.parse_iso8561(Read_str(i));}
|
||||
@gplx.Virtual public DateAdp Read_date_by_str(String k) {return DateAdp_.parse_iso8561(Read_str(k));}
|
||||
@gplx.Virtual public int Read_int(int i) {try {return rdr.getInt(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Int_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public int Read_int(String k) {try {return Int_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_("read failed: k={0} type={1} err={2}", k, Int_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public long Read_long(int i) {try {return rdr.getLong(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Long_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public long Read_long(String k) {try {return Long_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_("read failed: k={0} type={1} err={2}", k, Long_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public float Read_float(int i) {try {return rdr.getFloat(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Float_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public float Read_float(String k) {try {return Float_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_("read failed: k={0} type={1} err={2}", k, Float_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public double Read_double(int i) {try {return rdr.getDouble(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Double_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public double Read_double(String k) {try {return Double_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_("read failed: k={0} type={1} err={2}", k, Double_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public byte Read_byte(int i) {try {return rdr.getByte(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Byte_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public byte Read_byte(String k) {try {return Byte_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_("read failed: k={0} type={1} err={2}", k, Byte_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public boolean Read_bool_by_byte(int i) {try {return rdr.getByte(i + 1) == 1;} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Bool_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public boolean Read_bool_by_byte(String k) {try {return Byte_.cast_(rdr.getObject(k)) == 1;} catch (Exception e) {throw Err_.new_("read failed: k={0} type={1} err={2}", k, Bool_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@gplx.Virtual public void Rls() {
|
||||
try {rdr.close();}
|
||||
|
@ -38,5 +38,6 @@ public interface Db_engine {
|
||||
void Ddl_delete_tbl(String tbl);
|
||||
void Env_db_attach(String alias, Io_url db_url);
|
||||
void Env_db_detach(String alias);
|
||||
boolean Schema_tbl_exists(String name);
|
||||
boolean Meta_tbl_exists(String tbl);
|
||||
boolean Meta_fld_exists(String tbl, String fld);
|
||||
}
|
||||
|
@ -74,7 +74,8 @@ public abstract class Db_engine_sql_base implements Db_engine {
|
||||
public void Ddl_delete_tbl(String tbl) {Exec_as_int(Db_sqlbldr__sqlite.I.Bld_drop_tbl(tbl));}
|
||||
@gplx.Virtual public void Env_db_attach(String alias, Io_url db_url) {}
|
||||
@gplx.Virtual public void Env_db_detach(String alias) {}
|
||||
@gplx.Virtual public boolean Schema_tbl_exists(String name) {return false;}
|
||||
@gplx.Virtual public boolean Meta_tbl_exists(String tbl) {return false;}
|
||||
@gplx.Virtual public boolean Meta_fld_exists(String tbl, String fld) {return false;}
|
||||
@gplx.Virtual public DataRdr New_rdr(ResultSet rdr, String sql) {return gplx.stores.Db_data_rdr_.new_(rdr, sql);}
|
||||
@gplx.Virtual public Sql_qry_wtr SqlWtr() {return Sql_qry_wtr_.new_ansi();}
|
||||
private Db_rdr New_rdr(Db_stmt stmt, Object rdr, String sql) {
|
||||
|
@ -46,6 +46,11 @@ public class Db_engine__mem implements Db_engine {
|
||||
public void Ddl_delete_tbl(String tbl) {}
|
||||
public void Env_db_attach(String alias, Io_url db_url) {}
|
||||
public void Env_db_detach(String alias) {}
|
||||
public boolean Schema_tbl_exists(String name) {return tbl_hash.Has(name);}
|
||||
public boolean Meta_tbl_exists(String tbl) {return tbl_hash.Has(tbl);}
|
||||
public boolean Meta_fld_exists(String tbl, String fld) {
|
||||
Mem_tbl mem_tbl = (Mem_tbl)tbl_hash.Get_by(tbl); if (mem_tbl == null) return false;
|
||||
return mem_tbl.Meta().Flds_has(fld);
|
||||
}
|
||||
// public boolean Meta_fld_exists(String name) {return tbl_hash.Has(name);}
|
||||
public static final Db_engine__mem _ = new Db_engine__mem(); Db_engine__mem() {}
|
||||
}
|
||||
|
@ -28,25 +28,16 @@ public class Db_rdr__mem implements Db_rdr {
|
||||
row = rows[row_idx];
|
||||
return rv;
|
||||
}
|
||||
public byte[] Read_bry(int i) {return (byte[])row.Get_at(i);}
|
||||
public byte[] Read_bry(String k) {return (byte[])row.Get_by(k);}
|
||||
public String Read_str(int i) {return (String)row.Get_at(i);}
|
||||
public String Read_str(String k) {return (String)row.Get_by(k);}
|
||||
public byte[] Read_bry_by_str(int i) {return Bry_.new_u8_safe((String)row.Get_at(i));} // NOTE: null b/c db can have NULL
|
||||
public byte[] Read_bry_by_str(String k) {return Bry_.new_u8_safe((String)row.Get_by(k));} // NOTE: null b/c db can have NULL
|
||||
public DateAdp Read_date_by_str(int i) {return DateAdp_.parse_iso8561((String)row.Get_at(i));}
|
||||
@gplx.Virtual public byte[] Read_bry_in_parts(String tbl, String fld, String crt_key, Object crt_val) {throw Err_.not_implemented_();}
|
||||
public DateAdp Read_date_by_str(String k) {return DateAdp_.parse_iso8561((String)row.Get_by(k));}
|
||||
public byte Read_byte(int i) {return Byte_.cast_(row.Get_at(i));}
|
||||
public byte Read_byte(String k) {return Byte_.cast_(row.Get_by(k));}
|
||||
public int Read_int(int i) {return Int_.cast_(row.Get_at(i));}
|
||||
public int Read_int(String k) {return Int_.cast_(row.Get_by(k));}
|
||||
public long Read_long(int i) {return Long_.cast_(row.Get_at(i));}
|
||||
public long Read_long(String k) {return Long_.cast_(row.Get_by(k));}
|
||||
public float Read_float(int i) {return Float_.cast_(row.Get_at(i));}
|
||||
public float Read_float(String k) {return Float_.cast_(row.Get_by(k));}
|
||||
public double Read_double(int i) {return Double_.cast_(row.Get_at(i));}
|
||||
public double Read_double(String k) {return Double_.cast_(row.Get_by(k));}
|
||||
public boolean Read_bool_by_byte(int i) {return Byte_.cast_(row.Get_at(i)) == 1;}
|
||||
public boolean Read_bool_by_byte(String k) {return Byte_.cast_(row.Get_by(k)) == 1;}
|
||||
public void Rls() {}
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs
|
||||
import gplx.core.primitives.*; import gplx.core.criterias.*; import gplx.dbs.qrys.*;
|
||||
public class Mem_tbl {
|
||||
private final List_adp rows = List_adp_.new_(); private final List_adp where_rows = List_adp_.new_();
|
||||
private final Hash_adp autonum_hash = Hash_adp_.new_();
|
||||
private final Db_meta_tbl meta;
|
||||
private final Hash_adp autonum_hash = Hash_adp_.new_();
|
||||
public Mem_tbl(Db_meta_tbl meta) {this.meta = meta;}
|
||||
public Db_meta_tbl Meta() {return meta;} private final Db_meta_tbl meta;
|
||||
public int Insert(Db_stmt__mem stmt) {
|
||||
Mem_itm itm = new Mem_itm();
|
||||
Db_meta_fld[] flds = meta.Flds();
|
||||
|
@ -16,8 +16,8 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.engines.nulls; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class Null_conn_info extends Db_conn_info__base {
|
||||
public class Noop_conn_info extends Db_conn_info__base {
|
||||
@Override public String Tid() {return Tid_const;} public static final String Tid_const = "null_db";
|
||||
@Override public Db_conn_info New_self(String raw, GfoMsg m) {return this;}
|
||||
public static final Null_conn_info _ = new Null_conn_info(); Null_conn_info() {this.Ctor("", "", "gplx_key=null_db", "");}
|
||||
public static final Noop_conn_info I = new Noop_conn_info(); Noop_conn_info() {this.Ctor("", "", "gplx_key=null_db", "");}
|
||||
}
|
@ -16,8 +16,8 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.engines.nulls; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class Null_engine implements Db_engine {
|
||||
public String Tid() {return Null_conn_info.Tid_const;}
|
||||
public class Noop_engine implements Db_engine {
|
||||
public String Tid() {return Noop_conn_info.Tid_const;}
|
||||
public Db_conn_info Conn_info() {return Db_conn_info_.Null;}
|
||||
public void Conn_open() {}
|
||||
public void Conn_term() {}
|
||||
@ -38,6 +38,7 @@ public class Null_engine implements Db_engine {
|
||||
public void Ddl_delete_tbl(String tbl) {}
|
||||
public void Env_db_attach(String alias, Io_url db_url) {}
|
||||
public void Env_db_detach(String alias) {}
|
||||
public boolean Schema_tbl_exists(String name) {return false;}
|
||||
public static final Null_engine _ = new Null_engine(); Null_engine() {}
|
||||
public boolean Meta_tbl_exists(String tbl) {return false;}
|
||||
public boolean Meta_fld_exists(String tbl, String fld) {return false;}
|
||||
public static final Noop_engine _ = new Noop_engine(); Noop_engine() {}
|
||||
}
|
@ -39,7 +39,8 @@ public class Sqlite_engine extends Db_engine_sql_base {
|
||||
@Override public void Txn_end() {txn_mgr.Txn_end();}
|
||||
@Override public void Txn_cxl() {txn_mgr.Txn_cxl();}
|
||||
@Override public void Txn_sav() {txn_mgr.Txn_sav();}
|
||||
@Override public boolean Schema_tbl_exists(String name) {return schema_mgr.Tbl_exists(name);}
|
||||
@Override public boolean Meta_tbl_exists(String tbl) {return schema_mgr.Tbl_exists(tbl);}
|
||||
@Override public boolean Meta_fld_exists(String tbl, String fld) {return schema_mgr.Fld_exists(tbl, fld);}
|
||||
static boolean loaded = false;
|
||||
@gplx.Internal @Override protected Connection Conn_new() {
|
||||
if (!loaded) {
|
||||
@ -55,8 +56,7 @@ public class Sqlite_engine extends Db_engine_sql_base {
|
||||
}
|
||||
public static final Sqlite_engine _ = new Sqlite_engine();
|
||||
}
|
||||
class Db_rdr__sqlite extends Db_rdr__basic { @Override public byte Read_byte(int i) {try {return (byte)rdr.getInt(i + 1);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Byte_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@Override public byte Read_byte(String k) {try {return (byte)Int_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_("read failed: k={0} type={1} err={2}", k, Byte_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
class Db_rdr__sqlite extends Db_rdr__basic { @Override public byte Read_byte(String k) {try {return (byte)Int_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_("read failed: k={0} type={1} err={2}", k, Byte_.Cls_val_name, Err_.Message_lang(e));}}
|
||||
@Override public boolean Read_bool_by_byte(String k) {
|
||||
try {
|
||||
int val = rdr.getInt(k);
|
||||
|
@ -16,36 +16,47 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.engines.sqlite; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.dbs.schemas.*; import gplx.dbs.qrys.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
import gplx.dbs.metas.*; import gplx.dbs.metas.parsers.*;
|
||||
public class Sqlite_schema_mgr {
|
||||
private final Db_engine engine; private boolean init = true;
|
||||
public Sqlite_schema_mgr(Db_engine engine) {this.engine = engine;}
|
||||
public Schema_tbl_mgr Tbl_mgr() {return tbl_mgr;} private final Schema_tbl_mgr tbl_mgr = new Schema_tbl_mgr();
|
||||
public Schema_idx_mgr Idx_mgr() {return idx_mgr;} private final Schema_idx_mgr idx_mgr = new Schema_idx_mgr();
|
||||
public Meta_tbl_mgr Tbl_mgr() {return tbl_mgr;} private final Meta_tbl_mgr tbl_mgr = new Meta_tbl_mgr();
|
||||
public Meta_idx_mgr Idx_mgr() {return idx_mgr;} private final Meta_idx_mgr idx_mgr = new Meta_idx_mgr();
|
||||
public boolean Tbl_exists(String name) {
|
||||
if (init) Init(engine);
|
||||
return tbl_mgr.Has(name);
|
||||
}
|
||||
public boolean Fld_exists(String tbl, String fld) {
|
||||
if (init) Init(engine);
|
||||
Meta_tbl_itm tbl_itm = tbl_mgr.Get_by(tbl);
|
||||
return (tbl_itm == null) ? false : tbl_itm.Flds().Has(fld);
|
||||
}
|
||||
private void Init(Db_engine engine) {
|
||||
init = false;
|
||||
Gfo_usr_dlg_.I.Log_many("", "", "db.schema.load.bgn: conn=~{0}", engine.Conn_info().Xto_api());
|
||||
Meta_parser__tbl tbl_parser = new Meta_parser__tbl();
|
||||
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.new_("sqlite_master", String_.Ary_empty, String_.Ary("type", "name", "sql"), Db_qry__select_in_tbl.Order_by_null);
|
||||
Db_rdr rdr = engine.New_stmt_prep(qry).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
String type_str = rdr.Read_str(0);
|
||||
int type_int = Schema_itm_tid.Xto_int(type_str);
|
||||
String type_str = rdr.Read_str("type");
|
||||
String name = rdr.Read_str("name");
|
||||
String sql = rdr.Read_str("sql");
|
||||
int type_int = Meta_itm_tid.Xto_int(type_str);
|
||||
switch (type_int) {
|
||||
case Schema_itm_tid.Tid_table:
|
||||
Schema_tbl_itm tbl_itm = new Schema_tbl_itm(rdr.Read_str(1), rdr.Read_str(2));
|
||||
case Meta_itm_tid.Tid_table:
|
||||
if (String_.Eq(name, "sqlite_sequence")) continue; // ignore b/c of non-orthodox syntax; EX: "CREATE TABLE sqlite_sequence(name, seq)";
|
||||
// Meta_tbl_itm tbl_itm = new Meta_tbl_itm(tbl_name, tbl_sql);
|
||||
Meta_tbl_itm tbl_itm = tbl_parser.Parse(Bry_.new_u8(sql));
|
||||
tbl_mgr.Add(tbl_itm);
|
||||
break;
|
||||
case Schema_itm_tid.Tid_index:
|
||||
Schema_idx_itm idx_itm = new Schema_idx_itm(rdr.Read_str(1), rdr.Read_str(2));
|
||||
case Meta_itm_tid.Tid_index:
|
||||
Meta_idx_itm idx_itm = new Meta_idx_itm(name, sql);
|
||||
idx_mgr.Add(idx_itm);
|
||||
break;
|
||||
default:
|
||||
Gfo_usr_dlg_.I.Log_many("", "", "db.schema.unknown type: conn=~{0} type=~{1} name=~{2} sql=~{3}", engine.Conn_info().Xto_api(), type_str, rdr.Read_str(1), rdr.Read_str(2));
|
||||
Gfo_usr_dlg_.I.Log_many("", "", "db.schema.unknown type: conn=~{0} type=~{1} name=~{2} sql=~{3}", engine.Conn_info().Xto_api(), type_str, name, sql);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,8 @@ public class TdbEngine implements Db_engine {
|
||||
public void Ddl_delete_tbl(String tbl) {}
|
||||
public void Env_db_attach(String alias, Io_url db_url) {}
|
||||
public void Env_db_detach(String alias) {}
|
||||
public boolean Schema_tbl_exists(String name) {return false;}
|
||||
public boolean Meta_tbl_exists(String name) {return false;}
|
||||
public boolean Meta_fld_exists(String tbl, String fld) {return false;}
|
||||
|
||||
Hash_adp wkrs = Hash_adp_.new_(); TdbDbLoadMgr loadMgr = TdbDbLoadMgr.new_(); TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_();
|
||||
public static final TdbEngine _ = new TdbEngine();
|
||||
|
31
140_dbs/src/gplx/dbs/metas/Meta_fld_itm.java
Normal file
31
140_dbs/src/gplx/dbs/metas/Meta_fld_itm.java
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Meta_fld_itm {
|
||||
public Meta_fld_itm(String name, Meta_type_itm type) {
|
||||
this.name = name; this.type = type;
|
||||
}
|
||||
public String Name() {return name;} private final String name;
|
||||
public Meta_type_itm Type() {return type;} private final Meta_type_itm type;
|
||||
public int Nullable_tid() {return nullable_tid;} public void Nullable_tid_(int v) {nullable_tid = v;} private int nullable_tid;
|
||||
public boolean Autonumber() {return autonumber;} public void Autonumber_y_() {autonumber = true;} private boolean autonumber;
|
||||
public boolean Primary_key() {return primary_key;} public void Primary_key_y_() {primary_key = true;} private boolean primary_key;
|
||||
public Object Default_val() {return default_val;} private Object default_val;
|
||||
public void Default_val_(Object v) {this.default_val = v;}
|
||||
public static final int Nullable_unknown = 0, Nullable_null = 1, Nullable_not_null = 2;
|
||||
}
|
26
140_dbs/src/gplx/dbs/metas/Meta_fld_mgr.java
Normal file
26
140_dbs/src/gplx/dbs/metas/Meta_fld_mgr.java
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Meta_fld_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.new_();
|
||||
public int Len() {return hash.Count();}
|
||||
public void Add(Meta_fld_itm itm) {hash.Add(itm.Name(), itm);}
|
||||
public boolean Has(String name) {return hash.Has(name);}
|
||||
public Meta_fld_itm Get_by(String name) {return (Meta_fld_itm)hash.Get_by(name);}
|
||||
public Meta_fld_itm Get_at(int i) {return (Meta_fld_itm)hash.Get_at(i);}
|
||||
}
|
@ -15,9 +15,9 @@ 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.schemas; import gplx.*; import gplx.dbs.*;
|
||||
public class Schema_tbl_itm {
|
||||
public Schema_tbl_itm(String name, String sql) {this.name = name; this.sql = sql;}
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Meta_idx_itm {
|
||||
public Meta_idx_itm(String name, String sql) {this.name = name; this.sql = sql;}
|
||||
public String Name() {return name;} private final String name;
|
||||
public String Sql() {return sql;} private final String sql;
|
||||
}
|
@ -15,10 +15,10 @@ 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.schemas; import gplx.*; import gplx.dbs.*;
|
||||
public class Schema_tbl_mgr {
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Meta_idx_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.new_();
|
||||
public void Add(Schema_tbl_itm itm) {hash.Add(itm.Name(), itm);}
|
||||
public void Add(Meta_idx_itm itm) {hash.Add(itm.Name(), itm);}
|
||||
public boolean Has(String name) {return hash.Has(name);}
|
||||
public Schema_tbl_itm Get(String name) {return (Schema_tbl_itm)hash.Get_by(name);}
|
||||
public Meta_idx_itm Get(String name) {return (Meta_idx_itm)hash.Get_by(name);}
|
||||
}
|
@ -15,8 +15,8 @@ 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.schemas; import gplx.*; import gplx.dbs.*;
|
||||
public class Schema_itm_tid {
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Meta_itm_tid {
|
||||
public static final int Tid_unknown = 0, Tid_table = 1, Tid_index = 2;
|
||||
public static final String Key_table = "table", Key_index = "index";
|
||||
public static int Xto_int(String s) {
|
@ -15,9 +15,10 @@ 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.schemas; import gplx.*; import gplx.dbs.*;
|
||||
public class Schema_idx_itm {
|
||||
public Schema_idx_itm(String name, String sql) {this.name = name; this.sql = sql;}
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Meta_tbl_itm {
|
||||
public Meta_tbl_itm(String name, String sql) {this.name = name; this.sql = sql;}
|
||||
public Meta_fld_mgr Flds() {return flds;} private final Meta_fld_mgr flds = new Meta_fld_mgr();
|
||||
public String Name() {return name;} private final String name;
|
||||
public String Sql() {return sql;} private final String sql;
|
||||
}
|
@ -15,10 +15,10 @@ 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.schemas; import gplx.*; import gplx.dbs.*;
|
||||
public class Schema_idx_mgr {
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Meta_tbl_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.new_();
|
||||
public void Add(Schema_idx_itm itm) {hash.Add(itm.Name(), itm);}
|
||||
public void Add(Meta_tbl_itm itm) {hash.Add(itm.Name(), itm);}
|
||||
public boolean Has(String name) {return hash.Has(name);}
|
||||
public Schema_idx_itm Get(String name) {return (Schema_idx_itm)hash.Get_by(name);}
|
||||
public Meta_tbl_itm Get_by(String name) {return (Meta_tbl_itm)hash.Get_by(name);}
|
||||
}
|
28
140_dbs/src/gplx/dbs/metas/Meta_type_itm.java
Normal file
28
140_dbs/src/gplx/dbs/metas/Meta_type_itm.java
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Meta_type_itm {
|
||||
public Meta_type_itm(int tid_ansi, int tid_sqlite, byte[] name, int len_1, int len_2) {
|
||||
this.tid_ansi = tid_ansi; this.tid_sqlite = tid_sqlite; this.name = name; this.len_1 = len_1; this.len_2 = len_2;
|
||||
}
|
||||
public int Tid_ansi() {return tid_ansi;} private final int tid_ansi;
|
||||
public int Tid_sqlite() {return tid_sqlite;} private final int tid_sqlite;
|
||||
public byte[] Name() {return name;} private final byte[] name;
|
||||
public int Len_1() {return len_1;} private final int len_1;
|
||||
public int Len_2() {return len_2;} private final int len_2;
|
||||
}
|
117
140_dbs/src/gplx/dbs/metas/parsers/Meta_fld_wkr__base.java
Normal file
117
140_dbs/src/gplx/dbs/metas/parsers/Meta_fld_wkr__base.java
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
abstract class Meta_fld_wkr__base {
|
||||
private byte[] hook;
|
||||
private byte[][] words_ary; private int words_len;
|
||||
@gplx.Virtual public int Tid() {return Tid_other;}
|
||||
public void Ctor(byte[] hook, byte[]... words_ary) {
|
||||
this.hook = hook;
|
||||
this.words_ary = words_ary;
|
||||
this.words_len = words_ary.length;
|
||||
}
|
||||
public void Reg(Btrie_slim_mgr trie) {
|
||||
trie.Add_obj(hook, this);
|
||||
}
|
||||
@gplx.Virtual public void Match(Bry_rdr rdr, Meta_fld_itm fld) {
|
||||
for (int i = 0; i < words_len; ++i) {
|
||||
rdr.Skip_ws();
|
||||
byte[] word = words_ary[i];
|
||||
rdr.Chk_bry_or_fail(word);
|
||||
}
|
||||
When_match(fld);
|
||||
}
|
||||
protected abstract void When_match(Meta_fld_itm fld);
|
||||
public static final int Tid_end_comma = 1, Tid_end_paren = 2, Tid_other = 3;
|
||||
}
|
||||
class Meta_fld_wkr__end_comma extends Meta_fld_wkr__base {
|
||||
public Meta_fld_wkr__end_comma() {this.Ctor(Hook);}
|
||||
@Override public int Tid() {return Tid_end_comma;}
|
||||
@Override protected void When_match(Meta_fld_itm fld) {}
|
||||
private static final byte[] Hook = Bry_.new_a7(",");
|
||||
public static final Meta_fld_wkr__end_comma I = new Meta_fld_wkr__end_comma();
|
||||
}
|
||||
class Meta_fld_wkr__end_paren extends Meta_fld_wkr__base {
|
||||
public Meta_fld_wkr__end_paren() {this.Ctor(Hook);}
|
||||
@Override public int Tid() {return Tid_end_paren;}
|
||||
@Override protected void When_match(Meta_fld_itm fld) {}
|
||||
private static final byte[] Hook = Bry_.new_a7(")");
|
||||
public static final Meta_fld_wkr__end_paren I = new Meta_fld_wkr__end_paren();
|
||||
}
|
||||
class Meta_fld_wkr__nullable_null extends Meta_fld_wkr__base {
|
||||
public Meta_fld_wkr__nullable_null() {this.Ctor(Hook);}
|
||||
@Override protected void When_match(Meta_fld_itm fld) {
|
||||
fld.Nullable_tid_(Meta_fld_itm.Nullable_null);
|
||||
}
|
||||
private static final byte[] Hook = Bry_.new_a7("null");
|
||||
public static final Meta_fld_wkr__nullable_null I = new Meta_fld_wkr__nullable_null();
|
||||
}
|
||||
class Meta_fld_wkr__nullable_not extends Meta_fld_wkr__base {
|
||||
public Meta_fld_wkr__nullable_not() {this.Ctor(Hook, Bry_null);}
|
||||
@Override protected void When_match(Meta_fld_itm fld) {
|
||||
fld.Nullable_tid_(Meta_fld_itm.Nullable_not_null);
|
||||
}
|
||||
private static final byte[] Hook = Bry_.new_a7("not"), Bry_null = Bry_.new_a7("null");
|
||||
public static final Meta_fld_wkr__nullable_not I = new Meta_fld_wkr__nullable_not();
|
||||
}
|
||||
class Meta_fld_wkr__primary_key extends Meta_fld_wkr__base {
|
||||
public Meta_fld_wkr__primary_key() {this.Ctor(Hook, Bry_key);}
|
||||
@Override protected void When_match(Meta_fld_itm fld) {
|
||||
fld.Primary_key_y_();
|
||||
}
|
||||
private static final byte[] Hook = Bry_.new_a7("primary"), Bry_key = Bry_.new_a7("key");
|
||||
public static final Meta_fld_wkr__primary_key I = new Meta_fld_wkr__primary_key();
|
||||
}
|
||||
class Meta_fld_wkr__autonumber extends Meta_fld_wkr__base {
|
||||
public Meta_fld_wkr__autonumber() {this.Ctor(Hook);}
|
||||
@Override protected void When_match(Meta_fld_itm fld) {
|
||||
fld.Autonumber_y_();
|
||||
}
|
||||
private static final byte[] Hook = Bry_.new_a7("autoincrement");
|
||||
public static final Meta_fld_wkr__autonumber I = new Meta_fld_wkr__autonumber();
|
||||
}
|
||||
class Meta_fld_wkr__default extends Meta_fld_wkr__base {
|
||||
public Meta_fld_wkr__default() {this.Ctor(Hook);}
|
||||
@Override public void Match(Bry_rdr rdr, Meta_fld_itm fld) {
|
||||
Object default_val = null;
|
||||
rdr.Skip_ws();
|
||||
byte[] src = rdr.Src();
|
||||
byte b = src[rdr.Pos()];
|
||||
switch (b) {
|
||||
case Byte_ascii.Quote:
|
||||
case Byte_ascii.Apos:
|
||||
int bgn_pos = rdr.Pos() + 1;
|
||||
int end_pos = Bry_finder.Find_fwd(src, b, bgn_pos); if (end_pos == Bry_finder.Not_found) throw Err_.new_("unclosed quote; {0}", rdr.Mid_by_len_safe(40));
|
||||
default_val = Bry_.Mid(src, bgn_pos, end_pos);
|
||||
rdr.Pos_(end_pos + 1);
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
default_val = rdr.Read_int_to_non_num();
|
||||
break;
|
||||
default:
|
||||
throw Err_.new_("invalid field_default; {0}", rdr.Mid_by_len_safe(40));
|
||||
}
|
||||
fld.Default_val_(default_val);
|
||||
}
|
||||
@Override protected void When_match(Meta_fld_itm fld) {}
|
||||
private static final byte[] Hook = Bry_.new_a7("default");
|
||||
public static final Meta_fld_wkr__default I = new Meta_fld_wkr__default();
|
||||
}
|
118
140_dbs/src/gplx/dbs/metas/parsers/Meta_parser__fld.java
Normal file
118
140_dbs/src/gplx/dbs/metas/parsers/Meta_parser__fld.java
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
public class Meta_parser__fld {
|
||||
public Meta_type_itm Parse_type(Bry_rdr rdr) {
|
||||
rdr.Skip_ws();
|
||||
Object type_obj = type_trie.Match_bgn(rdr.Src(), rdr.Pos(), rdr.Src_len());
|
||||
if (type_obj == null) throw Err_.new_("invalid fld type; excerpt={0}", rdr.Mid_by_len_safe(40));
|
||||
Meta_parser__fld_itm type_itm = (Meta_parser__fld_itm)type_obj;
|
||||
rdr.Pos_add(type_itm.Word().length);
|
||||
int paren_itms_count = type_itm.Paren_itms_count();
|
||||
int len_1 = Int_.MinValue, len_2 = Int_.MinValue;
|
||||
if (paren_itms_count > 0) {
|
||||
rdr.Skip_ws().Chk_byte_or_fail(Byte_ascii.Paren_bgn);
|
||||
len_1 = rdr.Skip_ws().Read_int_to_non_num(); if (len_1 == Int_.MinValue) throw Err_.new_("invalid fld len_1; excerpt={0}", rdr.Mid_by_len_safe(40));
|
||||
if (paren_itms_count == 2) {
|
||||
rdr.Skip_ws().Chk_byte_or_fail(Byte_ascii.Comma);
|
||||
len_2 = rdr.Skip_ws().Read_int_to_non_num(); if (len_2 == Int_.MinValue) throw Err_.new_("invalid fld len_2; excerpt={0}", rdr.Mid_by_len_safe(40));
|
||||
}
|
||||
rdr.Skip_ws().Chk_byte_or_fail(Byte_ascii.Paren_end);
|
||||
}
|
||||
return new Meta_type_itm(type_itm.Tid_ansi(), type_itm.Tid_sqlite(), type_itm.Word(), len_1, len_2);
|
||||
}
|
||||
public Meta_fld_itm Parse_fld(Sql_bry_rdr rdr) { // starts after "(" or ","; EX: "(fld1 int", ", fld2 int"; ends at ")"
|
||||
byte[] name = rdr.Read_sql_identifier();
|
||||
Meta_type_itm type = this.Parse_type(rdr);
|
||||
Meta_fld_itm fld = new Meta_fld_itm(String_.new_u8(name), type);
|
||||
byte[] src = rdr.Src(); int src_len = rdr.Src_len();
|
||||
while (true) {
|
||||
rdr.Skip_ws();
|
||||
if (rdr.Pos() == src_len) return fld; // eos
|
||||
switch (src[rdr.Pos()]) {
|
||||
case Byte_ascii.Comma: return fld;
|
||||
case Byte_ascii.Paren_end: return fld;
|
||||
}
|
||||
Object type_obj = fld_trie.Match_bgn(src, rdr.Pos(), src_len); if (type_obj == null) throw Err_.new_("invalid; excerpt={0}", rdr.Mid_by_len_safe(40));
|
||||
Meta_fld_wkr__base type_wkr = (Meta_fld_wkr__base)type_obj;
|
||||
switch (type_wkr.Tid()) {
|
||||
case Meta_fld_wkr__base.Tid_end_comma:
|
||||
case Meta_fld_wkr__base.Tid_end_paren: return fld;
|
||||
default:
|
||||
rdr.Pos_(fld_trie.Match_pos());
|
||||
type_wkr.Match(rdr, fld);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// return fld; // NOTE: will happen for tests; EX: "fld_1 int" vs "fld_1 int,"
|
||||
}
|
||||
private static final Btrie_slim_mgr fld_trie = fld_trie_init
|
||||
( Meta_fld_wkr__nullable_null.I
|
||||
, Meta_fld_wkr__nullable_not.I
|
||||
, Meta_fld_wkr__autonumber.I
|
||||
, Meta_fld_wkr__primary_key.I
|
||||
, Meta_fld_wkr__default.I
|
||||
);
|
||||
private static Btrie_slim_mgr fld_trie_init(Meta_fld_wkr__base... wkrs) {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_ascii_();
|
||||
for (Meta_fld_wkr__base wkr : wkrs)
|
||||
wkr.Reg(rv);
|
||||
return rv;
|
||||
}
|
||||
private static final Btrie_slim_mgr type_trie = type_trie_init();
|
||||
private static Btrie_slim_mgr type_trie_init() {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_ascii_();
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_byte , Sqlite_tid.Tid_int , 0, "tinyint", "int2");
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_short , Sqlite_tid.Tid_int , 0, "smallint");
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_int , Sqlite_tid.Tid_int , 0, "int", "integer", "mediumint");
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_long , Sqlite_tid.Tid_int , 0, "bigint", "int8"); // "UNSIGNED BIG INT"
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_str , Sqlite_tid.Tid_text , 1, "character", "varchar", "nchar"); // "varying character", "native character"
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_text , Sqlite_tid.Tid_text , 0, "text", "clob");
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_bry , Sqlite_tid.Tid_none , 0, "blob");
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_float , Sqlite_tid.Tid_real , 0, "float");
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_double , Sqlite_tid.Tid_real , 0, "real", "double"); // "double precision"
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_decimal , Sqlite_tid.Tid_numeric , 0, "numeric");
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_decimal , Sqlite_tid.Tid_numeric , 2, "decimal");
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_decimal , Sqlite_tid.Tid_numeric , 2, "decimal");
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_bool , Sqlite_tid.Tid_numeric , 0, "boolean", "bit"); // "bit" is not SQLITE
|
||||
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_date , Sqlite_tid.Tid_numeric , 0, "date", "datetime");
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Meta_parser__fld_itm {
|
||||
public Meta_parser__fld_itm(int tid_ansi, int tid_sqlite, byte[] word, int paren_itms_count) {
|
||||
this.tid_ansi = tid_ansi; this.tid_sqlite = tid_sqlite;
|
||||
this.word = word; this.paren_itms_count = paren_itms_count;
|
||||
}
|
||||
public int Tid_ansi() {return tid_ansi;} private final int tid_ansi;
|
||||
public int Tid_sqlite() {return tid_sqlite;} private final int tid_sqlite;
|
||||
public byte[] Word() {return word;} private final byte[] word;
|
||||
public int Paren_itms_count() {return paren_itms_count;} private final int paren_itms_count;
|
||||
public static void reg_many(Btrie_slim_mgr trie, int tid_ansi, int tid_sqlite, int paren_itms_count, String... names_str) {
|
||||
int len = names_str.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
byte[] name_bry = Bry_.new_a7(names_str[i]);
|
||||
Meta_parser__fld_itm itm = new Meta_parser__fld_itm(tid_ansi, tid_sqlite, name_bry, paren_itms_count);
|
||||
trie.Add_obj(name_bry, itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
class Sqlite_tid {
|
||||
public static final int Tid_int = 1, Tid_text = 2, Tid_none = 3, Tid_real = 4, Tid_numeric = 5;
|
||||
}
|
71
140_dbs/src/gplx/dbs/metas/parsers/Meta_parser__fld_tst.java
Normal file
71
140_dbs/src/gplx/dbs/metas/parsers/Meta_parser__fld_tst.java
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import org.junit.*;
|
||||
public class Meta_parser__fld_tst {
|
||||
@Before public void init() {fxt.Clear();} private Meta_parser__fld_fxt fxt = new Meta_parser__fld_fxt();
|
||||
@Test public void Parse_type() {
|
||||
fxt.Test_parse_type("int" , fxt.Make_type(Db_meta_fld.Tid_int));
|
||||
fxt.Test_parse_type("varchar(255)" , fxt.Make_type(Db_meta_fld.Tid_str, 255));
|
||||
fxt.Test_parse_type("decimal(12,10)" , fxt.Make_type(Db_meta_fld.Tid_decimal, 12, 10));
|
||||
fxt.Test_parse_type(" int" , fxt.Make_type(Db_meta_fld.Tid_int));
|
||||
fxt.Test_parse_type(" decimal ( 12 , 10 )" , fxt.Make_type(Db_meta_fld.Tid_decimal, 12, 10));
|
||||
}
|
||||
@Test public void Parse_fld() {
|
||||
fxt.Test_parse_fld("name_1 int" , fxt.Make_fld("name_1", Db_meta_fld.Tid_int, Meta_fld_itm.Nullable_unknown));
|
||||
fxt.Test_parse_fld("name_1 int null" , fxt.Make_fld("name_1", Db_meta_fld.Tid_int, Meta_fld_itm.Nullable_null));
|
||||
fxt.Test_parse_fld("name_1 int not null" , fxt.Make_fld("name_1", Db_meta_fld.Tid_int, Meta_fld_itm.Nullable_not_null));
|
||||
fxt.Test_parse_fld("name_1 int not null autoincrement" , fxt.Make_fld("name_1", Db_meta_fld.Tid_int, Meta_fld_itm.Nullable_not_null, Bool_.N, Bool_.Y));
|
||||
fxt.Test_parse_fld("name_1 int not null primary key" , fxt.Make_fld("name_1", Db_meta_fld.Tid_int, Meta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N));
|
||||
fxt.Test_parse_fld("name_1 int not null default -1" , fxt.Make_fld("name_1", Db_meta_fld.Tid_int, Meta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N, -1));
|
||||
fxt.Test_parse_fld("name_1 int not null default 'abc'" , fxt.Make_fld("name_1", Db_meta_fld.Tid_int, Meta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N, "abc"));
|
||||
}
|
||||
}
|
||||
class Meta_parser__fld_fxt {
|
||||
private final Meta_parser__fld fld_parser = new Meta_parser__fld();
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
public void Clear() {}
|
||||
public Meta_type_itm Make_type(int tid_ansi) {return new Meta_type_itm(tid_ansi, -1, null, Int_.MinValue, Int_.MinValue);}
|
||||
public Meta_type_itm Make_type(int tid_ansi, int len_1) {return new Meta_type_itm(tid_ansi, -1, null, len_1, Int_.MinValue);}
|
||||
public Meta_type_itm Make_type(int tid_ansi, int len_1, int len_2) {return new Meta_type_itm(tid_ansi, -1, null, len_1, len_2);}
|
||||
public Meta_fld_itm Make_fld(String name, int tid_ansi, int nullable) {return Make_fld(name, tid_ansi, nullable, false, false, null);}
|
||||
public Meta_fld_itm Make_fld(String name, int tid_ansi, int nullable, boolean autonumber, boolean primary_key) {return Make_fld(name, tid_ansi, nullable, false, false, null);}
|
||||
public Meta_fld_itm Make_fld(String name, int tid_ansi, int nullable, boolean autonumber, boolean primary_key, Object default_val) {
|
||||
Meta_fld_itm rv = new Meta_fld_itm(name, Make_type(tid_ansi));
|
||||
rv.Nullable_tid_(nullable);
|
||||
if (autonumber) rv.Autonumber_y_();
|
||||
if (primary_key) rv.Primary_key_y_();
|
||||
rv.Default_val_(default_val);
|
||||
return rv;
|
||||
}
|
||||
public void Test_parse_type(String src, Meta_type_itm expd_type) {
|
||||
rdr.Init(Bry_.new_u8(src));
|
||||
Meta_type_itm actl_type = fld_parser.Parse_type(rdr);
|
||||
Tfds.Eq(expd_type.Tid_ansi() , actl_type.Tid_ansi());
|
||||
Tfds.Eq(expd_type.Len_1() , actl_type.Len_1());
|
||||
Tfds.Eq(expd_type.Len_2() , actl_type.Len_2());
|
||||
}
|
||||
public void Test_parse_fld(String src, Meta_fld_itm expd_fld) {
|
||||
rdr.Init(Bry_.new_u8(src));
|
||||
Meta_fld_itm actl_fld = fld_parser.Parse_fld(rdr);
|
||||
Tfds.Eq(expd_fld.Name() , actl_fld.Name());
|
||||
Tfds.Eq(expd_fld.Type().Tid_ansi() , actl_fld.Type().Tid_ansi());
|
||||
Tfds.Eq(expd_fld.Nullable_tid() , actl_fld.Nullable_tid());
|
||||
Tfds.Eq(Object_.Xto_str_strict_or_empty(expd_fld.Default_val()), Object_.Xto_str_strict_or_empty(actl_fld.Default_val()));
|
||||
}
|
||||
}
|
57
140_dbs/src/gplx/dbs/metas/parsers/Meta_parser__tbl.java
Normal file
57
140_dbs/src/gplx/dbs/metas/parsers/Meta_parser__tbl.java
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
public class Meta_parser__tbl {
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
private final Meta_parser__fld fld_parser = new Meta_parser__fld();
|
||||
private Meta_tbl_itm tbl;
|
||||
public Meta_tbl_itm Parse(byte[] src) {
|
||||
src = Bry_.Lower_ascii(src);
|
||||
rdr.Init(src);
|
||||
tbl = null;
|
||||
Parse_hdr();
|
||||
Parse_flds();
|
||||
return tbl;
|
||||
}
|
||||
private void Parse_hdr() {
|
||||
rdr.Skip_ws().Chk_bry_or_fail(Tkn_create);
|
||||
rdr.Skip_ws().Chk_bry_or_fail(Tkn_table);
|
||||
byte[] tbl_name = rdr.Read_sql_identifier();
|
||||
this.tbl = new Meta_tbl_itm(String_.new_u8(tbl_name), String_.new_u8(rdr.Src()));
|
||||
rdr.Skip_ws().Chk_byte_or_fail(Byte_ascii.Paren_bgn);
|
||||
}
|
||||
private void Parse_flds() {
|
||||
byte[] src = rdr.Src();
|
||||
while (true) {
|
||||
Meta_fld_itm fld = fld_parser.Parse_fld(rdr); if (fld == null) throw Err_.new_("unknown field; src={0}", rdr.Src());
|
||||
tbl.Flds().Add(fld);
|
||||
int pos = rdr.Pos();
|
||||
byte b = pos == rdr.Src_len() ? Byte_ascii.Nil : src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Comma: rdr.Pos_add_one(); break;
|
||||
case Byte_ascii.Paren_end: rdr.Pos_add_one(); return;
|
||||
default: throw Err_.new_("premature end of flds; src={0}", rdr.Mid_by_len_safe(40));
|
||||
}
|
||||
}
|
||||
}
|
||||
private static final byte[]
|
||||
Tkn_create = Bry_.new_a7("create")
|
||||
, Tkn_table = Bry_.new_a7("table")
|
||||
;
|
||||
}
|
66
140_dbs/src/gplx/dbs/metas/parsers/Meta_parser__tbl_tst.java
Normal file
66
140_dbs/src/gplx/dbs/metas/parsers/Meta_parser__tbl_tst.java
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import org.junit.*;
|
||||
public class Meta_parser__tbl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Meta_parser__tbl_fxt fxt = new Meta_parser__tbl_fxt();
|
||||
@Test public void Test_parse() {
|
||||
fxt.Test_parse("CREATE TABLE tbl_1 (fld_1 int, fld_2 int)", fxt.Make_tbl("tbl_1", "fld_1", "fld_2"));
|
||||
}
|
||||
@Test public void Test_smoke() {
|
||||
fxt.Test_parse(String_.Concat_lines_nl_skip_last
|
||||
( "CREATE TABLE page"
|
||||
, "( page_id integer NOT NULL PRIMARY KEY"
|
||||
, ", page_namespace integer NOT NULL"
|
||||
, ", page_title varchar(255) NOT NULL"
|
||||
, ", page_is_redirect integer NOT NULL"
|
||||
, ", page_touched varchar(14) NOT NULL"
|
||||
, ", page_len integer NOT NULL"
|
||||
, ", page_random_int integer NOT NULL"
|
||||
, ", page_text_db_id integer NOT NULL"
|
||||
, ", page_html_db_id integer NOT NULL DEFAULT -1"
|
||||
, ", page_redirect_id integer NOT NULL DEFAULT -1"
|
||||
, ");"
|
||||
), fxt.Make_tbl("page", "page_id", "page_namespace", "page_title", "page_is_redirect", "page_touched", "page_len", "page_random_int", "page_text_db_id", "page_html_db_id", "page_redirect_id"));
|
||||
}
|
||||
}
|
||||
class Meta_parser__tbl_fxt {
|
||||
private final Meta_parser__tbl tbl_parser = new Meta_parser__tbl();
|
||||
public void Clear() {}
|
||||
public Meta_tbl_itm Make_tbl(String tbl_name, String... fld_names) {
|
||||
Meta_tbl_itm rv = new Meta_tbl_itm(tbl_name, "NONE");
|
||||
int len = fld_names.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
rv.Flds().Add(new Meta_fld_itm(fld_names[i], new Meta_type_itm(Db_meta_fld.Tid_int, Sqlite_tid.Tid_int, Bry_.new_a7("int"), Int_.MinValue, Int_.MinValue)));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Test_parse(String src, Meta_tbl_itm expd_tbl) {
|
||||
Meta_tbl_itm actl_tbl = tbl_parser.Parse(Bry_.new_u8(src));
|
||||
Tfds.Eq(expd_tbl.Name(), actl_tbl.Name());
|
||||
Tfds.Eq_ary_str(To_str_ary(expd_tbl.Flds()), To_str_ary(actl_tbl.Flds()));
|
||||
}
|
||||
private static String[] To_str_ary(Meta_fld_mgr fld_mgr) {
|
||||
int len = fld_mgr.Len();
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
rv[i] = fld_mgr.Get_at(i).Name();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
57
140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr.java
Normal file
57
140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr.java
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import gplx.core.brys.*;
|
||||
public class Sql_bry_rdr extends Bry_rdr { public byte[] Read_sql_identifier() {
|
||||
this.Skip_ws();
|
||||
int bgn = pos, end = -1;
|
||||
if (pos == src_len) return null;
|
||||
if (src[pos] == Byte_ascii.Brack_bgn) { // EX: [name with space]
|
||||
bgn = ++pos; // set bgn after [
|
||||
end = this.Find_fwd(Byte_ascii.Brack_end);
|
||||
pos = end + 1; // set pos after ]
|
||||
}
|
||||
else {
|
||||
this.Skip_alpha_num_under(); // ASSUME: identifier is ASCII and alpha / num / underscore
|
||||
if (pos == bgn) return null; // String is not identifier; EX: "!@#"
|
||||
end = pos;
|
||||
}
|
||||
return Bry_.Mid(src, bgn, end);
|
||||
}
|
||||
@Override public Bry_rdr Skip_ws() {
|
||||
byte b_0 = pos < src_len ? src[pos] : Byte_ascii.Nil;
|
||||
byte bgn_1 = Byte_ascii.Nil;
|
||||
byte[] end_bry = null;
|
||||
switch (b_0) {
|
||||
case Byte_ascii.Dash: bgn_1 = Byte_ascii.Dash; end_bry = Comm_end_line; break;
|
||||
case Byte_ascii.Slash: bgn_1 = Byte_ascii.Asterisk; end_bry = Comm_end_multi; break;
|
||||
case Byte_ascii.Tab: case Byte_ascii.NewLine: case Byte_ascii.CarriageReturn: case Byte_ascii.Space:
|
||||
++pos;
|
||||
return super.Skip_ws();
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
byte b_1 = pos + 1 < src_len ? src[pos + 1] : Byte_ascii.Nil;
|
||||
if (b_1 != bgn_1) return this;
|
||||
int end_pos = Bry_finder.Find_fwd(src, end_bry, pos + 2, src_len);
|
||||
if (end_pos == Bry_finder.Not_found) return this;
|
||||
pos = end_pos + end_bry.length;
|
||||
return this.Skip_ws();
|
||||
}
|
||||
private static final byte[] Comm_end_line = Byte_ascii.NewLine_bry, Comm_end_multi = Bry_.new_a7("*/");
|
||||
}
|
52
140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr_tst.java
Normal file
52
140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr_tst.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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import org.junit.*;
|
||||
public class Sql_bry_rdr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Sql_bry_rdr_fxt fxt = new Sql_bry_rdr_fxt();
|
||||
@Test public void Skip_ws() {
|
||||
fxt.Test_skip_ws("a", 0); // char
|
||||
fxt.Test_skip_ws("\ta", 1); // tab
|
||||
fxt.Test_skip_ws("\na", 1); // \n
|
||||
fxt.Test_skip_ws("\ra", 1); // \r
|
||||
fxt.Test_skip_ws(" a", 1); // space
|
||||
fxt.Test_skip_ws("\t\n\r a", 4); // multi
|
||||
fxt.Test_skip_ws("", 0); // eos
|
||||
}
|
||||
@Test public void Read_sql_identifier() {
|
||||
fxt.Test_read_sql_identifier("a", "a"); // one
|
||||
fxt.Test_read_sql_identifier("abc_1", "abc_1"); // many
|
||||
fxt.Test_read_sql_identifier("[abc_1]", "abc_1"); // bracket
|
||||
fxt.Test_read_sql_identifier(" a ", "a"); // ws
|
||||
fxt.Test_read_sql_identifier("", null); // eos
|
||||
fxt.Test_read_sql_identifier("!@#", null); // sym
|
||||
}
|
||||
}
|
||||
class Sql_bry_rdr_fxt {
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
public void Clear() {}
|
||||
public void Test_skip_ws(String src, int expd_pos) {
|
||||
rdr.Init(Bry_.new_u8(src));
|
||||
rdr.Skip_ws();
|
||||
Tfds.Eq(expd_pos, rdr.Pos());
|
||||
}
|
||||
public void Test_read_sql_identifier(String src, String expd) {
|
||||
rdr.Init(Bry_.new_u8(src));
|
||||
Tfds.Eq(expd, String_.new_u8(rdr.Read_sql_identifier()));
|
||||
}
|
||||
}
|
@ -50,7 +50,7 @@ public class IptArgChainMgr_tst {
|
||||
}
|
||||
else if (expd == 1) {
|
||||
Tfds.Eq(process, "", "1:{0} should be empty:process", literal);
|
||||
Tfds.Eq_true(String_.HasAtEnd(activeKey, key.Key() + ","), "1:{0} should set key:activeKey,{1}", literal, activeKey);
|
||||
Tfds.Eq_true(String_.Has_at_end(activeKey, key.Key() + ","), "1:{0} should set key:activeKey,{1}", literal, activeKey);
|
||||
}
|
||||
else if (expd == 2) {
|
||||
Tfds.Eq_true(String_.EqNot(process, ""), "2:{0} should not be empty;process,{1}", literal, process);
|
||||
|
@ -63,7 +63,7 @@ public class IptKey_ {
|
||||
return (rv == null) ? new_(val, enm_mgr.GetStr(val)) : rv;
|
||||
}
|
||||
static IptKey new_(int val, String name) {
|
||||
IptKey rv = new IptKey(val, String_.HasAtBgn(name, "key.") ? name : "key." + name);
|
||||
IptKey rv = new IptKey(val, String_.Has_at_bgn(name, "key.") ? name : "key." + name);
|
||||
enm_mgr.RegObj(val, name, rv);
|
||||
return rv;
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ class GfoConsoleWinCmds implements GfoInvkAble {
|
||||
GfsCore._.ExecRegy("gplx.gfui.GfoConsoleWin.ini");
|
||||
}
|
||||
public void Results_add(String s) {
|
||||
if (!String_.HasAtEnd(s, GfuiTextBox_.NewLine))
|
||||
if (!String_.Has_at_end(s, GfuiTextBox_.NewLine))
|
||||
s += GfuiTextBox_.NewLine;
|
||||
statusBox.Text_(statusBox.Text() + s);
|
||||
statusBox.SelBgn_set(String_.Len(statusBox.Text()) - 1);
|
||||
|
@ -236,12 +236,12 @@ class Swt_html_lnr_location implements LocationListener {
|
||||
String location = arg.location;
|
||||
if (String_.Eq(location, "about:blank")) return; // location changing event fires once when page is loaded; ignore
|
||||
if ( html_box.Browser_tid() == Swt_html.Browser_tid_webkit // webkit prefixes "about:blank" to anchors; causes TOC to fail when clicking on links; EX:about:blank#TOC1; DATE:2015-06-09
|
||||
&& String_.HasAtBgn(location, "about:blank")) {
|
||||
&& String_.Has_at_bgn(location, "about:blank")) {
|
||||
location = String_.Mid(location, 11); // 11 = "about:blank".length
|
||||
}
|
||||
if ( html_box.Html_doc_html_load_tid() == Gxw_html_load_tid_.Tid_url // navigating to file://page.html will fire location event; ignore if url mode
|
||||
&& String_.HasAtBgn(location, "file:")
|
||||
&& String_.HasAtEnd(location, ".html")
|
||||
&& String_.Has_at_bgn(location, "file:")
|
||||
&& String_.Has_at_end(location, ".html")
|
||||
)
|
||||
return;
|
||||
try {
|
||||
|
@ -43,7 +43,7 @@ public class Bry_rdr_tst {
|
||||
class Bry_rdr_fxt {
|
||||
private Bry_rdr rdr;
|
||||
public void Clear() {rdr = new Bry_rdr();}
|
||||
public Bry_rdr_fxt Init_src(String v) {rdr.Src_(Bry_.new_u8(v)); return this;}
|
||||
public Bry_rdr_fxt Init_src(String v) {rdr.Init(Bry_.new_u8(v)); return this;}
|
||||
public Bry_rdr_fxt Init_pos(int v) {rdr.Pos_(v); return this;}
|
||||
public void Test_read_int(int expd_val) {
|
||||
Tfds.Eq(expd_val, rdr.Read_int_to_pipe());
|
||||
|
@ -66,7 +66,7 @@ public class Gfo_thread_cmd_unzip implements Gfo_thread_cmd {
|
||||
Io_url zip_dir = Io_url_.Empty;
|
||||
for (int i = 0; i < dirs_len; i++) {
|
||||
Io_url dir = dirs[i];
|
||||
if (String_.HasAtBgn(String_.Lower(dir.NameOnly()), String_.Lower(trg.NameOnly()))) { // HACK: check that directory starts with archive name; DATE:2013-12-22
|
||||
if (String_.Has_at_bgn(String_.Lower(dir.NameOnly()), String_.Lower(trg.NameOnly()))) { // HACK: check that directory starts with archive name; DATE:2013-12-22
|
||||
zip_dir = dir;
|
||||
break;
|
||||
}
|
||||
|
@ -15,12 +15,12 @@ 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.schemas; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.schemas.updates.*;
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.metas.updates.*;
|
||||
public class Schema_db_mgr {
|
||||
public Schema_loader_mgr Loader() {return loader;} public void Loader_(Schema_loader_mgr v) {loader = v;} private Schema_loader_mgr loader;
|
||||
public Schema_update_mgr Updater() {return updater;} private final Schema_update_mgr updater = new Schema_update_mgr();
|
||||
public Schema_tbl_mgr Tbl_mgr() {return tbl_mgr;} private final Schema_tbl_mgr tbl_mgr = new Schema_tbl_mgr();
|
||||
public Meta_tbl_mgr Tbl_mgr() {return tbl_mgr;} private final Meta_tbl_mgr tbl_mgr = new Meta_tbl_mgr();
|
||||
public void Init(Db_conn conn) {
|
||||
loader.Load(this, conn);
|
||||
updater.Update(this, conn);
|
@ -15,7 +15,7 @@ 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.schemas; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
public interface Schema_loader_mgr {
|
||||
void Load(Schema_db_mgr db_mgr, Db_conn conn);
|
||||
}
|
@ -15,7 +15,7 @@ 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.schemas; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
public class Schema_loader_mgr_ {
|
||||
public static final Schema_loader_mgr Null = new Schema_loader_mgr__null();
|
||||
@ -27,19 +27,22 @@ class Schema_loader_mgr__null implements Schema_loader_mgr {
|
||||
class Schema_loader_mgr__sqlite implements Schema_loader_mgr {
|
||||
public void Load(Schema_db_mgr db_mgr, Db_conn conn) {
|
||||
Gfo_usr_dlg_.I.Log_many("", "", "db.schema.load.bgn: conn=~{0}", conn.Conn_info().Xto_api());
|
||||
Schema_tbl_mgr tbl_mgr = db_mgr.Tbl_mgr();
|
||||
Meta_tbl_mgr tbl_mgr = db_mgr.Tbl_mgr();
|
||||
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.new_("sqlite_master", String_.Ary_empty, String_.Ary("type", "name", "sql"), Db_qry__select_in_tbl.Order_by_null);
|
||||
Db_rdr rdr = conn.Stmt_new(qry).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
int type = Schema_itm_tid.Xto_int(rdr.Read_str(0));
|
||||
switch (type) {
|
||||
case Schema_itm_tid.Tid_table:
|
||||
Schema_tbl_itm tbl_itm = new Schema_tbl_itm(rdr.Read_str(1), rdr.Read_str(2));
|
||||
String type_str = rdr.Read_str("type");
|
||||
String name = rdr.Read_str("name");
|
||||
String sql = rdr.Read_str("sql");
|
||||
int type_int = Meta_itm_tid.Xto_int(type_str);
|
||||
switch (type_int) {
|
||||
case Meta_itm_tid.Tid_table:
|
||||
Meta_tbl_itm tbl_itm = new Meta_tbl_itm(name, sql);
|
||||
tbl_mgr.Add(tbl_itm);
|
||||
break;
|
||||
case Schema_itm_tid.Tid_index: break; // noop for now
|
||||
default: throw Err_.unhandled(type);
|
||||
case Meta_itm_tid.Tid_index: break; // noop for now
|
||||
default: throw Err_.unhandled(type_str);
|
||||
}
|
||||
}
|
||||
} finally {rdr.Rls();}
|
@ -15,7 +15,7 @@ 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.schemas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.schemas.*;
|
||||
package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
public interface Schema_update_cmd {
|
||||
String Name();
|
||||
boolean Exec_is_done();
|
@ -15,7 +15,7 @@ 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.schemas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.schemas.*;
|
||||
package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import gplx.dbs.engines.sqlite.*;
|
||||
public class Schema_update_cmd_ {
|
||||
public static Schema_update_cmd Make_tbl_create(String tbl_name, String tbl_sql, Db_idx_itm... tbl_idxs) {return new Schema_update_cmd__tbl_create(tbl_name, tbl_sql, tbl_idxs);}
|
@ -15,7 +15,7 @@ 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.schemas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.schemas.*;
|
||||
package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
public class Schema_update_mgr {
|
||||
private List_adp cmds = List_adp_.new_();
|
||||
public void Add(Schema_update_cmd cmd) {cmds.Add(cmd);}
|
@ -15,7 +15,7 @@ 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.schemas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.schemas.*;
|
||||
package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import org.junit.*; import gplx.dbs.*;
|
||||
public class Schema_update_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Schema_update_mgr_fxt fxt = new Schema_update_mgr_fxt();
|
||||
@ -23,7 +23,7 @@ public class Schema_update_mgr_tst {
|
||||
fxt.Test_exec_y(new Schema_update_cmd__mock());
|
||||
}
|
||||
@Test public void Delete() {
|
||||
fxt.Init_itm(Schema_itm_tid.Tid_table, Schema_update_cmd__mock.Tbl_name);
|
||||
fxt.Init_itm(Meta_itm_tid.Tid_table, Schema_update_cmd__mock.Tbl_name);
|
||||
fxt.Test_exec_n(new Schema_update_cmd__mock());
|
||||
}
|
||||
}
|
||||
@ -34,7 +34,7 @@ class Schema_update_mgr_fxt {
|
||||
db_mgr = new Schema_db_mgr();
|
||||
}
|
||||
public void Init_itm(int tid, String name) {
|
||||
db_mgr.Tbl_mgr().Add(new Schema_tbl_itm(name, "sql"));
|
||||
db_mgr.Tbl_mgr().Add(new Meta_tbl_itm(name, "sql"));
|
||||
}
|
||||
public void Test_exec_y(Schema_update_cmd cmd) {Test_exec(cmd, Bool_.Y);}
|
||||
public void Test_exec_n(Schema_update_cmd cmd) {Test_exec(cmd, Bool_.N);}
|
@ -46,7 +46,13 @@ public class Fsdb_db_mgr__v1 implements Fsdb_db_mgr {
|
||||
Io_url url = file_dir.GenSubFil_nest(mnt_name, bin_name); // EX: /xowa/enwiki/fsdb.main/fsdb.bin.0000.sqlite3
|
||||
return new Fsdb_db_file(url, Db_conn_bldr.I.Get(url));
|
||||
}
|
||||
public Fsdb_db_file File__bin_file__new(int mnt_id, String file_name) {throw Err_.not_implemented_();}
|
||||
public Fsdb_db_file File__bin_file__new(int mnt_id, String file_name) {
|
||||
String mnt_name = mnt_id == Fsm_mnt_mgr.Mnt_idx_main ? Fsm_mnt_tbl.Mnt_name_main : Fsm_mnt_tbl.Mnt_name_user;
|
||||
Io_url url = file_dir.GenSubFil_nest(mnt_name, file_name); // EX: /xowa/enwiki/fsdb.main/fsdb.bin.0000.sqlite3
|
||||
Db_conn conn = Db_conn_bldr.I.New(url);
|
||||
Fsd_bin_tbl bin_tbl = new Fsd_bin_tbl(conn, Bool_.Y); bin_tbl.Create_tbl();
|
||||
return new Fsdb_db_file(url, conn);
|
||||
}
|
||||
public static final String Orig_name = "wiki.orig#00.sqlite3", Mnt_name = "wiki.mnt.sqlite3", Abc_name = "fsdb.abc.sqlite3", Atr_name= "fsdb.atr.00.sqlite3";
|
||||
private static Fsdb_db_file get_db(Io_url file) {
|
||||
Db_conn conn = Db_conn_bldr.I.Get(file);
|
||||
|
@ -20,7 +20,7 @@ import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.fsdb.meta.*; import gplx.
|
||||
import gplx.xowa.*; import gplx.xowa.wikis.data.*; import gplx.xowa.bldrs.infos.*;
|
||||
public class Fsdb_db_mgr__v2_bldr {
|
||||
public Fsdb_db_mgr__v2 Get_or_make(Xow_wiki wiki, boolean delete_if_exists) { // NOTE: must check if file exists else imports with existing v2 dbs will fail; DATE:2015-05-23
|
||||
Xowd_db_layout layout = wiki.Data_mgr__core_mgr().Props().Layout_file();
|
||||
Xowd_db_layout layout = wiki.Data__core_mgr().Props().Layout_file();
|
||||
String domain_str = wiki.Domain_str();
|
||||
Io_url wiki_dir = wiki.Fsys_mgr().Root_dir();
|
||||
String main_core_name = Main_core_name(layout, domain_str);
|
||||
@ -99,7 +99,7 @@ public class Fsdb_db_mgr__v2_bldr {
|
||||
}
|
||||
public static void Make_cfg_data(Xow_wiki wiki, String file_core_name, Fsdb_db_file file, byte file_tid, int part_id) {
|
||||
Db_cfg_tbl cfg_tbl = file.Tbl__cfg();
|
||||
Xowd_db_file core_db = wiki.Data_mgr__core_mgr().Db__core();
|
||||
Xowd_db_file core_db = wiki.Data__core_mgr().Db__core();
|
||||
core_db.Info_session().Save(cfg_tbl);
|
||||
Xob_info_file info_file = new Xob_info_file(-1, Xowd_db_file_.To_key(file_tid), Xob_info_file.Ns_ids_empty, part_id, Guid_adp_.new_(), 2, file_core_name, file.Url().NameAndExt());
|
||||
info_file.Save(cfg_tbl);
|
||||
|
@ -68,7 +68,13 @@ public class Fsd_bin_tbl implements RlsAble {
|
||||
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_owner_id, owner_id).Exec_select__rls_manual();
|
||||
try {
|
||||
if (rdr.Move_next()) {
|
||||
byte[] rv = rdr.Read_bry(fld_data);
|
||||
byte[] rv = null;
|
||||
try {rv = rdr.Read_bry(fld_data);}
|
||||
catch (Exception e) {
|
||||
if (Op_sys.Cur().Tid_is_drd() && String_.Has(Err_.Message_lang(e), "get field slot from row")) { // get field slot from row 0 col 0 failed
|
||||
rv = rdr.Read_bry_in_parts(tbl_name, fld_data, fld_owner_id, owner_id);
|
||||
}
|
||||
}
|
||||
return rv == null ? Bry_.Empty : rv; // NOTE: bug in v0.10.1 where .ogg would save as null; return Bry_.Empty instead, else java.io.ByteArrayInputStream would fail on null
|
||||
}
|
||||
else
|
||||
|
@ -20,13 +20,14 @@ import gplx.ios.*; import gplx.dbs.*;
|
||||
import gplx.fsdb.data.*;
|
||||
public class Fsm_bin_fil {
|
||||
private final Fsd_bin_tbl tbl;
|
||||
public Fsm_bin_fil(int id, String url_rel, long bin_len, Db_conn conn, boolean schema_is_1) {
|
||||
this.id = id; this.url_rel = url_rel; this.bin_len = bin_len; this.conn = conn;
|
||||
public Fsm_bin_fil(boolean schema_is_1, int id, Io_url url, String url_rel, Db_conn conn, long bin_len) {
|
||||
this.id = id; this.url = url; this.url_rel = url_rel; this.conn = conn; this.bin_len = bin_len;
|
||||
this.tbl = new Fsd_bin_tbl(conn, schema_is_1);
|
||||
}
|
||||
public int Id() {return id;} private final int id;
|
||||
public Io_url Url() {return url;} private Io_url url;
|
||||
public String Url_rel() {return url_rel;} private final String url_rel;
|
||||
public long Bin_len() {return bin_len;} private void Bin_len_(long v) {bin_len = v;} private long bin_len;
|
||||
public long Bin_len() {return bin_len;} public void Bin_len_(long v) {bin_len = v;} private long bin_len;
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public boolean Select_to_url(int id, Io_url url) {return tbl.Select_to_url(id, url);}
|
||||
public Io_stream_rdr Select_as_rdr(int id) {return tbl.Select_as_rdr(id);}
|
||||
|
@ -29,11 +29,12 @@ public class Fsm_bin_mgr {
|
||||
this.dbs__ary_len = dbs__ary.length;
|
||||
if (dbs__ary_len > 0) this.nth_db = dbs__ary[dbs__ary_len - 1];
|
||||
}
|
||||
public int Dbs__len() {return dbs__ary_len;}
|
||||
public Fsm_bin_fil Dbs__get_nth() {return nth_db;}
|
||||
public Fsm_bin_fil Dbs__get_at(int i) {return dbs__ary[i];}
|
||||
public Fsm_bin_fil Dbs__make(String file_name) {
|
||||
Fsdb_db_file db = core_mgr.File__bin_file__new(mnt_id, file_name);
|
||||
Fsm_bin_fil rv = new Fsm_bin_fil(dbs__ary_len, db.Url().NameAndExt(), Fsm_bin_fil.Bin_len_null, db.Conn(), core_mgr.File__schema_is_1());
|
||||
Fsm_bin_fil rv = new Fsm_bin_fil(core_mgr.File__schema_is_1(), dbs__ary_len, db.Url(), db.Url().NameAndExt(), db.Conn(), Fsm_bin_fil.Bin_len_null);
|
||||
tbl.Insert(rv.Id(), rv.Url_rel());
|
||||
Dbs__add(rv);
|
||||
return rv;
|
||||
|
@ -19,19 +19,27 @@ package gplx.fsdb.meta; import gplx.*; import gplx.fsdb.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*;
|
||||
public class Fsm_bin_tbl {
|
||||
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_uid, fld_url;
|
||||
private final String fld_uid, fld_url, fld_bin_len, fld_bin_max;
|
||||
private final Db_conn conn; private int mnt_id;
|
||||
public Fsm_bin_tbl(Db_conn conn, boolean schema_is_1, int mnt_id) {
|
||||
this.conn = conn; this.mnt_id = mnt_id;
|
||||
String fld_prefix = "";
|
||||
if (schema_is_1) {tbl_name = "fsdb_db_bin";}
|
||||
else {tbl_name = "fsdb_dbb"; fld_prefix = "dbb_";}
|
||||
if (schema_is_1) {tbl_name = "fsdb_db_bin";}
|
||||
else {tbl_name = "fsdb_dbb"; fld_prefix = "dbb_";}
|
||||
fld_uid = flds.Add_int_pkey (fld_prefix + "uid");
|
||||
fld_url = flds.Add_str (fld_prefix + "url", 255);
|
||||
if (schema_is_1) {
|
||||
fld_bin_len = flds.Add_long("bin_len");
|
||||
fld_bin_max = flds.Add_long("bin_max");
|
||||
}
|
||||
else {
|
||||
fld_bin_len = Db_meta_fld.Key_null;
|
||||
fld_bin_max = Db_meta_fld.Key_null;
|
||||
}
|
||||
}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Insert(int id, String url_rel) {
|
||||
conn.Stmt_insert(tbl_name, flds).Crt_int(fld_uid, id).Val_str(fld_url, url_rel).Exec_insert();
|
||||
conn.Stmt_insert(tbl_name, flds).Crt_int(fld_uid, id).Val_str(fld_url, url_rel).Val_long(fld_bin_len, 0).Val_long(fld_bin_max, 0).Exec_insert();
|
||||
}
|
||||
public Fsm_bin_fil[] Select_all(Fsdb_db_mgr db_conn_mgr) {
|
||||
List_adp rv = List_adp_.new_();
|
||||
@ -41,7 +49,7 @@ public class Fsm_bin_tbl {
|
||||
int bin_id = rdr.Read_int(fld_uid);
|
||||
String bin_url = rdr.Read_str(fld_url);
|
||||
Fsdb_db_file bin_db = db_conn_mgr.File__bin_file__at(mnt_id, bin_id, bin_url);
|
||||
Fsm_bin_fil itm = new Fsm_bin_fil(bin_id, bin_url, Fsm_bin_fil.Bin_len_null, bin_db.Conn(), db_conn_mgr.File__schema_is_1());
|
||||
Fsm_bin_fil itm = new Fsm_bin_fil(db_conn_mgr.File__schema_is_1(), bin_id, bin_db.Url(), bin_url, bin_db.Conn(), Fsm_bin_fil.Bin_len_null);
|
||||
rv.Add(itm);
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
|
@ -147,7 +147,7 @@ class Gfs_parser_fxt {
|
||||
catch (Exception e) {
|
||||
String actl_err = Err_.Message_gplx_brief(e);
|
||||
actl_err = String_.GetStrBefore(actl_err, ":");
|
||||
boolean match = String_.HasAtBgn(actl_err, expd_err);
|
||||
boolean match = String_.Has_at_bgn(actl_err, expd_err);
|
||||
if (!match) Tfds.Fail("expecting '" + expd_err + "' got '" + actl_err + "'");
|
||||
return;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class Xoa_app_ {
|
||||
boot_mgr.Run(args);
|
||||
}
|
||||
public static final String Name = "xowa";
|
||||
public static final String Version = "2.6.3.1";
|
||||
public static final String Version = "2.6.4.1";
|
||||
public static String Build_date = "2012-12-30 00:00:00";
|
||||
public static String Op_sys;
|
||||
public static String User_agent = "";
|
||||
|
@ -42,7 +42,7 @@ public class Xoapi_url implements GfoInvkAble {
|
||||
else {
|
||||
for (int i = 0; i < urls_len; i++) {
|
||||
String url = urls[i];
|
||||
if (String_.HasAtBgn(url, "\"") && String_.HasAtBgn(url, "\""))
|
||||
if (String_.Has_at_bgn(url, "\"") && String_.Has_at_bgn(url, "\""))
|
||||
url = String_.Mid(url, 1, String_.Len(url) - 1);
|
||||
app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_link(url, false);
|
||||
}
|
||||
|
@ -71,11 +71,11 @@ public class Xob_wiki_cfg_bldr_tst {
|
||||
// line = String_.Replace(line, "/** ", "");
|
||||
// int pos = String_.FindBwd(line, " (");
|
||||
// if (pos == String_.Find_none) continue; // en; en_rtl have no "language" line
|
||||
// if ( String_.HasAtBgn(lang_code, "be_")
|
||||
// || String_.HasAtBgn(lang_code, "crh_")
|
||||
// || String_.HasAtBgn(lang_code, "kk_")
|
||||
// || String_.HasAtBgn(lang_code, "ku_")
|
||||
// || String_.HasAtBgn(lang_code, "sr_")
|
||||
// if ( String_.Has_at_bgn(lang_code, "be_")
|
||||
// || String_.Has_at_bgn(lang_code, "crh_")
|
||||
// || String_.Has_at_bgn(lang_code, "kk_")
|
||||
// || String_.Has_at_bgn(lang_code, "ku_")
|
||||
// || String_.Has_at_bgn(lang_code, "sr_")
|
||||
// || String_.In(lang_code, "de_formal", "nb", "nl_informal", "nn", "no")
|
||||
// ) {
|
||||
// int new_pos = String_.FindBwd(line, " (", pos - 1);
|
||||
|
@ -29,7 +29,7 @@ public abstract class Xob_categorylinks_base extends Xob_sql_dump_base implement
|
||||
public void Exec(byte[] src, byte[] fld_key, int fld_idx, int fld_bgn, int fld_end, Bry_bfr file_bfr, Sql_file_parser_data data) {
|
||||
if (Bry_.Eq(fld_key, Fld_cl_from)) cur_id = Bry_.Xto_int_or(src, fld_bgn, fld_end, -1);
|
||||
else if (Bry_.Eq(fld_key, Fld_cl_to)) cur_ctg = Bry_.Mid(src, fld_bgn, fld_end);
|
||||
else if (Bry_.Eq(fld_key, Fld_cl_collation)) cur_collation_is_uca = Bry_.HasAtBgn(src, Collation_uca, fld_bgn, fld_end);
|
||||
else if (Bry_.Eq(fld_key, Fld_cl_collation)) cur_collation_is_uca = Bry_.Has_at_bgn(src, Collation_uca, fld_bgn, fld_end);
|
||||
else if (Bry_.Eq(fld_key, Fld_cl_timestamp)) {
|
||||
date_parser.Parse_iso8651_like(cur_modified_on, src, fld_bgn, fld_end);
|
||||
cur_date = fld_end - fld_bgn == 0 // ignore null dates added by ctg_v1
|
||||
|
57
400_xowa/src/gplx/xowa/bldrs/cmds/files/Xob_bin_db_itm.java
Normal file
57
400_xowa/src/gplx/xowa/bldrs/cmds/files/Xob_bin_db_itm.java
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
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.xowa.bldrs.cmds.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.fsdb.meta.*;
|
||||
class Xob_bin_db_itm {
|
||||
public Xob_bin_db_itm(int id, Io_url db_url, int ns_id, int pt_id) {this.id = id; this.db_url = db_url; this.ns_id = ns_id; this.pt_id = pt_id;}
|
||||
public int Id() {return id;} private int id;
|
||||
public int Ns_id() {return ns_id;} private final int ns_id;
|
||||
public int Pt_id() {return pt_id;} private int pt_id;
|
||||
public long Db_len() {return db_len;} public void Db_len_(long v) {this.db_len = v;} private long db_len;
|
||||
public Io_url Db_url() {return db_url;} public void Db_url_(Io_url v) {db_url = v;} private Io_url db_url;
|
||||
public void Set(int id, int pt_id, Io_url db_url) {
|
||||
this.id = id; this.pt_id = pt_id; this.db_url = db_url;
|
||||
}
|
||||
public static String Gen_name_v1(int pt_id) {
|
||||
return String_.Format("fsdb.bin.{0}.sqlite3", Int_.Xto_str_pad_bgn_zero(pt_id, 4));
|
||||
}
|
||||
public static String Gen_name_v2(String domain_str, int ns_id, int pt_id) {
|
||||
String ns_id_str = Int_.Xto_str_pad_bgn_zero(ns_id, 3);
|
||||
String pt_id_str = Int_.Xto_str_pad_bgn_zero(pt_id, 3);
|
||||
return String_.Format("{0}-file-ns.{1}-db.{2}.xowa", domain_str, ns_id_str, pt_id_str);
|
||||
}
|
||||
public static Xob_bin_db_itm new_v1(Fsm_bin_fil fil) {
|
||||
byte[] name = Bry_.new_u8(fil.Url_rel()); // EX: "fsdb.bin.0000.sqlite3"
|
||||
int ns_id = 0; // assume v1 dbs are all in main ns
|
||||
int pt_id = Bry_.Xto_int_or(name, 9 , 13, Int_.MinValue); if (pt_id == Int_.MinValue) throw Err_.new_("bin_db_itm.parse: invalid pt_id; name={0} conn={1}", fil.Url_rel(), fil.Conn().Conn_info().Xto_raw());
|
||||
return new Xob_bin_db_itm(fil.Id(), fil.Url(), ns_id, pt_id);
|
||||
}
|
||||
public static Xob_bin_db_itm new_v2(Fsm_bin_fil fil) {
|
||||
byte[] ns_bgn_tkn = Bry_.new_a7("file-ns."), ns_end_tkn = Bry_.new_a7("-db."), pt_end_tkn = Bry_.new_a7(".xowa");
|
||||
int ns_bgn_tkn_len = ns_bgn_tkn.length, ns_end_tkn_len = ns_end_tkn.length;
|
||||
byte[] name = Bry_.new_u8(fil.Url_rel()); // EX: en.wikipedia.org-file-ns.000-db.001.xowa
|
||||
int ns_bgn = Bry_finder.Find_fwd(name, ns_bgn_tkn, 0); if (ns_bgn == Bry_finder.Not_found) throw Err_.new_("bin_db_itm.parse: invalid ns_bgn; name={0} conn={1}", fil.Url_rel(), fil.Conn().Conn_info().Xto_raw());
|
||||
ns_bgn += ns_bgn_tkn_len;
|
||||
int ns_end = Bry_finder.Find_fwd(name, ns_end_tkn, ns_bgn); if (ns_end == Bry_finder.Not_found) throw Err_.new_("bin_db_itm.parse: invalid ns_end; name={0} conn={1}", fil.Url_rel(), fil.Conn().Conn_info().Xto_raw());
|
||||
int pt_bgn = ns_end + ns_end_tkn_len;
|
||||
int pt_end = Bry_finder.Find_fwd(name, pt_end_tkn, pt_bgn); if (pt_end == Bry_finder.Not_found) throw Err_.new_("bin_db_itm.parse: invalid pt_end; name={0} conn={1}", fil.Url_rel(), fil.Conn().Conn_info().Xto_raw());
|
||||
int ns_id = Bry_.Xto_int_or(name, ns_bgn, ns_end, Int_.MinValue); if (ns_id == Int_.MinValue) throw Err_.new_("bin_db_itm.parse: invalid ns_id; name={0} conn={1}", fil.Url_rel(), fil.Conn().Conn_info().Xto_raw());
|
||||
int pt_id = Bry_.Xto_int_or(name, pt_bgn, pt_end, Int_.MinValue); if (pt_id == Int_.MinValue) throw Err_.new_("bin_db_itm.parse: invalid pt_id; name={0} conn={1}", fil.Url_rel(), fil.Conn().Conn_info().Xto_raw());
|
||||
return new Xob_bin_db_itm(fil.Id(), fil.Url(), ns_id, pt_id);
|
||||
}
|
||||
}
|
71
400_xowa/src/gplx/xowa/bldrs/cmds/files/Xob_bin_db_mgr.java
Normal file
71
400_xowa/src/gplx/xowa/bldrs/cmds/files/Xob_bin_db_mgr.java
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.xowa.bldrs.cmds.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.core.primitives.*; import gplx.ios.*;
|
||||
import gplx.fsdb.meta.*;
|
||||
class Xob_bin_db_mgr {
|
||||
private final int[] ns_ids; private final int ns_ids_len;
|
||||
private final Ordered_hash nth_hash = Ordered_hash_.new_(); private final Int_obj_ref tier_key = Int_obj_ref.neg1_();
|
||||
public Xob_bin_db_mgr(int[] ns_ids) {
|
||||
this.ns_ids = ns_ids; this.ns_ids_len = ns_ids.length;
|
||||
}
|
||||
public boolean Schema_is_1() {return schema_is_1;} private boolean schema_is_1;
|
||||
public void Init_by_mnt_mgr(Fsm_mnt_mgr trg_mnt_mgr) {
|
||||
Fsm_mnt_itm trg_mnt_itm = trg_mnt_mgr.Mnts__get_main();
|
||||
this.schema_is_1 = trg_mnt_itm.Db_mgr().File__schema_is_1();
|
||||
Fsm_bin_mgr bin_db_mgr = trg_mnt_itm.Bin_mgr();
|
||||
int len = ns_ids_len;
|
||||
for (int i = 0; i < len; ++i) { // iterate ns_ids and add default nth
|
||||
int ns_id = ns_ids[i];
|
||||
Xob_bin_db_itm nth = new Xob_bin_db_itm(-1, null, ns_id, 0);
|
||||
nth_hash.Add(Int_obj_ref.new_(ns_ids[i]), nth);
|
||||
}
|
||||
len = bin_db_mgr.Dbs__len();
|
||||
for (int i = 0; i < len; ++i) { // iterate bin_dbs to find max pt_id for each ns
|
||||
Fsm_bin_fil fil = bin_db_mgr.Dbs__get_at(i);
|
||||
Xob_bin_db_itm itm = schema_is_1 ? Xob_bin_db_itm.new_v1(fil) : Xob_bin_db_itm.new_v2(fil);
|
||||
int ns_id = itm.Ns_id();
|
||||
Xob_bin_db_itm nth = (Xob_bin_db_itm)nth_hash.Get_by(tier_key.Val_(ns_id));
|
||||
if (itm.Pt_id() > nth.Pt_id()) // update max pt_id
|
||||
nth.Set(itm.Id(), itm.Pt_id(), itm.Db_url()); // note that ns_id is same
|
||||
}
|
||||
len = nth_hash.Count();
|
||||
for (int i = 0; i < len; ++i) { // iterated tiers to calculate max_size
|
||||
Xob_bin_db_itm nth = (Xob_bin_db_itm)nth_hash.Get_at(i);
|
||||
if (nth.Id() == -1) continue; // ignore default nth
|
||||
IoItmFil nth_itm = Io_mgr.I.QueryFil(nth.Db_url());
|
||||
nth.Db_len_(nth_itm.Size());
|
||||
}
|
||||
}
|
||||
public boolean Tier_id_is_last(int tier_id) {return tier_id >= ns_ids_len;} // assumes tier_id is 0 based; EX: 0,1,2 for
|
||||
public int Get_ns_id(int tier_id) {return ns_ids[tier_id];}
|
||||
public int Increment_pt_id(Xob_bin_db_itm itm) {
|
||||
itm.Set(-1, itm.Pt_id() + 1, null);
|
||||
itm.Db_len_(0);
|
||||
return itm.Pt_id();
|
||||
}
|
||||
public String Gen_name(String domain_str, int ns_id, int pt_id) {
|
||||
return schema_is_1 ? Xob_bin_db_itm.Gen_name_v1(pt_id) : Xob_bin_db_itm.Gen_name_v2(domain_str, ns_id, pt_id);
|
||||
}
|
||||
public Xob_bin_db_itm Get_nth_by_tier(int tier_id) {
|
||||
if (schema_is_1) return (Xob_bin_db_itm)nth_hash.Get_by(tier_key.Val_(0)); // v1 is always in ns_0
|
||||
if (tier_id >= ns_ids_len) throw Err_.new_("tier out of range: tier_id={0} len={1}", tier_id, ns_ids_len);
|
||||
int ns_id = ns_ids[tier_id];
|
||||
return (Xob_bin_db_itm)nth_hash.Get_by(tier_key.Val_(ns_id));
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
private Db_conn bldr_conn; private Db_cfg_tbl bldr_cfg_tbl;
|
||||
private Xof_bin_mgr src_bin_mgr; private Xof_bin_wkr__fsdb_sql src_fsdb_wkr; private boolean src_bin_mgr__cache_enabled = Bool_.N; private String src_bin_mgr__fsdb_version; private String[] src_bin_mgr__fsdb_skip_wkrs; private boolean src_bin_mgr__wmf_enabled;
|
||||
private Fsm_mnt_itm trg_mnt_itm; private Fsm_cfg_mgr trg_cfg_mgr; private Fsm_atr_fil trg_atr_fil; private Fsm_bin_fil trg_bin_fil; private long trg_bin_db_max;
|
||||
private final Xof_bin_updater trg_bin_updater = new Xof_bin_updater(); private Xob_tier_namer tier_namer; private int[] ns_ids; private int prv_lnki_tier_id = -1;
|
||||
private final Xof_bin_updater trg_bin_updater = new Xof_bin_updater(); private Xob_bin_db_mgr bin_db_mgr; private int[] ns_ids; private int prv_lnki_tier_id = -1;
|
||||
private long download_size_max = Io_mgr.Len_mb_long * 5; private int[] download_keep_tier_ids = Int_.Ary(0);
|
||||
private Xobu_poll_mgr poll_mgr; private int poll_interval; private long time_bgn;
|
||||
private int select_interval = 2500, progress_interval = 1, commit_interval = 1, delete_interval = 5000;
|
||||
@ -41,7 +41,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
public void Cmd_bgn(Xob_bldr bldr) {
|
||||
wiki.Init_assert();
|
||||
this.poll_interval = poll_mgr.Poll_interval();
|
||||
this.tier_namer = new Xob_tier_namer(wiki.Domain_str(), ns_ids);
|
||||
this.bin_db_mgr = new Xob_bin_db_mgr(ns_ids);
|
||||
// src_bin_mgr
|
||||
if (src_bin_mgr__fsdb_version != null) {
|
||||
this.src_fsdb_wkr = Xof_bin_wkr__fsdb_sql.new_(wiki.File__mnt_mgr());
|
||||
@ -72,7 +72,9 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
Fsm_mnt_mgr.Patch(trg_mnt_itm.Cfg_mgr().Tbl()); // NOTE: always patch again; fsdb_make may be run separately without lnki_temp; DATE:2014-04-26
|
||||
this.trg_atr_fil = trg_mnt_itm.Atr_mgr().Db__core();
|
||||
this.trg_cfg_mgr = trg_mnt_itm.Cfg_mgr();
|
||||
bin_db_mgr.Init_by_mnt_mgr(trg_mnt_mgr);
|
||||
trg_atr_fil.Conn().Txn_bgn();
|
||||
trg_cfg_mgr.Tbl().Conn().Txn_bgn();
|
||||
// bldr_db
|
||||
Xob_db_file bldr_db = Xob_db_file.new__file_make(wiki.Fsys_mgr().Root_dir());
|
||||
this.bldr_conn = bldr_db.Conn();
|
||||
@ -91,7 +93,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
byte rslt = Select_fsdb_itms(list);
|
||||
switch (rslt) {
|
||||
case Select_rv_stop:
|
||||
if (tier_namer.Is_last(tier_id_val))
|
||||
if (bin_db_mgr.Tier_id_is_last(tier_id_val))
|
||||
loop = false;
|
||||
else {
|
||||
++tier_id_val;
|
||||
@ -126,6 +128,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Txn_end(); // NOTE: src_fsdb_wkr will be null if no src db defined
|
||||
}
|
||||
trg_atr_fil.Conn().Txn_end(); trg_atr_fil.Conn().Rls_conn();
|
||||
trg_cfg_mgr.Tbl().Conn().Txn_end(); trg_cfg_mgr.Tbl().Conn().Rls_conn();
|
||||
if (!trg_mnt_itm.Db_mgr().File__solo_file()) {
|
||||
trg_bin_fil.Conn().Txn_end(); trg_bin_fil.Conn().Rls_conn();
|
||||
}
|
||||
@ -222,13 +225,14 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
usr_dlg.Warn_many("", "", "skipped; ttl=~{0} w=~{1} size=~{2} tier=~{3}", fsdb.Orig_ttl(), fsdb.Lnki_w(), src_rdr_len, lnki_tier_id);
|
||||
return;
|
||||
}
|
||||
if (trg_bin_fil == null) // no trg_bin_fil
|
||||
Make_trg_bin_file(fsdb);
|
||||
else if (trg_bin_fil.Bin_len() + src_rdr_len > trg_bin_db_max) // or trg_bin_fil is out of space
|
||||
Make_trg_bin_file(fsdb);
|
||||
else if (prv_lnki_tier_id != lnki_tier_id) {
|
||||
if (prv_lnki_tier_id != -1)
|
||||
Make_trg_bin_file(fsdb);
|
||||
if (trg_bin_fil == null) // no trg_bin_fil
|
||||
Make_trg_bin_file(Bool_.Y, fsdb, src_rdr_len);
|
||||
else if (trg_bin_fil.Bin_len() + src_rdr_len > trg_bin_db_max) // or trg_bin_fil is out of space
|
||||
Make_trg_bin_file(Bool_.N, fsdb, src_rdr_len);
|
||||
else if (prv_lnki_tier_id != lnki_tier_id) { // or tier has changed
|
||||
if ( prv_lnki_tier_id != -1
|
||||
&& !bin_db_mgr.Schema_is_1()) // do not increment dbs for v1
|
||||
Make_trg_bin_file(Bool_.Y, fsdb, src_rdr_len);
|
||||
prv_lnki_tier_id = lnki_tier_id;
|
||||
}
|
||||
trg_bin_updater.Save_bin(trg_mnt_itm, trg_atr_fil, trg_bin_fil, fsdb, src_rdr, src_rdr_len);
|
||||
@ -236,17 +240,34 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
}
|
||||
finally {src_rdr.Rls();}
|
||||
}
|
||||
private void Make_trg_bin_file(Xodb_tbl_oimg_xfer_itm fsdb) {
|
||||
private void Make_trg_bin_file(boolean try_nth, Xodb_tbl_oimg_xfer_itm fsdb, long src_rdr_len) {
|
||||
if ( trg_bin_fil != null // null-check needed for 1st call
|
||||
&& !trg_mnt_itm.Db_mgr().File__solo_file()) // don't close if one file
|
||||
trg_bin_fil.Conn().Txn_end(); // close txn
|
||||
String trg_bin_fil_name = tier_namer.Gen_name_and_add(fsdb.Lnki_tier_id()); // gen name
|
||||
this.trg_bin_fil = trg_mnt_itm.Bin_mgr().Dbs__make(trg_bin_fil_name); // create trg_bin_fil
|
||||
if (!trg_mnt_itm.Db_mgr().File__solo_file()) {
|
||||
Fsdb_db_file trg_bin_db = trg_mnt_itm.Db_mgr().File__bin_file__at(trg_mnt_itm.Id(), trg_bin_fil.Id(), trg_bin_fil_name);
|
||||
Fsdb_db_mgr__v2_bldr.Make_cfg_data(wiki, trg_atr_fil.Url_rel(), trg_bin_db, Xowd_db_file_.Tid_file_data, trg_bin_fil.Id() + List_adp_.Base1);
|
||||
trg_bin_fil.Conn().Txn_bgn();
|
||||
boolean make = true;
|
||||
int tier_id = fsdb.Lnki_tier_id();
|
||||
Xob_bin_db_itm nth_bin_db = bin_db_mgr.Get_nth_by_tier(tier_id);
|
||||
if (try_nth) { // try_nth is true; occurs for new runs or changed tier
|
||||
if ( nth_bin_db.Id() != -1 // nth exists;
|
||||
&& nth_bin_db.Db_len() + src_rdr_len < trg_bin_db_max) // if src_rdr_len exceeds
|
||||
make = false; // do not make; use existing
|
||||
}
|
||||
if (make) { // no nth; make it;
|
||||
int ns_id = bin_db_mgr.Get_ns_id(tier_id);
|
||||
int pt_id = bin_db_mgr.Increment_pt_id(nth_bin_db);
|
||||
String new_bin_db_name = bin_db_mgr.Gen_name(wiki.Domain_str(), ns_id, pt_id);
|
||||
this.trg_bin_fil = trg_mnt_itm.Bin_mgr().Dbs__make(new_bin_db_name);
|
||||
if (!trg_mnt_itm.Db_mgr().File__solo_file()) {
|
||||
Fsdb_db_file trg_bin_db = trg_mnt_itm.Db_mgr().File__bin_file__at(trg_mnt_itm.Id(), trg_bin_fil.Id(), new_bin_db_name);
|
||||
if (!bin_db_mgr.Schema_is_1())
|
||||
Fsdb_db_mgr__v2_bldr.Make_cfg_data(wiki, trg_atr_fil.Url_rel(), trg_bin_db, Xowd_db_file_.Tid_file_data, trg_bin_fil.Id() + List_adp_.Base1);
|
||||
}
|
||||
}
|
||||
else { // nth available; use it
|
||||
this.trg_bin_fil = trg_mnt_itm.Bin_mgr().Dbs__get_at(nth_bin_db.Id());
|
||||
trg_bin_fil.Bin_len_(nth_bin_db.Db_len());
|
||||
}
|
||||
trg_bin_fil.Conn().Txn_bgn();
|
||||
}
|
||||
private void Txn_sav() {
|
||||
usr_dlg.Prog_many("", "", "committing data: count=~{0} failed=~{1}", exec_count, exec_fail);
|
||||
@ -255,6 +276,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
bldr_cfg_tbl.Conn().Txn_sav();
|
||||
trg_cfg_mgr.Next_id_commit();
|
||||
trg_atr_fil.Conn().Txn_sav();
|
||||
trg_cfg_mgr.Tbl().Conn().Txn_sav();
|
||||
if (src_bin_mgr__fsdb_version != null && src_bin_mgr__fsdb_skip_wkrs != null) {
|
||||
src_fsdb_wkr.Skip_mgr().Skip_term(src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Cfg_mgr());
|
||||
}
|
||||
@ -303,7 +325,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
, Invk_src_bin_mgr__cache_enabled_ = "src_bin_mgr__cache_enabled_", Invk_ns_ids_ = "ns_ids_"
|
||||
, Invk_download_size_max = "download_size_max", Invk_download_keep_tier_ids = "download_keep_tier_ids"
|
||||
;
|
||||
private static Fsdb_db_mgr new_src_bin_db_mgr(Xow_wiki wiki, String version) {
|
||||
public static Fsdb_db_mgr new_src_bin_db_mgr(Xow_wiki wiki, String version) {
|
||||
String domain_str = wiki.Domain_str();
|
||||
Fsdb_db_mgr rv = null; Io_url url = null;
|
||||
if (String_.Eq(version, "v1")) {
|
||||
@ -345,22 +367,3 @@ class Xodb_tbl_oimg_xfer_itm extends Xof_fsdb_itm { public int Lnki_id() {re
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Xob_tier_namer {
|
||||
private final String domain_str; private final int[] ns_ids;
|
||||
private final int[] db_ids;
|
||||
public Xob_tier_namer(String domain_str, int[] ns_ids) {
|
||||
this.domain_str = domain_str;
|
||||
this.ns_ids = ns_ids;
|
||||
this.db_ids = new int[ns_ids.length];
|
||||
}
|
||||
public boolean Is_last(int v) {return v >= ns_ids.length;}
|
||||
public int Db_id(int tier_id) {return db_ids[tier_id];}
|
||||
public String Gen_name_and_add(int tier_id) {// en.wikipedia.org-file-ns.000-db.0001.xowa
|
||||
if (tier_id >= ns_ids.length) throw Err_.new_("unknown grp: tier_id={0} len={1}", tier_id, ns_ids.length);
|
||||
String ns_id = Int_.Xto_str_pad_bgn_zero(ns_ids[tier_id], 3);
|
||||
int db_id_int = db_ids[tier_id];
|
||||
db_ids[tier_id] = db_id_int + 1;
|
||||
String db_id = Int_.Xto_str_pad_bgn_zero(db_id_int + List_adp_.Base1, 3);
|
||||
return String_.Format("{0}-file-ns.{1}-db.{2}.xowa", domain_str, ns_id, db_id);
|
||||
}
|
||||
}
|
||||
|
@ -38,8 +38,9 @@ public class Xob_xfer_regy_update_cmd extends Xob_itm_basic_base implements Xob_
|
||||
Sqlite_engine_.Tbl_create_and_delete(make_db_provider, Xob_fsdb_regy_tbl.Tbl_name, Xob_fsdb_regy_tbl.Tbl_sql);
|
||||
Sqlite_engine_.Db_attach(make_db_provider, "fsdb_db", fsdb_atr_url.Raw());
|
||||
make_db_provider.Txn_bgn();
|
||||
make_db_provider.Exec_sql(Xob_fsdb_regy_tbl.Update_regy_nil);
|
||||
make_db_provider.Exec_sql(Xob_fsdb_regy_tbl.Insert_fsdb_fil);
|
||||
String fsdb_thm_tbl = "fsdb_thm";
|
||||
String fsdb_thm_tbl = fsdb_abc_mgr.Db_mgr().File__schema_is_1() ? "fsdb_xtn_thm" : "fsdb_thm";
|
||||
String insert_sql_fsdb_thm = wiki.File_mgr().Fsdb_mgr().Mnt_mgr().Mnts__get_main().Cfg_mgr().Schema_thm_page() // Cfg_get(Fsm_cfg_mgr.Grp_core).Get_yn_or_n(Fsm_cfg_mgr.Key_schema_thm_page)
|
||||
? String_.Format(Xob_fsdb_regy_tbl.Insert_fsdb_thm, fsdb_thm_tbl)
|
||||
: Xob_fsdb_regy_tbl.Insert_fsdb_thm_v0
|
||||
@ -133,6 +134,7 @@ class Xob_fsdb_regy_tbl {
|
||||
, " JOIN fsdb_db.fsdb_dir d ON f.fil_owner_id = d.dir_id"
|
||||
, ";"
|
||||
)
|
||||
, Update_regy_nil = "UPDATE xfer_regy SET xfer_status = 0;"
|
||||
, Update_regy_fil = String_.Concat_lines_nl
|
||||
( "REPLACE INTO xfer_regy "
|
||||
, "( lnki_id, lnki_tier_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
|
||||
|
@ -79,7 +79,7 @@ public class Xob_page_cmd extends Xob_itm_basic_base implements Xobd_wkr, GfoInv
|
||||
Xowd_db_file db_core = db_mgr.Db__core();
|
||||
db_core.Tbl__site_stats().Update(page_count_main, page_count_all, ns_mgr.Ns_file().Count()); // save page stats
|
||||
db_core.Tbl__ns().Insert(ns_mgr); // save ns
|
||||
db_mgr.Tbl__cfg().Insert_str(Xow_cfg_consts.Grp_wiki_init, "props.modified_latest", modified_latest.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
|
||||
db_mgr.Tbl__cfg().Insert_str(Xow_cfg_consts.Grp__wiki_init, "props.modified_latest", modified_latest.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
|
||||
if (idx_mode.Tid_is_end()) page_core_tbl.Create_index();
|
||||
if (redirect_id_enabled) {
|
||||
redirect_tbl.Conn().Txn_end();
|
||||
|
@ -22,12 +22,12 @@ public class Xob_term_cmd extends Xob_term_base {
|
||||
@Override public String Cmd_key() {return KEY;} public static final String KEY = "text.term";
|
||||
@Override public void Cmd_end_hook() {
|
||||
Io_mgr.I.DeleteDirDeep(wiki.Fsys_mgr().Tmp_dir());
|
||||
Db_cfg_tbl cfg_tbl = wiki.Data_mgr__core_mgr().Tbl__cfg();
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp_wiki_init, "props.bldr_version", wiki.Props().Bldr_version());
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp_wiki_init, "props.main_page", wiki.Props().Main_page());
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp_wiki_init, "props.siteinfo_misc", wiki.Props().Siteinfo_misc());
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp_wiki_init, "props.siteinfo_mainpage", wiki.Props().Siteinfo_mainpage());
|
||||
Db_cfg_tbl cfg_tbl = wiki.Data__core_mgr().Tbl__cfg();
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, "props.bldr_version", wiki.Props().Bldr_version());
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__main_page, wiki.Props().Main_page());
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, "props.siteinfo_misc", wiki.Props().Siteinfo_misc());
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, "props.siteinfo_mainpage", wiki.Props().Siteinfo_mainpage());
|
||||
gplx.fsdb.Fsdb_db_mgr__v2_bldr.I.Get_or_make(wiki, false);// always build file.user db; DATE:2015-05-12
|
||||
wiki.Data_mgr__core_mgr().Rls();
|
||||
wiki.Data__core_mgr().Rls();
|
||||
}
|
||||
}
|
||||
|
@ -119,8 +119,8 @@ public class Xob_cleanup_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
if ( !String_.Eq(url.Ext(), ".xowa")
|
||||
&& !String_.Eq(url.Ext(), ".sqlite3"))
|
||||
continue;
|
||||
if ( String_.HasAtBgn(url.NameAndExt(), file_prefix)
|
||||
|| String_.HasAtBgn(url.NameAndExt(), html_prefix)
|
||||
if ( String_.Has_at_bgn(url.NameAndExt(), file_prefix)
|
||||
|| String_.Has_at_bgn(url.NameAndExt(), html_prefix)
|
||||
) continue; // skip
|
||||
Io_mgr.I.DeleteFil(url);
|
||||
deleted++;
|
||||
|
@ -22,7 +22,7 @@ public class Xob_page_dump_cmd_drop extends Xob_itm_basic_base implements Xob_cm
|
||||
public String Cmd_key() {return Xob_cmd_keys.Key_wiki_page_dump_drop;}
|
||||
public void Cmd_run() {
|
||||
wiki.Init_assert();
|
||||
Xowd_db_mgr db_mgr = wiki.Data_mgr__core_mgr();
|
||||
Xowd_db_mgr db_mgr = wiki.Data__core_mgr();
|
||||
int len = db_mgr.Dbs__len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_db_file db_file = db_mgr.Dbs__get_at(i);
|
||||
|
@ -22,7 +22,7 @@ public class Xob_page_dump_cmd_make extends Xob_itm_basic_base implements Xob_cm
|
||||
public String Cmd_key() {return Xob_cmd_keys.Key_wiki_page_dump_make;}
|
||||
public void Cmd_run() {
|
||||
wiki.Init_assert();
|
||||
Xowd_db_mgr db_mgr = wiki.Data_mgr__core_mgr();
|
||||
Xowd_db_mgr db_mgr = wiki.Data__core_mgr();
|
||||
Io_url page_db_url = db_mgr.Db__core().Url();
|
||||
int len = db_mgr.Dbs__len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
@ -57,7 +57,7 @@ public class Xoa_css_extractor {
|
||||
this.Install_by_wmf((Xowe_wiki)wiki, wiki_html_dir);
|
||||
}
|
||||
catch (Exception e) { // if error, failover; paranoia catch for outliers like bad network connectivity fail, or MediaWiki: message not existing; DATE:2013-11-21
|
||||
wiki.App().Usr_dlg().Warn_many("", "", "failed while trying to generate css; failing over; wiki='~{0}' err=~{1}", wiki.Domain_str(), Err_.Message_gplx(e));
|
||||
wiki.App().Usr_dlg().Warn_many("", "", "failed to get css; failing over; wiki='~{0}' err=~{1}", wiki.Domain_str(), Err_.Message_gplx(e));
|
||||
Css_common_failover(); // only failover xowa_common.css; xowa_wiki.css comes from MediaWiki:Common.css / Vector.css
|
||||
}
|
||||
}
|
||||
@ -77,7 +77,7 @@ public class Xoa_css_extractor {
|
||||
Logo_setup();
|
||||
}
|
||||
private boolean Install_by_db(Xow_wiki wiki, Io_url wiki_html_dir, String css_key) {
|
||||
Xowd_db_mgr core_db_mgr = wiki.Data_mgr__core_mgr();
|
||||
Xowd_db_mgr core_db_mgr = wiki.Data__core_mgr();
|
||||
if ( core_db_mgr == null
|
||||
|| core_db_mgr.Props() == null
|
||||
|| core_db_mgr.Props().Schema_is_1()
|
||||
|
@ -70,7 +70,7 @@ public class Xoa_css_img_downloader {
|
||||
continue;
|
||||
}
|
||||
byte[] img_raw = Bry_.Mid(src, bgn_pos, end_pos); int img_raw_len = img_raw.length;
|
||||
if (Bry_.HasAtBgn(img_raw, Bry_data_image, 0, img_raw_len)) { // base64
|
||||
if (Bry_.Has_at_bgn(img_raw, Bry_data_image, 0, img_raw_len)) { // base64
|
||||
bfr.Add_mid(src, prv_pos, end_pos); // nothing to download; just add entire String
|
||||
prv_pos = end_pos;
|
||||
continue;
|
||||
@ -104,7 +104,7 @@ public class Xoa_css_img_downloader {
|
||||
}
|
||||
}
|
||||
public static byte[] Import_url_build(byte[] stylesheet_prefix, byte[] rel_url_prefix, byte[] css_url) {
|
||||
return Bry_.HasAtBgn(css_url, Bry_http_protocol) // css_url already starts with "http"; return self; PAGE:tr.n:Main_Page; DATE:2014-06-04
|
||||
return Bry_.Has_at_bgn(css_url, Bry_http_protocol) // css_url already starts with "http"; return self; PAGE:tr.n:Main_Page; DATE:2014-06-04
|
||||
? css_url
|
||||
: Bry_.Add(stylesheet_prefix, css_url)
|
||||
;
|
||||
@ -141,8 +141,8 @@ public class Xoa_css_img_downloader {
|
||||
;
|
||||
public byte[] Clean_img_url(byte[] raw, int raw_len) {
|
||||
int pos_bgn = 0;
|
||||
if (Bry_.HasAtBgn(raw, Bry_fwd_slashes, 0, raw_len)) pos_bgn = Bry_fwd_slashes.length;
|
||||
if (Bry_.HasAtBgn(raw, Bry_http, 0, raw_len)) pos_bgn = Bry_http.length;
|
||||
if (Bry_.Has_at_bgn(raw, Bry_fwd_slashes, 0, raw_len)) pos_bgn = Bry_fwd_slashes.length;
|
||||
if (Bry_.Has_at_bgn(raw, Bry_http, 0, raw_len)) pos_bgn = Bry_http.length;
|
||||
int pos_slash = Bry_finder.Find_fwd(raw, Byte_ascii.Slash, pos_bgn, raw_len);
|
||||
if (pos_slash == Bry_.NotFound) return null; // first segment is site_name; at least one slash must be present for image name; EX: site.org/img_name.jpg
|
||||
if (pos_slash == raw_len - 1) return null; // "site.org/" is invalid
|
||||
|
@ -24,7 +24,7 @@ class Xob_css_parser__import {
|
||||
public Xob_css_tkn__base Parse(byte[] src, int src_len, int tkn_bgn, int tkn_end) { // " @import"
|
||||
int bgn_pos = Bry_finder.Find_fwd_while_ws(src, tkn_end, src_len); // skip any ws after " @import"
|
||||
if (bgn_pos == src_len) return Xob_css_tkn__warn.new_(tkn_bgn, tkn_end, "mirror.parser.import:EOS after import; bgn=~{0}", tkn_bgn);
|
||||
if (!Bry_.HasAtBgn(src, Tkn_url_bry, bgn_pos, src_len)) return Xob_css_tkn__warn.new_(tkn_bgn, tkn_end, "mirror.parser.import:url missing; bgn=~{0}", tkn_bgn);
|
||||
if (!Bry_.Has_at_bgn(src, Tkn_url_bry, bgn_pos, src_len)) return Xob_css_tkn__warn.new_(tkn_bgn, tkn_end, "mirror.parser.import:url missing; bgn=~{0}", tkn_bgn);
|
||||
tkn_end = bgn_pos + Tkn_url_bry.length;
|
||||
Xob_css_tkn__base frag = url_parser.Parse(src, src_len, bgn_pos, tkn_end);
|
||||
if (frag.Tid() != Xob_css_tkn__url.Tid_url) return Xob_css_tkn__warn.new_(tkn_bgn, frag.Pos_end(), "mirror.parser.import:url invalid; bgn=~{0}", tkn_bgn);
|
||||
|
@ -47,7 +47,7 @@ class Xob_css_parser__url {
|
||||
else
|
||||
return Xob_css_tkn__warn.new_(tkn_bgn, end_pos, "mirror.parser.url:base64 dangling; bgn=~{0} excerpt=~{1}", bgn_pos, String_.new_u8(url_orig));
|
||||
}
|
||||
if (Bry_.HasAtBgn(url_orig, Bry_data_image)) // base64
|
||||
if (Bry_.Has_at_bgn(url_orig, Bry_data_image)) // base64
|
||||
return Xob_css_tkn__base64.new_(tkn_bgn, end_pos);
|
||||
byte[] src_url = Xob_url_fixer.Fix(site, url_orig, url_orig_len);
|
||||
if (src_url == null) // could not convert
|
||||
|
@ -47,7 +47,7 @@ abstract class Xoctg_fmtr_itm_base implements Xoctg_fmtr_itm {
|
||||
Xoa_ttl ttl = itm.Ttl();
|
||||
byte[] itm_sortkey = itm.Sortkey();
|
||||
byte[] ttl_bry = ttl.Page_txt();
|
||||
if (!Bry_.HasAtBgn(itm_sortkey, ttl_char_0, 0, itm_sortkey.length)) {
|
||||
if (!Bry_.Has_at_bgn(itm_sortkey, ttl_char_0, 0, itm_sortkey.length)) {
|
||||
grp_end_idx = i;
|
||||
grp_end_at_col = i == col_end;
|
||||
return;
|
||||
|
@ -31,13 +31,13 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
}
|
||||
public void Load_init(Xowe_wiki wiki) {
|
||||
Load_init_cfg(wiki);
|
||||
Xowd_db_file db_core = wiki.Data_mgr__core_mgr().Db__core();
|
||||
Xowd_db_file db_core = wiki.Data__core_mgr().Db__core();
|
||||
db_core.Tbl__site_stats().Select(wiki.Stats());
|
||||
db_core.Tbl__ns().Select_all(wiki.Ns_mgr());
|
||||
}
|
||||
private void Load_init_cfg(Xowe_wiki wiki) {
|
||||
String version_key = Xoa_gfs_mgr.Build_code(Xowe_wiki.Invk_props, Xow_wiki_props.Invk_bldr_version);
|
||||
Db_cfg_hash cfg_hash = db_mgr.Core_data_mgr().Tbl__cfg().Select_as_hash(Xow_cfg_consts.Grp_wiki_init);
|
||||
Db_cfg_hash cfg_hash = db_mgr.Core_data_mgr().Tbl__cfg().Select_as_hash(Xow_cfg_consts.Grp__wiki_init);
|
||||
String version_val = cfg_hash.Get(version_key).To_str_or("");
|
||||
Xodb_upgrade_mgr.Upgrade(db_mgr, cfg_hash, version_key, version_val);
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
|
@ -39,7 +39,7 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
|
||||
return Io_mgr.I.QueryFil(url).ModifiedTime();
|
||||
}
|
||||
public void Category_version_update(boolean version_is_1) {
|
||||
String grp = Xow_cfg_consts.Grp_wiki_init;
|
||||
String grp = Xow_cfg_consts.Grp__wiki_init;
|
||||
String key = Xoa_gfs_mgr.Build_code(Xowe_wiki.Invk_db_mgr, Xodb_mgr_sql.Invk_category_version);
|
||||
core_data_mgr.Tbl__cfg().Delete_val(grp, key);// always delete ctg version
|
||||
category_version = version_is_1 ? Xoa_ctg_mgr.Version_1 : Xoa_ctg_mgr.Version_2;
|
||||
|
@ -22,7 +22,7 @@ class Xodb_page_rdr__sql implements Xodb_page_rdr {
|
||||
private final Xowd_db_mgr db_mgr;
|
||||
private final Xowd_page_tbl page_tbl; private final Db_rdr rdr;
|
||||
public Xodb_page_rdr__sql(Xowe_wiki wiki) {
|
||||
this.db_mgr = wiki.Data_mgr__core_mgr();
|
||||
this.db_mgr = wiki.Data__core_mgr();
|
||||
this.page_tbl = db_mgr.Tbl__page();
|
||||
this.rdr = page_tbl.Select_all();
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user