public class DASemantext extends Object implements io.odysz.semantics.ISemantext
For example, pageSql(String, int, int)
is an example that must
handled by context, but not interested by semantic.jserv. When composing SQL
like select statement, if the results needing to be paged at server side,
the paging sql statement is different for different DB. But semantic-transact
don't care DB type or JDBC connection, so it's the context that will handling
this.
See the Connects.pagingSql(dbtype, String, int, int)
.
Modifier and Type | Field and Description |
---|---|
protected String |
basePath |
protected String |
connId |
static int |
file_sys |
protected HashMap<String,io.odysz.semantics.meta.TableMeta> |
metas |
protected ArrayList<io.odysz.transact.sql.Statement.IPostOptn> |
onRowsOk |
protected LinkedHashMap<String,io.odysz.transact.sql.Statement.IPostSelectOptn> |
onSelecteds |
protected LinkedHashMap<String,io.odysz.transact.sql.Statement.IPostOptn> |
onTableOk |
protected DATranscxt.SemanticsMap |
semants
Semantic Configurations
|
protected static io.odysz.semantics.IUser |
sqliteDumyUser
for generating sqlite auto seq
|
protected io.odysz.semantics.IUser |
usr |
Modifier | Constructor and Description |
---|---|
protected |
DASemantext(String connId,
DATranscxt.SemanticsMap semanticsMap,
io.odysz.semantics.IUser usr,
String rtPath)
Initialize a context for semantics handling.
|
Modifier and Type | Method and Description |
---|---|
void |
addOnRowsCommitted(io.odysz.transact.sql.Statement.IPostOptn op) |
void |
addOnSelectedHandler(String name,
io.odysz.transact.sql.Statement.IPostSelectOptn op) |
void |
addOnTableCommitted(String tabl,
io.odysz.transact.sql.Statement.IPostOptn op) |
void |
clear()
Deprecated.
|
protected io.odysz.semantics.ISemantext |
clone(DASemantext srctx,
io.odysz.semantics.IUser usr) |
io.odysz.semantics.ISemantext |
clone(io.odysz.semantics.IUser usr) |
io.odysz.transact.sql.parts.AbsPart |
composeVal(Object v,
String tabl,
String col) |
String |
connId() |
io.odysz.semantics.ISemantext |
connId(String conn) |
String |
containerRoot() |
io.odysz.common.dbtype |
dbtype() |
String |
genId(String conn,
String tabl,
String col,
String... preval) |
protected static String |
genIdPrefix(String conn,
String target,
String idField,
String subCate)
Generate new Id with the help of db function f_incSeq(varchar idName)
Sql script for stored function: Mysql: |
io.odysz.semantics.meta.TableMeta |
getTableMeta(String tbl) |
boolean |
hasOnSelectedHandler(String name) |
io.odysz.semantics.ISemantext |
insert(io.odysz.transact.sql.Insert insert,
String tabl,
io.odysz.semantics.IUser usr) |
void |
onCommitted(io.odysz.semantics.ISemantext ctx,
String tabl) |
io.odysz.semantics.ISemantext |
onDelete(io.odysz.transact.sql.Delete delete,
String tabl,
io.odysz.transact.sql.parts.condition.Condit whereCondt) |
io.odysz.semantics.ISemantext |
onInsert(io.odysz.transact.sql.Insert insert,
String tabl,
List<ArrayList<Object[]>> rows)
When inserting, process data row with configured semantics, like auto-pk, fk-ins, etc..
|
io.odysz.semantics.ISemantext |
onPost(io.odysz.transact.sql.Statement<?> stmt,
String tabl,
ArrayList<Object[]> row,
ArrayList<String> sqls) |
void |
onSelected(Object resultset) |
io.odysz.transact.sql.Statement.IPostOptn |
onTableCommittedHandler(String tabl) |
io.odysz.semantics.ISemantext |
onUpdate(io.odysz.transact.sql.Update update,
String tabl,
ArrayList<Object[]> nvs) |
String |
pageSql(String rawSql,
int page,
int size) |
static String |
pagingSql(io.odysz.common.dbtype dt,
String sql,
int pageIx,
int pgSize)
Deprecated.
replaced by
Connects.pagingSql(dbtype, String, int, int) |
static String |
radix64_32(long v)
Try generate a radix 64 string of v.
|
String |
relativpath(String... sub) |
List<Object> |
resulvedVals(String tabl,
String col) |
io.odysz.semantics.SemanticObject |
resulves()
Get the resolved value in
autoVals
a.k.a return value of Statement.doneOp(io.odysz.transact.sql.Statement.IPostOptn) . |
io.odysz.semantics.meta.TableMeta |
tablType(String tabl) |
static String |
totalSql(io.odysz.common.dbtype dt,
String sql) |
String |
totalSql(String rawSql) |
io.odysz.semantics.ISemantext |
update(io.odysz.transact.sql.Update update,
String tabl,
io.odysz.semantics.IUser usr) |
protected DATranscxt.SemanticsMap semants
protected io.odysz.semantics.IUser usr
protected String connId
protected String basePath
protected ArrayList<io.odysz.transact.sql.Statement.IPostOptn> onRowsOk
protected LinkedHashMap<String,io.odysz.transact.sql.Statement.IPostSelectOptn> onSelecteds
protected LinkedHashMap<String,io.odysz.transact.sql.Statement.IPostOptn> onTableOk
protected static io.odysz.semantics.IUser sqliteDumyUser
public static int file_sys
protected DASemantext(String connId, DATranscxt.SemanticsMap semanticsMap, io.odysz.semantics.IUser usr, String rtPath) throws SemanticException, SQLException
connId
- semanticsMap
- semantic configurations, usually load by DATranscxt
.
sample code:
DATranscxt.initConfigs("inet", rootINF + "/semantics.xml");usr
- rtPath
- runtime root path, for docker layer, it's typically the volume folder.SemanticException
- metas is nullSQLException
public io.odysz.semantics.ISemantext onInsert(io.odysz.transact.sql.Insert insert, String tabl, List<ArrayList<Object[]>> rows) throws SemanticException
onInsert
in interface io.odysz.semantics.ISemantext
SemanticException
ISemantext.onInsert(io.odysz.transact.sql.Insert, java.lang.String, java.util.List)
public io.odysz.semantics.ISemantext onUpdate(io.odysz.transact.sql.Update update, String tabl, ArrayList<Object[]> nvs) throws SemanticException
onUpdate
in interface io.odysz.semantics.ISemantext
SemanticException
public io.odysz.semantics.ISemantext onDelete(io.odysz.transact.sql.Delete delete, String tabl, io.odysz.transact.sql.parts.condition.Condit whereCondt) throws io.odysz.transact.x.TransException
onDelete
in interface io.odysz.semantics.ISemantext
io.odysz.transact.x.TransException
public io.odysz.semantics.ISemantext onPost(io.odysz.transact.sql.Statement<?> stmt, String tabl, ArrayList<Object[]> row, ArrayList<String> sqls) throws io.odysz.transact.x.TransException
onPost
in interface io.odysz.semantics.ISemantext
io.odysz.transact.x.TransException
public io.odysz.semantics.ISemantext insert(io.odysz.transact.sql.Insert insert, String tabl, io.odysz.semantics.IUser usr) throws SQLException
insert
in interface io.odysz.semantics.ISemantext
SQLException
public io.odysz.semantics.ISemantext update(io.odysz.transact.sql.Update update, String tabl, io.odysz.semantics.IUser usr) throws SQLException
update
in interface io.odysz.semantics.ISemantext
SQLException
public io.odysz.common.dbtype dbtype()
dbtype
in interface io.odysz.semantics.ISemantext
public String connId()
connId
in interface io.odysz.semantics.ISemantext
public io.odysz.semantics.ISemantext connId(String conn)
connId
in interface io.odysz.semantics.ISemantext
public io.odysz.semantics.ISemantext clone(io.odysz.semantics.IUser usr)
clone
in interface io.odysz.semantics.ISemantext
protected io.odysz.semantics.ISemantext clone(DASemantext srctx, io.odysz.semantics.IUser usr)
public List<Object> resulvedVals(String tabl, String col)
resulvedVals
in interface io.odysz.semantics.ISemantext
public io.odysz.semantics.SemanticObject resulves()
autoVals
a.k.a return value of Statement.doneOp(io.odysz.transact.sql.Statement.IPostOptn)
.resulves
in interface io.odysz.semantics.ISemantext
autoVals
ISemantext.resulves()
public String genId(String conn, String tabl, String col, String... preval) throws SQLException, io.odysz.transact.x.TransException
genId
in interface io.odysz.semantics.ISemantext
SQLException
io.odysz.transact.x.TransException
protected static String genIdPrefix(String conn, String target, String idField, String subCate) throws SQLException, io.odysz.transact.x.TransException
create FUNCTION f_incSeq2 (seqId varchar(100), prefix varchar(4)) RETURNS int(11) begin DECLARE seqName varchar(100); DECLARE cnt INT DEFAULT 0; if prefix = '' then set seqName = seqId; else set seqName = concat(seqId, '.', prefix); end if; select count(seq) into cnt from ir_autoSeqs where sid = seqName; if cnt = 0 then insert into ir_autoSeqs(sid, seq, remarks) values (seqName, 0, now()); end if; select seq into cnt from ir_autoSeqs where sid = seqName; update ir_autoSeqs set seq = cnt + 1 where sid = seqName; return cnt; end;select f_incSeq2('%s.%s', '%s') newId
CREATE OR REPLACE FUNCTION GZDX_YJPT.f_incSeq2(seqId in varchar, prefix in varchar) RETURN integer IS PRAGMA AUTONOMOUS_TRANSACTION; seqName varchar(100); cnt integer DEFAULT 0; begin if prefix = '' then seqName := seqId; else seqName := concat(concat(seqId, '.'), prefix); end if; select count(seq) into cnt from ir_autoSeqs where sid = seqName; if cnt = 0 then insert into ir_autoSeqs(sid, seq, remarks) values (seqName, 0, to_char(sysdate, 'MM-DD-YYYY HH24:MI:SS')); commit; end if; select seq into cnt from ir_autoSeqs where sid = seqName; update ir_autoSeqs set seq = cnt + 1, remarks = to_char(sysdate, 'MM-DD-YYYY HH24:MI:SS') where sid = seqName; commit; return cnt; end;select f_incSeq2('%s.%s', '%s') newId from dual
auto ID for sqlite is handled by genSqliteId(String, String, String)
- needing table initialization.
conn
- connection idtarget
- target tableidField
- table id column (no multi-column id supported)subCate
- Radix64
)SQLException
io.odysz.transact.x.TransException
public static String radix64_32(long v)
v
- public String totalSql(String rawSql) throws io.odysz.transact.x.TransException
io.odysz.transact.x.TransException
public String pageSql(String rawSql, int page, int size) throws io.odysz.transact.x.TransException
io.odysz.transact.x.TransException
public static String pagingSql(io.odysz.common.dbtype dt, String sql, int pageIx, int pgSize) throws io.odysz.transact.x.TransException
Connects.pagingSql(dbtype, String, int, int)
dt
- sql
- pageIx
- pgSize
- io.odysz.transact.x.TransException
public static String totalSql(io.odysz.common.dbtype dt, String sql) throws io.odysz.transact.x.TransException
dt
- sql
- io.odysz.transact.x.TransException
public void clear()
public io.odysz.semantics.meta.TableMeta tablType(String tabl)
tablType
in interface io.odysz.semantics.ISemantext
public String relativpath(String... sub) throws io.odysz.transact.x.TransException
relativpath
in interface io.odysz.semantics.ISemantext
io.odysz.transact.x.TransException
public String containerRoot()
containerRoot
in interface io.odysz.semantics.ISemantext
public void onCommitted(io.odysz.semantics.ISemantext ctx, String tabl) throws io.odysz.transact.x.TransException, SQLException
onCommitted
in interface io.odysz.semantics.ISemantext
io.odysz.transact.x.TransException
SQLException
public void addOnRowsCommitted(io.odysz.transact.sql.Statement.IPostOptn op)
addOnRowsCommitted
in interface io.odysz.semantics.ISemantext
public void addOnTableCommitted(String tabl, io.odysz.transact.sql.Statement.IPostOptn op)
addOnTableCommitted
in interface io.odysz.semantics.ISemantext
public io.odysz.transact.sql.Statement.IPostOptn onTableCommittedHandler(String tabl)
onTableCommittedHandler
in interface io.odysz.semantics.ISemantext
public boolean hasOnSelectedHandler(String name)
hasOnSelectedHandler
in interface io.odysz.semantics.ISemantext
public void onSelected(Object resultset) throws SQLException, io.odysz.transact.x.TransException
onSelected
in interface io.odysz.semantics.ISemantext
SQLException
io.odysz.transact.x.TransException
public void addOnSelectedHandler(String name, io.odysz.transact.sql.Statement.IPostSelectOptn op)
addOnSelectedHandler
in interface io.odysz.semantics.ISemantext
public io.odysz.transact.sql.parts.AbsPart composeVal(Object v, String tabl, String col)
composeVal
in interface io.odysz.semantics.ISemantext
public io.odysz.semantics.meta.TableMeta getTableMeta(String tbl)
getTableMeta
in interface io.odysz.semantics.ISemantext
Copyright © 2024. All rights reserved.