mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.2.1
This commit is contained in:
28
400_xowa/src/gplx/dbs/metas/Schema_db_mgr.java
Normal file
28
400_xowa/src/gplx/dbs/metas/Schema_db_mgr.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.metas.updates.*;
|
||||
public class Schema_db_mgr {
|
||||
public Schema_loader_mgr Loader() {return loader;} public void Loader_(Schema_loader_mgr v) {loader = v;} private Schema_loader_mgr loader;
|
||||
public Schema_update_mgr Updater() {return updater;} private final Schema_update_mgr updater = new Schema_update_mgr();
|
||||
public Meta_tbl_mgr Tbl_mgr() {return tbl_mgr;} private final Meta_tbl_mgr tbl_mgr = new Meta_tbl_mgr();
|
||||
public void Init(Db_conn conn) {
|
||||
loader.Load(this, conn);
|
||||
updater.Update(this, conn);
|
||||
}
|
||||
}
|
||||
21
400_xowa/src/gplx/dbs/metas/Schema_loader_mgr.java
Normal file
21
400_xowa/src/gplx/dbs/metas/Schema_loader_mgr.java
Normal file
@@ -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.metas; import gplx.*; import gplx.dbs.*;
|
||||
public interface Schema_loader_mgr {
|
||||
void Load(Schema_db_mgr db_mgr, Db_conn conn);
|
||||
}
|
||||
51
400_xowa/src/gplx/dbs/metas/Schema_loader_mgr_.java
Normal file
51
400_xowa/src/gplx/dbs/metas/Schema_loader_mgr_.java
Normal file
@@ -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; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
public class Schema_loader_mgr_ {
|
||||
public static final Schema_loader_mgr Null = new Schema_loader_mgr__null();
|
||||
public static final Schema_loader_mgr Sqlite = new Schema_loader_mgr__sqlite();
|
||||
}
|
||||
class Schema_loader_mgr__null implements Schema_loader_mgr {
|
||||
public void Load(Schema_db_mgr db_mgr, Db_conn conn) {}
|
||||
}
|
||||
class Schema_loader_mgr__sqlite implements Schema_loader_mgr {
|
||||
public void Load(Schema_db_mgr db_mgr, Db_conn conn) {
|
||||
Gfo_usr_dlg_.I.Log_many("", "", "db.schema.load.bgn: conn=~{0}", conn.Conn_info().Xto_api());
|
||||
Meta_tbl_mgr tbl_mgr = db_mgr.Tbl_mgr();
|
||||
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.new_("sqlite_master", String_.Ary_empty, String_.Ary("type", "name", "sql"), Db_qry__select_in_tbl.Order_by_null);
|
||||
Db_rdr rdr = conn.Stmt_new(qry).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
String type_str = rdr.Read_str("type");
|
||||
String name = rdr.Read_str("name");
|
||||
String sql = rdr.Read_str("sql");
|
||||
int type_int = Meta_itm_tid.Xto_int(type_str);
|
||||
switch (type_int) {
|
||||
case Meta_itm_tid.Tid_table:
|
||||
Meta_tbl_itm tbl_itm = new Meta_tbl_itm(name, sql);
|
||||
tbl_mgr.Add(tbl_itm);
|
||||
break;
|
||||
case Meta_itm_tid.Tid_index: break; // noop for now
|
||||
default: throw Exc_.new_unhandled(type_str);
|
||||
}
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
Gfo_usr_dlg_.I.Log_many("", "", "db.schema.load.end");
|
||||
}
|
||||
}
|
||||
23
400_xowa/src/gplx/dbs/metas/updates/Schema_update_cmd.java
Normal file
23
400_xowa/src/gplx/dbs/metas/updates/Schema_update_cmd.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
public interface Schema_update_cmd {
|
||||
String Name();
|
||||
boolean Exec_is_done();
|
||||
void Exec(Schema_db_mgr mgr, Db_conn conn);
|
||||
}
|
||||
37
400_xowa/src/gplx/dbs/metas/updates/Schema_update_cmd_.java
Normal file
37
400_xowa/src/gplx/dbs/metas/updates/Schema_update_cmd_.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import gplx.dbs.engines.sqlite.*;
|
||||
public class Schema_update_cmd_ {
|
||||
public static Schema_update_cmd Make_tbl_create(String tbl_name, String tbl_sql, Db_idx_itm... tbl_idxs) {return new Schema_update_cmd__tbl_create(tbl_name, tbl_sql, tbl_idxs);}
|
||||
}
|
||||
class Schema_update_cmd__tbl_create implements Schema_update_cmd {
|
||||
private final String tbl_sql; private final Db_idx_itm[] tbl_idxs;
|
||||
public Schema_update_cmd__tbl_create(String tbl_name, String tbl_sql, Db_idx_itm... tbl_idxs) {
|
||||
this.tbl_name = tbl_name; this.tbl_sql = tbl_sql; this.tbl_idxs = tbl_idxs;
|
||||
}
|
||||
public String Name() {return "schema.tbl.create." + tbl_name;} private final String tbl_name;
|
||||
public boolean Exec_is_done() {return exec_is_done;} private boolean exec_is_done;
|
||||
public void Exec(Schema_db_mgr db_mgr, Db_conn conn) {
|
||||
if (db_mgr.Tbl_mgr().Has(tbl_name)) return;
|
||||
Gfo_usr_dlg_.I.Log_many("", "", "schema.tbl.create: tbl=~{0}", tbl_name);
|
||||
Sqlite_engine_.Tbl_create(conn, tbl_name, tbl_sql);
|
||||
Sqlite_engine_.Idx_create(conn, tbl_idxs);
|
||||
exec_is_done = true;
|
||||
}
|
||||
}
|
||||
32
400_xowa/src/gplx/dbs/metas/updates/Schema_update_mgr.java
Normal file
32
400_xowa/src/gplx/dbs/metas/updates/Schema_update_mgr.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.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
public class Schema_update_mgr {
|
||||
private List_adp cmds = List_adp_.new_();
|
||||
public void Add(Schema_update_cmd cmd) {cmds.Add(cmd);}
|
||||
public void Update(Schema_db_mgr schema_mgr, Db_conn conn) {
|
||||
int cmds_len = cmds.Count();
|
||||
for (int i = 0; i < cmds_len; ++i) {
|
||||
Schema_update_cmd cmd = (Schema_update_cmd)cmds.Get_at(i);
|
||||
try {cmd.Exec(schema_mgr, conn);}
|
||||
catch (Exception e) {
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "failed to run update cmd; name=~{0} err=~{1}", cmd.Name(), Err_.Message_gplx_brief(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
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.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import org.junit.*; import gplx.dbs.*;
|
||||
public class Schema_update_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Schema_update_mgr_fxt fxt = new Schema_update_mgr_fxt();
|
||||
@Test public void Create() {
|
||||
fxt.Test_exec_y(new Schema_update_cmd__mock());
|
||||
}
|
||||
@Test public void Delete() {
|
||||
fxt.Init_itm(Meta_itm_tid.Tid_table, Schema_update_cmd__mock.Tbl_name);
|
||||
fxt.Test_exec_n(new Schema_update_cmd__mock());
|
||||
}
|
||||
}
|
||||
class Schema_update_mgr_fxt {
|
||||
private Schema_update_mgr update_mgr; private Schema_db_mgr db_mgr;
|
||||
public void Clear() {
|
||||
update_mgr = new Schema_update_mgr();
|
||||
db_mgr = new Schema_db_mgr();
|
||||
}
|
||||
public void Init_itm(int tid, String name) {
|
||||
db_mgr.Tbl_mgr().Add(new Meta_tbl_itm(name, "sql"));
|
||||
}
|
||||
public void Test_exec_y(Schema_update_cmd cmd) {Test_exec(cmd, Bool_.Y);}
|
||||
public void Test_exec_n(Schema_update_cmd cmd) {Test_exec(cmd, Bool_.N);}
|
||||
private void Test_exec(Schema_update_cmd cmd, boolean expd) {
|
||||
update_mgr.Add(cmd);
|
||||
update_mgr.Update(db_mgr, Db_conn_.Noop);
|
||||
Tfds.Eq(expd, cmd.Exec_is_done());
|
||||
}
|
||||
}
|
||||
class Schema_update_cmd__mock implements Schema_update_cmd {
|
||||
public String Name() {return "xowa.user.cfg_regy.create";}
|
||||
public boolean Exec_is_done() {return exec_is_done;} private boolean exec_is_done;
|
||||
public void Exec(Schema_db_mgr mgr, Db_conn conn) {
|
||||
if (mgr.Tbl_mgr().Has(Tbl_name)) return;
|
||||
exec_is_done = true;
|
||||
}
|
||||
public static final String Tbl_name = "tbl_mock";
|
||||
}
|
||||
Reference in New Issue
Block a user