mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.6.5.1
This commit is contained in:
66
140_dbs/src_130_misc/gplx/dbs/Db_cmd_backup.java
Normal file
66
140_dbs/src_130_misc/gplx/dbs/Db_cmd_backup.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_cmd_backup implements GfoInvkAble {
|
||||
public String DbName() {return dbName;} public Db_cmd_backup DbName_(String val) {dbName = val; return this;} private String dbName = "db";
|
||||
public Io_url ExeUrl() {return exeUrl;} public Db_cmd_backup ExeUrl_(Io_url val) {exeUrl = val; return this;} Io_url exeUrl;
|
||||
public Io_url BkpDir() {return bkpDir;} public Db_cmd_backup BkpDir_(Io_url val) {bkpDir = val; return this;} Io_url bkpDir;
|
||||
public String Usr() {return usr;} public Db_cmd_backup Usr_(String val) {usr = val; return this;} private String usr;
|
||||
public String Pwd() {return pwd;} public Db_cmd_backup Pwd_(String val) {pwd = val; return this;} private String pwd;
|
||||
public String DteFmt() {return dteFmt;} public Db_cmd_backup DteFmt_(String val) {dteFmt = val; return this;} private String dteFmt = "yyyyMMdd_HHmm";
|
||||
public String BkpFilNameFmt() {return bkpFilNameFmt;} public Db_cmd_backup BkpFilNameFmt_(String val) {bkpFilNameFmt = val; return this;} private String bkpFilNameFmt = "{0}_{1}.sql";
|
||||
public String BkpFilName() {return bkpFilName;} private String bkpFilName;
|
||||
public Io_url BkpFil() {return bkpFil;} Io_url bkpFil;
|
||||
public String CmdText() {return cmdText;} private String cmdText;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_ExeUrl)) return exeUrl;
|
||||
else if (ctx.Match(k, Invk_BkpDir)) return bkpDir;
|
||||
else if (ctx.Match(k, Invk_Usr)) return usr;
|
||||
else if (ctx.Match(k, Invk_Pwd)) return pwd;
|
||||
else if (ctx.Match(k, Invk_DteFmt)) return dteFmt;
|
||||
else if (ctx.Match(k, Invk_BkpFilNameFmt)) return bkpFilNameFmt;
|
||||
else if (ctx.Match(k, Invk_ExeUrl_)) exeUrl = GfoMsgUtl.SetIoUrl(ctx, m, exeUrl);
|
||||
else if (ctx.Match(k, Invk_BkpDir_)) bkpDir = GfoMsgUtl.SetIoUrl(ctx, m, exeUrl);
|
||||
else if (ctx.Match(k, Invk_Usr_)) usr = GfoMsgUtl.SetStr(ctx, m, usr);
|
||||
else if (ctx.Match(k, Invk_Pwd_)) pwd = GfoMsgUtl.SetStr(ctx, m, pwd);
|
||||
else if (ctx.Match(k, Invk_DteFmt_)) dteFmt = GfoMsgUtl.SetStr(ctx, m, dteFmt);
|
||||
else if (ctx.Match(k, Invk_BkpFilNameFmt_)) bkpFilNameFmt = GfoMsgUtl.SetStr(ctx, m, bkpFilNameFmt);
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} public static final String
|
||||
Invk_ExeUrl = "ExeUrl", Invk_BkpDir = "BkpDir", Invk_Usr = "Usr", Invk_Pwd = "Pwd", Invk_DteFmt = "DteFmt", Invk_BkpFilNameFmt = "BkpFilNameFmt"
|
||||
, Invk_ExeUrl_ = "ExeUrl_", Invk_BkpDir_ = "BkpDir_", Invk_Usr_ = "Usr_", Invk_Pwd_ = "Pwd_", Invk_DteFmt_ = "DteFmt_", Invk_BkpFilNameFmt_ = "BkpFilNameFmt_"
|
||||
;
|
||||
public Db_cmd_backup Exec() {
|
||||
this.InitVars();
|
||||
Io_url bkpCmdFil = bkpDir.GenSubFil_ary("backup_", dbName, ".cmd");
|
||||
// Io_url bkpCmdFil = Io_url_.new_dir_("/home/").GenSubFil_ary("backup_", dbName, ".cmd"); // LNX: uncomment
|
||||
Io_mgr._.SaveFilStr_args(bkpCmdFil, cmdText).Exec(); // explicitly state utf8;
|
||||
ProcessAdp.run_wait_(bkpCmdFil);
|
||||
Io_mgr._.DeleteFil(bkpCmdFil);
|
||||
return this;
|
||||
}
|
||||
@gplx.Internal protected Db_cmd_backup InitVars() {
|
||||
String dteStr = DateAdp_.Now().XtoStr_fmt(dteFmt);
|
||||
bkpFilName = String_.Format(bkpFilNameFmt, dbName, dteStr);
|
||||
bkpFil = bkpDir.GenSubFil(bkpFilName);
|
||||
cmdText = String_.Format("\"{0}\" -u {1} -p{2} {3} > {4}", exeUrl.Xto_api(), usr, pwd, dbName, bkpFil.Xto_api());
|
||||
return this;
|
||||
}
|
||||
public static Db_cmd_backup new_() {return new Db_cmd_backup();} Db_cmd_backup() {}
|
||||
}
|
||||
31
140_dbs/src_130_misc/gplx/dbs/Db_cmd_backup_tst.java
Normal file
31
140_dbs/src_130_misc/gplx/dbs/Db_cmd_backup_tst.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class Db_cmd_backup_tst {
|
||||
@Test public void Basic() {
|
||||
Tfds.Now_enabled_y_();
|
||||
Db_cmd_backup bkpWkr = Db_cmd_backup.new_()
|
||||
.ExeUrl_(Io_url_.new_any_("C:\\mysql\\mysqldump.exe"))
|
||||
.BkpDir_(Io_url_.new_any_("C:\\bkp\\"))
|
||||
.Usr_("username")
|
||||
.Pwd_("password")
|
||||
.DbName_("dbname").InitVars();
|
||||
Tfds.Eq("\"C:\\mysql\\mysqldump.exe\" -u username -ppassword dbname > C:\\bkp\\dbname_20010101_0000.sql", bkpWkr.CmdText());
|
||||
}
|
||||
}
|
||||
32
140_dbs/src_130_misc/gplx/dbs/Db_cmd_mode.java
Normal file
32
140_dbs/src_130_misc/gplx/dbs/Db_cmd_mode.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_cmd_mode {
|
||||
public static final byte Create = 1, Update = 2, Delete = 3, Ignore = 4;
|
||||
public static byte X_to_update(byte cur) {
|
||||
switch (cur) {
|
||||
case Create: // ignore update if item is already marked for create
|
||||
case Delete: // ignore update if item is already marked for delete (might want to throw error)
|
||||
return cur;
|
||||
case Ignore: // must mark for update
|
||||
case Update: // return self
|
||||
return Update;
|
||||
default: throw Err_.unhandled(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
52
140_dbs/src_130_misc/gplx/dbs/Db_crt_.java
Normal file
52
140_dbs/src_130_misc/gplx/dbs/Db_crt_.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.criterias.*;
|
||||
public class Db_crt_ {
|
||||
public static final Criteria Wildcard = Criteria_.All;
|
||||
public static Criteria eq_(String name, Object val) {return Criteria_wrapper.new_(name, Criteria_.eq_(val));}
|
||||
public static Criteria eqn_(String name, Object val) {return Criteria_wrapper.new_(name, Criteria_.eqn_(val));}
|
||||
public static Criteria lt_(String name, Comparable val) {return Criteria_wrapper.new_(name, Criteria_.lt_(val));}
|
||||
public static Criteria lte_(String name, Comparable val) {return Criteria_wrapper.new_(name, Criteria_.lte_(val));}
|
||||
public static Criteria mt_(String name, Comparable val) {return Criteria_wrapper.new_(name, Criteria_.mt_(val));}
|
||||
public static Criteria mte_(String name, Comparable val) {return Criteria_wrapper.new_(name, Criteria_.mte_(val));}
|
||||
public static Criteria between_(String name, Comparable lhs, Comparable rhs) {return Criteria_wrapper.new_(name, Criteria_.between_(lhs, rhs));}
|
||||
public static Criteria in_(String name, Object... vals) {return Criteria_wrapper.new_(name, Criteria_.in_(vals));}
|
||||
public static Criteria like_(String name, String pattern) {return Criteria_wrapper.new_(name, Criteria_.like_(pattern));}
|
||||
public static Criteria liken_(String name, String pattern) {return Criteria_wrapper.new_(name, Criteria_.liken_(pattern));}
|
||||
public static Criteria eqMany_(KeyVal... array) {
|
||||
Criteria rv = null;
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
KeyVal pair = array[i];
|
||||
Criteria crt = Db_crt_.eq_(pair.Key(), pair.Val());
|
||||
rv = (i == 0)? crt : Criteria_.And(rv, crt);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static Criteria eq_(String name) {return Criteria_wrapper.new_(name, Criteria_.eq_(null));}
|
||||
public static Criteria eq_many_(String... ary) {
|
||||
Criteria rv = null;
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Criteria crt = Db_crt_.eq_(ary[i], null);
|
||||
rv = (i == 0)? crt : Criteria_.And(rv, crt);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static Criteria wrap_(String name, Criteria crt) {return Criteria_wrapper.new_(name, crt);}
|
||||
}
|
||||
34
140_dbs/src_130_misc/gplx/dbs/Db_idx_itm.java
Normal file
34
140_dbs/src_130_misc/gplx/dbs/Db_idx_itm.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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_idx_itm {
|
||||
public String Xto_sql() {return sql;} private String sql;
|
||||
public static Db_idx_itm sql_(String sql) {
|
||||
Db_idx_itm rv = new Db_idx_itm();
|
||||
rv.sql = sql;
|
||||
return rv;
|
||||
}
|
||||
public static Db_idx_itm[] ary_sql_(String... ary) {
|
||||
int len = ary.length;
|
||||
Db_idx_itm[] rv = new Db_idx_itm[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rv[i] = sql_(ary[i]);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
30
140_dbs/src_130_misc/gplx/dbs/Db_obj_state.java
Normal file
30
140_dbs/src_130_misc/gplx/dbs/Db_obj_state.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_obj_state {
|
||||
public int Val() {return val;} int val;
|
||||
public Db_obj_state MarkUpdated() {return this == Retrieved ? Updated : this;} // Created/Deleted noops
|
||||
public boolean Modified() {return this == Created || this == Updated;}
|
||||
Db_obj_state(int val) {this.val = val;}
|
||||
public static final Db_obj_state
|
||||
Created = new Db_obj_state(1)
|
||||
, Retrieved = new Db_obj_state(2)
|
||||
, Updated = new Db_obj_state(3)
|
||||
, Deleted = new Db_obj_state(4)
|
||||
;
|
||||
}
|
||||
50
140_dbs/src_130_misc/gplx/dbs/PoolIds.java
Normal file
50
140_dbs/src_130_misc/gplx/dbs/PoolIds.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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 PoolIds {
|
||||
public int FetchNext(Db_provider provider, String url) {
|
||||
Db_qry_select cmd = Db_qry_.select_().From_(Tbl_Name).Where_(Db_crt_.eq_(Fld_id_path, url));
|
||||
int rv = 0;//boolean isNew = true;
|
||||
DataRdr rdr = DataRdr_.Null;
|
||||
try {
|
||||
rdr = cmd.Exec_qry_as_rdr(provider);
|
||||
if (rdr.MoveNextPeer()) {
|
||||
rv = rdr.ReadInt(Fld_id_next_id);
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
return rv;
|
||||
}
|
||||
public int FetchNextAndCommit(String dbInfo, String url) {
|
||||
Db_provider provider = Db_provider_pool._.FetchOrNew(dbInfo);
|
||||
int rv = PoolIds._.FetchNext(provider, url);
|
||||
PoolIds._.Commit(provider, url, rv + 1);
|
||||
return rv;
|
||||
}
|
||||
public void Commit(Db_provider provider, String url, int val) {
|
||||
int rv = provider.Exec_qry(Db_qry_.update_(Tbl_Name, Db_crt_.eq_(Fld_id_path, url)).Arg_(Fld_id_path, url).Arg_(Fld_id_next_id, val));
|
||||
if (rv == 0) {
|
||||
rv = provider.Exec_qry(Db_qry_.insert_(Tbl_Name).Arg_(Fld_id_path, url).Arg_(Fld_id_next_id, val));
|
||||
}
|
||||
if (rv != 1) throw Err_.new_("failed to update nextId").Add("provider", provider.ConnectInfo().Raw_of_db_connect()).Add("url", url).Add("nextId", val);
|
||||
}
|
||||
public static final String Tbl_Name = "pool_ids";
|
||||
@gplx.Internal protected static final String Fld_id_path = "id_path";
|
||||
@gplx.Internal protected static final String Fld_id_next_id = "id_next_id";
|
||||
public static final PoolIds _ = new PoolIds(); PoolIds() {}
|
||||
}
|
||||
Reference in New Issue
Block a user