Package io.odysz.semantic
Class DASemantext
java.lang.Object
io.odysz.semantic.DASemantext
- All Implemented Interfaces:
io.odysz.semantics.ISemantext
- Direct Known Subclasses:
DBSynmantext
A basic semantic context for generating sql.
Handling semantics defined in runtime-root/semantics.xml file.
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)
.
- Author:
- odys-z@github.com
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
protected String
static int
protected ArrayList<io.odysz.transact.sql.Statement.IPostOptn>
protected LinkedHashMap<String,
io.odysz.transact.sql.Statement.IPostSelectOptn> protected LinkedHashMap<String,
io.odysz.transact.sql.Statement.IPostOptn> protected DATranscxt.SemanticsMap
Semantic Configurationsprotected static io.odysz.semantics.IUser
for generating sqlite auto seqprotected io.odysz.semantics.IUser
-
Constructor Summary
ModifierConstructorDescriptionprotected
DASemantext
(String connId, DATranscxt.SemanticsMap semanticsMap, io.odysz.semantics.IUser usr, String rtPath) Initialize a context for semantics handling. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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) connId()
io.odysz.semantics.ISemantext
io.odysz.common.dbtype
dbtype()
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
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
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
io.odysz.semantics.ISemantext
static String
Deprecated.static String
radix64_32
(long v) Try generate a radix 64 string of v.relativpath
(String... sub) resulvedVals
(String tabl, String col) io.odysz.semantics.SemanticObject
resulves()
Get the resolved value inautoVals
a.k.a return value ofStatement.doneOp(io.odysz.transact.sql.Statement.IPostOptn)
.io.odysz.semantics.meta.TableMeta
static String
io.odysz.semantics.ISemantext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.odysz.semantics.ISemantext
creator, resulvedVal
-
Field Details
-
semants
Semantic Configurations -
metas
-
usr
protected io.odysz.semantics.IUser usr -
connId
-
basePath
-
onRowsOk
-
onSelecteds
-
onTableOk
-
sqliteDumyUser
protected static io.odysz.semantics.IUser sqliteDumyUserfor generating sqlite auto seq -
file_sys
public static int file_sys
-
-
Constructor Details
-
DASemantext
protected DASemantext(String connId, DATranscxt.SemanticsMap semanticsMap, io.odysz.semantics.IUser usr, String rtPath) throws SemanticException, SQLException Initialize a context for semantics handling. This class handling semantics comes form path, usually an xml like test/res/semantics.xml.- Parameters:
connId
-semanticsMap
- semantic configurations, usually load byDATranscxt
.sample code:
DATranscxt.initConfigs("inet", rootINF + "/semantics.xml");usr
-rtPath
- runtime root path, for docker layer, it's typically the volume folder.- Throws:
SemanticException
- metas is nullSQLException
-
-
Method Details
-
onInsert
public io.odysz.semantics.ISemantext onInsert(io.odysz.transact.sql.Insert insert, String tabl, List<ArrayList<Object[]>> rows) throws io.odysz.transact.x.TransException When inserting, process data row with configured semantics, like auto-pk, fk-ins, etc..- Specified by:
onInsert
in interfaceio.odysz.semantics.ISemantext
- Throws:
io.odysz.transact.x.TransException
- See Also:
-
ISemantext.onInsert(io.odysz.transact.sql.Insert, java.lang.String, java.util.List)
-
onUpdate
public io.odysz.semantics.ISemantext onUpdate(io.odysz.transact.sql.Update update, String tabl, ArrayList<Object[]> nvs) throws io.odysz.transact.x.TransException - Specified by:
onUpdate
in interfaceio.odysz.semantics.ISemantext
- Throws:
io.odysz.transact.x.TransException
-
onDelete
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 - Specified by:
onDelete
in interfaceio.odysz.semantics.ISemantext
- Throws:
io.odysz.transact.x.TransException
-
onPost
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 - Specified by:
onPost
in interfaceio.odysz.semantics.ISemantext
- Throws:
io.odysz.transact.x.TransException
-
insert
public io.odysz.semantics.ISemantext insert(io.odysz.transact.sql.Insert insert, String tabl, io.odysz.semantics.IUser usr) throws SQLException - Specified by:
insert
in interfaceio.odysz.semantics.ISemantext
- Throws:
SQLException
-
update
public io.odysz.semantics.ISemantext update(io.odysz.transact.sql.Update update, String tabl, io.odysz.semantics.IUser usr) throws SQLException - Specified by:
update
in interfaceio.odysz.semantics.ISemantext
- Throws:
SQLException
-
dbtype
public io.odysz.common.dbtype dbtype()- Specified by:
dbtype
in interfaceio.odysz.semantics.ISemantext
-
connId
- Specified by:
connId
in interfaceio.odysz.semantics.ISemantext
-
connId
- Specified by:
connId
in interfaceio.odysz.semantics.ISemantext
-
clone
public io.odysz.semantics.ISemantext clone(io.odysz.semantics.IUser usr) - Specified by:
clone
in interfaceio.odysz.semantics.ISemantext
-
clone
-
resulvedVals
- Specified by:
resulvedVals
in interfaceio.odysz.semantics.ISemantext
-
resulves
public io.odysz.semantics.SemanticObject resulves()Get the resolved value inautoVals
a.k.a return value ofStatement.doneOp(io.odysz.transact.sql.Statement.IPostOptn)
.- Specified by:
resulves
in interfaceio.odysz.semantics.ISemantext
- Returns:
autoVals
- See Also:
-
ISemantext.resulves()
-
genId
public String genId(String conn, String tabl, String col, String... preval) throws SQLException, io.odysz.transact.x.TransException - Specified by:
genId
in interfaceio.odysz.semantics.ISemantext
- Throws:
SQLException
io.odysz.transact.x.TransException
-
genIdPrefix
protected static String genIdPrefix(String conn, String target, String idField, String subCate) throws SQLException, io.odysz.transact.x.TransException Generate new Id with the help of db function f_incSeq(varchar idName)
Sql script for stored function:
Mysql: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
Oracle: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 dualauto ID for sqlite is handled by
genSqliteId(String, String, String)
- needing table initialization.- Parameters:
conn
- connection idtarget
- target tableidField
- table id column (no multi-column id supported)subCate
-- Returns:
- new Id (shortened in radix 64 by
Radix64
) - Throws:
SQLException
io.odysz.transact.x.TransException
-
radix64_32
Try generate a radix 64 string of v. String length is controlled by connfigs.xml/k=db-len, overriding default 8 for windows, or 6 for others. If configs.xml/k=filesys is "windows", then generate a radix 32 string.- Parameters:
v
-- Returns:
- radix 64/32
-
totalSql
- Throws:
io.odysz.transact.x.TransException
-
pageSql
- Throws:
io.odysz.transact.x.TransException
-
pagingSql
public static String pagingSql(io.odysz.common.dbtype dt, String sql, int pageIx, int pgSize) throws io.odysz.transact.x.TransException Deprecated.replaced byConnects.pagingSql(dbtype, String, int, int)
Wrap sql only for rows in a page, in stream mode.- Parameters:
dt
-sql
-pageIx
-pgSize
-- Returns:
- pagination wrapped sql
- Throws:
io.odysz.transact.x.TransException
-
totalSql
public static String totalSql(io.odysz.common.dbtype dt, String sql) throws io.odysz.transact.x.TransException - Parameters:
dt
-sql
-- Returns:
- SQL: select count(*) as total from [sql]
- Throws:
io.odysz.transact.x.TransException
-
clear
public void clear()Deprecated. -
tablType
- Specified by:
tablType
in interfaceio.odysz.semantics.ISemantext
-
relativpath
- Specified by:
relativpath
in interfaceio.odysz.semantics.ISemantext
- Throws:
io.odysz.transact.x.TransException
-
containerRoot
- Specified by:
containerRoot
in interfaceio.odysz.semantics.ISemantext
-
onCommitted
public void onCommitted(io.odysz.semantics.ISemantext ctx, String tabl) throws io.odysz.transact.x.TransException, SQLException - Specified by:
onCommitted
in interfaceio.odysz.semantics.ISemantext
- Throws:
io.odysz.transact.x.TransException
SQLException
-
addOnRowsCommitted
public void addOnRowsCommitted(io.odysz.transact.sql.Statement.IPostOptn op) - Specified by:
addOnRowsCommitted
in interfaceio.odysz.semantics.ISemantext
-
addOnTableCommitted
- Specified by:
addOnTableCommitted
in interfaceio.odysz.semantics.ISemantext
-
onTableCommittedHandler
- Specified by:
onTableCommittedHandler
in interfaceio.odysz.semantics.ISemantext
-
hasOnSelectedHandler
- Specified by:
hasOnSelectedHandler
in interfaceio.odysz.semantics.ISemantext
-
onSelected
- Specified by:
onSelected
in interfaceio.odysz.semantics.ISemantext
- Throws:
SQLException
io.odysz.transact.x.TransException
-
addOnSelectedHandler
- Specified by:
addOnSelectedHandler
in interfaceio.odysz.semantics.ISemantext
-
composeVal
- Specified by:
composeVal
in interfaceio.odysz.semantics.ISemantext
-
getTableMeta
- Specified by:
getTableMeta
in interfaceio.odysz.semantics.ISemantext
-
Connects.pagingSql(dbtype, String, int, int)