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
FieldsModifier and TypeFieldDescriptionprotected Stringprotected Stringstatic intprotected 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.SemanticsMapSemantic Configurationsprotected static io.odysz.semantics.IUserfor generating sqlite auto seqprotected io.odysz.semantics.IUser -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDASemantext(String connId, DATranscxt.SemanticsMap semanticsMap, io.odysz.semantics.IUser usr, String rtPath) Initialize a context for semantics handling. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOnRowsCommitted(io.odysz.transact.sql.Statement.IPostOptn op) voidaddOnSelectedHandler(String name, io.odysz.transact.sql.Statement.IPostSelectOptn op) voidaddOnTableCommitted(String tabl, io.odysz.transact.sql.Statement.IPostOptn op) voidclear()Deprecated.protected io.odysz.semantics.ISemantextclone(DASemantext srctx, io.odysz.semantics.IUser usr) io.odysz.semantics.ISemantextclone(io.odysz.semantics.IUser usr) io.odysz.transact.sql.parts.AbsPartcomposeVal(Object v, String tabl, String col) connId()io.odysz.semantics.ISemantextio.odysz.common.dbtypedbtype()protected static StringgenIdPrefix(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.TableMetagetTableMeta(String tbl) booleanhasOnSelectedHandler(String name) io.odysz.semantics.ISemantextvoidonCommitted(io.odysz.semantics.ISemantext ctx, String tabl) io.odysz.semantics.ISemantextonDelete(io.odysz.transact.sql.Delete delete, String tabl, io.odysz.transact.sql.parts.condition.Condit whereCondt) io.odysz.semantics.ISemantextWhen inserting, process data row with configured semantics, like auto-pk, fk-ins, etc..io.odysz.semantics.ISemantextonPost(io.odysz.transact.sql.Statement<?> stmt, String tabl, ArrayList<Object[]> row, ArrayList<String> sqls) voidonSelected(Object resultset) io.odysz.transact.sql.Statement.IPostOptnio.odysz.semantics.ISemantextstatic StringDeprecated.static Stringradix64_32(long v) Try generate a radix 64 string of v.relativpath(String... sub) resulvedVals(String tabl, String col) io.odysz.semantics.SemanticObjectresulves()Get the resolved value inautoValsa.k.a return value ofStatement.doneOp(io.odysz.transact.sql.Statement.IPostOptn).io.odysz.semantics.meta.TableMetastatic Stringio.odysz.semantics.ISemantextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
onInsertin 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:
onUpdatein 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:
onDeletein 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:
onPostin 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:
insertin 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:
updatein interfaceio.odysz.semantics.ISemantext- Throws:
SQLException
-
dbtype
public io.odysz.common.dbtype dbtype()- Specified by:
dbtypein interfaceio.odysz.semantics.ISemantext
-
connId
- Specified by:
connIdin interfaceio.odysz.semantics.ISemantext
-
connId
- Specified by:
connIdin interfaceio.odysz.semantics.ISemantext
-
clone
public io.odysz.semantics.ISemantext clone(io.odysz.semantics.IUser usr) - Specified by:
clonein interfaceio.odysz.semantics.ISemantext
-
clone
-
resulvedVals
- Specified by:
resulvedValsin interfaceio.odysz.semantics.ISemantext
-
resulves
public io.odysz.semantics.SemanticObject resulves()Get the resolved value inautoValsa.k.a return value ofStatement.doneOp(io.odysz.transact.sql.Statement.IPostOptn).- Specified by:
resulvesin 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:
genIdin interfaceio.odysz.semantics.ISemantext- Throws:
SQLExceptionio.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:
SQLExceptionio.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:
tablTypein interfaceio.odysz.semantics.ISemantext
-
relativpath
- Specified by:
relativpathin interfaceio.odysz.semantics.ISemantext- Throws:
io.odysz.transact.x.TransException
-
containerRoot
- Specified by:
containerRootin interfaceio.odysz.semantics.ISemantext
-
onCommitted
public void onCommitted(io.odysz.semantics.ISemantext ctx, String tabl) throws io.odysz.transact.x.TransException, SQLException - Specified by:
onCommittedin interfaceio.odysz.semantics.ISemantext- Throws:
io.odysz.transact.x.TransExceptionSQLException
-
addOnRowsCommitted
public void addOnRowsCommitted(io.odysz.transact.sql.Statement.IPostOptn op) - Specified by:
addOnRowsCommittedin interfaceio.odysz.semantics.ISemantext
-
addOnTableCommitted
- Specified by:
addOnTableCommittedin interfaceio.odysz.semantics.ISemantext
-
onTableCommittedHandler
- Specified by:
onTableCommittedHandlerin interfaceio.odysz.semantics.ISemantext
-
hasOnSelectedHandler
- Specified by:
hasOnSelectedHandlerin interfaceio.odysz.semantics.ISemantext
-
onSelected
- Specified by:
onSelectedin interfaceio.odysz.semantics.ISemantext- Throws:
SQLExceptionio.odysz.transact.x.TransException
-
addOnSelectedHandler
- Specified by:
addOnSelectedHandlerin interfaceio.odysz.semantics.ISemantext
-
composeVal
- Specified by:
composeValin interfaceio.odysz.semantics.ISemantext
-
getTableMeta
- Specified by:
getTableMetain interfaceio.odysz.semantics.ISemantext
-
Connects.pagingSql(dbtype, String, int, int)