1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Wiki: Support renamed folders (fix)

This commit is contained in:
gnosygnu
2017-02-06 22:12:56 -05:00
parent 6f9e92afff
commit 938beac9f9
4379 changed files with 0 additions and 327818 deletions

View File

@@ -1,46 +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.*;
import gplx.dbs.diffs.itms.*;
import gplx.dbs.diffs.builds.*;
public class Gdif_core {
private final Db_conn conn;
private final Gdif_job_tbl job_tbl;
private final Gdif_cmd_tbl cmd_tbl;
private final Gdif_txn_tbl txn_tbl;
public Gdif_core(Db_conn conn) {
this.conn = conn;
this.db = new Gdif_db(conn);
this.job_tbl = db.Job_tbl();
this.cmd_tbl = db.Cmd_tbl();
this.txn_tbl = db.Txn_tbl();
}
public Gdif_db Db() {return db;} private final Gdif_db db;
public Gdif_job_itm New_job(String name, String made_by) {
int job_id = conn.Sys_mgr().Autonum_next(job_tbl.Tbl_name(), job_tbl.Fld_job_id());
return job_tbl.Insert(job_id, name, made_by, Datetime_now.Get().XtoUtc(), "");
}
public Gdif_cmd_itm New_cmd(Gdif_bldr_ctx ctx, int tid) {
ctx.Cur_cmd_count++;
return cmd_tbl.Insert(ctx.Cur_job.Id, ctx.Cur_cmd_count, tid, "");
}
public Gdif_txn_itm New_txn(Gdif_bldr_ctx ctx, int cmd_id, int owner_txn) {
ctx.Cur_txn_count++;
return txn_tbl.Insert(ctx.Cur_job.Id, ctx.Cur_txn_count, cmd_id, owner_txn);
}
}

View File

@@ -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.diffs; import gplx.*; import gplx.dbs.*;
import gplx.dbs.diffs.itms.*;
public class Gdif_db {
public Gdif_db(Db_conn conn) {
this.conn = conn;
this.job_tbl = new Gdif_job_tbl(conn);
this.cmd_tbl = new Gdif_cmd_tbl(conn);
this.txn_tbl = new Gdif_txn_tbl(conn);
}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public Gdif_job_tbl Job_tbl() {return job_tbl;} private final Gdif_job_tbl job_tbl;
public Gdif_cmd_tbl Cmd_tbl() {return cmd_tbl;} private final Gdif_cmd_tbl cmd_tbl;
public Gdif_txn_tbl Txn_tbl() {return txn_tbl;} private final Gdif_txn_tbl txn_tbl;
}

View File

@@ -1,33 +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 Gdif_db_ {
public static final String
Fld__dif_txn = "dif_txn" // 0+ where 0+ is defined in a tbl
, Fld__dif_uid = "dif_uid" // 0+
, Fld__dif_type = "dif_type" // I,U,D,M
, Fld__dif_db_trg = "dif_db_trg" // -1 for single-db tables; 0+ for multiple-db tables
, Fld__dif_db_src = "dif_db_src" // -1 for I,U,D; 0+ for M
;
public static final byte
Tid__insert = 0
, Tid__update = 1
, Tid__delete = 2
, Tid__move = 3
;
}

View File

@@ -1,58 +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.*;
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(Gdif_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(Gdif_db db) {this.db = db;}
public Gdif_db Db() {return db;} private Gdif_db db;
}

View File

@@ -1,86 +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.*;
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_order(Name, Dbmeta_fld_itm.To_str_ary(Flds), Dbmeta_fld_itm.Str_ary_empty, Dbmeta_fld_itm.To_str_ary(Keys));
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;
}
}

View File

@@ -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.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, "");
*/
}
}

View File

@@ -1,78 +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.*;
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__byte: comp = Byte_.Compare (lhs_rdr.Read_byte(fld_name) , rhs_rdr.Read_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 bgn, int end, Db_rdr rdr) {
for (int i = bgn; i < end; ++i) {
Dbmeta_fld_itm fld = flds[i];
String fld_name = fld.Name();
int tid = fld.Type().Tid_ansi();
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);
}
}
}
public static void Stmt_args(Db_stmt stmt, Dbmeta_fld_list flds, int bgn, int end, Db_rdr rdr) {
for (int i = bgn; i < end; ++i) {
Dbmeta_fld_itm fld = flds.Get_at(i);
String fld_name = fld.Name();
int tid = fld.Type().Tid_ansi();
switch (tid) {
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (fld_name, rdr.Read_bool_by_byte(fld_name)); break;
case Dbmeta_fld_tid.Tid__byte: stmt.Val_byte (fld_name, rdr.Read_byte(fld_name)); break;
case Dbmeta_fld_tid.Tid__int: stmt.Val_int (fld_name, rdr.Read_int(fld_name)); break;
case Dbmeta_fld_tid.Tid__long: stmt.Val_long (fld_name, rdr.Read_long(fld_name)); break;
case Dbmeta_fld_tid.Tid__float: stmt.Val_float (fld_name, rdr.Read_float(fld_name)); break;
case Dbmeta_fld_tid.Tid__double: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
case Dbmeta_fld_tid.Tid__str: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
case Dbmeta_fld_tid.Tid__bry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
default: throw Err_.new_unhandled(tid);
}
}
}
}

View File

@@ -1,38 +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 gplx.dbs.diffs.itms.*;
public class Gdif_bldr_ctx {
public Gdif_bldr_ctx() {}
public Gdif_core Core;
public Gdif_job_itm Cur_job;
public Gdif_cmd_itm Cur_cmd;
public Gdif_txn_itm Cur_txn;
public int Cur_cmd_count;
public int Cur_txn_count;
public Gdif_bldr_ctx Init(Gdif_core core, Gdif_job_itm cur_job) {
this.Core = core; this.Cur_job = cur_job;
return this;
}
public void Clear() {
Cur_cmd_count = 0; Cur_txn_count = 0;
Cur_job = null;
Cur_cmd = null;
Cur_txn = null;
}
}

View File

@@ -1,40 +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 gplx.dbs.*;
public class Gfdb_diff_bldr {
private Gfdb_diff_rdr_comparer rdr_comparer = new Gfdb_diff_rdr_comparer();
private Gfdb_diff_wkr diff_wkr;
public void Init(Gfdb_diff_wkr diff_wkr) {this.diff_wkr = diff_wkr;}
public void Compare(Gdif_bldr_ctx ctx, Gfdb_diff_tbl tbl, Db_conn old_conn, Db_conn new_conn) {
Db_rdr old_rdr = tbl.Make_rdr(old_conn), new_rdr = tbl.Make_rdr(new_conn);
rdr_comparer.Init_rdrs(tbl, old_rdr, new_rdr);
diff_wkr.Init_rdrs(ctx, tbl, old_rdr, new_rdr);
boolean loop = true;
while (loop) {
int rslt = rdr_comparer.Compare();
switch (rslt) {
case Gfdb_diff_rdr_comparer.Rslt__same: diff_wkr.Handle_same(); break;
case Gfdb_diff_rdr_comparer.Rslt__old_missing: diff_wkr.Handle_old_missing(); break;
case Gfdb_diff_rdr_comparer.Rslt__new_missing: diff_wkr.Handle_new_missing(); break;
case Gfdb_diff_rdr_comparer.Rslt__done: loop = false; break;
}
}
diff_wkr.Term_tbls();
}
}

View File

@@ -1,107 +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.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";
private final Gdif_bldr_ctx ctx = new Gdif_bldr_ctx();
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() {
ctx.Clear();
old_conn.Meta_tbl_delete("tbl");
new_conn.Meta_tbl_delete("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(ctx, 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(Gdif_bldr_ctx ctx, Gfdb_diff_tbl tbl, Db_rdr old_rdr, Db_rdr new_rdr) {
this.old_rdr = old_rdr; this.new_rdr = new_rdr;
}
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();}
}

View File

@@ -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 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
;
}

View File

@@ -1,25 +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.*;
public interface Gfdb_diff_wkr {
void Init_rdrs(Gdif_bldr_ctx ctx, Gfdb_diff_tbl tbl, Db_rdr old_rdr, Db_rdr new_rdr);
void Term_tbls();
void Handle_same();
void Handle_old_missing();
void Handle_new_missing();
}

View File

@@ -1,89 +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 gplx.dbs.metas.*; import gplx.dbs.diffs.itms.*;
public class Gfdb_diff_wkr__db implements Gfdb_diff_wkr {
private Dbmeta_fld_itm[] val_flds; private int val_flds_len;
private Gfdb_diff_tbl tbl; private Db_rdr old_rdr, new_rdr;
private Gdif_bldr_ctx ctx;
private Db_conn dif_conn; private Db_stmt stmt;
private int uid, prog_interval, prog_count;
private boolean cmd_create;
public void Init_conn(Gdif_db dif_db, int prog_interval) {this.dif_conn = dif_db.Conn(); this.prog_interval = prog_interval;}
public void Init_rdrs(Gdif_bldr_ctx ctx, Gfdb_diff_tbl tbl, Db_rdr old_rdr, Db_rdr new_rdr) {
this.ctx = ctx; this.tbl = tbl; this.old_rdr = old_rdr; this.new_rdr = new_rdr;
this.val_flds = tbl.Vals; val_flds_len = val_flds.length;
this.uid = 0; this.prog_count = 0;
String dif_tbl = tbl.Name; Dbmeta_fld_itm[] dif_flds = Gfdb_diff_wkr__db_.New_dif_flds(tbl.Flds);
if (!dif_conn.Meta_tbl_exists(dif_tbl)) dif_conn.Meta_tbl_create(Dbmeta_tbl_itm.New(dif_tbl, dif_flds));
this.stmt = dif_conn.Stmt_insert(dif_tbl, Gfdb_diff_wkr__db_.To_str_ary(dif_flds));
dif_conn.Txn_bgn("dif_db_tbl_" + dif_tbl);
cmd_create = true;
}
public void Term_tbls() {
dif_conn.Txn_end();
}
public void Handle_old_missing() {Insert(Gdif_db_.Tid__insert, ++uid, new_rdr, tbl.Flds);}
public void Handle_new_missing() {Insert(Gdif_db_.Tid__delete, ++uid, old_rdr, tbl.Flds);}
public void Handle_same() {
if (Gfdb_rdr_utl_.Compare(val_flds, val_flds_len, old_rdr, new_rdr) != CompareAble_.Same)
Insert(Gdif_db_.Tid__update, ++uid, new_rdr, tbl.Flds);
}
private void Insert(byte dif_type, int uid, Db_rdr rdr, Dbmeta_fld_itm[] flds) {
if (cmd_create) {
cmd_create = false;
ctx.Cur_cmd = ctx.Core.New_cmd(ctx, Gdif_cmd_itm.Tid__data);
ctx.Cur_txn = ctx.Core.New_txn(ctx, ctx.Cur_cmd.Cmd_id, Gdif_txn_itm.Owner_txn__null);
}
stmt.Clear();
stmt.Val_int (Gdif_db_.Fld__dif_txn , ctx.Cur_txn.Txn_id)
.Val_int (Gdif_db_.Fld__dif_uid , uid)
.Val_int (Gdif_db_.Fld__dif_type , dif_type)
.Val_int (Gdif_db_.Fld__dif_db_src , -1)
.Val_int (Gdif_db_.Fld__dif_db_trg , -1);
Gfdb_rdr_utl_.Stmt_args(stmt, flds, 0, flds.length, rdr);
stmt.Exec_insert();
if ((++prog_count % prog_interval) == 0) dif_conn.Txn_sav();
}
}
class Gfdb_diff_wkr__db_ {
public static Dbmeta_fld_itm[] New_dif_flds(Dbmeta_fld_itm[] cur_flds) {
int len = cur_flds.length;
int sys_flds = 5;
Dbmeta_fld_itm[] rv = new Dbmeta_fld_itm[len + sys_flds];
rv[0] = Dbmeta_fld_itm.new_int (Gdif_db_.Fld__dif_txn);
rv[1] = Dbmeta_fld_itm.new_int (Gdif_db_.Fld__dif_uid);
rv[2] = Dbmeta_fld_itm.new_byte (Gdif_db_.Fld__dif_type);
rv[3] = Dbmeta_fld_itm.new_int (Gdif_db_.Fld__dif_db_trg);
rv[4] = Dbmeta_fld_itm.new_int (Gdif_db_.Fld__dif_db_src);
for (int i = 0; i < len; ++i) {
Dbmeta_fld_itm cur_fld = cur_flds[i];
Dbmeta_fld_itm dif_fld = new Dbmeta_fld_itm(cur_fld.Name(), cur_fld.Type());
rv[i + sys_flds] = dif_fld;
}
return rv;
}
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;
}
}

View File

@@ -1,305 +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.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}"
, ");"
);
}

View File

@@ -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.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.Meta_idx_create(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_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");
String name = rdr.Get_str ("fld_name");
int sort_tid = rdr.Get_int ("fld_sort");
cur = new Dbmeta_idx_fld(name, sort_tid);
rdr.Itm_end();
}
public static final Gfdb_diff_cmd__idx__fld Instance = new Gfdb_diff_cmd__idx__fld();
}
// 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();
// }

View File

@@ -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.diffs.cmds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
import org.junit.*;
import gplx.dbs.*; import gplx.dbs.engines.mems.*;
public class Gfdb_diff_cmd_sql_bldr_tst {
private final Gfdb_diff_cmd_sql_bldr_fxt fxt = new Gfdb_diff_cmd_sql_bldr_fxt();
@Test public void Insert() {
fxt.Test__insert("tbl1", String_.Ary("key1", "key2"), String_.Ary("fld1", "fld2"), 0, 99, String_.Concat_lines_nl_skip_last
( "INSERT INTO db_curr.tbl1"
, "SELECT d.key1, d.key2, d.fld1, d.fld2"
, "FROM db_temp.tbl1_pkey k"
, " JOIN db_diff.tbl1 d ON k.key1 = d.key1 AND k.key2 = d.key2"
, "WHERE k.diff_type = 1"
, "AND k.diff_uid BETWEEN 0 AND 99;"
));
}
@Test public void Update() {
fxt.Test__update("tbl1", String_.Ary("key1", "key2"), String_.Ary("fld1", "fld2"), 0, 99, String_.Concat_lines_nl_skip_last
( "REPLACE INTO db_curr.tbl1"
, "SELECT d.key1, d.key2, d.fld1, d.fld2"
, "FROM db_temp.tbl1_pkey k"
, " JOIN db_diff.tbl1 d ON k.key1 = d.key1 AND k.key2 = d.key2"
, "WHERE k.diff_type = 2"
, "AND k.diff_uid BETWEEN 0 AND 99;"
));
}
@Test public void Delete() {
fxt.Test__delete("tbl1", String_.Ary("key1", "key2"), 0, 99, String_.Concat_lines_nl_skip_last
( "DELETE db_curr.tbl1"
, "WHERE key1 || '|' || key2 IN"
, "( SELECT k.key1 || '|' || k.key2"
, " FROM db_temp.tbl1_pkey k"
, " JOIN db_diff.tbl1 d ON k.key1 = d.key1 AND k.key2 = d.key2"
, " WHERE k.diff_type = 0"
, " AND k.diff_uid BETWEEN 0 AND 99"
, ");"
));
}
}
class Gfdb_diff_cmd_sql_bldr_fxt {
private Gfdb_diff_cmd_sql_bldr bldr = new Gfdb_diff_cmd_sql_bldr();
private final Bry_bfr bfr = Bry_bfr_.New();
public void Test__insert(String tbl_name, String[] keys, String[] flds, int rng_bgn, int rng_end, String expd) {
bldr.Bld_insert(bfr, tbl_name, keys, flds, 0, 99);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
public void Test__update(String tbl_name, String[] keys, String[] flds, int rng_bgn, int rng_end, String expd) {
bldr.Bld_update(bfr, tbl_name, keys, flds, 0, 99);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
public void Test__delete(String tbl_name, String[] keys, int rng_bgn, int rng_end, String expd) {
bldr.Bld_delete(bfr, tbl_name, keys, 0, 99);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
}

View File

@@ -1,29 +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.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
public class Gdif_cmd_itm {
public Gdif_cmd_itm(int grp_id, int cmd_id, int tid) {
this.Grp_id = grp_id; this.Cmd_id = cmd_id; this.Tid = tid;
}
public final int Grp_id;
public final int Cmd_id;
public final int Tid;
public String Data;
public static final int Tid__data = 1;
}

View File

@@ -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.diffs.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
public class Gdif_cmd_tbl implements Rls_able {
private String tbl_name = "gdif_cmd";
private String fld_grp_id, fld_cmd_id, fld_tid, fld_data;
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final Db_conn conn; private Db_stmt stmt_insert;
public Gdif_cmd_tbl(Db_conn conn) {
this.conn = conn;
fld_grp_id = flds.Add_int("grp_id"); fld_cmd_id = flds.Add_int("cmd_id"); fld_tid = flds.Add_int("tid"); fld_data = flds.Add_text("data");
conn.Rls_reg(this);
}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_grp_id, fld_cmd_id)));}
public Gdif_cmd_itm Insert(int grp_id, int cmd_id, int tid, String data) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear()
.Val_int(fld_grp_id , grp_id)
.Val_int(fld_cmd_id , cmd_id)
.Val_int(fld_tid , tid)
.Val_str(fld_data , data)
.Exec_insert();
return new Gdif_cmd_itm(grp_id, cmd_id, tid);
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
}

View File

@@ -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.diffs.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
public class Gdif_job_itm {
public Gdif_job_itm(int id, String name, String made_by, DateAdp made_on) {
this.Id = id; this.Name = name; this.Made_by = made_by; this.Made_on = made_on;
}
public final int Id;
public final String Name;
public final String Made_by;
public final DateAdp Made_on;
public String Data;
}

View File

@@ -1,46 +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.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
public class Gdif_job_tbl implements Rls_able {
private String tbl_name = "gdif_job";
private String fld_job_id, fld_name, fld_made_by, fld_made_on, fld_data;
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final Db_conn conn; private Db_stmt stmt_insert;
public Gdif_job_tbl(Db_conn conn) {
this.conn = conn;
fld_job_id = flds.Add_int_pkey("job_id"); fld_name = flds.Add_str("name", 255); fld_made_by = flds.Add_str("made_by", 255); fld_made_on = flds.Add_date("made_on"); fld_data = flds.Add_text("data");
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;}
public String Fld_job_id() {return fld_job_id;}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public Gdif_job_itm Insert(int id, String name, String made_by, DateAdp made_on, String data) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear()
.Val_int(fld_job_id , id)
.Val_str(fld_name , name)
.Val_str(fld_made_by , made_by)
.Val_date(fld_made_on , made_on)
.Val_str(fld_data , data)
.Exec_insert();
return new Gdif_job_itm(id, name, made_by, made_on);
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
}

View File

@@ -1,29 +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.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
public class Gdif_txn_itm {
public Gdif_txn_itm(int job_id, int txn_id, int cmd_id, int owner_txn) {
this.Job_id = job_id; this.Txn_id = txn_id; this.Cmd_id = cmd_id; this.Owner_txn = owner_txn;
}
public final int Job_id;
public final int Txn_id;
public final int Cmd_id;
public final int Owner_txn;
public static final int Owner_txn__null = 0;
}

View File

@@ -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.diffs.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
public class Gdif_txn_tbl implements Rls_able {
private String tbl_name = "gdif_txn";
private String fld_job_id, fld_txn_id, fld_cmd_id, fld_owner_txn;
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final Db_conn conn; private Db_stmt stmt_insert;
public Gdif_txn_tbl(Db_conn conn) {
this.conn = conn;
fld_job_id = flds.Add_int("job_id"); fld_txn_id = flds.Add_int("txn_id"); fld_cmd_id = flds.Add_int("cmd_id"); fld_owner_txn = flds.Add_int("owner_txn");
conn.Rls_reg(this);
}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_job_id, fld_txn_id)));}
public Gdif_txn_itm Insert(int job_id, int txn_id, int cmd_id, int owner_txn) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear()
.Val_int(fld_job_id , job_id)
.Val_int(fld_txn_id , txn_id)
.Val_int(fld_cmd_id , cmd_id)
.Val_int(fld_owner_txn , owner_txn)
.Exec_insert();
return new Gdif_txn_itm(job_id, txn_id, cmd_id, owner_txn);
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
}