mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.9.2.1
This commit is contained in:
97
140_dbs/src_100_core/gplx/dbs/Db_conn_info.java
Normal file
97
140_dbs/src_100_core/gplx/dbs/Db_conn_info.java
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
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 interface Db_conn_info {
|
||||
String Key();
|
||||
String Server();
|
||||
String Database();
|
||||
String Str_raw();
|
||||
String Str_api();
|
||||
Db_conn_info Make_new(String raw, GfoMsg m);
|
||||
}
|
||||
class Db_conn_info__null extends Db_conn_info__base {
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "null_db";
|
||||
@Override public Db_conn_info Make_new(String raw, GfoMsg m) {return this;}
|
||||
public static final Db_conn_info__null _ = new Db_conn_info__null(); Db_conn_info__null() {this.Ctor_of_db_connect("", "", "gplx_key=null_db", "");}
|
||||
}
|
||||
class Db_conn_info__mysql extends Db_conn_info__base {
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "mysql";
|
||||
public String Uid() {return uid;} private String uid;
|
||||
public String Pwd() {return pwd;} private String pwd;
|
||||
public static Db_conn_info new_(String server, String database, String uid, String pwd) {
|
||||
return Db_conn_info_.parse_(BldRaw(GfoMsg_.new_cast_("Db_conn_info")
|
||||
.Add("gplx_key", Key_const)
|
||||
.Add("server", server)
|
||||
.Add("database", database)
|
||||
.Add("uid", uid)
|
||||
.Add("pwd", pwd)
|
||||
.Add("charset", "utf8")
|
||||
));
|
||||
}
|
||||
@Override public Db_conn_info Make_new(String raw, GfoMsg m) {
|
||||
Db_conn_info__mysql rv = new Db_conn_info__mysql();
|
||||
rv.Ctor_of_db_connect(m.ReadStr("server"), m.ReadStr("database"), raw, BldApi(m, KeyVal_.new_("charset", "utf8")));
|
||||
rv.uid = m.ReadStr("uid");
|
||||
rv.pwd = m.ReadStr("pwd");
|
||||
return rv;
|
||||
}
|
||||
public static final Db_conn_info__mysql _ = new Db_conn_info__mysql(); Db_conn_info__mysql() {}
|
||||
}
|
||||
class Db_conn_info__postgres extends Db_conn_info__base {
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "postgresql";
|
||||
public String Uid() {return uid;} private String uid;
|
||||
public String Pwd() {return pwd;} private String pwd;
|
||||
public static Db_conn_info new_(String server, String database, String uid, String pwd) {
|
||||
return Db_conn_info_.parse_(BldRaw(GfoMsg_.new_cast_("Db_conn_info")
|
||||
.Add("gplx_key", Key_const)
|
||||
.Add("server", server)
|
||||
.Add("database", database)
|
||||
.Add("port", 5432)
|
||||
.Add("user id", uid)
|
||||
.Add("password", pwd)
|
||||
.Add("encoding", "unicode") // needed for 1.1 provider; otherwise, ascii
|
||||
));
|
||||
}
|
||||
@Override public Db_conn_info Make_new(String raw, GfoMsg m) {
|
||||
Db_conn_info__postgres rv = new Db_conn_info__postgres();
|
||||
rv.Ctor_of_db_connect(m.ReadStr("server"), m.ReadStr("database"), raw, BldApi(m, KeyVal_.new_("encoding", "unicode")));
|
||||
rv.uid = m.ReadStr("user id");
|
||||
rv.pwd = m.ReadStr("password");
|
||||
return rv;
|
||||
}
|
||||
public static final Db_conn_info__postgres _ = new Db_conn_info__postgres(); Db_conn_info__postgres() {}
|
||||
}
|
||||
class Db_conn_info__tdb extends Db_conn_info__base {
|
||||
public Io_url Url() {return url;} Io_url url;
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "tdb";
|
||||
public static Db_conn_info new_(Io_url url) {
|
||||
return Db_conn_info_.parse_(BldRaw(GfoMsg_.new_cast_("Db_conn_info")
|
||||
.Add("gplx_key", Key_const)
|
||||
.Add("url", url.Raw())
|
||||
));
|
||||
} Db_conn_info__tdb() {}
|
||||
@Override public Db_conn_info Make_new(String raw, GfoMsg m) {
|
||||
Db_conn_info__tdb rv = new Db_conn_info__tdb();
|
||||
String urlStr = m.ReadStr("url");
|
||||
Io_url url = Io_url_.new_any_(urlStr);
|
||||
rv.Ctor_of_db_connect(urlStr, url.NameOnly(), raw, BldApi(m));
|
||||
rv.url = url;
|
||||
return rv;
|
||||
}
|
||||
public static final Db_conn_info__tdb _ = new Db_conn_info__tdb();
|
||||
}
|
||||
52
140_dbs/src_100_core/gplx/dbs/Db_conn_info_.java
Normal file
52
140_dbs/src_100_core/gplx/dbs/Db_conn_info_.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.*;
|
||||
public class Db_conn_info_ {
|
||||
public static final Db_conn_info Null = Db_conn_info__null._;
|
||||
public static final Db_conn_info Test = Db_conn_info__mysql.new_("127.0.0.1", "unit_tests", "root", "mysql7760");
|
||||
public static Db_conn_info parse_(String raw) {return Db_conn_info_pool._.Parse(raw);}
|
||||
public static Db_conn_info sqlite_(Io_url url) {return Db_conn_info__sqlite.load_(url);}
|
||||
public static Db_conn_info tdb_(Io_url url) {return Db_conn_info__tdb.new_(url);}
|
||||
public static final String Key_tdb = TdbEngine.KeyDef;
|
||||
}
|
||||
class Db_conn_info_pool {
|
||||
private OrderedHash regy = OrderedHash_.new_();
|
||||
public Db_conn_info_pool() {
|
||||
this.Add(Db_conn_info__null._).Add(Db_conn_info__tdb._).Add(Db_conn_info__mysql._).Add(Db_conn_info__postgres._).Add(Db_conn_info__sqlite._);
|
||||
}
|
||||
public Db_conn_info_pool Add(Db_conn_info itm) {regy.AddReplace(itm.Key(), itm); return this;}
|
||||
public Db_conn_info Parse(String raw) {// assume each pair has format of: name=val;
|
||||
try {
|
||||
GfoMsg m = GfoMsg_.new_parse_("db_conn_info");
|
||||
String[] terms = String_.Split(raw, ";");
|
||||
String conn_info_key = "";
|
||||
for (String term : terms) {
|
||||
if (String_.Len(term) == 0) continue;
|
||||
String[] kv = String_.Split(term, "=");
|
||||
if (String_.Eq(kv[0], "gplx_key"))
|
||||
conn_info_key = kv[1]; // NOTE: do not add to GfoMsg; will not be part of ApiStr
|
||||
else
|
||||
m.Add(kv[0], kv[1]);
|
||||
}
|
||||
Db_conn_info prototype = (Db_conn_info)regy.Fetch(conn_info_key);
|
||||
return prototype.Make_new(raw, m);
|
||||
}
|
||||
catch(Exception exc) {throw Err_.parse_type_exc_(exc, Db_conn_info.class, raw);}
|
||||
}
|
||||
public static final Db_conn_info_pool _ = new Db_conn_info_pool();
|
||||
}
|
||||
@@ -16,14 +16,15 @@ 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 abstract class Db_connect_base implements Db_connect {
|
||||
public abstract String Key_of_db_connect();
|
||||
public String Database() {return database;} public Db_connect_base Database_(String v) {database = v; return this;} private String database = "";
|
||||
public String Server() {return server;} public Db_connect_base Server_(String v) {server = v; return this;} private String server = "";
|
||||
public String Raw_of_db_connect() {return raw;} public Db_connect XtoStr_raw_(String v) {raw = v; return this;} private String raw = "";
|
||||
public String Api_of_db_connect() {return api;} public Db_connect XtoStr_std_(String v) {api = v; return this;} private String api = "";
|
||||
public abstract Db_connect Clone_of_db_connect(String raw, GfoMsg m);
|
||||
public abstract class Db_conn_info__base implements Db_conn_info {
|
||||
public abstract String Key();
|
||||
public String Database() {return database;} public Db_conn_info__base Database_(String v) {database = v; return this;} private String database = "";
|
||||
public String Server() {return server;} public Db_conn_info__base Server_(String v) {server = v; return this;} private String server = "";
|
||||
public String Str_raw() {return raw;} public Db_conn_info XtoStr_raw_(String v) {raw = v; return this;} private String raw = "";
|
||||
public String Str_api() {return api;} public Db_conn_info XtoStr_std_(String v) {api = v; return this;} private String api = "";
|
||||
public abstract Db_conn_info Make_new(String raw, GfoMsg m);
|
||||
protected void Ctor_of_db_connect(String server, String database, String raw, String api) {this.server = server; this.database = database; this.raw = raw; this.api = api;}
|
||||
|
||||
protected static String BldApi(GfoMsg m, KeyVal... xtnAry) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
HashAdp hash = HashAdp_.new_();
|
||||
@@ -16,30 +16,30 @@ 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_connect_sqlite extends Db_connect_base {
|
||||
@Override public String Key_of_db_connect() {return KeyDef;} public static final String KeyDef = "sqlite";
|
||||
public Io_url Url() {return url;} Io_url url;
|
||||
public static Db_connect load_(Io_url url) {
|
||||
return Db_connect_.parse_(BldRaw(GfoMsg_.new_cast_("Db_connect")
|
||||
.Add("gplx_key", KeyDef)
|
||||
public class Db_conn_info__sqlite extends Db_conn_info__base {
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "sqlite";
|
||||
public Io_url Url() {return url;} private Io_url url;
|
||||
public static Db_conn_info load_(Io_url url) {
|
||||
return Db_conn_info_.parse_(BldRaw(GfoMsg_.new_cast_("Db_conn_info")
|
||||
.Add("gplx_key", Key_const)
|
||||
.Add("data source", url.Xto_api())
|
||||
.Add("version", 3)
|
||||
));
|
||||
}
|
||||
public static Db_connect make_(Io_url url) {
|
||||
public static Db_conn_info make_(Io_url url) {
|
||||
Io_mgr._.CreateDirIfAbsent(url.OwnerDir());
|
||||
return Db_connect_.parse_(BldRaw(GfoMsg_.new_cast_("Db_connect")
|
||||
.Add("gplx_key", KeyDef)
|
||||
return Db_conn_info_.parse_(BldRaw(GfoMsg_.new_cast_("Db_conn_info")
|
||||
.Add("gplx_key", Key_const)
|
||||
.Add("data source", url.Xto_api())
|
||||
.Add("version", 3)
|
||||
));
|
||||
}
|
||||
@Override public Db_connect Clone_of_db_connect(String raw, GfoMsg m) {
|
||||
Db_connect_sqlite rv = new Db_connect_sqlite();
|
||||
String dataSourceUrl = m.ReadStr("data source");
|
||||
rv.url = Io_url_.new_any_(dataSourceUrl);
|
||||
rv.Ctor_of_db_connect("", dataSourceUrl, raw, BldApi(m, KeyVal_.new_("version", "3")));
|
||||
@Override public Db_conn_info Make_new(String raw, GfoMsg m) {
|
||||
Db_conn_info__sqlite rv = new Db_conn_info__sqlite();
|
||||
String url = m.ReadStr("data source");
|
||||
rv.url = Io_url_.new_any_(url);
|
||||
rv.Ctor_of_db_connect("", url, raw, BldApi(m, KeyVal_.new_("version", "3")));
|
||||
return rv;
|
||||
}
|
||||
public static final Db_connect_sqlite _ = new Db_connect_sqlite(); Db_connect_sqlite() {}
|
||||
public static final Db_conn_info__sqlite _ = new Db_conn_info__sqlite(); Db_conn_info__sqlite() {}
|
||||
}
|
||||
@@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class Db_connect_tst {
|
||||
public class Db_conn_info_tst {
|
||||
@Before public void setup() {
|
||||
regy = new Db_connect_pool();
|
||||
regy.Add(Db_connect_mock._);
|
||||
} Db_connect_pool regy;
|
||||
regy = new Db_conn_info_pool();
|
||||
regy.Add(Db_conn_info_mock._);
|
||||
} Db_conn_info_pool regy;
|
||||
@Test public void Parse() {
|
||||
tst_Parse("gplx_key=mock;id=1;", kv_("id", "1")); // one; gplx_key removed
|
||||
tst_Parse("gplx_key=mock;id=1;name=me;", kv_("id", "1"), kv_("name", "me")); // many
|
||||
@@ -29,19 +29,19 @@ public class Db_connect_tst {
|
||||
}
|
||||
KeyVal kv_(String key, Object val) {return KeyVal_.new_(key, val);}
|
||||
void tst_Parse(String raw, KeyVal... expd) {
|
||||
Db_connect_mock mock = (Db_connect_mock)regy.Parse(raw);
|
||||
Db_conn_info_mock mock = (Db_conn_info_mock)regy.Parse(raw);
|
||||
Tfds.Eq_ary_str(expd, mock.Kvs());
|
||||
}
|
||||
}
|
||||
class Db_connect_mock extends Db_connect_base {
|
||||
class Db_conn_info_mock extends Db_conn_info__base {
|
||||
public KeyVal[] Kvs() {return kvs;} KeyVal[] kvs;
|
||||
@Override public String Key_of_db_connect() {return KeyDef;} public static final String KeyDef = "mock";
|
||||
@Override public Db_connect Clone_of_db_connect(String raw, GfoMsg m) {
|
||||
Db_connect_mock rv = new Db_connect_mock();
|
||||
@Override public String Key() {return Key_const;} public static final String Key_const = "mock";
|
||||
@Override public Db_conn_info Make_new(String raw, GfoMsg m) {
|
||||
Db_conn_info_mock rv = new Db_conn_info_mock();
|
||||
rv.kvs = new KeyVal[m.Args_count()];
|
||||
for (int i = 0; i < m.Args_count(); i++)
|
||||
rv.kvs[i] = m.Args_getAt(i);
|
||||
return rv;
|
||||
}
|
||||
public static final Db_connect_mock _ = new Db_connect_mock(); Db_connect_mock() {}
|
||||
public static final Db_conn_info_mock _ = new Db_conn_info_mock(); Db_conn_info_mock() {}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public interface Db_connect {
|
||||
String Key_of_db_connect();
|
||||
String Server();
|
||||
String Database();
|
||||
String Raw_of_db_connect();
|
||||
String Api_of_db_connect();
|
||||
Db_connect Clone_of_db_connect(String raw, GfoMsg m);
|
||||
}
|
||||
class Db_connect_null extends Db_connect_base {
|
||||
@Override public String Key_of_db_connect() {return KeyDef;} public static final String KeyDef = "null_db";
|
||||
@Override public Db_connect Clone_of_db_connect(String raw, GfoMsg m) {return this;}
|
||||
public static final Db_connect_null _ = new Db_connect_null(); Db_connect_null() {this.Ctor_of_db_connect("", "", "gplx_key=null_db", "");}
|
||||
}
|
||||
class Db_connect_mysql extends Db_connect_base {
|
||||
public String Uid() {return uid;} private String uid;
|
||||
public String Pwd() {return pwd;} private String pwd;
|
||||
@Override public String Key_of_db_connect() {return KeyDef;} public static final String KeyDef = "mysql";
|
||||
public static Db_connect new_(String server, String database, String uid, String pwd) {
|
||||
return Db_connect_.parse_(BldRaw(GfoMsg_.new_cast_("Db_connect")
|
||||
.Add("gplx_key", KeyDef)
|
||||
.Add("server", server)
|
||||
.Add("database", database)
|
||||
.Add("uid", uid)
|
||||
.Add("pwd", pwd)
|
||||
.Add("charset", "utf8")
|
||||
));
|
||||
}
|
||||
@Override public Db_connect Clone_of_db_connect(String raw, GfoMsg m) {
|
||||
Db_connect_mysql rv = new Db_connect_mysql();
|
||||
rv.Ctor_of_db_connect(m.ReadStr("server"), m.ReadStr("database"), raw, BldApi(m, KeyVal_.new_("charset", "utf8")));
|
||||
rv.uid = m.ReadStr("uid");
|
||||
rv.pwd = m.ReadStr("pwd");
|
||||
return rv;
|
||||
}
|
||||
public static final Db_connect_mysql _ = new Db_connect_mysql(); Db_connect_mysql() {}
|
||||
}
|
||||
class Db_connect_postgres extends Db_connect_base {
|
||||
public String Uid() {return uid;} private String uid;
|
||||
public String Pwd() {return pwd;} private String pwd;
|
||||
@Override public String Key_of_db_connect() {return KeyDef;} public static final String KeyDef = "postgresql";
|
||||
public static Db_connect new_(String server, String database, String uid, String pwd) {
|
||||
return Db_connect_.parse_(BldRaw(GfoMsg_.new_cast_("Db_connect")
|
||||
.Add("gplx_key", KeyDef)
|
||||
.Add("server", server)
|
||||
.Add("database", database)
|
||||
.Add("port", 5432)
|
||||
.Add("user id", uid)
|
||||
.Add("password", pwd)
|
||||
.Add("encoding", "unicode") // needed for 1.1 provider; otherwise, ascii
|
||||
));
|
||||
}
|
||||
@Override public Db_connect Clone_of_db_connect(String raw, GfoMsg m) {
|
||||
Db_connect_postgres rv = new Db_connect_postgres();
|
||||
rv.Ctor_of_db_connect(m.ReadStr("server"), m.ReadStr("database"), raw, BldApi(m, KeyVal_.new_("encoding", "unicode")));
|
||||
rv.uid = m.ReadStr("user id");
|
||||
rv.pwd = m.ReadStr("password");
|
||||
return rv;
|
||||
}
|
||||
public static final Db_connect_postgres _ = new Db_connect_postgres(); Db_connect_postgres() {}
|
||||
}
|
||||
class Db_connect_tdb extends Db_connect_base {
|
||||
public Io_url Url() {return url;} Io_url url;
|
||||
@Override public String Key_of_db_connect() {return KeyDef;} public static final String KeyDef = "tdb";
|
||||
public static Db_connect new_(Io_url url) {
|
||||
return Db_connect_.parse_(BldRaw(GfoMsg_.new_cast_("Db_connect")
|
||||
.Add("gplx_key", KeyDef)
|
||||
.Add("url", url.Raw())
|
||||
));
|
||||
} Db_connect_tdb() {}
|
||||
@Override public Db_connect Clone_of_db_connect(String raw, GfoMsg m) {
|
||||
Db_connect_tdb rv = new Db_connect_tdb();
|
||||
String urlStr = m.ReadStr("url");
|
||||
Io_url url = Io_url_.new_any_(urlStr);
|
||||
rv.Ctor_of_db_connect(urlStr, url.NameOnly(), raw, BldApi(m));
|
||||
rv.url = url;
|
||||
return rv;
|
||||
}
|
||||
public static final Db_connect_tdb _ = new Db_connect_tdb();
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_connect_ {
|
||||
public static final Db_connect Null = Db_connect_null._;
|
||||
public static final Db_connect Test = Db_connect_mysql.new_("127.0.0.1", "unit_tests", "root", "mysql7760");
|
||||
public static Db_connect parse_(String raw) {return Db_connect_pool._.Parse(raw);}
|
||||
public static Db_connect tdb_(Io_url url) {return Db_connect_tdb.new_(url);}
|
||||
public static Db_connect sqlite_(Io_url url) {return Db_connect_sqlite.load_(url);}
|
||||
public static final String TdbKey = TdbEngine.KeyDef;
|
||||
}
|
||||
class Db_connect_pool {
|
||||
public Db_connect_pool() {
|
||||
this.Add(Db_connect_null._).Add(Db_connect_tdb._).Add(Db_connect_mysql._).Add(Db_connect_postgres._).Add(Db_connect_sqlite._);
|
||||
}
|
||||
public Db_connect_pool Add(Db_connect prototype) {regy.AddReplace(prototype.Key_of_db_connect(), prototype); return this;}
|
||||
public Db_connect Parse(String raw) {// assume each pair has format of: name=val;
|
||||
try {
|
||||
GfoMsg m = GfoMsg_.new_parse_("dbConnectionString");
|
||||
String[] terms = String_.Split(raw, ";");
|
||||
String gplxKey = "";
|
||||
for (String term : terms) {
|
||||
if (String_.Len(term) == 0) continue;
|
||||
String[] kv = String_.Split(term, "=");
|
||||
if (String_.Eq(kv[0], "gplx_key"))
|
||||
gplxKey = kv[1]; // NOTE: do not add to GfoMsg; will not be part of ApiStr
|
||||
else
|
||||
m.Add(kv[0], kv[1]);
|
||||
}
|
||||
Db_connect prototype = (Db_connect)regy.Fetch(gplxKey);
|
||||
return prototype.Clone_of_db_connect(raw, m);
|
||||
}
|
||||
catch(Exception exc) {throw Err_.parse_type_exc_(exc, Db_connect.class, raw);}
|
||||
}
|
||||
OrderedHash regy = OrderedHash_.new_();
|
||||
public static final Db_connect_pool _ = new Db_connect_pool();
|
||||
}
|
||||
@@ -16,21 +16,22 @@ 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_provider implements RlsAble {
|
||||
public class Db_provider {
|
||||
@gplx.Internal protected Db_provider(Db_engine engine) {
|
||||
this.engine = engine;
|
||||
txn_mgr = new Db_txn_mgr_base(engine);
|
||||
this.txn_mgr = new Db_txn_mgr_base(engine);
|
||||
}
|
||||
@gplx.Internal protected Db_engine Engine() {return engine;} private Db_engine engine;
|
||||
public Db_connect ConnectInfo() {return engine.ConnectInfo();}
|
||||
public Db_stmt Prepare(Db_qry qry) {return engine.New_db_stmt(this, qry);}
|
||||
public int Exec_qry(Db_qry qry) {txn_mgr.Txn_count_(txn_mgr.Txn_count() + 1); return Int_.cast_(engine.Execute(qry));}
|
||||
public DataRdr Exec_qry_as_rdr(Db_qry qry) {return DataRdr_.cast_(engine.Execute(qry));}
|
||||
public int Exec_sql(String sql) {return this.Exec_qry(Db_qry_sql.dml_(sql));}
|
||||
public DataRdr Exec_sql_as_rdr(String sql) {return this.Exec_qry_as_rdr(Db_qry_sql.rdr_(sql));}
|
||||
public Db_txn_mgr Txn_mgr() {return txn_mgr;} Db_txn_mgr txn_mgr;
|
||||
public void Rls() {
|
||||
engine.Rls();
|
||||
Db_provider_pool._.Del(this.ConnectInfo()); // remove from pool, else rls'd instance will be cached and fail upon next use
|
||||
public Db_conn_info Conn_info() {return engine.Conn_info();}
|
||||
public Db_engine Engine() {return engine;} private final Db_engine engine;
|
||||
public Db_txn_mgr Txn_mgr() {return txn_mgr;} private final Db_txn_mgr txn_mgr;
|
||||
|
||||
public Db_stmt Prepare(Db_qry qry) {return engine.New_db_stmt(this, qry);}
|
||||
public int Exec_qry(Db_qry qry) {txn_mgr.Txn_count_(txn_mgr.Txn_count() + 1); return Int_.cast_(engine.Execute(qry));}
|
||||
public DataRdr Exec_qry_as_rdr(Db_qry qry) {return DataRdr_.cast_(engine.Execute(qry));}
|
||||
public int Exec_sql(String sql) {return this.Exec_qry(Db_qry_sql.dml_(sql));}
|
||||
public DataRdr Exec_sql_as_rdr(String sql) {return this.Exec_qry_as_rdr(Db_qry_sql.rdr_(sql));}
|
||||
public void Conn_term() {
|
||||
engine.Conn_term();
|
||||
Db_provider_pool._.Del(this.Conn_info()); // remove from pool, else rls'd instance will be cached and fail upon next use
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,13 @@ 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_provider_ {
|
||||
public static final Db_provider Null = new_(Db_connect_.Null);
|
||||
public static Db_provider new_(Db_connect dbInfo) {
|
||||
Db_engine prototype = Db_engineRegy._.Get(dbInfo.Key_of_db_connect());
|
||||
Db_engine engine = prototype.MakeEngine(dbInfo);
|
||||
engine.Connect();
|
||||
Db_provider rv = new Db_provider(engine);
|
||||
// Env_.Dispose_reg(rv); // NOTE: need to dispose or else mysql error: Unable to release semaphore
|
||||
return rv;
|
||||
public class Db_provider_ {
|
||||
public static final Db_provider Null = new_and_open_(Db_conn_info_.Null);
|
||||
public static Db_provider new_and_open_(Db_conn_info conn_info) {
|
||||
Db_engine prototype = Db_engine_regy._.Get(conn_info.Key());
|
||||
Db_engine engine = prototype.Make_new(conn_info);
|
||||
engine.Conn_open(); // auto-open
|
||||
return new Db_provider(engine);
|
||||
}
|
||||
public static int Select_fld0_as_int_or(Db_provider p, String sql, int or) {
|
||||
DataRdr rdr = DataRdr_.Null;
|
||||
@@ -43,10 +41,3 @@ public class Db_provider_ {
|
||||
}
|
||||
}
|
||||
}
|
||||
class Db_engineRegy {
|
||||
public Db_engine Get(String key) {return (Db_engine)hash.FetchOrFail(key);}
|
||||
HashAdp hash = HashAdp_.new_();
|
||||
Db_engineRegy Add(Db_engine engine) {hash.Add(engine.Key(), engine); return this;}
|
||||
Db_engineRegy() {this.Add(Db_engine_null._).Add(TdbEngine._).Add(Mysql_engine._).Add(Postgres_engine._).Add(Sqlite_engine._);}
|
||||
public static final Db_engineRegy _ = new Db_engineRegy();
|
||||
}
|
||||
|
||||
@@ -16,25 +16,25 @@ 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_provider_pool {
|
||||
public void Del(Db_connect connectInfo) {hash.Del(connectInfo.Raw_of_db_connect());}
|
||||
public Db_provider FetchOrNew(Db_connect connectInfo) {return FetchOrNew(connectInfo.Raw_of_db_connect());}
|
||||
public Db_provider FetchOrNew(String raw) {
|
||||
public class Db_provider_pool {
|
||||
private final OrderedHash hash = OrderedHash_.new_();
|
||||
public Db_provider Get_or_new(Db_conn_info connectInfo) {return Get_or_new(connectInfo.Str_raw());}
|
||||
public Db_provider Get_or_new(String raw) {
|
||||
Db_provider rv = (Db_provider)hash.Fetch(raw);
|
||||
if (rv == null) {
|
||||
rv = Db_provider_.new_(Db_connect_.parse_(raw));
|
||||
rv = Db_provider_.new_and_open_(Db_conn_info_.parse_(raw));
|
||||
hash.Add(raw, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Del(Db_conn_info connectInfo) {hash.Del(connectInfo.Str_raw());}
|
||||
public void Clear() {
|
||||
for (int i = 0; i < hash.Count(); i++) {
|
||||
Db_provider provider = (Db_provider)hash.FetchAt(i);
|
||||
provider.Rls();
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Db_provider provider = (Db_provider)hash.FetchAt(0);
|
||||
provider.Conn_term();
|
||||
}
|
||||
hash.Clear();
|
||||
}
|
||||
OrderedHash hash = OrderedHash_.new_();
|
||||
@gplx.Internal protected static Db_provider_pool new_() {return new Db_provider_pool();} Db_provider_pool() {}
|
||||
public static final Db_provider_pool _ = new Db_provider_pool();
|
||||
}
|
||||
public static final Db_provider_pool _ = new Db_provider_pool(); Db_provider_pool() {}
|
||||
}
|
||||
|
||||
30
140_dbs/src_100_core/gplx/dbs/Db_rdr.java
Normal file
30
140_dbs/src_100_core/gplx/dbs/Db_rdr.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 interface Db_rdr {
|
||||
boolean Move_next();
|
||||
byte[] Read_bry(int i);
|
||||
byte[] Read_bry_by_str(int i);
|
||||
String Read_str(int i);
|
||||
byte Read_byte(int i);
|
||||
int Read_int(int i);
|
||||
long Read_long(int i);
|
||||
float Read_float(int i);
|
||||
double Read_double(int i);
|
||||
void Close();
|
||||
}
|
||||
33
140_dbs/src_100_core/gplx/dbs/Db_rdr_.java
Normal file
33
140_dbs/src_100_core/gplx/dbs/Db_rdr_.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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_rdr_ {
|
||||
public static final Db_rdr Null = new Db_rdr__null();
|
||||
}
|
||||
class Db_rdr__null implements Db_rdr {
|
||||
public boolean Move_next() {return false;}
|
||||
public byte[] Read_bry(int i) {return Bry_.Empty;}
|
||||
public byte[] Read_bry_by_str(int i) {return Bry_.Empty;}
|
||||
public byte Read_byte(int i) {return Byte_.MaxValue_127;}
|
||||
public String Read_str(int i) {return String_.Empty;}
|
||||
public int Read_int(int i) {return Int_.MinValue;}
|
||||
public long Read_long(int i) {return Long_.MinValue;}
|
||||
public float Read_float(int i) {return Float_.NaN;}
|
||||
public double Read_double(int i) {return Double_.NaN;}
|
||||
public void Close() {}
|
||||
}
|
||||
37
140_dbs/src_100_core/gplx/dbs/Db_rdr__basic.java
Normal file
37
140_dbs/src_100_core/gplx/dbs/Db_rdr__basic.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; import gplx.*;
|
||||
import java.sql.ResultSet;
|
||||
class Db_rdr__basic implements Db_rdr {
|
||||
private final ResultSet rdr;
|
||||
public Db_rdr__basic(ResultSet rdr, String sql) {this.rdr = rdr; this.sql = sql;}
|
||||
public String Sql() {return sql;} private final String sql;
|
||||
public boolean Move_next() {
|
||||
try {return rdr.next();}
|
||||
catch (Exception e) {throw Err_.new_fmt_("move_next failed; check column casting error in SQL: err={0} sql={1}", Err_.Message_lang(e), sql);}
|
||||
}
|
||||
public byte[] Read_bry(int i) {try {return rdr.getBytes(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Bry_.Cls_name, Err_.Message_lang(e));}}
|
||||
public byte[] Read_bry_by_str(int i) {try {return Bry_.new_utf8_(rdr.getString(i));} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, String_.Cls_name, Err_.Message_lang(e));}}
|
||||
public String Read_str(int i) {try {return rdr.getString(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, String_.Cls_name, Err_.Message_lang(e));}}
|
||||
public int Read_int(int i) {try {return rdr.getInt(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Int_.Cls_name, Err_.Message_lang(e));}}
|
||||
public long Read_long(int i) {try {return rdr.getLong(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Long_.Cls_name, Err_.Message_lang(e));}}
|
||||
public float Read_float(int i) {try {return rdr.getFloat(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Float_.Cls_name, Err_.Message_lang(e));}}
|
||||
public double Read_double(int i) {try {return rdr.getDouble(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Double_.Cls_name, Err_.Message_lang(e));}}
|
||||
public byte Read_byte(int i) {try {return rdr.getByte(i);} catch (Exception e) {throw Err_.new_("read failed: i={0} type={1} err={2}", i, Byte_.Cls_name, Err_.Message_lang(e));}}
|
||||
public void Close() {try {rdr.close();} catch (Exception e) {throw Err_.new_("close failed: err={0}", Err_.Message_lang(e));}}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public interface Db_qry {
|
||||
int Tid();
|
||||
String KeyOfDb_qry();
|
||||
boolean ExecRdrAble();
|
||||
String XtoSql();
|
||||
|
||||
@@ -47,6 +47,7 @@ public class Db_qry_ {
|
||||
}
|
||||
public static final Object WhereAll = null;
|
||||
public static Db_qry as_(Object obj) {return obj instanceof Db_qry ? (Db_qry)obj : null;}
|
||||
public static final int Tid_basic = 0, Tid_select_in_tbl = 1;
|
||||
}
|
||||
interface Db_qryWkr {
|
||||
Object Exec(Db_engine engine, Db_qry cmd);
|
||||
|
||||
60
140_dbs/src_110_dbQry/gplx/dbs/Db_qry__select_in_tbl.java
Normal file
60
140_dbs/src_110_dbQry/gplx/dbs/Db_qry__select_in_tbl.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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_qry__select_in_tbl implements Db_qry {
|
||||
public Db_qry__select_in_tbl(String tbl_name, String[] select_flds, String[] where_flds, String group_by_sql, String having_sql, String order_by_sql, String limit_sql) {
|
||||
this.tbl_name = tbl_name; this.select_flds = select_flds; this.where_flds = where_flds; this.group_by_sql = group_by_sql; this.having_sql = having_sql; this.order_by_sql = order_by_sql; this.limit_sql = limit_sql;
|
||||
}
|
||||
public int Tid() {return Db_qry_.Tid_select_in_tbl;}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public String[] Select_flds() {return select_flds;} private final String[] select_flds;
|
||||
public String[] Where_flds() {return where_flds;} private final String[] where_flds;
|
||||
public void Where_sql(String_bldr sb) {
|
||||
if (where_flds == null) return;
|
||||
int where_flds_len = where_flds.length;
|
||||
if (where_flds_len == 0) return;
|
||||
for (int i = 0; i < where_flds_len; ++i) {
|
||||
if (i != 0) sb.Add("AND ");
|
||||
sb.Add(where_flds[i]).Add(" = ? ");
|
||||
}
|
||||
}
|
||||
public String Group_by_sql() {return group_by_sql;} private final String group_by_sql;
|
||||
public String Having_sql() {return having_sql;} private final String having_sql;
|
||||
public String Order_by_sql() {return order_by_sql;} private final String order_by_sql;
|
||||
public String Limit_sql() {return limit_sql;} private final String limit_sql;
|
||||
public static Db_qry__select_in_tbl new_(String tbl_name, String[] where_flds, String[] select_flds) {return new Db_qry__select_in_tbl(tbl_name, select_flds, where_flds, null, null, null, null);}
|
||||
public String KeyOfDb_qry() {return "select_in_tbl";}
|
||||
public boolean ExecRdrAble() {return true;}
|
||||
public String XtoSql() {return Xto_sql();}
|
||||
public String Xto_sql() {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
sb.Add("SELECT ");
|
||||
int select_flds_len = select_flds.length;
|
||||
for (int i = 0; i < select_flds_len; ++i) {
|
||||
if (i != 0) sb.Add(",");
|
||||
sb.Add(select_flds[i]);
|
||||
}
|
||||
sb.Add(" FROM ").Add(tbl_name).Add(" ");
|
||||
if (where_flds != null) {sb.Add("WHERE "); Where_sql(sb);}
|
||||
if (group_by_sql != null) sb.Add(group_by_sql);
|
||||
if (having_sql != null) sb.Add(having_sql);
|
||||
if (order_by_sql != null) sb.Add(order_by_sql);
|
||||
if (limit_sql != null) sb.Add(limit_sql);
|
||||
return sb.XtoStr();
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.criterias.*;
|
||||
public class Db_qry_delete implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_basic;}
|
||||
public String KeyOfDb_qry() {return KeyConst;} public static final String KeyConst = "DELETE";
|
||||
public boolean ExecRdrAble() {return false;}
|
||||
public String XtoSql() {return Sql_cmd_wtr_.Ansi.XtoSqlQry(this, false);}
|
||||
public int Exec_qry(Db_provider provider) {return provider.Exec_qry(this);}
|
||||
|
||||
public Db_qry_delete Where_add_(String key, int val) {
|
||||
Criteria crt = Db_crt_.eq_(key, val);
|
||||
where = Sql_where.merge_or_new_(where, crt);
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_qry_flush implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_basic;}
|
||||
public String KeyOfDb_qry() {return KeyConst;} public static final String KeyConst = "FLUSH";
|
||||
public boolean ExecRdrAble() {return false;}
|
||||
public int Exec_qry(Db_provider provider) {return provider.Exec_qry(this);}
|
||||
|
||||
@@ -17,12 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_qry_insert implements Db_qry_arg_owner {
|
||||
public int Tid() {return Db_qry_.Tid_basic;}
|
||||
public String KeyOfDb_qry() {return KeyConst;} public static final String KeyConst = "INSERT";
|
||||
public boolean ExecRdrAble() {return false;}
|
||||
public String XtoSql() {return Sql_cmd_wtr_.Ansi.XtoSqlQry(this, false);}
|
||||
public int Exec_qry(Db_provider provider) {return provider.Exec_qry(this);}
|
||||
public Db_qry_arg_owner From_(String tbl) {baseTable = tbl; return this;}
|
||||
public Db_qry_arg_owner Arg_(String k, DecimalAdp v) {return Arg_obj_type_(k, v.XtoDecimal(), Db_val_type.Tid_decimal);}
|
||||
public Db_qry_arg_owner Arg_(String k, DecimalAdp v) {return Arg_obj_type_(k, v.Xto_decimal(), Db_val_type.Tid_decimal);}
|
||||
public Db_qry_arg_owner Arg_(String k, DateAdp v) {return Arg_obj_type_(k, v, Db_val_type.Tid_date);}
|
||||
public Db_qry_arg_owner Arg_byte_(String k, byte v) {return Arg_obj_type_(k, v, Db_val_type.Tid_byte);}
|
||||
public Db_qry_arg_owner Arg_(String k, int v) {return Arg_obj_type_(k, v, Db_val_type.Tid_int32);}
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.criterias.*;
|
||||
public class Db_qry_select implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_basic;}
|
||||
public String KeyOfDb_qry() {return KeyConst;} public static final String KeyConst = "SELECT";
|
||||
public boolean ExecRdrAble() {return true;}
|
||||
public DataRdr Exec_qry_as_rdr(Db_provider provider) {return provider.Exec_qry_as_rdr(this);}
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_qry_sql implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_basic;}
|
||||
public String KeyOfDb_qry() {return KeyConst;} public static final String KeyConst = "SQL";
|
||||
public boolean ExecRdrAble() {return isReader;} private boolean isReader;
|
||||
public int Exec_qry(Db_provider provider) {return provider.Exec_qry(this);}
|
||||
|
||||
@@ -18,13 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.criterias.*;
|
||||
public class Db_qry_update implements Db_qry_arg_owner {
|
||||
public int Tid() {return Db_qry_.Tid_basic;}
|
||||
public String KeyOfDb_qry() {return KeyConst;} public static final String KeyConst = "UPDATE";
|
||||
public boolean ExecRdrAble() {return false;}
|
||||
public int Exec_qry(Db_provider provider) {return provider.Exec_qry(this);}
|
||||
public String XtoSql() {return Sql_cmd_wtr_.Ansi.XtoSqlQry(this, false);}
|
||||
|
||||
public Db_qry_arg_owner From_(String tbl) {baseTable = tbl; return this;}
|
||||
public Db_qry_arg_owner Arg_(String k, DecimalAdp v) {return Arg_obj_type_(k, v.XtoDecimal(), Db_val_type.Tid_decimal);}
|
||||
public Db_qry_arg_owner Arg_(String k, DecimalAdp v) {return Arg_obj_type_(k, v.Xto_decimal(), Db_val_type.Tid_decimal);}
|
||||
public Db_qry_arg_owner Arg_(String k, DateAdp v) {return Arg_obj_type_(k, v, Db_val_type.Tid_date);}
|
||||
public Db_qry_arg_owner Arg_byte_(String k, byte v) {return Arg_obj_type_(k, v, Db_val_type.Tid_byte);}
|
||||
public Db_qry_arg_owner Arg_(String k, int v) {return Arg_obj_type_(k, v, Db_val_type.Tid_int32);}
|
||||
|
||||
@@ -35,6 +35,7 @@ public interface Db_stmt extends RlsAble {
|
||||
int Exec_update();
|
||||
int Exec_delete();
|
||||
DataRdr Exec_select();
|
||||
Db_rdr Exec_select_as_rdr();
|
||||
Object Exec_select_val();
|
||||
Db_stmt Clear();
|
||||
Db_stmt New();
|
||||
|
||||
@@ -47,4 +47,7 @@ public class Db_stmt_ {
|
||||
public static Db_stmt new_select_all_(Db_provider provider, String tbl) {
|
||||
return provider.Prepare(Db_qry_.select_tbl_(tbl));
|
||||
}
|
||||
public static Db_stmt new_select_as_rdr(Db_provider provider, Db_qry__select_in_tbl qry) {
|
||||
return provider.Prepare(qry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs; import gplx.*;
|
||||
import java.sql.*;
|
||||
class Db_stmt_cmd implements Db_stmt {
|
||||
Db_engine engine;
|
||||
PreparedStatement stmt = null;
|
||||
String sql;
|
||||
int val_idx = 0;
|
||||
private Db_engine engine;
|
||||
private PreparedStatement stmt = null;
|
||||
private String sql;
|
||||
private int val_idx = 0;
|
||||
public Db_stmt_cmd(Db_provider provider, Db_qry qry) {
|
||||
this.provider = provider; this.engine = provider.Engine();
|
||||
sql = Sql_cmd_wtr_.Ansi.XtoSqlQry(qry, true);
|
||||
sql = qry.Tid() == Db_qry_.Tid_select_in_tbl ? ((Db_qry__select_in_tbl)qry).Xto_sql() : Sql_cmd_wtr_.Ansi.XtoSqlQry(qry, true);
|
||||
New();
|
||||
}
|
||||
public Db_stmt New() {
|
||||
@@ -58,7 +58,7 @@ class Db_stmt_cmd implements Db_stmt {
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_decimal_(DecimalAdp v) {
|
||||
try {stmt.setBigDecimal(++val_idx, v.XtoDecimal());} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "decimal", v);}
|
||||
try {stmt.setBigDecimal(++val_idx, v.Xto_decimal());} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "decimal", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_bry_by_str_(String v) {return Val_bry_(Bry_.new_utf8_(v));}
|
||||
@@ -87,6 +87,9 @@ class Db_stmt_cmd implements Db_stmt {
|
||||
public DataRdr Exec_select() {
|
||||
try {DataRdr rv = engine.NewDataRdr(stmt.executeQuery(), sql); return rv;} catch (Exception e) {throw Err_.err_(e, "failed to exec prepared statement: sql={0}", sql);}
|
||||
}
|
||||
public Db_rdr Exec_select_as_rdr() {
|
||||
try {return engine.New_db_rdr(stmt.executeQuery(), sql);} catch (Exception e) {throw Err_.err_(e, "select failed: sql={0}", sql);}
|
||||
}
|
||||
public Object Exec_select_val() {
|
||||
try {Object rv = Db_qry_select.Rdr_to_val(engine.NewDataRdr(stmt.executeQuery(), sql)); return rv;} catch (Exception e) {throw Err_.err_(e, "failed to exec prepared statement: sql={0}", sql);}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
class Db_stmt_sql implements Db_stmt {
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
Bry_fmtr tmp_fmtr = Bry_fmtr.new_();
|
||||
int val_idx = 0;
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
private Bry_fmtr tmp_fmtr = Bry_fmtr.new_();
|
||||
private int val_idx = 0;
|
||||
public Db_provider Provider() {return provider;} public void Provider_(Db_provider v) {this.provider = v;} Db_provider provider;
|
||||
public Db_stmt New() {return this;}
|
||||
public Db_stmt Val_bool_(boolean v) {
|
||||
@@ -28,27 +28,27 @@ class Db_stmt_sql implements Db_stmt {
|
||||
}
|
||||
public Db_stmt Val_byte_by_bool_(boolean v) {return Val_byte_(v ? Bool_.Y_byte : Bool_.N_byte);}
|
||||
public Db_stmt Val_byte_(byte v) {
|
||||
try {Add(++val_idx, Byte_.XtoStr(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "byte", v);}
|
||||
try {Add(++val_idx, Byte_.Xto_str(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "byte", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_int_(int v) {
|
||||
try {Add(++val_idx, Int_.XtoStr(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "int", v);}
|
||||
try {Add(++val_idx, Int_.Xto_str(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "int", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_long_(long v) {
|
||||
try {Add(++val_idx, Long_.XtoStr(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "long", v);}
|
||||
try {Add(++val_idx, Long_.Xto_str(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "long", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_float_(float v) {
|
||||
try {Add(++val_idx, Float_.XtoStr(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "float", v);}
|
||||
try {Add(++val_idx, Float_.Xto_str(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "float", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_double_(double v) {
|
||||
try {Add(++val_idx, Double_.XtoStr(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "double", v);}
|
||||
try {Add(++val_idx, Double_.Xto_str(v));} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "double", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_decimal_(DecimalAdp v) {
|
||||
try {Add(++val_idx, v.XtoStr());} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "decimal", v);}
|
||||
try {Add(++val_idx, v.Xto_str());} catch (Exception e) {throw Err_.err_(e, "failed to add value: type={0} val={1}", "decimal", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_bry_by_str_(String v) {return Val_bry_(Bry_.new_utf8_(v));}
|
||||
@@ -84,6 +84,7 @@ class Db_stmt_sql implements Db_stmt {
|
||||
public DataRdr Exec_select() {
|
||||
try {DataRdr rv = provider.Exec_qry_as_rdr(Db_qry_sql.rdr_(this.Xto_sql())); return rv;} catch (Exception e) {throw Err_.err_(e, "failed to exec prepared statement: sql={0}", sql_orig);}
|
||||
}
|
||||
public Db_rdr Exec_select_as_rdr() {throw Err_.not_implemented_();}
|
||||
public Object Exec_select_val() {
|
||||
try {Object rv = Db_qry_select.Rdr_to_val(this.Exec_select()); return rv;} catch (Exception e) {throw Err_.err_(e, "failed to exec prepared statement: sql={0}", sql_orig);}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ class Sql_cmd_wtr_ansi implements Sql_cmd_wtr {
|
||||
}
|
||||
Class<?> valType = val.getClass();
|
||||
if (valType == Boolean.class)
|
||||
sb.Add_obj(Bool_.XtoInt(Bool_.cast_(val))); // NOTE!: save boolean to 0 or 1, b/c (a) db may not support bit datatype (sqllite) and (b) avoid i18n issues with "true"/"false"
|
||||
sb.Add_obj(Bool_.Xto_int(Bool_.cast_(val))); // NOTE!: save boolean to 0 or 1, b/c (a) db may not support bit datatype (sqllite) and (b) avoid i18n issues with "true"/"false"
|
||||
else if
|
||||
( valType == Byte.class || valType == Short.class
|
||||
|| valType == Integer.class || valType == Long.class
|
||||
@@ -162,7 +162,7 @@ class Sql_cmd_wtr_ansi implements Sql_cmd_wtr {
|
||||
XtoSqlVal_DateAdp(sb, prm, (DateAdp)val);
|
||||
else if (valType == DecimalAdp.class) {
|
||||
DecimalAdp valDecimal = (DecimalAdp)val;
|
||||
sb.Add(valDecimal.XtoStr());
|
||||
sb.Add(valDecimal.Xto_str());
|
||||
}
|
||||
// else if (valType == System.Enum.class)
|
||||
// sb.Add_any(Enm_.XtoInt(val)); // save enum as 0 or 1, since (a) no db supports enum datatype; (b) names are fungible; (c) int is less space than name
|
||||
|
||||
@@ -31,7 +31,7 @@ public class PoolIds {
|
||||
return rv;
|
||||
}
|
||||
public int FetchNextAndCommit(String dbInfo, String url) {
|
||||
Db_provider provider = Db_provider_pool._.FetchOrNew(dbInfo);
|
||||
Db_provider provider = Db_provider_pool._.Get_or_new(dbInfo);
|
||||
int rv = PoolIds._.FetchNext(provider, url);
|
||||
PoolIds._.Commit(provider, url, rv + 1);
|
||||
return rv;
|
||||
@@ -41,7 +41,7 @@ public class PoolIds {
|
||||
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);
|
||||
if (rv != 1) throw Err_.new_("failed to update nextId").Add("provider", provider.Conn_info().Str_raw()).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";
|
||||
|
||||
@@ -16,30 +16,35 @@ 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.*;
|
||||
interface Db_engine extends RlsAble {
|
||||
String Key();
|
||||
Db_connect ConnectInfo();
|
||||
void Connect();
|
||||
Object Execute(Db_qry cmd);
|
||||
DataRdr NewDataRdr(java.sql.ResultSet rdr, String sql);
|
||||
Db_stmt New_db_stmt(Db_provider provider, Db_qry sql);
|
||||
Object New_db_cmd(String sql);
|
||||
void Txn_bgn();
|
||||
void Txn_end();
|
||||
Db_engine MakeEngine(Db_connect connectInfo);
|
||||
public interface Db_engine {
|
||||
String Key();
|
||||
Db_conn_info Conn_info();
|
||||
void Conn_open();
|
||||
void Conn_term();
|
||||
void Txn_bgn();
|
||||
void Txn_end();
|
||||
Db_engine Make_new(Db_conn_info conn_info);
|
||||
|
||||
Db_rdr New_db_rdr(Object o, String sql); // ResultSet if desktop; Cursor if android
|
||||
Db_stmt New_db_stmt(Db_provider provider, Db_qry sql);
|
||||
Object Execute(Db_qry cmd);
|
||||
DataRdr NewDataRdr(java.sql.ResultSet rdr, String sql);
|
||||
Object New_db_cmd(String sql);
|
||||
}
|
||||
class Db_engine_null implements Db_engine {
|
||||
public String Key() {return Db_connect_.Null.Key_of_db_connect();}
|
||||
public Db_connect ConnectInfo() {return Db_connect_.Null;}
|
||||
public void Connect() {}
|
||||
public String Key() {return Db_conn_info_.Null.Key();}
|
||||
public Db_conn_info Conn_info() {return Db_conn_info_.Null;}
|
||||
public void Conn_open() {}
|
||||
public void Conn_term() {}
|
||||
public void Txn_bgn() {}
|
||||
public void Txn_end() {}
|
||||
public Db_engine Make_new(Db_conn_info conn_info) {return this;}
|
||||
|
||||
public Object Execute(Db_qry cmd) {return cmd.ExecRdrAble() ? (Object)DataRdr_.Null : -1;}
|
||||
public Object New_db_cmd(String sql) {throw Err_.not_implemented_();}
|
||||
public DataRdr NewDataRdr(java.sql.ResultSet rdr, String sql) {return DataRdr_.Null;}
|
||||
public Db_stmt New_db_stmt(Db_provider provider, Db_qry qry) {return Db_stmt_.Null;}
|
||||
public void Txn_bgn() {}
|
||||
public void Txn_end() {}
|
||||
public void Rls() {}
|
||||
public Db_engine MakeEngine(Db_connect connectInfo) {return this;}
|
||||
public Object New_db_cmd(String sql) {throw Err_.not_implemented_();}
|
||||
public DataRdr NewDataRdr(java.sql.ResultSet rdr, String sql) {return DataRdr_.Null;}
|
||||
public Db_rdr New_db_rdr(Object o, String sql) {return Db_rdr_.Null;}
|
||||
public Db_stmt New_db_stmt(Db_provider provider, Db_qry qry) {return Db_stmt_.Null;}
|
||||
public static final Db_engine_null _ = new Db_engine_null(); Db_engine_null() {}
|
||||
}
|
||||
class ExecSqlWkr implements Db_qryWkr {
|
||||
|
||||
32
140_dbs/src_200_engine/gplx/dbs/Db_engine_regy.java
Normal file
32
140_dbs/src_200_engine/gplx/dbs/Db_engine_regy.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_engine_regy {
|
||||
private final HashAdp hash = HashAdp_.new_();
|
||||
Db_engine_regy() {
|
||||
this.Add(Db_engine_null._)
|
||||
.Add(TdbEngine._)
|
||||
.Add(Mysql_engine._)
|
||||
.Add(Postgres_engine._)
|
||||
.Add(Sqlite_engine._)
|
||||
;
|
||||
}
|
||||
public Db_engine_regy Add(Db_engine engine) {hash.Add(engine.Key(), engine); return this;}
|
||||
public Db_engine Get(String key) {return (Db_engine)hash.FetchOrFail(key);}
|
||||
public static final Db_engine_regy _ = new Db_engine_regy();
|
||||
}
|
||||
@@ -17,19 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import java.sql.*;
|
||||
abstract class Db_engine_sql_base implements Db_engine, RlsAble {
|
||||
abstract class Db_engine_sql_base implements Db_engine {
|
||||
public abstract String Key();
|
||||
public Db_connect ConnectInfo() {return dbInfo;} protected Db_connect dbInfo;
|
||||
public abstract Db_engine MakeEngine(Db_connect dbInfo);
|
||||
public Db_conn_info Conn_info() {return conn_info;} protected Db_conn_info conn_info;
|
||||
@gplx.Virtual public void Txn_bgn() {Execute(Db_qry_sql.xtn_("BEGIN TRANSACTION;"));}
|
||||
@gplx.Virtual public void Txn_end() {Execute(Db_qry_sql.xtn_("COMMIT TRANSACTION;"));}
|
||||
public abstract Db_engine Make_new(Db_conn_info conn_info);
|
||||
@gplx.Virtual public Sql_cmd_wtr SqlWtr() {return Sql_cmd_wtr_.Ansi;}
|
||||
public Object Execute(Db_qry cmd) {
|
||||
Db_qryWkr wkr = (Db_qryWkr)wkrs.FetchOrFail(cmd.KeyOfDb_qry());
|
||||
return wkr.Exec(this, cmd);
|
||||
}
|
||||
@gplx.Virtual public void Txn_bgn() {Execute(Db_qry_sql.xtn_("BEGIN TRANSACTION;"));}
|
||||
@gplx.Virtual public void Txn_end() {Execute(Db_qry_sql.xtn_("COMMIT TRANSACTION;"));}
|
||||
@gplx.Internal protected void ctor_SqlEngineBase(Db_connect dbInfo) {
|
||||
this.dbInfo = dbInfo;
|
||||
@gplx.Internal protected void ctor_SqlEngineBase(Db_conn_info conn_info) {
|
||||
this.conn_info = conn_info;
|
||||
wkrs.Add(Db_qry_select.KeyConst, new ExecSqlWkr());
|
||||
wkrs.Add(Db_qry_insert.KeyConst, new ExecSqlWkr());
|
||||
wkrs.Add(Db_qry_update.KeyConst, new ExecSqlWkr());
|
||||
@@ -53,21 +53,22 @@ abstract class Db_engine_sql_base implements Db_engine, RlsAble {
|
||||
}
|
||||
catch (Exception exc) {throw Err_.err_(exc, "exec reader failed").Add("sql", sql).Add("err", Err_.Message_gplx_brief(exc));}
|
||||
}
|
||||
@gplx.Internal protected abstract Connection NewDbCon();
|
||||
@gplx.Internal protected abstract Connection Conn_new();
|
||||
@gplx.Virtual public DataRdr NewDataRdr(ResultSet rdr, String sql) {return gplx.stores.Db_data_rdr_.new_(rdr, sql);}
|
||||
public Db_stmt New_db_stmt(Db_provider provider, Db_qry qry) {return new Db_stmt_cmd(provider, qry);}
|
||||
public Db_rdr New_db_rdr(Object rdr, String sql) {return new Db_rdr__basic((ResultSet)rdr, sql);}
|
||||
public Db_stmt New_db_stmt(Db_provider provider, Db_qry qry) {return new Db_stmt_cmd(provider, qry);}
|
||||
public Object New_db_cmd(String sql) {
|
||||
try {return connection.prepareStatement(sql);}
|
||||
catch (Exception e) {
|
||||
throw Err_.err_(e, "failed to prepare sql; sql={0}", sql);}
|
||||
}
|
||||
public void Connect() {
|
||||
connection = NewDbCon();
|
||||
public void Conn_open() {
|
||||
connection = Conn_new();
|
||||
} private Connection connection;
|
||||
public void Rls() {
|
||||
public void Conn_term() {
|
||||
// if (Env_.Mode_testing()) return; // WORKAROUND:MYSQL:else errors randomly when running all tests. possible connection pooling issue (?); // commented out 2013-08-22
|
||||
try {connection.close();}
|
||||
catch (SQLException e) {throw Err_.err_(e, "close connection failed").Add("ConnectInfo", dbInfo.Raw_of_db_connect());}
|
||||
catch (SQLException e) {throw Err_.err_(e, "close connection failed").Add("ConnectInfo", conn_info.Str_raw());}
|
||||
}
|
||||
Statement NewDbCmd(String commandText) {
|
||||
Statement cmd = null;
|
||||
@@ -77,6 +78,6 @@ abstract class Db_engine_sql_base implements Db_engine, RlsAble {
|
||||
}
|
||||
protected Connection NewDbCon(String url, String uid, String pwd) {
|
||||
try {return DriverManager.getConnection(url, uid, pwd);}
|
||||
catch (SQLException e) {throw Err_.err_(e, "connection open failed").Add("ConnectInfo", ConnectInfo().Raw_of_db_connect());}
|
||||
catch (SQLException e) {throw Err_.err_(e, "connection open failed").Add("ConnectInfo", Conn_info().Str_raw());}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,16 @@ package gplx.dbs; import gplx.*;
|
||||
import gplx.stores.*;
|
||||
import java.sql.*;
|
||||
class Mysql_engine extends Db_engine_sql_base {
|
||||
@Override public String Key() {return Db_connect_mysql.KeyDef;}
|
||||
@Override public String Key() {return Db_conn_info__mysql.Key_const;}
|
||||
@Override public Sql_cmd_wtr SqlWtr() {return Sql_cmd_wtr_.BackslashSensitive;}
|
||||
@Override public Db_engine MakeEngine(Db_connect connectInfo) {
|
||||
@Override public Db_engine Make_new(Db_conn_info connectInfo) {
|
||||
Mysql_engine rv = new Mysql_engine();
|
||||
rv.ctor_SqlEngineBase(connectInfo);
|
||||
return rv;
|
||||
}
|
||||
@Override public DataRdr NewDataRdr(ResultSet rdr, String commandText) {return Mysql_rdr.new_(rdr, commandText);}
|
||||
@gplx.Internal @Override protected Connection NewDbCon() {
|
||||
Db_connect_mysql connUrl = (Db_connect_mysql)dbInfo;
|
||||
@gplx.Internal @Override protected Connection Conn_new() {
|
||||
Db_conn_info__mysql connUrl = (Db_conn_info__mysql)conn_info;
|
||||
return NewDbCon("jdbc:mysql://localhost/" + connUrl.Database() + "?characterEncoding=UTF8", connUrl.Uid(), connUrl.Pwd());
|
||||
}
|
||||
@gplx.Internal protected static final Mysql_engine _ = new Mysql_engine(); Mysql_engine() {}
|
||||
|
||||
@@ -19,17 +19,17 @@ package gplx.dbs; import gplx.*;
|
||||
import gplx.stores.*;
|
||||
import java.sql.*;
|
||||
class Postgres_engine extends Db_engine_sql_base {
|
||||
@Override public String Key() {return Db_connect_postgres.KeyDef;}
|
||||
@Override public String Key() {return Db_conn_info__postgres.Key_const;}
|
||||
@Override public Sql_cmd_wtr SqlWtr() {return Sql_cmd_wtr_.BackslashSensitive;}
|
||||
@Override public Db_engine MakeEngine(Db_connect connectInfo) {
|
||||
@Override public Db_engine Make_new(Db_conn_info connectInfo) {
|
||||
Postgres_engine rv = new Postgres_engine();
|
||||
rv.ctor_SqlEngineBase(connectInfo);
|
||||
return rv;
|
||||
}
|
||||
@Override public DataRdr NewDataRdr(ResultSet rdr, String commandText) {return Db_data_rdr_.new_(rdr, commandText);}
|
||||
@gplx.Internal @Override protected Connection NewDbCon() {
|
||||
Db_connect_postgres connUrl = (Db_connect_postgres)dbInfo;
|
||||
return NewDbCon("jdbc:" + connUrl.Key_of_db_connect() + "://localhost/" + connUrl.Database(), connUrl.Uid(), connUrl.Pwd());
|
||||
@gplx.Internal @Override protected Connection Conn_new() {
|
||||
Db_conn_info__postgres connUrl = (Db_conn_info__postgres)conn_info;
|
||||
return NewDbCon("jdbc:" + connUrl.Key() + "://localhost/" + connUrl.Database(), connUrl.Uid(), connUrl.Pwd());
|
||||
}
|
||||
@gplx.Internal protected static final Postgres_engine _ = new Postgres_engine(); Postgres_engine() {}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,15 @@ package gplx.dbs; import gplx.*;
|
||||
import gplx.stores.*;
|
||||
import java.sql.*;
|
||||
class Sqlite_engine extends Db_engine_sql_base {
|
||||
@Override public String Key() {return Db_connect_sqlite.KeyDef;}
|
||||
@Override public Db_engine MakeEngine(Db_connect connectInfo) {
|
||||
@Override public String Key() {return Db_conn_info__sqlite.Key_const;}
|
||||
@Override public Db_engine Make_new(Db_conn_info connectInfo) {
|
||||
Sqlite_engine rv = new Sqlite_engine();
|
||||
rv.ctor_SqlEngineBase(connectInfo);
|
||||
return rv;
|
||||
}
|
||||
@Override public DataRdr NewDataRdr(ResultSet rdr, String commandText) {return Sqlite_rdr.new_(rdr, commandText);}
|
||||
static boolean loaded = false;
|
||||
@gplx.Internal @Override protected Connection NewDbCon() {
|
||||
@gplx.Internal @Override protected Connection Conn_new() {
|
||||
if (!loaded) {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
@@ -35,7 +35,7 @@ class Sqlite_engine extends Db_engine_sql_base {
|
||||
catch (ClassNotFoundException e) {throw Err_.new_("could not load sqlite jdbc driver");}
|
||||
loaded = true;
|
||||
}
|
||||
Db_connect_sqlite connUrl = (Db_connect_sqlite)dbInfo;
|
||||
Db_conn_info__sqlite connUrl = (Db_conn_info__sqlite)conn_info;
|
||||
return NewDbCon("jdbc:sqlite://" + String_.Replace(connUrl.Database(), "\\", "/"), "", "");
|
||||
}
|
||||
private boolean pragma_needed = true;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class Sqlite_engine_ {
|
||||
}
|
||||
public static void Pragma_page_size_4096(Db_provider p) {Pragma_page_size(p, 4096);}
|
||||
public static void Pragma_page_size(Db_provider p, int val) {
|
||||
Db_qry qry = Db_qry_sql.ddl_("PRAGMA page_size = " + Int_.XtoStr(val) + ";");
|
||||
Db_qry qry = Db_qry_sql.ddl_("PRAGMA page_size = " + Int_.Xto_str(val) + ";");
|
||||
p.Exec_qry(qry);
|
||||
}
|
||||
public static void Idx_create(Db_provider p, Db_idx_itm... idxs) {Idx_create(Gfo_usr_dlg_.Null, p, "", idxs);}
|
||||
@@ -68,15 +68,15 @@ public class Sqlite_engine_ {
|
||||
public static Db_provider Provider_load_or_fail_(Io_url url) {
|
||||
boolean exists = Io_mgr._.ExistsFil(url);
|
||||
if (!exists) throw Err_.new_fmt_("db does not exist; url=~{0}", url.Raw());
|
||||
Db_connect connect = Db_connect_sqlite.load_(url);
|
||||
return Db_provider_.new_(connect);
|
||||
Db_conn_info connect = Db_conn_info__sqlite.load_(url);
|
||||
return Db_provider_.new_and_open_(connect);
|
||||
}
|
||||
public static Db_provider Provider_load_or_make_(Io_url url) {return Provider_load_or_make_(url, Bool_obj_ref.n_());}
|
||||
public static Db_provider Provider_load_or_make_(Io_url url, Bool_obj_ref created) {
|
||||
boolean exists = Io_mgr._.ExistsFil(url);
|
||||
created.Val_(!exists);
|
||||
Db_connect connect = exists ? Db_connect_sqlite.load_(url) : Db_connect_sqlite.make_(url);
|
||||
Db_provider p = Db_provider_.new_(connect);
|
||||
Db_conn_info connect = exists ? Db_conn_info__sqlite.load_(url) : Db_conn_info__sqlite.make_(url);
|
||||
Db_provider p = Db_provider_.new_and_open_(connect);
|
||||
if (!exists)
|
||||
Pragma_page_size(p, 4096);
|
||||
return p;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class db_DataTypes_tst {
|
||||
fx.RunAll(Db_provider_fxt.Mysql());
|
||||
}
|
||||
@Test public void Tdb() {if (Tfds.SkipDb) return;
|
||||
fx.Select_FloatStr_(Float_.XtoStr(Float_.Div(1, 3)));
|
||||
fx.Select_FloatStr_(Float_.Xto_str(Float_.Div(1, 3)));
|
||||
fx.RunAll(Db_provider_fxt.Tdb("110_dbs_multiple_data_types.dsv"));
|
||||
}
|
||||
@Test public void Postgres() {if (Db_provider_fxt.SkipPostgres) return;
|
||||
@@ -51,12 +51,12 @@ INSERT INTO dbs_multiple_data_types VALUES (1, 'John Doe', B'1', '3/30/2006 10:2
|
||||
class DataTypes_base_fxt {
|
||||
public Db_provider Provider() {return provider;} Db_provider provider;
|
||||
public DataTypes_base_fxt() {}
|
||||
public void Rls() {provider.Rls();}
|
||||
public void Rls() {provider.Conn_term();}
|
||||
public String Select_FloatStr() {return select_FloatStr;} public DataTypes_base_fxt Select_FloatStr_(String v) {select_FloatStr = v; return this;} private String select_FloatStr;
|
||||
public void RunAll(Db_provider provider) {
|
||||
this.provider = provider;
|
||||
this.Select_hook(select_FloatStr);
|
||||
provider.Rls();
|
||||
provider.Conn_term();
|
||||
}
|
||||
public void Select_hook(String floatStr) {
|
||||
DataRdr rdr = Db_qry_.select_tbl_("dbs_multiple_data_types").Exec_qry_as_rdr(provider);
|
||||
|
||||
@@ -19,14 +19,14 @@ package gplx.dbs; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class TdbConnectInfo_tst {
|
||||
@Test public void Full() {
|
||||
Db_connect connectInfo = Db_connect_.parse_("gplx_key=tdb;url=C:\\dir\\xmpl.tdb;format=dsv;");
|
||||
Db_conn_info connectInfo = Db_conn_info_.parse_("gplx_key=tdb;url=C:\\dir\\xmpl.tdb;format=dsv;");
|
||||
tst_Parse(connectInfo, Io_url_.new_any_("C:\\dir\\xmpl.tdb"), "dsv");
|
||||
}
|
||||
@Test public void DefaultFormat() {
|
||||
Db_connect connectInfo = Db_connect_.parse_("gplx_key=tdb;url=C:\\dir\\xmpl.tdb"); // dsv Format inferred
|
||||
Db_conn_info connectInfo = Db_conn_info_.parse_("gplx_key=tdb;url=C:\\dir\\xmpl.tdb"); // dsv Format inferred
|
||||
tst_Parse(connectInfo, Io_url_.new_any_("C:\\dir\\xmpl.tdb"), "dsv");
|
||||
}
|
||||
void tst_Parse(Db_connect connectInfo, Io_url url, String format) {
|
||||
Tfds.Eq(((Db_connect_tdb)connectInfo).Url(), url);
|
||||
void tst_Parse(Db_conn_info connectInfo, Io_url url, String format) {
|
||||
Tfds.Eq(((Db_conn_info__tdb)connectInfo).Url(), url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,5 +43,5 @@ public class TdbDatabase {
|
||||
}
|
||||
int FileId_next = TdbFile.MainFileId + 1;
|
||||
int TableId_next = 1;
|
||||
// public static Io_url UrlOf(Db_connect url) {return Io_url_.new_any_(url.ServerName());}
|
||||
// public static Io_url UrlOf(Db_conn_info url) {return Io_url_.new_any_(url.ServerName());}
|
||||
}
|
||||
|
||||
@@ -18,17 +18,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.dbs; import gplx.*;
|
||||
class TdbEngine implements Db_engine {
|
||||
public String Key() {return KeyDef;} public static final String KeyDef = "tdb";
|
||||
public Db_connect ConnectInfo() {return connectInfo;} Db_connect connectInfo;
|
||||
public Db_conn_info Conn_info() {return conn_info;} Db_conn_info conn_info;
|
||||
public TdbDatabase Db() {return db;} TdbDatabase db;
|
||||
public Db_engine MakeEngine(Db_connect connectInfo) {
|
||||
TdbEngine rv = new TdbEngine();
|
||||
rv.CtorTdbEngine(connectInfo);
|
||||
return rv;
|
||||
}
|
||||
public void Connect() {
|
||||
String urlStr = (String)connectInfo.Server();
|
||||
public void Conn_open() {
|
||||
String urlStr = (String)conn_info.Server();
|
||||
db = loadMgr.LoadTbls(Io_url_.new_any_(urlStr));
|
||||
}
|
||||
public void Conn_term() {}
|
||||
public void Txn_bgn() {}
|
||||
public void Txn_end() {}
|
||||
public Db_engine Make_new(Db_conn_info conn_info) {
|
||||
TdbEngine rv = new TdbEngine();
|
||||
rv.CtorTdbEngine(conn_info);
|
||||
return rv;
|
||||
}
|
||||
public Object Execute(Db_qry cmd) {
|
||||
Db_qryWkr wkr = (Db_qryWkr)wkrs.FetchOrFail(cmd.KeyOfDb_qry());
|
||||
return wkr.Exec(this, cmd);
|
||||
@@ -36,8 +39,7 @@ class TdbEngine implements Db_engine {
|
||||
public DataRdr NewDataRdr(java.sql.ResultSet rdr, String sql) {return DataRdr_.Null;}
|
||||
public Db_stmt New_db_stmt(Db_provider provider, Db_qry qry) {return new Db_stmt_sql().Parse(Sql_cmd_wtr_.Ansi.XtoSqlQry(qry, true));}
|
||||
public Object New_db_cmd(String sql) {throw Err_.not_implemented_();}
|
||||
public void Txn_bgn() {}
|
||||
public void Txn_end() {}
|
||||
public Db_rdr New_db_rdr(Object o, String sql) {return Db_rdr_.Null;}
|
||||
public TdbTable FetchTbl(String name) {
|
||||
TdbTable tbl = db.Tables().FetchOrFail(name);
|
||||
if (!tbl.IsLoaded()) loadMgr.LoadTbl(db, tbl);
|
||||
@@ -49,13 +51,12 @@ class TdbEngine implements Db_engine {
|
||||
public void FlushTbl(TdbTable tbl) {
|
||||
saveMgr.SaveFile(db, tbl.File());
|
||||
}
|
||||
public void Rls() {}
|
||||
|
||||
HashAdp wkrs = HashAdp_.new_(); TdbDbLoadMgr loadMgr = TdbDbLoadMgr.new_(); TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_();
|
||||
@gplx.Internal protected static final TdbEngine _ = new TdbEngine();
|
||||
//TdbEngine() {this.connectInfo = TdbConnectUrl._;}
|
||||
void CtorTdbEngine(Db_connect connectInfo) {
|
||||
this.connectInfo = connectInfo;
|
||||
//TdbEngine() {this.conn_info = TdbConnectUrl._;}
|
||||
void CtorTdbEngine(Db_conn_info conn_info) {
|
||||
this.conn_info = conn_info;
|
||||
wkrs.Add(Db_qry_select.KeyConst, TdbSelectWkr._);
|
||||
wkrs.Add(Db_qry_insert.KeyConst, TdbInsertWkr.new_());
|
||||
wkrs.Add(Db_qry_update.KeyConst, TdbUpdateWkr.new_());
|
||||
|
||||
@@ -81,9 +81,9 @@ public class TdbFlush_tst {
|
||||
}
|
||||
class TdbEngineFxt {
|
||||
public TdbEngine run_MakeEngine(Io_url url) {
|
||||
Db_connect connectInfo = Db_connect_.tdb_(url);
|
||||
TdbEngine engine = (TdbEngine)TdbEngine._.MakeEngine(connectInfo);
|
||||
engine.Connect();
|
||||
Db_conn_info connectInfo = Db_conn_info_.tdb_(url);
|
||||
TdbEngine engine = (TdbEngine)TdbEngine._.Make_new(connectInfo);
|
||||
engine.Conn_open();
|
||||
return engine;
|
||||
}
|
||||
public TdbFile run_MakeFile(TdbEngine engine, Io_url url) {return engine.Db().MakeFile(url);}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.stores; import gplx.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; /*Db_connect*/
|
||||
import gplx.dbs.*; /*Db_conn_info*/
|
||||
public class DbMaprMgr_tst {
|
||||
@Before public void setup() {
|
||||
mgr = DbMaprMgr.new_().RootIndexFlds_(DbMaprArg.new_("id", "disc_id"))
|
||||
@@ -37,9 +37,9 @@ public class DbMaprMgr_tst {
|
||||
. Flds_add(MockStream.id_idk, "stream_id").Flds_add(MockStream.name_idk, "stream_name")
|
||||
. ConstantFlds_add("stream_type", 1)
|
||||
)));
|
||||
wtr = DbMaprWtr.new_by_url_(Db_connect_.Test);
|
||||
wtr = DbMaprWtr.new_by_url_(Db_conn_info_.Test);
|
||||
wtr.EnvVars().Add(DbMaprWtr.Key_Mgr, mgr);
|
||||
provider = Db_provider_pool._.FetchOrNew(Db_connect_.Test);
|
||||
provider = Db_provider_pool._.Get_or_new(Db_conn_info_.Test);
|
||||
Db_qry_fxt.DeleteAll(provider, "mock_discs", "mock_titles", "mock_chapters", "mock_streams");
|
||||
} DbMaprMgr mgr; DbMaprWtr wtr; Db_provider provider; MockDisc disc; MockTitle title; MockChapter chapter; MockStream audio, subtitle; SrlMgr rdr;
|
||||
@Test public void PurgeObjTree() {
|
||||
@@ -133,7 +133,7 @@ public class DbMaprMgr_tst {
|
||||
Tfds.Eq("subtitle1", ((MockStream)t.Subtitles().FetchAt(0)).Name());
|
||||
}
|
||||
DbMaprRdr rdr_() {
|
||||
DbMaprRdr rv = DbMaprRdr.new_(Db_connect_.Test, Db_crt_.eq_("disc_id", 1));
|
||||
DbMaprRdr rv = DbMaprRdr.new_(Db_conn_info_.Test, Db_crt_.eq_("disc_id", 1));
|
||||
rv.EnvVars().Add(DbMaprWtr.Key_Mgr, mgr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -114,9 +114,9 @@ public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
HashAdp tables = HashAdp_.new_();
|
||||
Db_provider provider; Criteria rootCrt;
|
||||
DbMaprMgr mgr; ListAdp rowStack = ListAdp_.new_();
|
||||
public static DbMaprRdr new_(Db_connect dbInfo, Criteria rootCrt) {
|
||||
public static DbMaprRdr new_(Db_conn_info dbInfo, Criteria rootCrt) {
|
||||
DbMaprRdr rv = new DbMaprRdr();
|
||||
rv.provider = Db_provider_pool._.FetchOrNew(dbInfo); rv.rootCrt = rootCrt;
|
||||
rv.provider = Db_provider_pool._.Get_or_new(dbInfo); rv.rootCrt = rootCrt;
|
||||
return rv;
|
||||
} DbMaprRdr() {}
|
||||
}
|
||||
@@ -83,9 +83,9 @@ public class DbMaprWtr extends DataWtr_base implements DataWtr {
|
||||
public String XtoStr() {return "";}
|
||||
@Override public SrlMgr SrlMgr_new(Object o) {return new DbMaprWtr();}
|
||||
DbMaprMgr mgr; Db_provider provider; String curTableName; Db_qry_insert insertCmd;
|
||||
public static DbMaprWtr new_by_url_(Db_connect url) {
|
||||
public static DbMaprWtr new_by_url_(Db_conn_info url) {
|
||||
DbMaprWtr rv = new DbMaprWtr();
|
||||
rv.provider = Db_provider_pool._.FetchOrNew(url);
|
||||
rv.provider = Db_provider_pool._.Get_or_new(url);
|
||||
return rv;
|
||||
} DbMaprWtr() {}
|
||||
public static final String Key_Mgr = "DbMapr.mgr";
|
||||
|
||||
@@ -43,12 +43,12 @@ public class Db_provider_fxt implements RlsAble {
|
||||
Tfds.Eq_ary(actlValAry, expdValAry);
|
||||
return record;
|
||||
}
|
||||
public void Rls() {provider.Rls();}
|
||||
public void Rls() {provider.Conn_term();}
|
||||
|
||||
public static Db_provider Mysql() {return Db_provider_.new_(Db_connect_mysql.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_provider Tdb(String fileName) {return Db_provider_.new_(Db_connect_.tdb_(Tfds.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));}
|
||||
public static Db_provider Postgres() {return Db_provider_.new_(Db_connect_postgres.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_provider Sqlite() {return Db_provider_.new_(Db_connect_sqlite.load_(Tfds.RscDir.GenSubFil_nest("140_dbs", "sqlite", "unit_tests.db")));}
|
||||
public static Db_provider Mysql() {return Db_provider_.new_and_open_(Db_conn_info__mysql.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_provider Tdb(String fileName) {return Db_provider_.new_and_open_(Db_conn_info_.tdb_(Tfds.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));}
|
||||
public static Db_provider Postgres() {return Db_provider_.new_and_open_(Db_conn_info__postgres.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_provider Sqlite() {return Db_provider_.new_and_open_(Db_conn_info__sqlite.load_(Tfds.RscDir.GenSubFil_nest("140_dbs", "sqlite", "unit_tests.db")));}
|
||||
// public static Db_provider Mssql() {return MssqlConnectUrl.WindowsAuth(".", "unit_tests");
|
||||
public static final boolean SkipPostgres = Tfds.SkipDb || true;
|
||||
}
|
||||
@@ -19,7 +19,7 @@ package gplx.dbs; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class PoolIds_tst {
|
||||
@Before public void setup() {
|
||||
provider = Db_provider_pool._.FetchOrNew(Db_connect_.Test);
|
||||
provider = Db_provider_pool._.Get_or_new(Db_conn_info_.Test);
|
||||
Db_qry_fxt.DeleteAll(provider, PoolIds.Tbl_Name);
|
||||
mgr = PoolIds._;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public abstract class GroupBys_base_tst {
|
||||
Db_qry_.delete_tbl_("dbs_group_bys").Exec_qry(provider);
|
||||
}
|
||||
@After public void teardown() {
|
||||
provider.Rls();
|
||||
provider.Conn_term();
|
||||
}
|
||||
protected void GroupBy_1fld_hook() {
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 1));
|
||||
|
||||
@@ -26,7 +26,7 @@ public abstract class InsertIntos_base_tst {
|
||||
provider.Exec_qry(Db_qry_delete.new_().BaseTable_("dbs_insert_intos"));
|
||||
}
|
||||
@After public void teardown() {
|
||||
provider.Rls();
|
||||
provider.Conn_term();
|
||||
}
|
||||
protected void Select_hook() {
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 1));
|
||||
|
||||
@@ -25,7 +25,7 @@ public abstract class Joins_base_tst {
|
||||
Db_qry_delete.new_().BaseTable_("dbs_join1").Exec_qry(provider);
|
||||
}
|
||||
@After public void teardown() {
|
||||
provider.Rls();
|
||||
provider.Conn_term();
|
||||
}
|
||||
protected void InnerJoin_hook() {
|
||||
provider.Exec_qry(Db_qry_insert.new_().BaseTable_("dbs_crud_ops").Arg_("id", 0).Arg_("name", "me"));
|
||||
|
||||
@@ -23,7 +23,7 @@ public abstract class OrderBys_base_tst {
|
||||
fx.Provider_(provider);
|
||||
Db_qry_delete.new_().BaseTable_("dbs_crud_ops").Exec_qry(provider);
|
||||
} protected Db_provider_fxt fx = new Db_provider_fxt();
|
||||
@After public void teardown() {provider.Rls();}
|
||||
@After public void teardown() {provider.Conn_term();}
|
||||
protected abstract Db_provider provider_(); protected Db_provider provider;
|
||||
protected void Basic_hook() {
|
||||
fx.tst_ExecDml(1, Db_qry_insert.new_().BaseTable_("dbs_crud_ops").Arg_("id", 1).Arg_("name", "you"));
|
||||
|
||||
@@ -82,7 +82,7 @@ public class SqliteDbMain {
|
||||
}
|
||||
long time_elapsed = (Env_.TickCount() - time_bgn);
|
||||
// provider.Txn_mgr().Txn_end();
|
||||
provider.Rls();
|
||||
provider.Conn_term();
|
||||
Tfds.Write(time_elapsed, number / time_elapsed);
|
||||
// 250; 260
|
||||
Tfds.Write("");
|
||||
|
||||
Reference in New Issue
Block a user