1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-06-14 21:52:10 -04:00
parent 51e6188c1e
commit fe0ce6340d
159 changed files with 1381 additions and 483 deletions

View File

@@ -44,6 +44,7 @@ public class Db_conn {
public void Ddl_create_idx(Gfo_usr_dlg usr_dlg, Db_meta_idx... idxs) {engine.Ddl_create_idx(usr_dlg, idxs);}
public void Ddl_append_fld(String tbl, Db_meta_fld fld) {engine.Ddl_append_fld(tbl, fld);}
public void Ddl_delete_tbl(String tbl) {engine.Ddl_delete_tbl(tbl);}
public boolean Schema_tbl_exists(String tbl) {return engine.Schema_tbl_exists(tbl);}
public void Rls_reg(RlsAble rls) {rls_list.Add(rls);}
public void Rls_conn() {
int len = rls_list.Count();

View File

@@ -38,4 +38,5 @@ public interface Db_engine {
void Ddl_delete_tbl(String tbl);
void Env_db_attach(String alias, Io_url db_url);
void Env_db_detach(String alias);
boolean Schema_tbl_exists(String name);
}

View File

@@ -74,6 +74,7 @@ public abstract class Db_engine_sql_base implements Db_engine {
public void Ddl_delete_tbl(String tbl) {Exec_as_int(Db_sqlbldr__sqlite.I.Bld_drop_tbl(tbl));}
@gplx.Virtual public void Env_db_attach(String alias, Io_url db_url) {}
@gplx.Virtual public void Env_db_detach(String alias) {}
@gplx.Virtual public boolean Schema_tbl_exists(String name) {return false;}
@gplx.Virtual public DataRdr New_rdr(ResultSet rdr, String sql) {return gplx.stores.Db_data_rdr_.new_(rdr, sql);}
@gplx.Virtual public Sql_qry_wtr SqlWtr() {return Sql_qry_wtr_.new_ansi();}
private Db_rdr New_rdr(Db_stmt stmt, Object rdr, String sql) {

View File

@@ -45,6 +45,7 @@ public class Db_engine__mem implements Db_engine {
public void Ddl_append_fld(String tbl, Db_meta_fld fld) {}
public void Ddl_delete_tbl(String tbl) {}
public void Env_db_attach(String alias, Io_url db_url) {}
public void Env_db_detach(String alias) {}
public void Env_db_detach(String alias) {}
public boolean Schema_tbl_exists(String name) {return tbl_hash.Has(name);}
public static final Db_engine__mem _ = new Db_engine__mem(); Db_engine__mem() {}
}

View File

@@ -38,5 +38,6 @@ public class Null_engine implements Db_engine {
public void Ddl_delete_tbl(String tbl) {}
public void Env_db_attach(String alias, Io_url db_url) {}
public void Env_db_detach(String alias) {}
public boolean Schema_tbl_exists(String name) {return false;}
public static final Null_engine _ = new Null_engine(); Null_engine() {}
}

View File

@@ -20,9 +20,10 @@ import java.sql.*;
import gplx.stores.*; import gplx.dbs.engines.*; import gplx.dbs.engines.sqlite.*;
import gplx.dbs.qrys.*;
public class Sqlite_engine extends Db_engine_sql_base {
private final Sqlite_txn_mgr txn_mgr;
private final Sqlite_txn_mgr txn_mgr; private final Sqlite_schema_mgr schema_mgr;
Sqlite_engine() {
this.txn_mgr = new Sqlite_txn_mgr(this);
this.schema_mgr = new Sqlite_schema_mgr(this);
}
@Override public String Tid() {return Sqlite_conn_info.Tid_const;}
@Override public Db_engine New_clone(Db_conn_info connectInfo) {
@@ -38,6 +39,7 @@ public class Sqlite_engine extends Db_engine_sql_base {
@Override public void Txn_end() {txn_mgr.Txn_end();}
@Override public void Txn_cxl() {txn_mgr.Txn_cxl();}
@Override public void Txn_sav() {txn_mgr.Txn_sav();}
@Override public boolean Schema_tbl_exists(String name) {return schema_mgr.Tbl_exists(name);}
static boolean loaded = false;
@gplx.Internal @Override protected Connection Conn_new() {
if (!loaded) {
@@ -77,7 +79,7 @@ class Db_rdr__sqlite extends Db_rdr__basic { @Override public byte Read_byte(int
@Override public DateAdp Read_date_by_str(String k) {
try {
String val = rdr.getString(k);
return val == null ? null : DateAdp_.parse_fmt(val, "M/dd/yyyy hh:mm tt");
return val == null ? null : DateAdp_.parse_fmt(val, "yyyyMMdd_HHmmss");
} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", k, DateAdp_.Cls_ref_type, Err_.Message_lang(e));}
}
// @Override public DecimalAdp ReadDecimalOr(String key, DecimalAdp or) {

View File

@@ -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.engines.sqlite; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
import gplx.dbs.schemas.*; import gplx.dbs.qrys.*;
public class Sqlite_schema_mgr {
private final Db_engine engine; private boolean init = true;
public Sqlite_schema_mgr(Db_engine engine) {this.engine = engine;}
public Schema_tbl_mgr Tbl_mgr() {return tbl_mgr;} private final Schema_tbl_mgr tbl_mgr = new Schema_tbl_mgr();
public Schema_idx_mgr Idx_mgr() {return idx_mgr;} private final Schema_idx_mgr idx_mgr = new Schema_idx_mgr();
public boolean Tbl_exists(String name) {
if (init) Init(engine);
return tbl_mgr.Has(name);
}
private void Init(Db_engine engine) {
init = false;
Gfo_usr_dlg_.I.Log_many("", "", "db.schema.load.bgn: conn=~{0}", engine.Conn_info().Xto_api());
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.new_("sqlite_master", String_.Ary_empty, String_.Ary("type", "name", "sql"), Db_qry__select_in_tbl.Order_by_null);
Db_rdr rdr = engine.New_stmt_prep(qry).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
String type_str = rdr.Read_str(0);
int type_int = Schema_itm_tid.Xto_int(type_str);
switch (type_int) {
case Schema_itm_tid.Tid_table:
Schema_tbl_itm tbl_itm = new Schema_tbl_itm(rdr.Read_str(1), rdr.Read_str(2));
tbl_mgr.Add(tbl_itm);
break;
case Schema_itm_tid.Tid_index:
Schema_idx_itm idx_itm = new Schema_idx_itm(rdr.Read_str(1), rdr.Read_str(2));
idx_mgr.Add(idx_itm);
break;
default:
Gfo_usr_dlg_.I.Log_many("", "", "db.schema.unknown type: conn=~{0} type=~{1} name=~{2} sql=~{3}", engine.Conn_info().Xto_api(), type_str, rdr.Read_str(1), rdr.Read_str(2));
break;
}
}
} finally {rdr.Rls();}
Gfo_usr_dlg_.I.Log_many("", "", "db.schema.load.end");
}
}

View File

@@ -62,7 +62,8 @@ public class TdbEngine implements Db_engine {
public void Ddl_append_fld(String tbl, Db_meta_fld fld) {throw Err_.not_implemented_();}
public void Ddl_delete_tbl(String tbl) {}
public void Env_db_attach(String alias, Io_url db_url) {}
public void Env_db_detach(String alias) {}
public void Env_db_detach(String alias) {}
public boolean Schema_tbl_exists(String name) {return false;}
Hash_adp wkrs = Hash_adp_.new_(); TdbDbLoadMgr loadMgr = TdbDbLoadMgr.new_(); TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_();
public static final TdbEngine _ = new TdbEngine();

View 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.schemas; import gplx.*; import gplx.dbs.*;
public class Schema_idx_itm {
public Schema_idx_itm(String name, String sql) {this.name = name; this.sql = sql;}
public String Name() {return name;} private final String name;
public String Sql() {return sql;} private final String sql;
}

View File

@@ -0,0 +1,24 @@
/*
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.schemas; import gplx.*; import gplx.dbs.*;
public class Schema_idx_mgr {
private final Ordered_hash hash = Ordered_hash_.new_();
public void Add(Schema_idx_itm itm) {hash.Add(itm.Name(), itm);}
public boolean Has(String name) {return hash.Has(name);}
public Schema_idx_itm Get(String name) {return (Schema_idx_itm)hash.Get_by(name);}
}

View 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.schemas; import gplx.*; import gplx.dbs.*;
public class Schema_itm_tid {
public static final int Tid_unknown = 0, Tid_table = 1, Tid_index = 2;
public static final String Key_table = "table", Key_index = "index";
public static int Xto_int(String s) {
s = String_.Lower(s);
if (String_.Eq(s, Key_table)) return Tid_table;
else if (String_.Eq(s, Key_index)) return Tid_index;
else return Tid_unknown;
}
}

View 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.schemas; import gplx.*; import gplx.dbs.*;
public class Schema_tbl_itm {
public Schema_tbl_itm(String name, String sql) {this.name = name; this.sql = sql;}
public String Name() {return name;} private final String name;
public String Sql() {return sql;} private final String sql;
}

View File

@@ -0,0 +1,24 @@
/*
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.schemas; import gplx.*; import gplx.dbs.*;
public class Schema_tbl_mgr {
private final Ordered_hash hash = Ordered_hash_.new_();
public void Add(Schema_tbl_itm itm) {hash.Add(itm.Name(), itm);}
public boolean Has(String name) {return hash.Has(name);}
public Schema_tbl_itm Get(String name) {return (Schema_tbl_itm)hash.Get_by(name);}
}

View File

@@ -56,7 +56,7 @@ public class Db_data_rdr extends DataRdr_base implements DataRdr {
java.io.InputStream input_stream = rdr.getBinaryStream(key);
return gplx.ios.Io_stream_rdr_.file_(input_stream);
}
catch (SQLException e) {return gplx.ios.Io_stream_rdr_.Null;}
catch (SQLException e) {return gplx.ios.Io_stream_rdr_.Noop;}
}
public boolean MoveNextPeer() {