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-07-19 23:16:49 -04:00
parent 794b5a232f
commit 8e041d6e06
834 changed files with 4749 additions and 4461 deletions

View File

@@ -51,12 +51,12 @@ public class Db_qry__select_cmd implements Db_qry {
public Sql_from From() {return from;} Sql_from from;
public Db_qry__select_cmd From_(String tblName) {return From_(tblName, null);}
public Db_qry__select_cmd From_(String tblName, String alias) {
if (from != null) throw Exc_.new_("super table already defined", "from", from.Tbls().Count());
if (from != null) throw Err_.new_wo_type("super table already defined", "from", from.Tbls().Count());
from = Sql_from.new_(Sql_tbl_src.new_().JoinType_(Sql_join_itmType.From).TblName_(tblName).Alias_(alias));
return this;
}
public Db_qry__select_cmd Join_(String name, String alias, Sql_join_itm... ary) {
if (from == null) throw Exc_.new_("super table is not defined");
if (from == null) throw Err_.new_wo_type("super table is not defined");
Sql_tbl_src tbl = Sql_tbl_src.new_().JoinType_(Sql_join_itmType.Inner).TblName_(name).Alias_(alias);
for (Sql_join_itm itm : ary)
tbl.JoinLinks().Add(itm);
@@ -118,7 +118,7 @@ public class Db_qry__select_cmd implements Db_qry {
}
public Sql_group_by GroupBy() {return groupBy;} Sql_group_by groupBy = null;
public Db_qry__select_cmd GroupBy_(String... flds) {
if (groupBy != null) throw Exc_.new_("group by already defined", "group", groupBy);
if (groupBy != null) throw Err_.new_wo_type("group by already defined", "group", groupBy);
groupBy = Sql_group_by.new_(flds);
return this;
}

View File

@@ -28,7 +28,7 @@ public class Db_qry_flush implements Db_qry {
public static Db_qry_flush as_(Object obj) {return obj instanceof Db_qry_flush ? (Db_qry_flush)obj : null;}
public static Db_qry_flush cast_(Object obj) {try {return (Db_qry_flush)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, Db_qry_flush.class, obj);}}
public static Db_qry_flush cast_(Object obj) {try {return (Db_qry_flush)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, Db_qry_flush.class, obj);}}
public static Db_qry_flush new_(String... ary) {
Db_qry_flush rv = new Db_qry_flush();
rv.tableNames = ary;

View File

@@ -20,7 +20,7 @@ import gplx.dbs.sqls.*;
public class Db_qry_sql implements Db_qry {
public int Tid() {return Db_qry_.Tid_sql;}
public boolean Exec_is_rdr() {return isReader;} private boolean isReader;
public String Base_table() {throw Exc_.new_unimplemented();}
public String Base_table() {throw Err_.new_unimplemented();}
public String Xto_sql() {return sql;} private String sql;
public int Exec_qry(Db_conn conn) {return conn.Exec_qry(this);}
public static Db_qry_sql dml_(String sql) {return sql_(sql);}
@@ -37,7 +37,7 @@ public class Db_qry_sql implements Db_qry {
return rv;
}
public static Db_qry_sql as_(Object obj) {return obj instanceof Db_qry_sql ? (Db_qry_sql)obj : null;}
public static Db_qry_sql cast_(Object obj) {try {return (Db_qry_sql)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, Db_qry_sql.class, obj);}}
public static Db_qry_sql cast_(Object obj) {try {return (Db_qry_sql)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, Db_qry_sql.class, obj);}}
public static String Gen_sql(Db_qry qry, Object... args) {
byte[] src = Bry_.new_u8(Sql_qry_wtr_.Gen_placeholder_parameters(qry));
int src_len = src.length;

View File

@@ -42,7 +42,7 @@ public class Db_stmt_cmd implements Db_stmt {
public Db_stmt Val_byte(byte v) {return Add_byte(Bool_.N, Key_na, v);}
private Db_stmt Add_byte(boolean where, String k, byte v) {
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setByte(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v, "sql", sql);}
try {stmt.setByte(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_int(String k, int v) {return Add_int(Bool_.Y, k, v);}
@@ -50,7 +50,7 @@ public class Db_stmt_cmd implements Db_stmt {
public Db_stmt Val_int(int v) {return Add_int(Bool_.N, Key_na, v);}
private Db_stmt Add_int(boolean where, String k, int v) {
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setInt(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "int", "val", v, "sql", sql);}
try {stmt.setInt(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "int", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_long(String k, long v) {return Add_long(Bool_.Y, k, v);}
@@ -58,7 +58,7 @@ public class Db_stmt_cmd implements Db_stmt {
public Db_stmt Val_long(long v) {return Add_long(Bool_.N, Key_na, v);}
private Db_stmt Add_long(boolean where, String k, long v) {
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setLong(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "long", "val", v, "sql", sql);}
try {stmt.setLong(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "long", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_float(String k, float v) {return Add_float(Bool_.Y, k, v);}
@@ -66,7 +66,7 @@ public class Db_stmt_cmd implements Db_stmt {
public Db_stmt Val_float(float v) {return Add_float(Bool_.N, Key_na, v);}
private Db_stmt Add_float(boolean where, String k, float v) {
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setFloat(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "float", "val", v, "sql", sql);}
try {stmt.setFloat(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "float", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_double(String k, double v) {return Add_double(Bool_.Y, k, v);}
@@ -74,7 +74,7 @@ public class Db_stmt_cmd implements Db_stmt {
public Db_stmt Val_double(double v) {return Add_double(Bool_.N, Key_na, v);}
private Db_stmt Add_double(boolean where, String k, double v) {
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setDouble(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "double", "val", v, "sql", sql);}
try {stmt.setDouble(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.Y, k, v);}
@@ -82,7 +82,7 @@ public class Db_stmt_cmd implements Db_stmt {
public Db_stmt Val_decimal(DecimalAdp v) {return Add_decimal(Bool_.N, Key_na, v);}
private Db_stmt Add_decimal(boolean where, String k, DecimalAdp v) {
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setBigDecimal(++val_idx, v.Xto_decimal());} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v, "sql", sql);}
try {stmt.setBigDecimal(++val_idx, v.Xto_decimal());} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(Bool_.Y, k, v);}
@@ -90,7 +90,7 @@ public class Db_stmt_cmd implements Db_stmt {
public Db_stmt Val_bry(byte[] v) {return Add_bry(Bool_.N, Key_na, v);}
private Db_stmt Add_bry(boolean where, String k, byte[] v) {
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setBytes(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "byte[]", v.length, sql);}
try {stmt.setBytes(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "byte[]", v.length, sql);}
return this;
}
public Db_stmt Crt_bry_as_str(String k, byte[] v) {return Add_bry_as_str(Bool_.Y, k, v);}
@@ -102,11 +102,11 @@ public class Db_stmt_cmd implements Db_stmt {
public Db_stmt Val_str(String v) {return Add_str(Bool_.N, Key_na, v);}
private Db_stmt Add_str(boolean where, String k, String v) {
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setString(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "String", "val", v, "sql", sql);}
try {stmt.setString(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "String", "val", v, "sql", sql);}
return this;
}
public Db_stmt Val_rdr_(gplx.ios.Io_stream_rdr v, long rdr_len) {
try {stmt.setBinaryStream(++val_idx, (java.io.InputStream)v.Under(), (int)rdr_len);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
try {stmt.setBinaryStream(++val_idx, (java.io.InputStream)v.Under(), (int)rdr_len);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
return this;
}
public boolean Exec_insert() {
@@ -114,7 +114,7 @@ public class Db_stmt_cmd implements Db_stmt {
catch (Exception e) {
this.Rls();
Reset_stmt();
throw Exc_.new_exc(e, "db_stmt", "insert failed", "url", engine.Conn_info().Xto_api(), "sql", sql);
throw Err_.new_exc(e, "db_stmt", "insert failed", "url", engine.Conn_info().Xto_api(), "sql", sql);
}
}
public int Exec_update() {
@@ -122,7 +122,7 @@ public class Db_stmt_cmd implements Db_stmt {
catch (Exception e) {
this.Rls();
Reset_stmt();
throw Exc_.new_exc(e, "db_stmt", "update failed", "url", engine.Conn_info().Xto_api(), "sql", sql);
throw Err_.new_exc(e, "db_stmt", "update failed", "url", engine.Conn_info().Xto_api(), "sql", sql);
}
}
public int Exec_delete() {
@@ -130,25 +130,25 @@ public class Db_stmt_cmd implements Db_stmt {
catch (Exception e) {
this.Rls();
Reset_stmt();
throw Exc_.new_exc(e, "db_stmt", "delete failed", "url", engine.Conn_info().Xto_api(), "sql", sql);
throw Err_.new_exc(e, "db_stmt", "delete failed", "url", engine.Conn_info().Xto_api(), "sql", sql);
}
}
public DataRdr Exec_select() {
try {DataRdr rv = engine.New_rdr(stmt.executeQuery(), sql); return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql);}
try {DataRdr rv = engine.New_rdr(stmt.executeQuery(), sql); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql);}
}
public Db_rdr Exec_select__rls_auto() {
try {return engine.New_rdr__rls_auto(this, stmt.executeQuery(), sql);} catch (Exception e) {throw Exc_.new_exc(e, "db", "select failed", "sql", sql);}
try {return engine.New_rdr__rls_auto(this, stmt.executeQuery(), sql);} catch (Exception e) {throw Err_.new_exc(e, "db", "select failed", "sql", sql);}
}
public Db_rdr Exec_select__rls_manual() {
try {return engine.New_rdr__rls_manual(stmt.executeQuery(), sql);} catch (Exception e) {throw Exc_.new_exc(e, "db", "select failed", "sql", sql);}
try {return engine.New_rdr__rls_manual(stmt.executeQuery(), sql);} catch (Exception e) {throw Err_.new_exc(e, "db", "select failed", "sql", sql);}
}
public Object Exec_select_val() {
try {Object rv = Db_qry__select_cmd.Rdr_to_val(engine.New_rdr(stmt.executeQuery(), sql)); return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql);}
try {Object rv = Db_qry__select_cmd.Rdr_to_val(engine.New_rdr(stmt.executeQuery(), sql)); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql);}
}
public Db_stmt Clear() {
val_idx = 0;
try {stmt.clearBatch();}
catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to clear parameters", "sql", sql);}
catch (Exception e) {throw Err_.new_exc(e, "db", "failed to clear parameters", "sql", sql);}
return this;
}
public void Rls() {
@@ -158,6 +158,6 @@ public class Db_stmt_cmd implements Db_stmt {
stmt.close();
stmt = null;
}
catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to close command", "sql", sql);}
catch (Exception e) {throw Err_.new_exc(e, "db", "failed to close command", "sql", sql);}
}
}

View File

@@ -33,49 +33,49 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
public Db_stmt Val_byte(String k, byte v) {return Add_byte(Bool_.N, k, v);}
public Db_stmt Val_byte(byte v) {return Add_byte(Bool_.N, Key_na, v);}
private Db_stmt Add_byte(boolean where, String k, byte v) {
try {Add(k, Byte_.Xto_str(v));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v);}
try {Add(k, Byte_.Xto_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v);}
return this;
}
public Db_stmt Crt_int(String k, int v) {return Add_int(Bool_.Y, k, v);}
public Db_stmt Val_int(String k, int v) {return Add_int(Bool_.N, k, v);}
public Db_stmt Val_int(int v) {return Add_int(Bool_.N, Key_na, v);}
private Db_stmt Add_int(boolean where, String k, int v) {
try {Add(k, Int_.Xto_str(v));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "int", "val", v);}
try {Add(k, Int_.Xto_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "int", "val", v);}
return this;
}
public Db_stmt Crt_long(String k, long v) {return Add_long(Bool_.Y, k, v);}
public Db_stmt Val_long(String k, long v) {return Add_long(Bool_.N, k, v);}
public Db_stmt Val_long(long v) {return Add_long(Bool_.N, Key_na, v);}
private Db_stmt Add_long(boolean where, String k, long v) {
try {Add(k, Long_.Xto_str(v));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "long", "val", v);}
try {Add(k, Long_.Xto_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "long", "val", v);}
return this;
}
public Db_stmt Crt_float(String k, float v) {return Add_float(Bool_.Y, k, v);}
public Db_stmt Val_float(String k, float v) {return Add_float(Bool_.N, k, v);}
public Db_stmt Val_float(float v) {return Add_float(Bool_.N, Key_na, v);}
private Db_stmt Add_float(boolean where, String k, float v) {
try {Add(k, Float_.Xto_str(v));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "float", "val", v);}
try {Add(k, Float_.Xto_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "float", "val", v);}
return this;
}
public Db_stmt Crt_double(String k, double v) {return Add_double(Bool_.Y, k, v);}
public Db_stmt Val_double(String k, double v) {return Add_double(Bool_.N, k, v);}
public Db_stmt Val_double(double v) {return Add_double(Bool_.N, Key_na, v);}
private Db_stmt Add_double(boolean where, String k, double v) {
try {Add(k, Double_.Xto_str(v));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "double", "val", v);}
try {Add(k, Double_.Xto_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v);}
return this;
}
public Db_stmt Crt_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.Y, k, v);}
public Db_stmt Val_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.N, k, v);}
public Db_stmt Val_decimal(DecimalAdp v) {return Add_decimal(Bool_.N, Key_na, v);}
private Db_stmt Add_decimal(boolean where, String k, DecimalAdp v) {
try {Add(k, v.Xto_str());} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
try {Add(k, v.Xto_str());} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
return this;
}
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(Bool_.Y, k, v);}
public Db_stmt Val_bry(String k, byte[] v) {return Add_bry(Bool_.N, k, v);}
public Db_stmt Val_bry(byte[] v) {return Add_bry(Bool_.N, Key_na, v);}
private Db_stmt Add_bry(boolean where, String k, byte[] v) {// HACK: convert to String b/c tdb does not support byte[]
try {Add(k, Val_str_wrap(String_.new_u8(v)));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "byte[]", "val", v.length);}
try {Add(k, Val_str_wrap(String_.new_u8(v)));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "byte[]", "val", v.length);}
return this;
}
public Db_stmt Crt_bry_as_str(String k, byte[] v) {return Add_bry_as_str(Bool_.Y, k, v);}
@@ -86,7 +86,7 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
public Db_stmt Val_str(String k, String v) {return Add_str(Bool_.N, k, v);}
public Db_stmt Val_str(String v) {return Add_str(Bool_.N, Key_na, v);}
private Db_stmt Add_str(boolean where, String k, String v) {
try {Add(k, Val_str_wrap(v));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "String", "val", v);}
try {Add(k, Val_str_wrap(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "String", "val", v);}
return this;
}
public Db_stmt Val_rdr_(gplx.ios.Io_stream_rdr v, long rdr_len) {
@@ -94,28 +94,28 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
Bry_bfr bfr = Bry_bfr.new_();
gplx.ios.Io_stream_rdr_.Load_all_to_bfr(bfr, v);
Add(Key_na, bfr.Xto_str_and_clear());
} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
return this;
}
private String Val_str_wrap(String v) {
return "'" + String_.Replace(v, "'", "\\'") + "'";
}
public boolean Exec_insert() {
try {boolean rv = conn.Exec_qry(Db_qry_sql.dml_(this.Xto_sql())) != 0; return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
try {boolean rv = conn.Exec_qry(Db_qry_sql.dml_(this.Xto_sql())) != 0; return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
}
public int Exec_update() {
try {int rv = conn.Exec_qry(Db_qry_sql.dml_(this.Xto_sql())); return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
try {int rv = conn.Exec_qry(Db_qry_sql.dml_(this.Xto_sql())); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
}
public int Exec_delete() {
try {int rv = conn.Exec_qry(Db_qry_sql.dml_(this.Xto_sql())); return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
try {int rv = conn.Exec_qry(Db_qry_sql.dml_(this.Xto_sql())); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
}
public DataRdr Exec_select() {
try {DataRdr rv = conn.Exec_qry_as_rdr(Db_qry_sql.rdr_(this.Xto_sql())); return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
try {DataRdr rv = conn.Exec_qry_as_rdr(Db_qry_sql.rdr_(this.Xto_sql())); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
}
public Db_rdr Exec_select__rls_auto() {return Db_rdr_.Empty;}
public Db_rdr Exec_select__rls_manual() {return Db_rdr_.Empty;}
public Object Exec_select_val() {
try {Object rv = Db_qry__select_cmd.Rdr_to_val(this.Exec_select()); return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
try {Object rv = Db_qry__select_cmd.Rdr_to_val(this.Exec_select()); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
}
public Db_stmt Clear() {
args.Clear();