mirror of https://github.com/gnosygnu/xowa
parent
096045614c
commit
235228976e
@ -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.core.srls; import gplx.*; import gplx.core.*;
|
||||
public interface Gfo_srl_mgr_rdr {
|
||||
void Itm_bgn(String key);
|
||||
void Itm_end();
|
||||
boolean Get_bool (String key);
|
||||
int Get_int (String key);
|
||||
String Get_str (String key);
|
||||
Object Get_subs (Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_itm proto, Dbmeta_dat_mgr crt_mgr);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
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.core.srls; import gplx.*; import gplx.core.*;
|
||||
public interface Gfo_srl_mgr_wtr {
|
||||
int Uid_next__as_int();
|
||||
void Itm_bgn(String key);
|
||||
void Itm_end();
|
||||
void Set_bool (String key, boolean val);
|
||||
void Set_int (String key, int val);
|
||||
void Set_str (String key, String val);
|
||||
Object Set_subs (Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_itm proto, Object subs, Dbmeta_dat_mgr crt_mgr);
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.metas.*;
|
||||
public class Db_conn_utl {
|
||||
public static Db_conn Conn__new(String url_rel) {
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
return Db_conn_bldr.Instance.Get_or_new(Io_url_.mem_fil_("mem/" + url_rel)).Conn();
|
||||
}
|
||||
public static void Tbl__delete(Db_conn conn, String tbl) {
|
||||
conn.Ddl_delete_tbl(tbl);
|
||||
}
|
||||
public static void Tbl__new(Db_conn conn, String tbl, Dbmeta_fld_itm[] flds, Object[]... rows) {
|
||||
conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl, flds));
|
||||
int rows_len = rows.length;
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl, Dbmeta_fld_itm.To_str_ary(flds));
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
Object[] row = rows[i];
|
||||
int dat_len = row.length;
|
||||
stmt.Clear();
|
||||
for (int j = 0; j < dat_len; ++j) {
|
||||
Dbmeta_fld_itm fld = flds[j];
|
||||
String fld_name = fld.Name();
|
||||
Object val = row[j];
|
||||
switch (fld.Type().Tid_ansi()) {
|
||||
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (fld_name, Bool_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__byte: stmt.Val_byte (fld_name, Byte_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__int: stmt.Val_int (fld_name, Int_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__long: stmt.Val_long (fld_name, Long_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__float: stmt.Val_float (fld_name, Float_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__double: stmt.Val_double (fld_name, Double_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__str: stmt.Val_str (fld_name, String_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__bry: stmt.Val_bry (fld_name, Bry_.cast(val)); break;
|
||||
}
|
||||
}
|
||||
stmt.Exec_insert();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_meta_fld {
|
||||
public Db_meta_fld(String name, int tid, int len) {
|
||||
this.name = name; this.tid = tid; this.len = len;
|
||||
this.nullable = false; this.primary = false; this.autonum = false; this.default_val = Default_value_null;
|
||||
}
|
||||
public int Tid() {return tid;} private final int tid;
|
||||
public String Name() {return name;} private final String name;
|
||||
public int Len() {return len;} private final int len;
|
||||
public boolean Nullable() {return nullable;} public Db_meta_fld Nullable_y_() {nullable = true; return this;} private boolean nullable;
|
||||
public boolean Primary() {return primary;} public Db_meta_fld Primary_y_() {primary = true; return this;} private boolean primary;
|
||||
public boolean Autonum() {return autonum;} public Db_meta_fld Autonum_y_() {autonum = true; return this;} private boolean autonum;
|
||||
public Object Default() {return default_val;} public Db_meta_fld Default_(Object v) {default_val = v; return this;} private Object default_val;
|
||||
|
||||
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 Object Default_value_null = null;
|
||||
public static final String[] Ary_empty = String_.Ary_empty;
|
||||
public static Db_meta_fld new_bool(String name) {return new Db_meta_fld(name, Tid_bool , Len_null);}
|
||||
public static Db_meta_fld new_byte(String name) {return new Db_meta_fld(name, Tid_byte , Len_null);}
|
||||
public static Db_meta_fld new_short(String name) {return new Db_meta_fld(name, Tid_short , Len_null);}
|
||||
public static Db_meta_fld new_int(String name) {return new Db_meta_fld(name, Tid_int , Len_null);}
|
||||
public static Db_meta_fld new_long(String name) {return new Db_meta_fld(name, Tid_long , Len_null);}
|
||||
public static Db_meta_fld new_float(String name) {return new Db_meta_fld(name, Tid_float , Len_null);}
|
||||
public static Db_meta_fld new_double(String name) {return new Db_meta_fld(name, Tid_double, Len_null);}
|
||||
public static Db_meta_fld new_text(String name) {return new Db_meta_fld(name, Tid_text , Len_null);}
|
||||
public static Db_meta_fld new_bry(String name) {return new Db_meta_fld(name, Tid_bry , Len_null);}
|
||||
public static Db_meta_fld new_str(String name, int len) {return new Db_meta_fld(name, Tid_str , len);}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.sqls.*;
|
||||
public class Db_meta_idx {
|
||||
Db_meta_idx(String tbl, String name, boolean unique, String[] flds) {this.tbl = tbl; this.name = name; this.unique = unique; this.flds = flds;}
|
||||
public String Tbl() {return tbl;} private final String tbl;
|
||||
public String Name() {return name;} private final String name;
|
||||
public boolean Unique() {return unique;} private final boolean unique;
|
||||
public String[] Flds() {return flds;} private final String[] flds;
|
||||
public String To_sql_create() {return Db_sqlbldr__sqlite.Instance.Bld_create_idx(this);}
|
||||
public static Db_meta_idx new_unique_by_name(String tbl, String idx_name, String... flds) {return new Db_meta_idx(tbl, idx_name, Bool_.Y, flds);}
|
||||
public static Db_meta_idx new_normal_by_name(String tbl, String idx_name, String... flds) {return new Db_meta_idx(tbl, idx_name, Bool_.N, flds);}
|
||||
public static Db_meta_idx new_unique_by_tbl(String tbl, String name, String... flds) {return new Db_meta_idx(tbl, Bld_idx_name(tbl, name), Bool_.Y, flds);}
|
||||
public static Db_meta_idx new_normal_by_tbl(String tbl, String name, String... flds) {return new Db_meta_idx(tbl, Bld_idx_name(tbl, name), Bool_.N, flds);}
|
||||
public static Db_meta_idx new_unique_by_tbl_wo_null(String tbl, String name, String... flds) {return new Db_meta_idx(tbl, Bld_idx_name(tbl, name), Bool_.Y, String_.Ary_wo_null(flds));}
|
||||
public static Db_meta_idx new_normal_by_tbl_wo_null(String tbl, String name, String... flds) {return new Db_meta_idx(tbl, Bld_idx_name(tbl, name), Bool_.N, String_.Ary_wo_null(flds));}
|
||||
public static String Bld_idx_name(String tbl, String suffix) {return String_.Concat(tbl, "__", suffix);}
|
||||
public static final Db_meta_idx[] Ary_empty = new Db_meta_idx[0];
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.sqls.*;
|
||||
public class Db_meta_tbl {
|
||||
public Db_meta_tbl(String name, Db_meta_fld[] flds, Db_meta_idx[] idxs) {
|
||||
if (idxs == null) idxs = Db_meta_idx.Ary_empty; // empty params will pass idxs of null; set to idxs[0] else null ref when calling create_table
|
||||
this.name = name; this.flds = flds; this.idxs = idxs;
|
||||
}
|
||||
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.Instance.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);}
|
||||
public static Db_meta_tbl new_(String name, Db_meta_fld[] flds, Db_meta_idx... idxs) {return new Db_meta_tbl(name, flds, idxs);}
|
||||
public static Db_meta_tbl new_(String name, Db_meta_fld... flds) {return new Db_meta_tbl(name, flds, null);}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.metas.*;
|
||||
public class Dbmeta_fld_itm {
|
||||
public Dbmeta_fld_itm(String name, Dbmeta_fld_tid type) {
|
||||
this.name = name; this.type = type;
|
||||
this.primary = false; this.autonum = false; this.default_val = Default_value_null;
|
||||
}
|
||||
public String Name() {return name;} private final String name;
|
||||
public Dbmeta_fld_tid Type() {return type;} private final Dbmeta_fld_tid type;
|
||||
public int Nullable_tid() {return nullable_tid;} public Dbmeta_fld_itm Nullable_tid_(int v) {nullable_tid = v; return this;} private int nullable_tid;
|
||||
public Dbmeta_fld_itm Nullable_y_() {return Nullable_tid_(Nullable_null);}
|
||||
public boolean Primary() {return primary;} public Dbmeta_fld_itm Primary_y_() {primary = true; return this;} private boolean primary;
|
||||
public boolean Autonum() {return autonum;} public Dbmeta_fld_itm Autonum_y_() {autonum = true; return this;} private boolean autonum;
|
||||
public Object Default() {return default_val;} public Dbmeta_fld_itm Default_(Object v) {default_val = v; return this;} private Object default_val;
|
||||
public boolean Eq(Dbmeta_fld_itm comp) {
|
||||
return String_.Eq(name, comp.name)
|
||||
&& type.Eq(comp.type)
|
||||
&& nullable_tid == comp.nullable_tid
|
||||
&& primary == comp.primary
|
||||
&& autonum == comp.autonum
|
||||
&& Object_.Eq(default_val, comp.default_val);
|
||||
}
|
||||
|
||||
public static final int Nullable_unknown = 0, Nullable_null = 1, Nullable_not_null = 2;
|
||||
public static final Object Default_value_null = null;
|
||||
public static final String Key_null = null;
|
||||
public static final String[] Str_ary_empty = String_.Ary_empty;
|
||||
public static final Dbmeta_fld_itm[] Ary_empty = new Dbmeta_fld_itm[0];
|
||||
|
||||
public static Dbmeta_fld_itm new_bool(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__bool);}
|
||||
public static Dbmeta_fld_itm new_byte(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__byte);}
|
||||
public static Dbmeta_fld_itm new_short(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__short);}
|
||||
public static Dbmeta_fld_itm new_int(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__int);}
|
||||
public static Dbmeta_fld_itm new_long(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__long);}
|
||||
public static Dbmeta_fld_itm new_float(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__float);}
|
||||
public static Dbmeta_fld_itm new_double(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__double);}
|
||||
public static Dbmeta_fld_itm new_text(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__text);}
|
||||
public static Dbmeta_fld_itm new_bry(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__bry);}
|
||||
public static Dbmeta_fld_itm new_str(String name, int len) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__str(len));}
|
||||
public static String[] To_str_ary(Dbmeta_fld_itm[] ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv[i] = ary[i].name;
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.sqls.*; import gplx.dbs.metas.*;
|
||||
public class Dbmeta_idx_itm {
|
||||
public Dbmeta_idx_itm(boolean unique, String tbl, String name, Dbmeta_idx_fld[] flds) {
|
||||
this.tbl = tbl; this.name = name; this.unique = unique; this.Flds = flds;
|
||||
}
|
||||
public String Tbl() {return tbl;} private final String tbl;
|
||||
public String Name() {return name;} private final String name;
|
||||
public boolean Unique() {return unique;} private final boolean unique;
|
||||
public final Dbmeta_idx_fld[] Flds;
|
||||
public String To_sql_create() {return Db_sqlbldr__sqlite.Instance.Bld_create_idx(this);}
|
||||
public boolean Eq(Dbmeta_idx_itm comp) {
|
||||
return String_.Eq(name, comp.name)
|
||||
&& unique == comp.unique
|
||||
&& tbl == comp.tbl
|
||||
&& Dbmeta_idx_fld.Ary_eq(Flds, comp.Flds);
|
||||
}
|
||||
public static Dbmeta_idx_itm new_unique_by_name (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.Y, tbl, name, To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_normal_by_name (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, name, To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_unique_by_tbl (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.Y, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_normal_by_tbl (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_unique_by_tbl_wo_null (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.Y, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_normal_by_tbl_wo_null (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static String Bld_idx_name(String tbl, String suffix) {return String_.Concat(tbl, "__", suffix);}
|
||||
public static final Dbmeta_idx_itm[] Ary_empty = new Dbmeta_idx_itm[0];
|
||||
public static Dbmeta_idx_fld[] To_fld_ary(String[] ary) {
|
||||
int len = ary.length;
|
||||
Dbmeta_idx_fld[] rv = new Dbmeta_idx_fld[len];
|
||||
int order = -1;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String itm = ary[i]; if (itm == null) continue;
|
||||
rv[i] = new Dbmeta_idx_fld(++order, itm, Dbmeta_idx_fld.Sort_tid__none);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.metas.*; import gplx.dbs.sqls.*;
|
||||
public class Dbmeta_tbl_itm {
|
||||
public String Name() {return name;} private String name;
|
||||
public Dbmeta_idx_mgr Idxs() {return idxs;} private final Dbmeta_idx_mgr idxs = new Dbmeta_idx_mgr();
|
||||
public Dbmeta_fld_mgr Flds() {return flds;} private final Dbmeta_fld_mgr flds = new Dbmeta_fld_mgr();
|
||||
public String To_sql_create() {return Db_sqlbldr__sqlite.Instance.Bld_create_tbl(this);}
|
||||
|
||||
public static Dbmeta_tbl_itm New(String name, Dbmeta_fld_list flds, Dbmeta_idx_itm... idxs) {return New(name, flds.To_fld_ary(), idxs);}
|
||||
public static Dbmeta_tbl_itm New(String name, Dbmeta_fld_itm... flds) {return New(name, flds, Dbmeta_idx_itm.Ary_empty);}
|
||||
public static Dbmeta_tbl_itm New(String name, Dbmeta_fld_itm[] flds, Dbmeta_idx_itm... idxs) {
|
||||
Dbmeta_tbl_itm rv = new Dbmeta_tbl_itm();
|
||||
rv.name = name;
|
||||
if (flds != null) {
|
||||
int flds_len = flds.length;
|
||||
for (int i = 0; i < flds_len; ++i)
|
||||
rv.flds.Add(flds[i]);
|
||||
}
|
||||
if (idxs != null) {
|
||||
int idxs_len = idxs.length;
|
||||
for (int i = 0; i < idxs_len; ++i)
|
||||
rv.idxs.Add(idxs[i]);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
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.diffs; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.metas.*; import gplx.dbs.diffs.builds.*;
|
||||
class Gfdb_diff_cmd {
|
||||
private final Gfdb_diff_wkr__db diff_bldr_wkr = new Gfdb_diff_wkr__db();
|
||||
private final Gfdb_diff_bldr diff_bldr = new Gfdb_diff_bldr();
|
||||
public Gfdb_diff_cmd() {
|
||||
diff_bldr.Init(diff_bldr_wkr);
|
||||
}
|
||||
public Gfdb_diff_job New_job(Gfdb_diff_db db, String guid, String name, String made_by, String desc) {
|
||||
return new Gfdb_diff_job(db);
|
||||
}
|
||||
public void Bld(Gfdb_diff_job job, Gfdb_diff_tbl_mgr lhs_mgr, Gfdb_diff_tbl_mgr rhs_mgr) {
|
||||
diff_bldr_wkr.Init_conn(job.Db(), 1000);
|
||||
int rhs_len = rhs_mgr.Len();
|
||||
for (int i = 0; i < rhs_len; ++i) {
|
||||
Gfdb_diff_tbl rhs_tbl = rhs_mgr.Get_at(i);
|
||||
Gfdb_diff_tbl lhs_tbl = lhs_mgr.Get_by(rhs_tbl.Name);
|
||||
if (lhs_tbl == null) {
|
||||
// Add_cmd_tbl_create();
|
||||
// Add_cmd_tbl_insert_all());
|
||||
}
|
||||
else {
|
||||
// Compare_flds();
|
||||
// Compare_idxs();
|
||||
// diff_bldr.Compare(lhs_tbl, rhs_tbl);
|
||||
}
|
||||
}
|
||||
int lhs_len = lhs_mgr.Len();
|
||||
for (int i = 0; i < lhs_len; ++i) {
|
||||
Gfdb_diff_tbl lhs_tbl = lhs_mgr.Get_at(i);
|
||||
if (lhs_tbl == null) {
|
||||
// Add_cmd_dat_delete_all());
|
||||
// Add_cmd_tbl_delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_job {
|
||||
public Gfdb_diff_job(Gfdb_diff_db db) {this.db = db;}
|
||||
public Gfdb_diff_db Db() {return db;} private Gfdb_diff_db db;
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
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.diffs; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.metas.*;
|
||||
public class Gfdb_diff_tbl {
|
||||
public Gfdb_diff_tbl(String name, Dbmeta_fld_itm[] flds, Dbmeta_fld_itm[] keys, Dbmeta_fld_itm[] vals) {
|
||||
this.Name = name; this.Flds = flds; this.Keys = keys; this.Vals = vals;
|
||||
}
|
||||
public final String Name;
|
||||
public final Dbmeta_fld_itm[] Flds;
|
||||
public final Dbmeta_fld_itm[] Keys;
|
||||
public final Dbmeta_fld_itm[] Vals;
|
||||
public Db_rdr Make_rdr(Db_conn conn) {
|
||||
Db_stmt stmt = conn.Stmt_select(Name, Dbmeta_fld_itm.To_str_ary(Flds));
|
||||
return stmt.Exec_select__rls_auto();
|
||||
}
|
||||
|
||||
public static Gfdb_diff_tbl New(Dbmeta_tbl_itm tbl) {
|
||||
Dbmeta_fld_mgr flds = tbl.Flds();
|
||||
Dbmeta_fld_mgr keys = Calc_keys(tbl);
|
||||
Dbmeta_fld_mgr vals = Calc_vals(tbl.Flds(), keys);
|
||||
return new Gfdb_diff_tbl(tbl.Name(), flds.To_ary(), keys.To_ary(), vals.To_ary());
|
||||
}
|
||||
public static Dbmeta_fld_mgr Calc_keys(Dbmeta_tbl_itm tbl) {
|
||||
Dbmeta_fld_mgr rv = new Dbmeta_fld_mgr();
|
||||
// try to find primary
|
||||
Dbmeta_fld_mgr flds = tbl.Flds();
|
||||
int flds_len = flds.Len();
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
if (fld.Primary()) {
|
||||
rv.Add(fld);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
// try to find shortest unique index
|
||||
Dbmeta_idx_itm unique_idx = null; int unique_idx_len = Int_.Max_value;
|
||||
Dbmeta_idx_mgr idxs = tbl.Idxs();
|
||||
int idxs_len = idxs.Len();
|
||||
for (int i = 0; i < idxs_len; ++i) {
|
||||
Dbmeta_idx_itm idx = idxs.Get_at(i);
|
||||
if (idx.Unique() && idx.Flds.length < unique_idx_len) { // get first shortest unique index; note that "<" is "get first" whereas "<=" is "get last"
|
||||
unique_idx = idx;
|
||||
unique_idx_len = idx.Flds.length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (unique_idx != null) {
|
||||
Dbmeta_idx_fld[] idx_flds = unique_idx.Flds;
|
||||
int idx_flds_len = idx_flds.length;
|
||||
for (int i = 0; i < idx_flds_len; ++i)
|
||||
rv.Add(flds.Get_by(idx_flds[i].Name));
|
||||
return rv;
|
||||
}
|
||||
// just add all
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
rv.Add(fld);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static Dbmeta_fld_mgr Calc_vals(Dbmeta_fld_mgr flds, Dbmeta_fld_mgr keys) {
|
||||
Dbmeta_fld_mgr rv = new Dbmeta_fld_mgr();
|
||||
int flds_len = flds.Len();
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
if (!keys.Has(fld.Name())) rv.Add(fld);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
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.diffs; import gplx.*; import gplx.dbs.*;
|
||||
class Gfdb_diff_tbl_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Count();}
|
||||
public Gfdb_diff_tbl Get_at(int idx) {return (Gfdb_diff_tbl)hash.Get_at(idx);}
|
||||
public Gfdb_diff_tbl Get_by(String key) {return (Gfdb_diff_tbl)hash.Get_by(key);}
|
||||
}
|
||||
class Gfdb_diff_tbl_mgr__sqlite {
|
||||
public void Fill(Gfdb_diff_tbl_mgr tbl_mgr, Db_conn conn) {
|
||||
// String schema_str = ""; // conn.Get_schema();
|
||||
}
|
||||
public void Fill(Gfdb_diff_tbl_mgr tbl_mgr, String schema_str) {
|
||||
/*
|
||||
Db_conn conn = null;
|
||||
conn.Meta_get_tbls(Gfdb_diff_tbl_mgr tbl_mgr, "");
|
||||
*/
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
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.diffs; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.metas.*;
|
||||
public class Gfdb_rdr_utl_ {
|
||||
public static int Compare(Dbmeta_fld_itm[] flds, int len, Db_rdr lhs_rdr, Db_rdr rhs_rdr) {
|
||||
int comp = CompareAble_.Same;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
int tid = fld.Type().Tid_ansi();
|
||||
switch (tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: comp = Bool_.Compare (lhs_rdr.Read_bool_by_byte(fld_name), rhs_rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__int: comp = Int_.Compare (lhs_rdr.Read_int(fld_name) , rhs_rdr.Read_int(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__long: comp = Long_.Compare (lhs_rdr.Read_long(fld_name) , rhs_rdr.Read_long(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__float: comp = Float_.Compare (lhs_rdr.Read_float(fld_name) , rhs_rdr.Read_float(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__double: comp = Double_.Compare (lhs_rdr.Read_double(fld_name) , rhs_rdr.Read_double(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__str: comp = String_.Compare (lhs_rdr.Read_str(fld_name) , rhs_rdr.Read_str(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__bry: comp = Bry_.Compare (lhs_rdr.Read_bry(fld_name) , rhs_rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
if (comp != CompareAble_.Same) return comp;
|
||||
}
|
||||
return CompareAble_.Same;
|
||||
}
|
||||
public static void Stmt_args(Db_stmt stmt, Dbmeta_fld_itm[] flds, int len, Db_rdr rdr) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
int tid = fld.Type().Tid_ansi();
|
||||
switch (tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (fld_name, rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__byte: stmt.Val_byte (fld_name, rdr.Read_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__int: stmt.Val_int (fld_name, rdr.Read_int(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__long: stmt.Val_long (fld_name, rdr.Read_long(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__float: stmt.Val_float (fld_name, rdr.Read_float(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__double: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__str: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__bry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
/*
|
||||
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.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; import gplx.dbs.metas.*; import gplx.dbs.engines.mems.*;
|
||||
public class Gfdb_diff_bldr_tst {
|
||||
private final Gfdb_diff_bldr_fxt fxt = new Gfdb_diff_bldr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Same() {
|
||||
fxt.Init__tbl__old(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__cur(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Test__bld();
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt.Init__tbl__old(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__cur(Object_.Ary(1, "A1") , Object_.Ary(2, "B1"));
|
||||
fxt.Test__bld("U|1|A1", "U|2|B1");
|
||||
}
|
||||
@Test public void Insert() {
|
||||
fxt.Init__tbl__old(Object_.Ary(1, "A"));
|
||||
fxt.Init__tbl__cur(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Test__bld("I|2|B");
|
||||
}
|
||||
@Test public void Delete() {
|
||||
fxt.Init__tbl__old(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__cur(Object_.Ary(1, "A"));
|
||||
fxt.Test__bld("D|2");
|
||||
}
|
||||
@Test public void Basic() {
|
||||
fxt.Init__tbl__old
|
||||
( Object_.Ary(1, "A")
|
||||
, Object_.Ary(2, "B")
|
||||
, Object_.Ary(3, "C")
|
||||
);
|
||||
fxt.Init__tbl__cur
|
||||
( Object_.Ary(1, "A")
|
||||
, Object_.Ary(2, "B1")
|
||||
, Object_.Ary(4, "D")
|
||||
);
|
||||
fxt.Test__bld("U|2|B1", "D|3", "I|4|D");
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_bldr_fxt {
|
||||
private final Gfdb_diff_bldr bldr = new Gfdb_diff_bldr();
|
||||
private final Db_conn old_conn, new_conn;
|
||||
private final Gfdb_diff_tbl tbl;
|
||||
private final Gfdb_diff_wkr__test wkr = new Gfdb_diff_wkr__test();
|
||||
private final Dbmeta_fld_itm[] flds_ary;
|
||||
private final String tbl_name = "tbl";
|
||||
public Gfdb_diff_bldr_fxt() {
|
||||
old_conn = Db_conn_utl.Conn__new("old_db");
|
||||
new_conn = Db_conn_utl.Conn__new("new_db");
|
||||
this.flds_ary = new Dbmeta_fld_itm[] {Dbmeta_fld_itm.new_int("id").Primary_y_(), Dbmeta_fld_itm.new_str("val", 255)};
|
||||
tbl = Gfdb_diff_tbl.New(Dbmeta_tbl_itm.New(tbl_name, flds_ary));
|
||||
bldr.Init(wkr);
|
||||
}
|
||||
public void Clear() {
|
||||
Db_conn_utl.Tbl__delete(old_conn, "tbl");
|
||||
Db_conn_utl.Tbl__delete(new_conn, "tbl");
|
||||
}
|
||||
public void Init__tbl__old(Object[]... rows) {Db_conn_utl.Tbl__new(old_conn, "tbl", flds_ary, rows);}
|
||||
public void Init__tbl__cur(Object[]... rows) {Db_conn_utl.Tbl__new(new_conn, "tbl", flds_ary, rows);}
|
||||
public void Test__bld(String... expd) {
|
||||
bldr.Compare(tbl, old_conn, new_conn);
|
||||
Tfds.Eq_ary_str(expd, wkr.To_str_ary());
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_wkr__test implements Gfdb_diff_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private Db_rdr old_rdr, new_rdr;
|
||||
public void Init_rdrs(Gfdb_diff_tbl tbl, Db_rdr old_rdr, Db_rdr new_rdr) {
|
||||
this.old_rdr = old_rdr; this.new_rdr = new_rdr;
|
||||
}
|
||||
public void Term_tbls() {}
|
||||
public void Handle_same() {
|
||||
String old_val = old_rdr.Read_str("val");
|
||||
String new_val = new_rdr.Read_str("val");
|
||||
if (!String_.Eq(old_val, new_val))
|
||||
list.Add(bfr.Add_str_a7("U").Add_byte_pipe().Add_obj(old_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(new_val).To_str_and_clear());
|
||||
}
|
||||
public void Handle_old_missing() {
|
||||
String new_val = new_rdr.Read_str("val");
|
||||
list.Add(bfr.Add_str_a7("I").Add_byte_pipe().Add_obj(new_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(new_val).To_str_and_clear());
|
||||
}
|
||||
public void Handle_new_missing() {
|
||||
list.Add(bfr.Add_str_a7("D").Add_byte_pipe().Add_obj(old_rdr.Read_obj("id")).To_str_and_clear());
|
||||
}
|
||||
public String[] To_str_ary() {return list.To_str_ary_and_clear();}
|
||||
}
|
@ -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.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
class Gfdb_diff_rdr_comparer {
|
||||
private Db_rdr old_rdr, new_rdr;
|
||||
private boolean old_rdr_move, new_rdr_move;
|
||||
private boolean old_rdr_done, new_rdr_done;
|
||||
private Dbmeta_fld_itm[] key_flds; private int key_flds_len;
|
||||
public void Init_rdrs(Gfdb_diff_tbl tbl, Db_rdr old_rdr, Db_rdr new_rdr) {
|
||||
this.old_rdr = old_rdr; this.new_rdr = new_rdr;
|
||||
this.old_rdr_move = new_rdr_move = Bool_.Y;
|
||||
this.old_rdr_done = new_rdr_done = Bool_.N;
|
||||
this.key_flds = tbl.Keys; key_flds_len = key_flds.length;
|
||||
}
|
||||
public int Compare() {
|
||||
if (old_rdr_move) {
|
||||
old_rdr_move = old_rdr.Move_next();
|
||||
if (!old_rdr_move) old_rdr_done = true;
|
||||
}
|
||||
if (new_rdr_move) {
|
||||
new_rdr_move = new_rdr.Move_next();
|
||||
if (!new_rdr_move) new_rdr_done = true;
|
||||
}
|
||||
if (old_rdr_done && new_rdr_done) return Gfdb_diff_rdr_comparer.Rslt__done;
|
||||
else if (old_rdr_done) {new_rdr_move = true; return Gfdb_diff_rdr_comparer.Rslt__old_missing;}
|
||||
else if (new_rdr_done) {old_rdr_move = true; return Gfdb_diff_rdr_comparer.Rslt__new_missing;}
|
||||
else {
|
||||
int comp = Gfdb_rdr_utl_.Compare(key_flds, key_flds_len, old_rdr, new_rdr);
|
||||
switch (comp) {
|
||||
case CompareAble_.Same: // old == cur; move both
|
||||
old_rdr_move = new_rdr_move = true;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__same;
|
||||
case CompareAble_.Less: // old < cur; EX: old == 2; cur == 3
|
||||
old_rdr_move = true;
|
||||
new_rdr_move = false;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__new_missing;
|
||||
case CompareAble_.More: // old > cur; EX: old == 4; cur == 3
|
||||
old_rdr_move = false;
|
||||
new_rdr_move = true;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__old_missing;
|
||||
default: throw Err_.new_unhandled(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static final int
|
||||
Rslt__same = 0
|
||||
, Rslt__old_missing = 1
|
||||
, Rslt__new_missing = 2
|
||||
, Rslt__done = 3
|
||||
;
|
||||
}
|
@ -0,0 +1,305 @@
|
||||
/*
|
||||
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.diffs.cmds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.core.srls.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.dbs.metas.*;
|
||||
interface Gfdb_diff_cmd {
|
||||
void Merge_undo();
|
||||
void Merge_exec();
|
||||
}
|
||||
class Gfdb_diff_ctx implements Gfo_srl_ctx {
|
||||
public Gfo_srl_mgr_wtr Wtr_bgn(String key) {return null;}
|
||||
public Gfo_srl_mgr_rdr Rdr_bgn(String key) {return null;}
|
||||
public Dbmeta_dat_mgr Rdr_subs(String key) {return null;}
|
||||
public Dbmeta_tbl_itm Tbls__get(String key) {return null;}
|
||||
}
|
||||
class Gfo_srl_mgr_rdr__defn {
|
||||
public String Tbl = null;
|
||||
public String[] Select_crt_cols = null;
|
||||
public String[] Delete_crt_cols = null;
|
||||
}
|
||||
class Gfo_srl_mgr_rdr__db {
|
||||
public Object Get_subs (Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_itm proto, String defn_key, Dbmeta_dat_mgr crt_mgr) {
|
||||
List_adp list = List_adp_.new_();
|
||||
|
||||
Gfo_srl_mgr_rdr__defn defn = new Gfo_srl_mgr_rdr__defn(); // Get(key)
|
||||
Db_conn conn = Db_conn_.Noop;
|
||||
Db_stmt select = conn.Stmt_select(defn.Tbl, Dbmeta_fld_itm.Str_ary_empty, defn.Select_crt_cols);
|
||||
int crt_len = crt_mgr.Len();
|
||||
for (int i = 0; i < crt_len; ++i) {
|
||||
Dbmeta_dat_itm crt = crt_mgr.Get_at(i);
|
||||
switch (crt.Tid) {
|
||||
case Dbmeta_fld_tid.Tid__int: select.Crt_int(crt.Key, Int_.cast(crt.Val)); break;
|
||||
}
|
||||
}
|
||||
Db_rdr rdr = select.Exec_select__rls_manual();
|
||||
while (rdr.Move_next()) {
|
||||
Gfo_srl_itm sub = proto.Make_new(ctx);
|
||||
list.Add(sub);
|
||||
sub.Load(ctx, owner, null);
|
||||
}
|
||||
rdr.Rls();
|
||||
|
||||
return list.To_ary_and_clear(proto.getClass());
|
||||
}
|
||||
public void Set_subs (Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_itm proto, Gfo_srl_itm[] subs_ary, String defn_key, Dbmeta_dat_mgr crt_mgr) {
|
||||
Gfo_srl_mgr_rdr__defn defn = new Gfo_srl_mgr_rdr__defn(); // Get(key)
|
||||
Db_conn conn = Db_conn_.Noop;
|
||||
Db_stmt delete = conn.Stmt_delete(defn.Tbl, defn.Delete_crt_cols);
|
||||
int crt_len = crt_mgr.Len();
|
||||
for (int i = 0; i < crt_len; ++i) {
|
||||
Dbmeta_dat_itm crt = crt_mgr.Get_at(i);
|
||||
switch (crt.Tid) {
|
||||
case Dbmeta_fld_tid.Tid__int: delete.Crt_int(crt.Key, Int_.cast(crt.Val)); break;
|
||||
}
|
||||
}
|
||||
delete.Exec_delete();
|
||||
|
||||
int subs_len = subs_ary.length;
|
||||
for (int i = 0; i < subs_len; ++i) {
|
||||
Gfo_srl_itm itm = subs_ary[i];
|
||||
itm.Save(ctx, owner, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_cmd__idx__delete {
|
||||
public Gfdb_diff_cmd__idx__delete(Dbmeta_idx_itm old) {this.Old = old;}
|
||||
public final Dbmeta_idx_itm Old;
|
||||
}
|
||||
class Gfdb_diff_cmd__idx__modify {
|
||||
public Gfdb_diff_cmd__idx__modify(Dbmeta_idx_itm old, Dbmeta_idx_itm cur) {this.Old = old; this.Cur = cur;}
|
||||
public final Dbmeta_idx_itm Old;
|
||||
public final Dbmeta_idx_itm Cur;
|
||||
}
|
||||
class Gfdb_diff_txn {
|
||||
public int Id = 0;
|
||||
}
|
||||
class Gfdb_diff_cmd__fld__create {
|
||||
public Gfdb_diff_cmd__fld__create(Dbmeta_fld_itm cur) {this.cur = cur;}
|
||||
private Dbmeta_fld_itm cur;
|
||||
public void Save(Gfo_srl_ctx ctx, Gfo_srl_itm owner) {
|
||||
Gfo_srl_mgr_wtr wtr = ctx.Wtr_bgn("cmd.fld");
|
||||
wtr.Set_int ("txn_id" , ((Gfdb_diff_txn)owner).Id);
|
||||
wtr.Set_str ("name" , cur.Name());
|
||||
wtr.Set_int ("type_tid" , cur.Type().Tid_ansi());
|
||||
wtr.Set_int ("type_len_1" , cur.Type().Len_1());
|
||||
wtr.Set_int ("type_len_2" , cur.Type().Len_2());
|
||||
wtr.Set_bool ("primary" , cur.Primary());
|
||||
wtr.Set_int ("nullable" , cur.Nullable_tid());
|
||||
wtr.Set_str ("dflt" , Object_.Xto_str_or(cur.Default(), null));
|
||||
wtr.Itm_end();
|
||||
}
|
||||
public void Load(Gfo_srl_ctx ctx, Gfo_srl_itm owner) {
|
||||
Gfo_srl_mgr_rdr rdr = ctx.Rdr_bgn("cmd.fld");
|
||||
String name = rdr.Get_str("name");
|
||||
int type_tid = rdr.Get_int("type_tid");
|
||||
int type_len_1 = rdr.Get_int("type_len_1");
|
||||
// int type_len_2 = rdr.Get_int("type_len_2");
|
||||
boolean primary = rdr.Get_bool("primary");
|
||||
int nullable_tid = rdr.Get_int("nullable");
|
||||
String dflt_str = rdr.Get_str("dflt");
|
||||
cur = new Dbmeta_fld_itm(name, Dbmeta_fld_tid.New(type_tid, type_len_1));
|
||||
cur.Nullable_tid_(nullable_tid);
|
||||
if (primary) cur.Primary_y_();
|
||||
if (dflt_str != null) cur.Default_(dflt_str);
|
||||
rdr.Itm_end();
|
||||
// Gfdb_diff_cmd__idx__create idx = ((Gfdb_diff_cmd__idx__create)owner);
|
||||
// Dbmeta_tbl_itm tbl = ((Gfdb_diff_ctx)ctx).Tbls__get(idx.cur.Tbl());
|
||||
// Dbmeta_fld_tid tid = tbl.Flds().Get_by(name).Type();
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_cmd__fld__delete {
|
||||
public Gfdb_diff_cmd__fld__delete(Dbmeta_fld_itm old) {this.Old = old;}
|
||||
public final Dbmeta_fld_itm Old;
|
||||
}
|
||||
class Gfdb_diff_cmd__fld__modify {
|
||||
public Gfdb_diff_cmd__fld__modify(Dbmeta_fld_itm old, Dbmeta_fld_itm cur) {this.Old = old; this.Cur = cur;}
|
||||
public final Dbmeta_fld_itm Old;
|
||||
public final Dbmeta_fld_itm Cur;
|
||||
}
|
||||
class Gfdb_diff_cmd__tbl__create {
|
||||
public Gfdb_diff_cmd__tbl__create(Dbmeta_tbl_itm cur) {this.Cur = cur;}
|
||||
public final Dbmeta_tbl_itm Cur;
|
||||
}
|
||||
class Gfdb_diff_cmd__tbl__delete {
|
||||
public Gfdb_diff_cmd__tbl__delete(Dbmeta_tbl_itm old) {this.Old = old;}
|
||||
public final Dbmeta_tbl_itm Old;
|
||||
}
|
||||
class Gfdb_diff_cmd_bldr {
|
||||
public void Chk_tbls(List_adp rv, Dbmeta_tbl_mgr old_tbls, Dbmeta_tbl_mgr cur_tbls) {
|
||||
int cur_tbls_len = cur_tbls.Len();
|
||||
for (int i = 0; i < cur_tbls_len; ++i) {
|
||||
Dbmeta_tbl_itm cur_tbl = cur_tbls.Get_at(i);
|
||||
Dbmeta_tbl_itm old_tbl = old_tbls.Get_by(cur_tbl.Name());
|
||||
if (old_tbl == null)
|
||||
rv.Add(new Gfdb_diff_cmd__tbl__create(cur_tbl));
|
||||
else {
|
||||
Chk_idxs(rv, old_tbl, cur_tbl);
|
||||
Chk_flds(rv, old_tbl, cur_tbl);
|
||||
// Chk_data?
|
||||
}
|
||||
}
|
||||
int old_tbls_len = old_tbls.Len();
|
||||
for (int i = 0; i < old_tbls_len; ++i) {
|
||||
Dbmeta_tbl_itm old_tbl = old_tbls.Get_at(i);
|
||||
Dbmeta_tbl_itm cur_tbl = cur_tbls.Get_by(old_tbl.Name());
|
||||
if (cur_tbl == null)
|
||||
rv.Add(new Gfdb_diff_cmd__tbl__delete(old_tbl));
|
||||
}
|
||||
}
|
||||
public void Chk_idxs(List_adp rv, Dbmeta_tbl_itm old_tbl, Dbmeta_tbl_itm cur_tbl) {
|
||||
Dbmeta_idx_mgr old_idxs = old_tbl.Idxs(), cur_idxs = cur_tbl.Idxs();
|
||||
int cur_idxs_len = cur_idxs.Len();
|
||||
for (int i = 0; i < cur_idxs_len; ++i) {
|
||||
Dbmeta_idx_itm cur_idx = cur_idxs.Get_at(i);
|
||||
Dbmeta_idx_itm old_idx = old_idxs.Get_by(cur_idx.Name());
|
||||
if (old_idx == null)
|
||||
rv.Add(new Gfdb_diff_cmd__idx__create(cur_idx));
|
||||
else
|
||||
if (!cur_idx.Eq(old_idx))
|
||||
rv.Add(new Gfdb_diff_cmd__idx__modify(old_idx, cur_idx));
|
||||
}
|
||||
int old_idxs_len = old_idxs.Len();
|
||||
for (int i = 0; i < old_idxs_len; ++i) {
|
||||
Dbmeta_idx_itm old_idx = old_idxs.Get_at(i);
|
||||
Dbmeta_idx_itm cur_idx = cur_idxs.Get_by(old_idx.Name());
|
||||
if (cur_idx == null)
|
||||
rv.Add(new Gfdb_diff_cmd__idx__delete(old_idx));
|
||||
}
|
||||
}
|
||||
public void Chk_flds(List_adp rv, Dbmeta_tbl_itm old_tbl, Dbmeta_tbl_itm cur_tbl) {
|
||||
Dbmeta_fld_mgr old_flds = old_tbl.Flds(), cur_flds = cur_tbl.Flds();
|
||||
int cur_flds_len = cur_flds.Len();
|
||||
for (int i = 0; i < cur_flds_len; ++i) {
|
||||
Dbmeta_fld_itm cur_fld = cur_flds.Get_at(i);
|
||||
Dbmeta_fld_itm old_fld = old_flds.Get_by(cur_fld.Name());
|
||||
if (old_fld == null)
|
||||
rv.Add(new Gfdb_diff_cmd__fld__create(cur_fld));
|
||||
else
|
||||
if (!cur_fld.Eq(old_fld))
|
||||
rv.Add(new Gfdb_diff_cmd__fld__modify(old_fld, cur_fld));
|
||||
}
|
||||
int old_flds_len = old_flds.Len();
|
||||
for (int i = 0; i < old_flds_len; ++i) {
|
||||
Dbmeta_fld_itm old_fld = old_flds.Get_at(i);
|
||||
Dbmeta_fld_itm cur_fld = cur_flds.Get_by(old_fld.Name());
|
||||
if (cur_fld == null)
|
||||
rv.Add(new Gfdb_diff_cmd__fld__delete(old_fld));
|
||||
}
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_cmd__insert {
|
||||
// else if I
|
||||
// // txn_bgn
|
||||
// // audit
|
||||
// INSERT INTO db_temp.page (diff_type, diff, *)
|
||||
// SELECT 'D', d.page_id, *
|
||||
// FROM db_diff.page d
|
||||
// JOIN db_main.page m ON d.page_id = m.page_id
|
||||
// WHERE d.diff_type = 0
|
||||
// AND d.diff_idx BETWEEN lo and hi
|
||||
//
|
||||
// // update
|
||||
// INSERT INTO db_main.page
|
||||
// SELECT d.page_title
|
||||
// FROM db_diff.page d
|
||||
// JOIN db_main.page m
|
||||
// // txn_end
|
||||
private Db_conn conn;
|
||||
private String exec_sql;
|
||||
public void Init(Db_conn main_conn, Db_conn diff_conn, Db_conn temp_conn, Gfdb_diff_tbl tbl) {
|
||||
this.conn = temp_conn;
|
||||
this.exec_sql = "";
|
||||
// this.exec_sql = String_.Format(String_.Concat_lines_nl_skip_last
|
||||
// ( "INSERT INTO db_curr.{tbl}"
|
||||
// ), Gfdb_diff_cmd_ctx.Alias__curr);
|
||||
}
|
||||
public void Merge_exec() {
|
||||
conn.Exec_sql(exec_sql);
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_cmd_sql_bldr {
|
||||
private final Bry_fmtr fmtr = Bry_fmtr.new_();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
public void Bld_insert(Bry_bfr bfr, String tbl_name, String[] keys, String[] vals, int rng_bgn, int rng_end) {
|
||||
fmtr.Fmt_(Insert__fmt).Keys_(Insert__keys);
|
||||
fmtr.Bld_bfr_many(bfr, tbl_name, Bld_flds(tmp_bfr, ", ", "d.", keys, vals), Bld_join(keys), rng_bgn, rng_end);
|
||||
}
|
||||
public void Bld_update(Bry_bfr bfr, String tbl_name, String[] keys, String[] vals, int rng_bgn, int rng_end) {
|
||||
fmtr.Fmt_(Update__fmt).Keys_(Update__keys);
|
||||
fmtr.Bld_bfr_many(bfr, tbl_name, Bld_flds(tmp_bfr, ", ", "d.", keys, vals), Bld_join(keys), rng_bgn, rng_end);
|
||||
}
|
||||
public void Bld_delete(Bry_bfr bfr, String tbl_name, String[] keys, int rng_bgn, int rng_end) {
|
||||
fmtr.Fmt_(Delete__fmt).Keys_(Delete__keys);
|
||||
fmtr.Bld_bfr_many(bfr, tbl_name, Bld_flds(tmp_bfr, " || '|' || ", "", keys, String_.Ary_empty), Bld_flds(tmp_bfr, " || '|' || ", "k.", keys, String_.Ary_empty), Bld_join(keys), rng_bgn, rng_end);
|
||||
}
|
||||
private static String Bld_flds(Bry_bfr tmp_bfr, String dlm, String alias, String[] keys, String[] vals) {
|
||||
int keys_len = keys.length;
|
||||
for (int i = 0; i < keys_len; ++i) {
|
||||
String key = keys[i];
|
||||
if (i != 0) tmp_bfr.Add_str_a7(dlm);
|
||||
tmp_bfr.Add_str_a7(alias).Add_str_a7(key);
|
||||
}
|
||||
int flds_len = vals.length;
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
String val = vals[i];
|
||||
tmp_bfr.Add_str_a7(dlm);
|
||||
tmp_bfr.Add_str_a7(alias).Add_str_a7(val);
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
private String Bld_join(String[] keys) {
|
||||
int len = keys.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String key = keys[i];
|
||||
tmp_bfr.Add_str_a7(i == 0 ? " ON " : " AND ");
|
||||
tmp_bfr.Add_str_a7("k.").Add_str_a7(key).Add_str_a7(" = ");
|
||||
tmp_bfr.Add_str_a7("d.").Add_str_a7(key);
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
private static final String[] Insert__keys = String_.Ary("tbl", "flds", "join", "rng_bgn", "rng_end");
|
||||
private static final String Insert__fmt = String_.Concat_lines_nl_skip_last
|
||||
( "INSERT INTO db_curr.~{tbl}"
|
||||
, "SELECT ~{flds}"
|
||||
, "FROM db_temp.~{tbl}_pkey k"
|
||||
, " JOIN db_diff.~{tbl} d~{join}"
|
||||
, "WHERE k.diff_type = 1"
|
||||
, "AND k.diff_uid BETWEEN ~{rng_bgn} AND ~{rng_end};"
|
||||
);
|
||||
private static final String[] Update__keys = String_.Ary("tbl", "flds", "join", "rng_bgn", "rng_end");
|
||||
private static final String Update__fmt = String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO db_curr.~{tbl}"
|
||||
, "SELECT ~{flds}"
|
||||
, "FROM db_temp.~{tbl}_pkey k"
|
||||
, " JOIN db_diff.~{tbl} d~{join}"
|
||||
, "WHERE k.diff_type = 2"
|
||||
, "AND k.diff_uid BETWEEN ~{rng_bgn} AND ~{rng_end};"
|
||||
);
|
||||
private static final String[] Delete__keys = String_.Ary("tbl", "pkey_where", "pkey_select", "join", "rng_bgn", "rng_end");
|
||||
private static final String Delete__fmt = String_.Concat_lines_nl_skip_last
|
||||
( "DELETE db_curr.~{tbl}"
|
||||
, "WHERE ~{pkey_where} IN"
|
||||
, "( SELECT ~{pkey_select}"
|
||||
, " FROM db_temp.~{tbl}_pkey k"
|
||||
, " JOIN db_diff.~{tbl} d~{join}"
|
||||
, " WHERE k.diff_type = 0"
|
||||
, " AND k.diff_uid BETWEEN ~{rng_bgn} AND ~{rng_end}"
|
||||
, ");"
|
||||
);
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
/*
|
||||
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.diffs.cmds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.core.srls.*; import gplx.dbs.metas.*;
|
||||
|
||||
class Gfdb_diff_cmd__idx__create implements Gfo_srl_itm {
|
||||
public Gfdb_diff_cmd__idx__create(Dbmeta_idx_itm cur) {this.cur = cur;}
|
||||
public Dbmeta_idx_itm cur;
|
||||
private Gfdb_diff_cmd__idx__fld[] flds = new Gfdb_diff_cmd__idx__fld[0];
|
||||
public Gfo_srl_itm Make_new(Gfo_srl_ctx ctx) {return new Gfdb_diff_cmd__idx__create();} Gfdb_diff_cmd__idx__create() {}
|
||||
private int idx_uid;
|
||||
// *_sdif_ddl_idx : txn_uid,idx_uid,idx_tbl,idx_name,idx_unique
|
||||
public void Save(Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_mgr_wtr wtr) {
|
||||
wtr.Itm_bgn("idx");
|
||||
wtr.Set_int ("idx_uid" , idx_uid);
|
||||
wtr.Set_str ("idx_tbl" , cur.Tbl());
|
||||
wtr.Set_str ("idx_name" , cur.Name());
|
||||
wtr.Set_bool ("idx_unique" , cur.Unique());
|
||||
wtr.Set_subs (ctx, this, Gfdb_diff_cmd__idx__fld.Instance, flds, ctx.Rdr_subs("idx_fld").Add_int("idx_uid", idx_uid));
|
||||
wtr.Itm_end();
|
||||
}
|
||||
public void Load(Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_mgr_rdr rdr) {
|
||||
rdr.Itm_bgn("idx");
|
||||
this.idx_uid = rdr.Get_int ("idx_uid");
|
||||
String tbl = rdr.Get_str ("idx_tbl");
|
||||
String name = rdr.Get_str ("idx_name");
|
||||
boolean unique = rdr.Get_bool ("idx_unique");
|
||||
this.flds = (Gfdb_diff_cmd__idx__fld[])rdr.Get_subs(ctx, this, Gfdb_diff_cmd__idx__fld.Instance, ctx.Rdr_subs("idx_fld").Add_int("idx_uid", idx_uid));
|
||||
cur = new Dbmeta_idx_itm(unique, tbl, name, Dbmeta_idx_fld.Ary_empty);
|
||||
rdr.Itm_end();
|
||||
}
|
||||
public void Exec(Db_conn conn) {
|
||||
conn.Ddl_create_idx(cur);
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_cmd__idx__fld implements Gfo_srl_itm {
|
||||
public Gfdb_diff_cmd__idx__fld(Dbmeta_idx_fld cur) {this.cur = cur;}
|
||||
private Dbmeta_idx_fld cur;
|
||||
public Gfo_srl_itm Make_new(Gfo_srl_ctx ctx) {return new Gfdb_diff_cmd__idx__fld();} Gfdb_diff_cmd__idx__fld() {}
|
||||
// *_sdif_ddl_idx_fld : idx_uid,fld_order,fld_name,fld_asc
|
||||
public void Save(Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_mgr_wtr wtr) {
|
||||
wtr.Itm_bgn("idx_fld");
|
||||
wtr.Set_int ("fld_order" , cur.Order);
|
||||
wtr.Set_str ("fld_name" , cur.Name);
|
||||
wtr.Set_int ("fld_asc" , cur.Sort_tid);
|
||||
wtr.Itm_end();
|
||||
}
|
||||
public void Load(Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_mgr_rdr rdr) {
|
||||
rdr.Itm_bgn("idx_fld");
|
||||
int order = rdr.Get_int ("fld_order");
|
||||
String name = rdr.Get_str ("fld_name");
|
||||
int sort_tid = rdr.Get_int ("fld_sort");
|
||||
cur = new Dbmeta_idx_fld(order, name, sort_tid);
|
||||
rdr.Itm_end();
|
||||
}
|
||||
|
||||
public static final Gfdb_diff_cmd__idx__fld Instance = new Gfdb_diff_cmd__idx__fld();
|
||||
}
|
||||
// class Gfdb_diff_cmd__tbl__fld : Gfo_srl_itm {
|
||||
// public Gfdb_diff_cmd__tbl__fld(Dbmeta_fld_itm cur) {this.cur = cur;}
|
||||
// private Dbmeta_fld_itm cur;
|
||||
// public String Name;
|
||||
// public int Type_tid;
|
||||
// public int Len1;
|
||||
// public int Len2;
|
||||
// public int Nullable;
|
||||
// public boolean Primary;
|
||||
// public boolean Autonum;
|
||||
//
|
||||
// public Gfo_srl_itm Make_new(Gfo_srl_ctx ctx) {return new Gfdb_diff_cmd__tbl__fld();} Gfdb_diff_cmd__tbl__fld() {}
|
||||
// // *_sdif_ddl_tbl_fld : tbl_uid,fld_idx,fld_name,fld_type,fld_len1, fld_len2, fld_nullable, fld_primary, fld_autonumber
|
||||
// public void Save(Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_mgr_wtr wtr) {
|
||||
// wtr.Itm_bgn("tbl_fld");
|
||||
// wtr.Set_str ("fld_name" , cur.Name());
|
||||
// wtr.Set_int ("fld_type" , cur.Type().Tid_ansi());
|
||||
// wtr.Set_int ("fld_len1" , cur.Type().Len_1());
|
||||
// wtr.Set_int ("fld_len2" , cur.Type().Len_2());
|
||||
// wtr.Set_int ("fld_nullable" , cur.Nullable_tid());
|
||||
// wtr.Set_bool ("fld_primary" , cur.Primary());
|
||||
// wtr.Set_bool ("fld_autonum" , cur.Autonum());
|
||||
// wtr.Set_str ("fld_dflt" , Object_.Xto_str_or(cur.Default(), null));
|
||||
//// wtr.Set_int ("fld_asc" , cur.Sort_tid);
|
||||
// wtr.Itm_end();
|
||||
// }
|
||||
// public void Load(Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_mgr_rdr rdr) {
|
||||
// rdr.Itm_bgn("tbl_fld");
|
||||
// String name = rdr.Get_str("name");
|
||||
// int type_tid = rdr.Get_int("type_tid");
|
||||
// int type_len_1 = rdr.Get_int("type_len_1");
|
||||
// boolean primary = rdr.Get_bool("primary");
|
||||
// int nullable_tid = rdr.Get_int("nullable");
|
||||
// String dflt_str = rdr.Get_str("dflt");
|
||||
// cur = new Dbmeta_fld_itm(name, Dbmeta_fld_tid.New(type_tid, type_len_1));
|
||||
// cur.Nullable_tid_(nullable_tid);
|
||||
// if (primary) cur.Primary_y_();
|
||||
// if (dflt_str != null) cur.Default_(dflt_str);
|
||||
// rdr.Itm_end();
|
||||
//// Gfdb_diff_cmd__idx__create idx = ((Gfdb_diff_cmd__idx__create)owner);
|
||||
//// Dbmeta_tbl_itm tbl = ((Gfdb_diff_ctx)ctx).Tbls__get(idx.cur.Tbl());
|
||||
//// Dbmeta_fld_tid tid = tbl.Flds().Get_by(name).Type();
|
||||
// }
|
||||
//
|
||||
// public static final Gfdb_diff_cmd__tbl__fld Instance = new Gfdb_diff_cmd__tbl__fld();
|
||||
// }
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.engines.sqlite; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class Sqlite_tid {
|
||||
public static final int Tid_int = 1, Tid_text = 2, Tid_none = 3, Tid_real = 4, Tid_numeric = 5;
|
||||
}
|
@ -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 Dbmeta_fld_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Count();}
|
||||
public void Clear() {hash.Clear();}
|
||||
public void Add(Dbmeta_fld_itm itm) {hash.Add(itm.Name(), itm);}
|
||||
public boolean Has(String name) {return hash.Has(name);}
|
||||
public Dbmeta_fld_itm Get_at(int idx) {return (Dbmeta_fld_itm)hash.Get_at(idx);}
|
||||
public Dbmeta_fld_itm Get_by(String name) {return (Dbmeta_fld_itm)hash.Get_by(name);}
|
||||
public Dbmeta_fld_itm[] To_ary() {return hash.Count() == 0 ? Dbmeta_fld_itm.Ary_empty : (Dbmeta_fld_itm[])hash.To_ary(Dbmeta_fld_itm.class);}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
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.*;
|
||||
import gplx.dbs.engines.sqlite.*;
|
||||
public class Dbmeta_fld_tid {
|
||||
public Dbmeta_fld_tid(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;
|
||||
public boolean Eq(Dbmeta_fld_tid comp) {
|
||||
return tid_ansi == comp.tid_ansi
|
||||
&& tid_sqlite == comp.tid_sqlite
|
||||
&& Bry_.Eq(name, comp.name)
|
||||
&& len_1 == comp.len_1
|
||||
&& len_2 == comp.len_2;
|
||||
}
|
||||
|
||||
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 Dbmeta_fld_tid
|
||||
Itm__byte = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__byte , Sqlite_tid.Tid_int , Bry_.new_a7("tinyint") , -1, -1)
|
||||
, Itm__short = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__short , Sqlite_tid.Tid_int , Bry_.new_a7("smallint") , -1, -1)
|
||||
, Itm__int = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__int , Sqlite_tid.Tid_int , Bry_.new_a7("integer") , -1, -1)
|
||||
, Itm__long = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__long , Sqlite_tid.Tid_int , Bry_.new_a7("bigint") , -1, -1)
|
||||
, Itm__text = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__text , Sqlite_tid.Tid_text , Bry_.new_a7("text") , -1, -1)
|
||||
, Itm__bry = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__bry , Sqlite_tid.Tid_none , Bry_.new_a7("blob") , -1, -1)
|
||||
, Itm__float = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__float , Sqlite_tid.Tid_real , Bry_.new_a7("float") , -1, -1)
|
||||
, Itm__double = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__double , Sqlite_tid.Tid_real , Bry_.new_a7("double") , -1, -1)
|
||||
, Itm__numeric = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__decimal , Sqlite_tid.Tid_numeric , Bry_.new_a7("numeric") , -1, -1)
|
||||
, Itm__bool = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__bool , Sqlite_tid.Tid_numeric , Bry_.new_a7("bit") , -1, -1) // "bit" is not SQLITE
|
||||
, Itm__date = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__date , Sqlite_tid.Tid_numeric , Bry_.new_a7("date") , -1, -1)
|
||||
;
|
||||
public static Dbmeta_fld_tid Itm__str (int len) {return new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__str , Sqlite_tid.Tid_text , Bry_.new_a7("varchar") , len, -1);}
|
||||
public static Dbmeta_fld_tid Itm__decimal (int len_1, int len_2) {return new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__decimal , Sqlite_tid.Tid_numeric , Bry_.new_a7("decimal") , len_1, len_2);}
|
||||
public static Dbmeta_fld_tid New(int tid, int len1) {
|
||||
switch (tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: return Itm__bool;
|
||||
case Dbmeta_fld_tid.Tid__byte: return Itm__byte;
|
||||
case Dbmeta_fld_tid.Tid__short: return Itm__short;
|
||||
case Dbmeta_fld_tid.Tid__int: return Itm__int;
|
||||
case Dbmeta_fld_tid.Tid__long: return Itm__long;
|
||||
case Dbmeta_fld_tid.Tid__float: return Itm__float;
|
||||
case Dbmeta_fld_tid.Tid__double: return Itm__double;
|
||||
case Dbmeta_fld_tid.Tid__str: return Itm__str(len1);
|
||||
case Dbmeta_fld_tid.Tid__text: return Itm__text;
|
||||
case Dbmeta_fld_tid.Tid__bry: return Itm__bry;
|
||||
case Dbmeta_fld_tid.Tid__date: return Itm__date;
|
||||
case Dbmeta_fld_tid.Tid__decimal: // return Itm__decimal(len1);
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
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 Dbmeta_idx_fld {
|
||||
public Dbmeta_idx_fld(int order, String name, int sort_tid) {this.Name = name; this.Order = order; this.Sort_tid = sort_tid;}
|
||||
public int Order;
|
||||
public String Name;
|
||||
public int Sort_tid;
|
||||
public boolean Eq(Dbmeta_idx_fld comp) {
|
||||
return String_.Eq(Name, comp.Name)
|
||||
&& Order == comp.Order
|
||||
&& Sort_tid == comp.Sort_tid;
|
||||
}
|
||||
|
||||
public static final Dbmeta_idx_fld[] Ary_empty = new Dbmeta_idx_fld[0];
|
||||
public static final int Sort_tid__none = 0, Sort_tid__asc = 1, Sort_tid__desc = 2;
|
||||
public static boolean Ary_eq(Dbmeta_idx_fld[] lhs_ary, Dbmeta_idx_fld[] rhs_ary) {
|
||||
int lhs_len = lhs_ary.length, rhs_len = rhs_ary.length;
|
||||
if (lhs_len != rhs_len) return false;
|
||||
for (int i = 0; i < lhs_len; ++i)
|
||||
if (!lhs_ary[i].Eq(rhs_ary[i])) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
@ -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 Dbmeta_idx_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Count();}
|
||||
public boolean Has(String name) {return hash.Has(name);}
|
||||
public Dbmeta_idx_itm Get_at(int idx) {return (Dbmeta_idx_itm)hash.Get_at(idx);}
|
||||
public Dbmeta_idx_itm Get_by(String name) {return (Dbmeta_idx_itm)hash.Get_by(name);}
|
||||
public void Add(Dbmeta_idx_itm itm) {hash.Add(itm.Name(), itm);}
|
||||
public void Clear() {hash.Clear();}
|
||||
public Dbmeta_idx_itm[] To_ary() {return (Dbmeta_idx_itm[])hash.To_ary(Dbmeta_idx_itm.class);}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.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;
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.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;
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
/*
|
||||
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 Dbmeta_fld_wkr__base {
|
||||
private byte[] hook;
|
||||
private final Btrie_slim_mgr words_trie = Btrie_slim_mgr.ci_a7();
|
||||
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_len = words_ary.length;
|
||||
for (byte i = 0; i < words_len; ++i)
|
||||
words_trie.Add_bry_byte(words_ary[i], i);
|
||||
}
|
||||
public void Reg(Btrie_slim_mgr trie) {
|
||||
trie.Add_obj(hook, this);
|
||||
}
|
||||
@gplx.Virtual public void Match(Bry_rdr rdr, Dbmeta_fld_itm fld) {
|
||||
int words_len = words_trie.Count();
|
||||
for (int i = 0; i < words_len; ++i) {
|
||||
rdr.Skip_ws();
|
||||
rdr.Chk(words_trie);
|
||||
}
|
||||
When_match(fld);
|
||||
}
|
||||
protected abstract void When_match(Dbmeta_fld_itm fld);
|
||||
public static final int Tid_end_comma = 1, Tid_end_paren = 2, Tid_other = 3;
|
||||
}
|
||||
class Dbmeta_fld_wkr__end_comma extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__end_comma() {this.Ctor(Hook);}
|
||||
@Override public int Tid() {return Tid_end_comma;}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {}
|
||||
private static final byte[] Hook = Bry_.new_a7(",");
|
||||
public static final Dbmeta_fld_wkr__end_comma Instance = new Dbmeta_fld_wkr__end_comma();
|
||||
}
|
||||
class Dbmeta_fld_wkr__end_paren extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__end_paren() {this.Ctor(Hook);}
|
||||
@Override public int Tid() {return Tid_end_paren;}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {}
|
||||
private static final byte[] Hook = Bry_.new_a7(")");
|
||||
public static final Dbmeta_fld_wkr__end_paren Instance = new Dbmeta_fld_wkr__end_paren();
|
||||
}
|
||||
class Dbmeta_fld_wkr__nullable_null extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__nullable_null() {this.Ctor(Hook);}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {
|
||||
fld.Nullable_tid_(Dbmeta_fld_itm.Nullable_null);
|
||||
}
|
||||
private static final byte[] Hook = Bry_.new_a7("null");
|
||||
public static final Dbmeta_fld_wkr__nullable_null Instance = new Dbmeta_fld_wkr__nullable_null();
|
||||
}
|
||||
class Dbmeta_fld_wkr__nullable_not extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__nullable_not() {this.Ctor(Hook, Bry_null);}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {
|
||||
fld.Nullable_tid_(Dbmeta_fld_itm.Nullable_not_null);
|
||||
}
|
||||
private static final byte[] Hook = Bry_.new_a7("not"), Bry_null = Bry_.new_a7("null");
|
||||
public static final Dbmeta_fld_wkr__nullable_not Instance = new Dbmeta_fld_wkr__nullable_not();
|
||||
}
|
||||
class Dbmeta_fld_wkr__primary_key extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__primary_key() {this.Ctor(Hook, Bry_key);}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {
|
||||
fld.Primary_y_();
|
||||
}
|
||||
private static final byte[] Hook = Bry_.new_a7("primary"), Bry_key = Bry_.new_a7("key");
|
||||
public static final Dbmeta_fld_wkr__primary_key Instance = new Dbmeta_fld_wkr__primary_key();
|
||||
}
|
||||
class Dbmeta_fld_wkr__autonumber extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__autonumber() {this.Ctor(Hook);}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {
|
||||
fld.Autonum_y_();
|
||||
}
|
||||
private static final byte[] Hook = Bry_.new_a7("autoincrement");
|
||||
public static final Dbmeta_fld_wkr__autonumber Instance = new Dbmeta_fld_wkr__autonumber();
|
||||
}
|
||||
class Dbmeta_fld_wkr__default extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__default() {this.Ctor(Hook);}
|
||||
@Override public void Match(Bry_rdr rdr, Dbmeta_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_find_.Find_fwd(src, b, bgn_pos); if (end_pos == Bry_find_.Not_found) rdr.Err_wkr().Fail("unclosed quote");
|
||||
default_val = Bry_.Mid(src, bgn_pos, end_pos);
|
||||
rdr.Move_to(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:
|
||||
rdr.Err_wkr().Fail("invalid field_default"); break;
|
||||
}
|
||||
fld.Default_(default_val);
|
||||
}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {}
|
||||
private static final byte[] Hook = Bry_.new_a7("default");
|
||||
public static final Dbmeta_fld_wkr__default Instance = new Dbmeta_fld_wkr__default();
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
/*
|
||||
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.*;
|
||||
import gplx.dbs.engines.sqlite.*;
|
||||
public class Dbmeta_parser__fld {
|
||||
public Dbmeta_fld_itm Parse_fld(Sql_bry_rdr rdr) { // starts after "(" or ","; EX: "(fld1 int", ", fld2 int"; ends at ")"
|
||||
byte[] name = rdr.Read_sql_identifier();
|
||||
Dbmeta_fld_tid type = this.Parse_type(rdr);
|
||||
Dbmeta_fld_itm fld = new Dbmeta_fld_itm(String_.new_u8(name), type);
|
||||
byte[] src = rdr.Src(); int src_len = rdr.Src_end();
|
||||
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;
|
||||
}
|
||||
Dbmeta_fld_wkr__base type_wkr = (Dbmeta_fld_wkr__base)rdr.Chk_trie_as_obj(fld_trie);
|
||||
switch (type_wkr.Tid()) {
|
||||
case Dbmeta_fld_wkr__base.Tid_end_comma:
|
||||
case Dbmeta_fld_wkr__base.Tid_end_paren: return fld;
|
||||
default:
|
||||
rdr.Move_to(fld_trie.Match_pos());
|
||||
type_wkr.Match(rdr, fld);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@gplx.Internal protected Dbmeta_fld_tid Parse_type(Bry_rdr rdr) {
|
||||
rdr.Skip_ws();
|
||||
Dbmeta_parser__fld_itm type_itm = (Dbmeta_parser__fld_itm)rdr.Chk_trie_as_obj(type_trie);
|
||||
rdr.Move_by(type_itm.Word().length);
|
||||
int paren_itms_count = type_itm.Paren_itms_count();
|
||||
int len_1 = Int_.Min_value, len_2 = Int_.Min_value;
|
||||
if (paren_itms_count > 0) {
|
||||
rdr.Skip_ws().Chk(Byte_ascii.Paren_bgn);
|
||||
len_1 = rdr.Skip_ws().Read_int_to_non_num(); if (len_1 == Int_.Min_value) rdr.Err_wkr().Fail("invalid fld len_1");
|
||||
if (paren_itms_count == 2) {
|
||||
rdr.Skip_ws().Chk(Byte_ascii.Comma);
|
||||
len_2 = rdr.Skip_ws().Read_int_to_non_num(); if (len_2 == Int_.Min_value) rdr.Err_wkr().Fail("invalid fld len_2");
|
||||
}
|
||||
rdr.Skip_ws().Chk(Byte_ascii.Paren_end);
|
||||
}
|
||||
return new Dbmeta_fld_tid(type_itm.Tid_ansi(), type_itm.Tid_sqlite(), type_itm.Word(), len_1, len_2);
|
||||
}
|
||||
private static final Btrie_slim_mgr fld_trie = fld_trie_init
|
||||
( Dbmeta_fld_wkr__nullable_null.Instance
|
||||
, Dbmeta_fld_wkr__nullable_not.Instance
|
||||
, Dbmeta_fld_wkr__autonumber.Instance
|
||||
, Dbmeta_fld_wkr__primary_key.Instance
|
||||
, Dbmeta_fld_wkr__default.Instance
|
||||
);
|
||||
private static Btrie_slim_mgr fld_trie_init(Dbmeta_fld_wkr__base... wkrs) {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_a7();
|
||||
for (Dbmeta_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_a7();
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__byte , Sqlite_tid.Tid_int , 0, "tinyint", "int2");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__short , Sqlite_tid.Tid_int , 0, "smallint");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__int , Sqlite_tid.Tid_int , 0, "int", "integer", "mediumint");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__long , Sqlite_tid.Tid_int , 0, "bigint", "int8"); // "UNSIGNED BIG INT"
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__str , Sqlite_tid.Tid_text , 1, "character", "varchar", "nchar"); // "varying character", "native character"
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__text , Sqlite_tid.Tid_text , 0, "text", "clob");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__bry , Sqlite_tid.Tid_none , 0, "blob");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__float , Sqlite_tid.Tid_real , 0, "float");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__double , Sqlite_tid.Tid_real , 0, "real", "double"); // "double precision"
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__decimal , Sqlite_tid.Tid_numeric , 0, "numeric");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__decimal , Sqlite_tid.Tid_numeric , 2, "decimal");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__decimal , Sqlite_tid.Tid_numeric , 2, "decimal");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__bool , Sqlite_tid.Tid_numeric , 0, "boolean", "bit"); // "bit" is not SQLITE
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__date , Sqlite_tid.Tid_numeric , 0, "date", "datetime");
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Dbmeta_parser__fld_itm {
|
||||
public Dbmeta_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]);
|
||||
Dbmeta_parser__fld_itm itm = new Dbmeta_parser__fld_itm(tid_ansi, tid_sqlite, name_bry, paren_itms_count);
|
||||
trie.Add_obj(name_bry, itm);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 Dbmeta_parser__fld_tst {
|
||||
@Before public void init() {fxt.Clear();} private Dbmeta_parser__fld_fxt fxt = new Dbmeta_parser__fld_fxt();
|
||||
@Test public void Parse_type() {
|
||||
fxt.Test_parse_type("int" , fxt.Make_type(Dbmeta_fld_tid.Tid__int));
|
||||
fxt.Test_parse_type("varchar(255)" , fxt.Make_type(Dbmeta_fld_tid.Tid__str, 255));
|
||||
fxt.Test_parse_type("decimal(12,10)" , fxt.Make_type(Dbmeta_fld_tid.Tid__decimal, 12, 10));
|
||||
fxt.Test_parse_type(" int" , fxt.Make_type(Dbmeta_fld_tid.Tid__int));
|
||||
fxt.Test_parse_type(" decimal ( 12 , 10 )" , fxt.Make_type(Dbmeta_fld_tid.Tid__decimal, 12, 10));
|
||||
}
|
||||
@Test public void Parse_fld() {
|
||||
fxt.Test_parse_fld("name_1 int" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_unknown));
|
||||
fxt.Test_parse_fld("name_1 int null" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_null));
|
||||
fxt.Test_parse_fld("name_1 int not null" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null));
|
||||
fxt.Test_parse_fld("name_1 int not null autoincrement" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_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", Dbmeta_fld_tid.Tid__int, Dbmeta_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", Dbmeta_fld_tid.Tid__int, Dbmeta_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", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N, "abc"));
|
||||
}
|
||||
}
|
||||
class Dbmeta_parser__fld_fxt {
|
||||
private final Dbmeta_parser__fld fld_parser = new Dbmeta_parser__fld();
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
public void Clear() {}
|
||||
public Dbmeta_fld_tid Make_type(int tid_ansi) {return new Dbmeta_fld_tid(tid_ansi, -1, null, Int_.Min_value, Int_.Min_value);}
|
||||
public Dbmeta_fld_tid Make_type(int tid_ansi, int len_1) {return new Dbmeta_fld_tid(tid_ansi, -1, null, len_1, Int_.Min_value);}
|
||||
public Dbmeta_fld_tid Make_type(int tid_ansi, int len_1, int len_2) {return new Dbmeta_fld_tid(tid_ansi, -1, null, len_1, len_2);}
|
||||
public Dbmeta_fld_itm Make_fld(String name, int tid_ansi, int nullable) {return Make_fld(name, tid_ansi, nullable, false, false, null);}
|
||||
public Dbmeta_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 Dbmeta_fld_itm Make_fld(String name, int tid_ansi, int nullable, boolean autonumber, boolean primary_key, Object default_val) {
|
||||
Dbmeta_fld_itm rv = new Dbmeta_fld_itm(name, Make_type(tid_ansi));
|
||||
rv.Nullable_tid_(nullable);
|
||||
if (autonumber) rv.Autonum_y_();
|
||||
if (primary_key) rv.Primary_y_();
|
||||
rv.Default_(default_val);
|
||||
return rv;
|
||||
}
|
||||
public void Test_parse_type(String src, Dbmeta_fld_tid expd_type) {
|
||||
rdr.Init_by_src(Bry_.new_u8(src));
|
||||
Dbmeta_fld_tid 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, Dbmeta_fld_itm expd_fld) {
|
||||
rdr.Init_by_src(Bry_.new_u8(src));
|
||||
Dbmeta_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()), Object_.Xto_str_strict_or_empty(actl_fld.Default()));
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
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 Dbmeta_parser__idx {
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
private final List_adp tmp_list = List_adp_.new_();
|
||||
public Dbmeta_idx_itm Parse(byte[] src) {
|
||||
rdr.Init_by_page(Bry_.Empty, src, src.length);
|
||||
rdr.Skip_ws().Chk_trie_val(trie, Tid__create);
|
||||
boolean unique = false;
|
||||
byte tid = rdr.Skip_ws().Chk_or(trie, Byte_.Max_value_127);
|
||||
switch (tid) {
|
||||
case Tid__index: break;
|
||||
case Tid__unique: rdr.Skip_ws().Chk_trie_val(trie, Tid__index); unique = true; break;
|
||||
default: throw Err_.new_("db", "index parse failed; 'CREATE' should be followed by 'INDEX' or 'UNIQUE'", "src", src);
|
||||
}
|
||||
byte[] idx_name = rdr.Read_sql_identifier();
|
||||
rdr.Skip_ws().Chk_trie_val(trie, Tid__on);
|
||||
byte[] tbl_name = rdr.Read_sql_identifier();
|
||||
rdr.Skip_ws().Chk(Byte_ascii.Paren_bgn);
|
||||
int order = -1;
|
||||
while (true) {
|
||||
byte[] fld_bry = rdr.Read_sql_identifier(); if (fld_bry == null) throw Err_.new_("db", "index parse failed; index field is not an identifier", "src", src);
|
||||
// TODO: check for ASC / DESC
|
||||
Dbmeta_idx_fld fld_itm = new Dbmeta_idx_fld(++order, String_.new_u8(fld_bry), Dbmeta_idx_fld.Sort_tid__none);
|
||||
tmp_list.Add(fld_itm);
|
||||
byte sym = rdr.Skip_ws().Read_byte();
|
||||
if (sym == Byte_ascii.Paren_end) break;
|
||||
}
|
||||
return new Dbmeta_idx_itm(unique, String_.new_u8(tbl_name), String_.new_u8(idx_name), (Dbmeta_idx_fld[])tmp_list.To_ary_and_clear(Dbmeta_idx_fld.class));
|
||||
}
|
||||
private static final byte Tid__create = 0, Tid__unique = 1, Tid__index = 2, Tid__on = 3;
|
||||
private static final byte[]
|
||||
Bry__create = Bry_.new_a7("create")
|
||||
, Bry__unique = Bry_.new_a7("unique")
|
||||
, Bry__index = Bry_.new_a7("index")
|
||||
, Bry__on = Bry_.new_a7("on");
|
||||
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
|
||||
.Add_bry_byte(Bry__create , Tid__create)
|
||||
.Add_bry_byte(Bry__unique , Tid__unique)
|
||||
.Add_bry_byte(Bry__index , Tid__index)
|
||||
.Add_bry_byte(Bry__on , Tid__on);
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import org.junit.*;
|
||||
public class Dbmeta_parser__idx_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Dbmeta_parser__idx_fxt fxt = new Dbmeta_parser__idx_fxt();
|
||||
@Test public void Unique() {fxt.Test_parse("CREATE UNIQUE INDEX idx_1 ON tbl_1 (fld_1, fld_2, fld_3)" , fxt.Make_idx(Bool_.Y, "idx_1", "tbl_1", "fld_1", "fld_2", "fld_3"));}
|
||||
@Test public void Normal() {fxt.Test_parse("CREATE INDEX idx_1 ON tbl_1 (fld_1, fld_2, fld_3)" , fxt.Make_idx(Bool_.N, "idx_1", "tbl_1", "fld_1", "fld_2", "fld_3"));}
|
||||
@Test public void Fld_1() {fxt.Test_parse("CREATE INDEX idx_1 ON tbl_1 (fld_1)" , fxt.Make_idx(Bool_.N, "idx_1", "tbl_1", "fld_1"));}
|
||||
}
|
||||
class Dbmeta_parser__idx_fxt {
|
||||
private final Dbmeta_parser__idx parser = new Dbmeta_parser__idx();
|
||||
public void Clear() {}
|
||||
public Dbmeta_idx_itm Make_idx(boolean unique, String idx_name, String tbl_name, String... fld_names) {return new Dbmeta_idx_itm(unique, tbl_name, idx_name, Dbmeta_idx_itm.To_fld_ary(fld_names));}
|
||||
public void Test_parse(String src, Dbmeta_idx_itm expd) {
|
||||
Dbmeta_idx_itm actl = parser.Parse(Bry_.new_u8(src));
|
||||
Tfds.Eq_bool(expd.Unique(), actl.Unique());
|
||||
Tfds.Eq_str(expd.Name(), actl.Name());
|
||||
Tfds.Eq_str(expd.Tbl(), actl.Tbl());
|
||||
Tfds.Eq_bool(Bool_.Y, Dbmeta_idx_fld.Ary_eq(expd.Flds, actl.Flds));
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
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 Dbmeta_parser__tbl {
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
private final Dbmeta_parser__fld fld_parser = new Dbmeta_parser__fld();
|
||||
public Dbmeta_tbl_itm Parse(byte[] src) {
|
||||
rdr.Init_by_page(Bry_.Empty, src, src.length);
|
||||
rdr.Skip_ws().Chk_trie_val(trie, Tid__create);
|
||||
rdr.Skip_ws().Chk_trie_val(trie, Tid__table);
|
||||
byte[] tbl_name = rdr.Read_sql_identifier();
|
||||
rdr.Skip_ws().Chk(Byte_ascii.Paren_bgn);
|
||||
Dbmeta_tbl_itm rv = Dbmeta_tbl_itm.New(String_.new_u8(tbl_name));
|
||||
boolean loop = true;
|
||||
while (loop) {
|
||||
Dbmeta_fld_itm fld = fld_parser.Parse_fld(rdr); if (fld == null) rdr.Err_wkr().Fail("unknown field", "src", src);
|
||||
rv.Flds().Add(fld);
|
||||
int pos = rdr.Pos();
|
||||
byte b = pos == rdr.Src_end() ? Byte_ascii.Null : src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Comma: rdr.Move_by_one(); break;
|
||||
case Byte_ascii.Paren_end: rdr.Move_by_one(); loop = false; break;
|
||||
default: rdr.Err_wkr().Fail("premature end of flds"); break;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static final byte Tid__create = 0, Tid__table = 1;
|
||||
private static final byte[]
|
||||
Bry__create = Bry_.new_a7("create")
|
||||
, Bry__table = Bry_.new_a7("table");
|
||||
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
|
||||
.Add_bry_byte(Bry__create , Tid__create)
|
||||
.Add_bry_byte(Bry__table , Tid__table);
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.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_old 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 Instance = 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 Instance = 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 Instance = 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 Instance = 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 Instance = 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 Instance = 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_old 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_find_.Find_fwd(src, b, bgn_pos); if (end_pos == Bry_find_.Not_found) throw Err_.new_wo_type("unclosed quote", "snip", 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_wo_type("invalid field_default", "snip", 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 Instance = new Meta_fld_wkr__default();
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.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_old 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_wo_type("invalid fld type", "snip", 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_.Min_value, len_2 = Int_.Min_value;
|
||||
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_.Min_value) throw Err_.new_wo_type("invalid fld len_1", "snip", 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_.Min_value) throw Err_.new_wo_type("invalid fld len_2", "snip", 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_wo_type("invalid", "snip", 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.Instance
|
||||
, Meta_fld_wkr__nullable_not.Instance
|
||||
, Meta_fld_wkr__autonumber.Instance
|
||||
, Meta_fld_wkr__primary_key.Instance
|
||||
, Meta_fld_wkr__default.Instance
|
||||
);
|
||||
private static Btrie_slim_mgr fld_trie_init(Meta_fld_wkr__base... wkrs) {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_a7();
|
||||
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_a7();
|
||||
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;
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.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_.Min_value, Int_.Min_value);}
|
||||
public Meta_type_itm Make_type(int tid_ansi, int len_1) {return new Meta_type_itm(tid_ansi, -1, null, len_1, Int_.Min_value);}
|
||||
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()));
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.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_.Lcase__all(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_wo_type("unknown field", "src", rdr.Src());
|
||||
tbl.Flds().Add(fld);
|
||||
int pos = rdr.Pos();
|
||||
byte b = pos == rdr.Src_len() ? Byte_ascii.Null : 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_wo_type("premature end of flds", "src", rdr.Mid_by_len_safe(40));
|
||||
}
|
||||
}
|
||||
}
|
||||
private static final byte[]
|
||||
Tkn_create = Bry_.new_a7("create")
|
||||
, Tkn_table = Bry_.new_a7("table")
|
||||
;
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
public class Gfdb_diff_tbl {
|
||||
public Gfdb_diff_tbl(String name, Db_meta_fld[] keys, Db_meta_fld[] vals, Db_rdr rdr) {
|
||||
this.name = name; this.keys = keys; this.vals = vals; this.rdr = rdr;
|
||||
int keys_len = keys.length; int vals_len = vals.length;
|
||||
this.flds = new Db_meta_fld[keys_len + vals_len];
|
||||
for (int i = 0; i < keys_len; ++i)
|
||||
flds[i] = keys[i];
|
||||
for (int i = 0; i < vals_len; ++i)
|
||||
flds[i + keys_len] = vals[i];
|
||||
}
|
||||
public String Name() {return name;} private final String name;
|
||||
public Db_meta_fld[] Flds() {return flds;} private final Db_meta_fld[] flds;
|
||||
public Db_meta_fld[] Keys() {return keys;} private final Db_meta_fld[] keys;
|
||||
public Db_meta_fld[] Vals() {return vals;} private final Db_meta_fld[] vals;
|
||||
public Db_rdr Rdr() {return rdr;} private final Db_rdr rdr;
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
public class Gfdb_rdr_utl_ {
|
||||
public static int Compare(Db_meta_fld[] flds, int len, Db_rdr lhs_rdr, Db_rdr rhs_rdr) {
|
||||
int comp = CompareAble_.Same;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_meta_fld fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
switch (fld.Tid()) {
|
||||
case Db_meta_fld.Tid_bool: comp = Bool_.Compare (lhs_rdr.Read_bool_by_byte(fld_name), rhs_rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Db_meta_fld.Tid_int: comp = Int_.Compare (lhs_rdr.Read_int(fld_name) , rhs_rdr.Read_int(fld_name)); break;
|
||||
case Db_meta_fld.Tid_long: comp = Long_.Compare (lhs_rdr.Read_long(fld_name) , rhs_rdr.Read_long(fld_name)); break;
|
||||
case Db_meta_fld.Tid_float: comp = Float_.Compare (lhs_rdr.Read_float(fld_name) , rhs_rdr.Read_float(fld_name)); break;
|
||||
case Db_meta_fld.Tid_double: comp = Double_.Compare (lhs_rdr.Read_double(fld_name) , rhs_rdr.Read_double(fld_name)); break;
|
||||
case Db_meta_fld.Tid_str: comp = String_.Compare (lhs_rdr.Read_str(fld_name) , rhs_rdr.Read_str(fld_name)); break;
|
||||
case Db_meta_fld.Tid_bry: comp = Bry_.Compare (lhs_rdr.Read_bry(fld_name) , rhs_rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(fld.Tid());
|
||||
}
|
||||
if (comp != CompareAble_.Same) return comp;
|
||||
}
|
||||
return CompareAble_.Same;
|
||||
}
|
||||
public static void Stmt_args(Db_stmt stmt, Db_meta_fld[] flds, int len, Db_rdr rdr) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_meta_fld fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
switch (fld.Tid()) {
|
||||
case Db_meta_fld.Tid_bool: stmt.Val_bool_as_byte (fld_name, rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Db_meta_fld.Tid_byte: stmt.Val_byte (fld_name, rdr.Read_byte(fld_name)); break;
|
||||
case Db_meta_fld.Tid_int: stmt.Val_int (fld_name, rdr.Read_int(fld_name)); break;
|
||||
case Db_meta_fld.Tid_long: stmt.Val_long (fld_name, rdr.Read_long(fld_name)); break;
|
||||
case Db_meta_fld.Tid_float: stmt.Val_float (fld_name, rdr.Read_float(fld_name)); break;
|
||||
case Db_meta_fld.Tid_double: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case Db_meta_fld.Tid_str: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case Db_meta_fld.Tid_bry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(fld.Tid());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; import gplx.dbs.engines.mems.*;
|
||||
public class Gfdb_diff_bldr_tst {
|
||||
private final Gfdb_diff_bldr_fxt fxt = new Gfdb_diff_bldr_fxt();
|
||||
@Test public void Same() {
|
||||
fxt.Init__tbl__lhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__rhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Test__bld();
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt.Init__tbl__lhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__rhs(Object_.Ary(1, "A1") , Object_.Ary(2, "B1"));
|
||||
fxt.Test__bld("U|1|A1", "U|2|B1");
|
||||
}
|
||||
@Test public void Insert() {
|
||||
fxt.Init__tbl__lhs(Object_.Ary(1, "A"));
|
||||
fxt.Init__tbl__rhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Test__bld("I|2|B");
|
||||
}
|
||||
@Test public void Delete() {
|
||||
fxt.Init__tbl__lhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__rhs(Object_.Ary(1, "A"));
|
||||
fxt.Test__bld("D|2");
|
||||
}
|
||||
@Test public void Basic() {
|
||||
fxt.Init__tbl__lhs
|
||||
( Object_.Ary(1, "A")
|
||||
, Object_.Ary(2, "B")
|
||||
, Object_.Ary(3, "C")
|
||||
);
|
||||
fxt.Init__tbl__rhs
|
||||
( Object_.Ary(1, "A")
|
||||
, Object_.Ary(2, "B1")
|
||||
, Object_.Ary(4, "D")
|
||||
);
|
||||
fxt.Test__bld("U|2|B1", "D|3", "I|4|D");
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_bldr_fxt {
|
||||
private final Gfdb_diff_bldr bldr = new Gfdb_diff_bldr();
|
||||
private final Gfdb_diff_wkr__test wkr = new Gfdb_diff_wkr__test();
|
||||
private final Db_meta_fld[] key_flds, val_flds;
|
||||
private Gfdb_diff_tbl lhs_tbl, rhs_tbl;
|
||||
public Gfdb_diff_bldr_fxt() {
|
||||
Db_meta_fld_list fld_list = new Db_meta_fld_list();
|
||||
fld_list.Add_int("id");
|
||||
key_flds = fld_list.To_fld_ary();
|
||||
fld_list.Clear();
|
||||
fld_list.Add_str("val", 255);
|
||||
val_flds = fld_list.To_fld_ary();
|
||||
bldr.Init(wkr);
|
||||
}
|
||||
public void Init__tbl__lhs(Object[]... rows) {this.lhs_tbl = Make__tbl(key_flds, val_flds, rows);}
|
||||
public void Init__tbl__rhs(Object[]... rows) {this.rhs_tbl = Make__tbl(key_flds, val_flds, rows);}
|
||||
public void Test__bld(String... expd) {
|
||||
bldr.Compare(lhs_tbl, rhs_tbl);
|
||||
Tfds.Eq_ary_str(expd, wkr.To_str_ary());
|
||||
}
|
||||
private static Gfdb_diff_tbl Make__tbl(Db_meta_fld[] keys, Db_meta_fld[] vals, Object[][] rows) {
|
||||
int keys_len = keys.length; int vals_len = vals.length;
|
||||
int cols_len = keys_len + vals_len;
|
||||
String[] cols = new String[cols_len];
|
||||
for (int i = 0; i < keys_len; ++i)
|
||||
cols[i] = keys[i].Name();
|
||||
for (int i = 0; i < vals_len; ++i)
|
||||
cols[i + keys_len] = vals[i].Name();
|
||||
|
||||
int rows_len = rows.length;
|
||||
Mem_row[] mem_rows = new Mem_row[rows_len];
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
Object[] row = rows[i];
|
||||
Mem_row mem_row = new Mem_row();
|
||||
mem_rows[i] = mem_row;
|
||||
for (int j = 0; j < cols_len; ++j) {
|
||||
Object cell = row[j];
|
||||
mem_row.Add(cols[j], cell);
|
||||
}
|
||||
}
|
||||
Db_rdr rdr = new Db_rdr__mem(cols, mem_rows);
|
||||
return new Gfdb_diff_tbl("tbl1", keys, vals, rdr);
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_wkr__test implements Gfdb_diff_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private Db_rdr lhs_rdr, rhs_rdr;
|
||||
public void Init_tbls(Gfdb_diff_tbl lhs_tbl, Gfdb_diff_tbl rhs_tbl) {
|
||||
this.lhs_rdr = lhs_tbl.Rdr(); this.rhs_rdr = rhs_tbl.Rdr();
|
||||
}
|
||||
public void Term_tbls() {}
|
||||
public void Handle_same() {
|
||||
String lhs_val = lhs_rdr.Read_str("val");
|
||||
String rhs_val = rhs_rdr.Read_str("val");
|
||||
if (!String_.Eq(lhs_val, rhs_val))
|
||||
list.Add(bfr.Add_str_a7("U").Add_byte_pipe().Add_obj(lhs_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(rhs_val).To_str_and_clear());
|
||||
}
|
||||
public void Handle_lhs_missing() {
|
||||
String rhs_val = rhs_rdr.Read_str("val");
|
||||
list.Add(bfr.Add_str_a7("I").Add_byte_pipe().Add_obj(rhs_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(rhs_val).To_str_and_clear());
|
||||
}
|
||||
public void Handle_rhs_missing() {
|
||||
list.Add(bfr.Add_str_a7("D").Add_byte_pipe().Add_obj(lhs_rdr.Read_obj("id")).To_str_and_clear());
|
||||
}
|
||||
public String[] To_str_ary() {return list.To_str_ary_and_clear();}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
class Gfdb_diff_rdr_comparer {
|
||||
private Db_rdr lhs_rdr, rhs_rdr;
|
||||
private boolean lhs_rdr_move, rhs_rdr_move;
|
||||
private boolean lhs_rdr_done, rhs_rdr_done;
|
||||
private Db_meta_fld[] key_flds; private int key_flds_len;
|
||||
public void Init(Gfdb_diff_tbl lhs_tbl, Gfdb_diff_tbl rhs_tbl) {
|
||||
this.lhs_rdr = lhs_tbl.Rdr(); this.rhs_rdr = rhs_tbl.Rdr();
|
||||
this.lhs_rdr_move = rhs_rdr_move = Bool_.Y;
|
||||
this.lhs_rdr_done = rhs_rdr_done = Bool_.N;
|
||||
this.key_flds = rhs_tbl.Keys(); key_flds_len = key_flds.length;
|
||||
}
|
||||
public int Compare() {
|
||||
if (lhs_rdr_move) {
|
||||
lhs_rdr_move = lhs_rdr.Move_next();
|
||||
if (!lhs_rdr_move) lhs_rdr_done = true;
|
||||
}
|
||||
if (rhs_rdr_move) {
|
||||
rhs_rdr_move = rhs_rdr.Move_next();
|
||||
if (!rhs_rdr_move) rhs_rdr_done = true;
|
||||
}
|
||||
if (lhs_rdr_done && rhs_rdr_done) return Gfdb_diff_rdr_comparer.Rslt__done;
|
||||
else if (lhs_rdr_done) {rhs_rdr_move = true; return Gfdb_diff_rdr_comparer.Rslt__lhs_missing;}
|
||||
else if (rhs_rdr_done) {lhs_rdr_move = true; return Gfdb_diff_rdr_comparer.Rslt__rhs_missing;}
|
||||
else {
|
||||
int comp = Gfdb_rdr_utl_.Compare(key_flds, key_flds_len, lhs_rdr, rhs_rdr);
|
||||
switch (comp) {
|
||||
case CompareAble_.Same: // lhs == rhs; move both
|
||||
lhs_rdr_move = rhs_rdr_move = true;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__same;
|
||||
case CompareAble_.Less: // lhs < rhs; EX: lhs == 2; rhs == 3
|
||||
lhs_rdr_move = true;
|
||||
rhs_rdr_move = false;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__rhs_missing;
|
||||
case CompareAble_.More: // lhs > rhs; EX: lhs == 4; rhs == 3
|
||||
lhs_rdr_move = false;
|
||||
rhs_rdr_move = true;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__lhs_missing;
|
||||
default: throw Err_.new_unhandled(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static final int
|
||||
Rslt__same = 0
|
||||
, Rslt__lhs_missing = 1
|
||||
, Rslt__rhs_missing = 2
|
||||
, Rslt__done = 3
|
||||
;
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.diffs.merges; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
interface Gfdb_diff_cmd {
|
||||
void Merge_undo();
|
||||
void Merge_exec();
|
||||
}
|
||||
class Gfdb_diff_cmd__insert {
|
||||
// else if I
|
||||
// // txn_bgn
|
||||
// // audit
|
||||
// INSERT INTO db_temp.page (diff_type, diff, *)
|
||||
// SELECT 'D', d.page_id, *
|
||||
// FROM db_diff.page d
|
||||
// JOIN db_main.page m ON d.page_id = m.page_id
|
||||
// WHERE d.diff_type = 0
|
||||
// AND d.diff_idx BETWEEN lo and hi
|
||||
//
|
||||
// // update
|
||||
// INSERT INTO db_main.page
|
||||
// SELECT d.page_title
|
||||
// FROM db_diff.page d
|
||||
// JOIN db_main.page m
|
||||
// // txn_end
|
||||
private Db_conn conn;
|
||||
private String exec_sql;
|
||||
public void Init(Db_conn main_conn, Db_conn diff_conn, Db_conn temp_conn, Gfdb_diff_tbl tbl) {
|
||||
this.conn = temp_conn;
|
||||
this.exec_sql = "";
|
||||
// this.exec_sql = String_.Format(String_.Concat_lines_nl_skip_last
|
||||
// ( "INSERT INTO db_curr.{tbl}"
|
||||
// ), Gfdb_diff_cmd_ctx.Alias__curr);
|
||||
}
|
||||
public void Merge_exec() {
|
||||
conn.Exec_sql(exec_sql);
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_cmd_sql_bldr {
|
||||
private final Bry_fmtr fmtr = Bry_fmtr.new_();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
public void Bld_insert(Bry_bfr bfr, String tbl_name, String[] keys, String[] vals, int rng_bgn, int rng_end) {
|
||||
fmtr.Fmt_(Insert__fmt).Keys_(Insert__keys);
|
||||
fmtr.Bld_bfr_many(bfr, tbl_name, Bld_flds(tmp_bfr, ", ", "d.", keys, vals), Bld_join(keys), rng_bgn, rng_end);
|
||||
}
|
||||
public void Bld_update(Bry_bfr bfr, String tbl_name, String[] keys, String[] vals, int rng_bgn, int rng_end) {
|
||||
fmtr.Fmt_(Update__fmt).Keys_(Update__keys);
|
||||
fmtr.Bld_bfr_many(bfr, tbl_name, Bld_flds(tmp_bfr, ", ", "d.", keys, vals), Bld_join(keys), rng_bgn, rng_end);
|
||||
}
|
||||
public void Bld_delete(Bry_bfr bfr, String tbl_name, String[] keys, int rng_bgn, int rng_end) {
|
||||
fmtr.Fmt_(Delete__fmt).Keys_(Delete__keys);
|
||||
fmtr.Bld_bfr_many(bfr, tbl_name, Bld_flds(tmp_bfr, " || '|' || ", "", keys, String_.Ary_empty), Bld_flds(tmp_bfr, " || '|' || ", "k.", keys, String_.Ary_empty), Bld_join(keys), rng_bgn, rng_end);
|
||||
}
|
||||
private static String Bld_flds(Bry_bfr tmp_bfr, String dlm, String alias, String[] keys, String[] vals) {
|
||||
int keys_len = keys.length;
|
||||
for (int i = 0; i < keys_len; ++i) {
|
||||
String key = keys[i];
|
||||
if (i != 0) tmp_bfr.Add_str_a7(dlm);
|
||||
tmp_bfr.Add_str_a7(alias).Add_str_a7(key);
|
||||
}
|
||||
int flds_len = vals.length;
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
String val = vals[i];
|
||||
tmp_bfr.Add_str_a7(dlm);
|
||||
tmp_bfr.Add_str_a7(alias).Add_str_a7(val);
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
private String Bld_join(String[] keys) {
|
||||
int len = keys.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String key = keys[i];
|
||||
tmp_bfr.Add_str_a7(i == 0 ? " ON " : " AND ");
|
||||
tmp_bfr.Add_str_a7("k.").Add_str_a7(key).Add_str_a7(" = ");
|
||||
tmp_bfr.Add_str_a7("d.").Add_str_a7(key);
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
private static final String[] Insert__keys = String_.Ary("tbl", "flds", "join", "rng_bgn", "rng_end");
|
||||
private static final String Insert__fmt = String_.Concat_lines_nl_skip_last
|
||||
( "INSERT INTO db_curr.~{tbl}"
|
||||
, "SELECT ~{flds}"
|
||||
, "FROM db_temp.~{tbl}_pkey k"
|
||||
, " JOIN db_diff.~{tbl} d~{join}"
|
||||
, "WHERE k.diff_type = 1"
|
||||
, "AND k.diff_uid BETWEEN ~{rng_bgn} AND ~{rng_end};"
|
||||
);
|
||||
private static final String[] Update__keys = String_.Ary("tbl", "flds", "join", "rng_bgn", "rng_end");
|
||||
private static final String Update__fmt = String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO db_curr.~{tbl}"
|
||||
, "SELECT ~{flds}"
|
||||
, "FROM db_temp.~{tbl}_pkey k"
|
||||
, " JOIN db_diff.~{tbl} d~{join}"
|
||||
, "WHERE k.diff_type = 2"
|
||||
, "AND k.diff_uid BETWEEN ~{rng_bgn} AND ~{rng_end};"
|
||||
);
|
||||
private static final String[] Delete__keys = String_.Ary("tbl", "pkey_where", "pkey_select", "join", "rng_bgn", "rng_end");
|
||||
private static final String Delete__fmt = String_.Concat_lines_nl_skip_last
|
||||
( "DELETE db_curr.~{tbl}"
|
||||
, "WHERE ~{pkey_where} IN"
|
||||
, "( SELECT ~{pkey_select}"
|
||||
, " FROM db_temp.~{tbl}_pkey k"
|
||||
, " JOIN db_diff.~{tbl} d~{join}"
|
||||
, " WHERE k.diff_type = 0"
|
||||
, " AND k.diff_uid BETWEEN ~{rng_bgn} AND ~{rng_end}"
|
||||
, ");"
|
||||
);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue