Class DASemantics
- Direct Known Subclasses:
DBSynmantics
The default table semantics plugin used by semantic-DA.
The DASemantext
use this to manage semantics configuration for
resolving data semantics.
DASemantics.SemanticHandler
's container,
with subclass handlers handling different semantics (processing values).
What's DASemantics for?
Well, the word semantics is a computer science term. The author don't want to redefine this word, but here is some explanation what semantic-DA with semantic-transact is trying to support.
In a typical relational database based application, the main operation of data is CRUD. And the most often such data operation can be abstracted to some operation pattern, and they are always organized as a database transaction/batch operation described in SQL.
Take "book-author" relation for example, the author's ID is also the parent referenced by book's author FK. If trying to delete an author in DB, there are 2 typical policies can be applied by the application. The first is delete all books by the author accordingly; the second is warning and denying the operation if some books are referencing the author. Both of this must/can been organized into a transact/batch operation, with the second transact as check-then-delete.
In this case, you will find the FK relationship can be handled in a generalized operation, through parameterizing some variables like table name, child referencing column name and parent ID.
Take the DASemantics.smtype.parentChildrenOnDel
for example, it's
automatically support "deleting all children when deleting parent" semantics.
What the user (application developer) need to do is configure a semantics
item then delete the parent directly.
Now you (a developer) will definitely understand what's the "parentChildrenOnDel" for. Semantic-DA abstract and hide these patterns, wrapped them automatically into a transaction. That's what semantic- DA want to do.
How to Use
To use this function:
1. Configure the "semantics.xml". See example in
test/resources/semantics.xml.
2. Set the configured semantics as context of
Statement
. See example in
io.odysz.semantic.DASemantextTest
. Then use Statement's subclass's
commit() method to generate SQLs
Is this Enough?
The 9 or 10 types of semantics defined in DASemantics.smtype
is
enough for some enterprise projects. It depends on how abstract the semantics
we want to support. But it seems enough for us, at least now.
Before doing that, check the semantics-cheapflow workflow engine first, which is based on semantics-*, and can handle typical - not very cheap if by our define - logics all necessary for enterprise applications. It's a good example illustrating that if the semantics is designed carefully, those semantics supported by this pattern is enough.
But it do needs the application developers follow some design conventions. If
you need you own semantics implementation, implement the interface
ISemantext
, or simply initialize
Transcxt
with null semantics, which will
disable semantic supporting. In that way, it's working as a structured sql
composing API.
Documents
- Author:
- odys-z@github.com
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
Notestatic enum
Semantics type supported by DASemantics. -
Field Summary
Modifier and TypeFieldDescriptionprotected io.odysz.transact.sql.Transcxt
Static transact context for DB accessing without semantics support.
Used to generate auto ID.static final String
error code key wordprotected ArrayList<DASemantics.SemanticHandler>
final String
boolean
-
Constructor Summary
ConstructorDescriptionDASemantics
(io.odysz.transact.sql.Transcxt basicTx, String tabl, String recId, boolean... verbose) Note: basicTx is already created per the connection, i. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHandler
(DASemantics.smtype semantic, String tabl, String recId, String[] args) clone()
Shallow copy, with new list of handlers, with each elements referring to the original one.createSMap
(String conn) boolean
void
onDelete
(io.odysz.semantics.ISemantext semantx, io.odysz.transact.sql.Delete stmt, io.odysz.transact.sql.parts.condition.Condit whereCondt, io.odysz.semantics.IUser usr) void
onInsert
(io.odysz.semantics.ISemantext semantx, io.odysz.transact.sql.Insert statemt, ArrayList<Object[]> row, Map<String, Integer> cols, io.odysz.semantics.IUser usr) void
onPost
(io.odysz.semantics.ISemantext sx, io.odysz.transact.sql.Statement<? extends io.odysz.transact.sql.Statement<?>> stmt, ArrayList<Object[]> row, Map<String, Integer> cols, io.odysz.semantics.IUser usr, ArrayList<String> sqlBuf) void
onUpdate
(io.odysz.semantics.ISemantext semantx, io.odysz.transact.sql.Update satemt, ArrayList<Object[]> row, Map<String, Integer> cols, io.odysz.semantics.IUser usr) parseHandler
(io.odysz.transact.sql.Transcxt trb, String tabl, DASemantics.smtype semantic, String recId, String[] args) static io.odysz.semantics.meta.TableMeta
replaceMeta
(String tbl, io.odysz.semantics.meta.TableMeta m, String... connId) Deprecated.static Object[]
requiredNv
(String n, io.odysz.transact.sql.parts.AbsPart v, Map<String, Integer> cols, ArrayList<Object[]> row, String target, io.odysz.semantics.IUser usr) Force to set or extend a nv pair into row
-
Field Details
-
ERR_CHK
error code key word- See Also:
-
verbose
public boolean verbose -
basicTsx
protected io.odysz.transact.sql.Transcxt basicTsxStatic transact context for DB accessing without semantics support.
Used to generate auto ID. -
handlers
-
tabl
-
-
Constructor Details
-
Method Details
-
replaceMeta
public static io.odysz.semantics.meta.TableMeta replaceMeta(String tbl, io.odysz.semantics.meta.TableMeta m, String... connId) throws io.odysz.transact.x.TransException, SQLException Deprecated.since 2.0.0, to have a meta be the type ofSemanticTableMeta
, configure the class name in semantics.xml/t[id=metas], instead of calling this method.Use this to replace metas from DB for semantics extension.- Parameters:
tbl
-m
-connId
-- Returns:
- replaced meta
- Throws:
io.odysz.transact.x.TransException
SQLException
- Since:
- 1.4.25
-
addHandler
-
addHandler
public void addHandler(DASemantics.smtype semantic, String tabl, String recId, String[] args) throws Exception - Throws:
Exception
-
handler
-
createSMap
-
parseHandler
public DASemantics.SemanticHandler parseHandler(io.odysz.transact.sql.Transcxt trb, String tabl, DASemantics.smtype semantic, String recId, String[] args) throws Exception - Throws:
Exception
-
has
-
onInsert
public void onInsert(io.odysz.semantics.ISemantext semantx, io.odysz.transact.sql.Insert statemt, ArrayList<Object[]> row, Map<String, Integer> cols, io.odysz.semantics.IUser usr) throws io.odysz.transact.x.TransException- Throws:
io.odysz.transact.x.TransException
-
onUpdate
public void onUpdate(io.odysz.semantics.ISemantext semantx, io.odysz.transact.sql.Update satemt, ArrayList<Object[]> row, Map<String, Integer> cols, io.odysz.semantics.IUser usr) throws io.odysz.transact.x.TransException- Throws:
io.odysz.transact.x.TransException
-
onDelete
public void onDelete(io.odysz.semantics.ISemantext semantx, io.odysz.transact.sql.Delete stmt, io.odysz.transact.sql.parts.condition.Condit whereCondt, io.odysz.semantics.IUser usr) throws io.odysz.transact.x.TransException - Throws:
io.odysz.transact.x.TransException
-
onPost
public void onPost(io.odysz.semantics.ISemantext sx, io.odysz.transact.sql.Statement<? extends io.odysz.transact.sql.Statement<?>> stmt, ArrayList<Object[]> row, Map<String, Integer> cols, io.odysz.semantics.IUser usr, ArrayList<String> sqlBuf) throws SemanticException- Throws:
SemanticException
-
requiredNv
public static Object[] requiredNv(String n, io.odysz.transact.sql.parts.AbsPart v, Map<String, Integer> cols, ArrayList<Object[]> row, String target, io.odysz.semantics.IUser usr) Force to set or extend a nv pair into row- Parameters:
n
- forced fieldv
- forced valuecols
-row
- row to be expandedtarget
- for the tableusr
- operator- Returns:
- the extended or forced value's nv pair
-
clone
Shallow copy, with new list of handlers, with each elements referring to the original one.
-
SemanticTableMeta
, configure the class name in semantics.xml/t[id=metas], instead of calling this method.