Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjs-bd-common
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
s_guodong
gjjs-bd-common
Commits
f1ae9ead
Commit
f1ae9ead
authored
Sep 01, 2023
by
s_guodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checkAll
parent
0d2d9f5f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
69 deletions
+85
-69
AbstractAutoCompileEmitter.java
.../driver/compile/component/AbstractAutoCompileEmitter.java
+82
-69
AbstractRuleEmitter.java
.../brilliance/mda/runtime/mda/impl/AbstractRuleEmitter.java
+3
-0
No files found.
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/AbstractAutoCompileEmitter.java
View file @
f1ae9ead
...
...
@@ -17,39 +17,47 @@ public abstract class AbstractAutoCompileEmitter extends AbstractRuleEmitter {
private
static
Logger
log
=
LoggerFactory
.
getLogger
(
AbstractAutoCompileEmitter
.
class
);
private
boolean
executeRuleList
(
String
ruleType
,
String
target
,
int
order
)
{
return
executeRuleList
(
ruleType
,
target
,
order
,
false
);
private
boolean
executeRuleList
(
String
ruleType
,
String
target
,
int
order
)
{
return
executeRuleList
(
ruleType
,
target
,
order
,
false
);
}
private
boolean
executeRuleList
(
String
ruleType
,
String
target
,
int
order
,
boolean
verifyHead
)
{
private
boolean
executeRuleList
(
String
ruleType
,
String
target
,
int
order
,
boolean
verifyHead
)
{
String
moduleName
=
getModuleName
();
ModuleRuleContext
moduleRuleContext
=
ModuleAnnotationProcess
.
cache
.
get
(
moduleName
);
if
(
moduleRuleContext
==
null
)
{
if
(
moduleRuleContext
==
null
)
{
return
false
;
}
if
(
target
!=
null
)
{
if
(
target
!=
null
)
{
target
=
getRealPath
(
target
);
// if(target.charAt(0) == '.' ||
target.charAt(0) == '\\') {
//
target = target.substring(1);
//
}
if
(
target
.
charAt
(
0
)
==
'\\'
)
{
target
=
target
.
substring
(
1
);
}
MdaEnv
.
getContext
().
pushEventPath
(
target
);
}
List
<
RuleItem
>
ruleItemList
=
null
;
switch
(
ruleType
){
case
RuleItem
.
INIT
:
ruleItemList
=
moduleRuleContext
.
getInitList
();
break
;
case
RuleItem
.
RULE
:
ruleItemList
=
moduleRuleContext
.
getEventRule
().
get
(
target
);
break
;
case
RuleItem
.
CHECK
:
ruleItemList
=
moduleRuleContext
.
getCheckRule
().
get
(
target
);
break
;
case
RuleItem
.
DEFAULT
:
ruleItemList
=
moduleRuleContext
.
getDefaultRule
().
get
(
target
);
break
;
switch
(
ruleType
)
{
case
RuleItem
.
INIT
:
ruleItemList
=
moduleRuleContext
.
getInitList
();
break
;
case
RuleItem
.
RULE
:
ruleItemList
=
moduleRuleContext
.
getEventRule
().
get
(
target
);
break
;
case
RuleItem
.
CHECK
:
ruleItemList
=
moduleRuleContext
.
getCheckRule
().
get
(
target
);
break
;
case
RuleItem
.
DEFAULT
:
ruleItemList
=
moduleRuleContext
.
getDefaultRule
().
get
(
target
);
break
;
}
if
(
ruleItemList
==
null
)
{
if
(
ruleItemList
==
null
)
{
return
false
;
}
//开始执行RuleChain
for
(
int
i
=
0
;
i
<
ruleItemList
.
size
();
i
++)
{
RuleItem
ruleItem
=
ruleItemList
.
get
(
i
);
log
.
debug
(
"executeRule {}.{}.{}{}"
,
MdaEnv
.
getContext
().
getTransName
(),
ruleItem
.
getDotPath
(),
ruleItem
.
getRuleType
(),
ruleItem
.
getOrder
());
log
.
debug
(
"executeRule {}.{}.{}{}"
,
MdaEnv
.
getContext
().
getTransName
(),
ruleItem
.
getDotPath
(),
ruleItem
.
getRuleType
(),
ruleItem
.
getOrder
());
//校验函数头,当是复合型的rule声明时,需要第一个target为当前target时才会被ExecuteDefaultRule执行
if
(
verifyHead
&&
!
verifyMethodHead
(
this
,
ruleItem
,
target
,
ruleType
))
{
if
(
verifyHead
&&
!
verifyMethodHead
(
this
,
ruleItem
,
target
,
ruleType
))
{
continue
;
}
try
{
...
...
@@ -68,7 +76,7 @@ public abstract class AbstractAutoCompileEmitter extends AbstractRuleEmitter {
break
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"execute Rule Exception"
,
e
);
log
.
error
(
"execute Rule Exception"
,
e
);
throw
e
;
}
finally
{
this
.
printSlowExecutionLog
();
...
...
@@ -77,54 +85,56 @@ public abstract class AbstractAutoCompileEmitter extends AbstractRuleEmitter {
this
.
printSlowExecutionLog
();
return
true
;
}
public
static
boolean
verifyMethodHead
(
IRuleEmitter
emitter
,
RuleItem
ruleItem
,
String
target
,
String
ruleType
){
if
(
ruleItem
.
getMethod
()
instanceof
Method
&&
ruleType
.
equals
(
RuleItem
.
DEFAULT
)){
public
static
boolean
verifyMethodHead
(
IRuleEmitter
emitter
,
RuleItem
ruleItem
,
String
target
,
String
ruleType
)
{
if
(
ruleItem
.
getMethod
()
instanceof
Method
&&
ruleType
.
equals
(
RuleItem
.
DEFAULT
))
{
Method
method
=
(
Method
)
ruleItem
.
getMethod
();
Default
defaultAno
=
method
.
getAnnotation
(
Default
.
class
);
if
(
defaultAno
.
value
()!=
null
&&
defaultAno
.
value
().
length
>
1
)
{
if
(
defaultAno
.
value
()
!=
null
&&
defaultAno
.
value
().
length
>
1
)
{
String
firstTarget
=
defaultAno
.
value
()[
0
];
String
path
=
null
;;
if
(
firstTarget
.
startsWith
(
"."
)){
String
path
=
null
;
;
if
(
firstTarget
.
startsWith
(
"."
))
{
path
=
firstTarget
;
}
else
{
path
=
ruleItem
.
getDotPath
()
+
"."
+
firstTarget
;
}
else
{
path
=
ruleItem
.
getDotPath
()
+
"."
+
firstTarget
;
}
path
=
emitter
.
getRealPath
(
path
);
//复合声明,仅与第一个路径相等时,才触发
if
(!
target
.
equals
(
path
))
{
if
(!
target
.
equals
(
path
))
{
return
false
;
}
}
}
return
true
;
}
public
boolean
invokeRuleList
(
String
ruleType
,
String
target
,
int
order
){
return
invokeRuleList
(
ruleType
,
target
,
order
,
false
);
public
boolean
invokeRuleList
(
String
ruleType
,
String
target
,
int
order
)
{
return
invokeRuleList
(
ruleType
,
target
,
order
,
false
);
}
public
boolean
invokeRuleList
(
String
ruleType
,
String
target
,
int
order
,
boolean
verifyHead
){
public
boolean
invokeRuleList
(
String
ruleType
,
String
target
,
int
order
,
boolean
verifyHead
)
{
IContext
ctx
=
MdaEnv
.
getContext
();
try
{
//ctx.pushEventPath(target);
return
executeRuleList
(
ruleType
,
target
,
order
,
verifyHead
);
return
executeRuleList
(
ruleType
,
target
,
order
,
verifyHead
);
}
catch
(
Exception
e
)
{
if
(
e
.
getCause
()
instanceof
RuleExitException
)
if
(
e
.
getCause
()
instanceof
RuleExitException
)
throw
(
RuleExitException
)
e
.
getCause
();
else
if
(
e
instanceof
RuleExitException
)
{
else
if
(
e
instanceof
RuleExitException
)
{
throw
(
RuleExitException
)
e
;
}
else
if
(
e
.
getCause
()
instanceof
RulePromptException
)
{
}
else
if
(
e
.
getCause
()
instanceof
RulePromptException
)
{
throw
(
RulePromptException
)
e
.
getCause
();
}
else
if
(
e
instanceof
RulePromptException
)
{
}
else
if
(
e
instanceof
RulePromptException
)
{
throw
(
RulePromptException
)
e
;
}
else
if
(
e
.
getCause
()
instanceof
RuleExecuteException
){
}
else
if
(
e
.
getCause
()
instanceof
RuleExecuteException
)
{
throw
(
RuleExecuteException
)
e
.
getCause
();
}
else
if
(
e
instanceof
RuleExecuteException
)
{
}
else
if
(
e
instanceof
RuleExecuteException
)
{
throw
(
RuleExecuteException
)
e
;
}
else
}
else
throw
new
RuntimeException
(
e
);
}
finally
{
if
(!
RuleItem
.
INIT
.
equals
(
ruleType
))
{
}
finally
{
if
(!
RuleItem
.
INIT
.
equals
(
ruleType
))
{
ctx
.
popEventPath
();
}
}
...
...
@@ -132,65 +142,67 @@ public abstract class AbstractAutoCompileEmitter extends AbstractRuleEmitter {
@Override
public
boolean
executeInit
(
int
order
)
{
return
invokeRuleList
(
RuleItem
.
INIT
,
null
,
order
);
return
invokeRuleList
(
RuleItem
.
INIT
,
null
,
order
);
}
//执行Rule
public
boolean
executeRule
(
String
target
,
int
order
)
{
return
invokeRuleList
(
RuleItem
.
RULE
,
target
,
order
);
public
boolean
executeRule
(
String
target
,
int
order
)
{
return
invokeRuleList
(
RuleItem
.
RULE
,
target
,
order
);
}
//执行Check
public
boolean
executeCheck
(
String
target
,
int
order
)
{
public
boolean
executeCheck
(
String
target
,
int
order
)
{
target
=
getRealPath
(
target
);
String
moduleName
=
getModuleName
();
ModuleRuleContext
moduleRuleContext
=
ModuleAnnotationProcess
.
cache
.
get
(
moduleName
);
if
(
moduleRuleContext
==
null
)
{
if
(
moduleRuleContext
==
null
)
{
return
true
;
}
for
(
Map
.
Entry
<
String
,
List
<
RuleItem
>>
entry:
moduleRuleContext
.
getCheckRule
().
entrySet
())
{
if
(!
checkPathMatch
(
entry
.
getKey
(),
target
))
for
(
Map
.
Entry
<
String
,
List
<
RuleItem
>>
entry
:
moduleRuleContext
.
getCheckRule
().
entrySet
())
{
if
(!
checkPathMatch
(
entry
.
getKey
(),
target
))
continue
;
boolean
result
=
invokeRuleList
(
RuleItem
.
CHECK
,
entry
.
getKey
(),
order
);
if
(!
result
)
{
boolean
result
=
invokeRuleList
(
RuleItem
.
CHECK
,
entry
.
getKey
(),
order
);
if
(!
result
)
{
log
.
warn
(
String
.
format
(
"execute @Check[%s,%d] return false"
,
entry
.
getKey
(),
order
));
}
}
return
true
;
}
//执行Default
public
boolean
executeDefault
(
String
target
,
int
order
)
{
public
boolean
executeDefault
(
String
target
,
int
order
)
{
boolean
result
;
try
{
result
=
invokeRuleList
(
RuleItem
.
DEFAULT
,
target
,
order
);
}
catch
(
Exception
ex
)
{
result
=
invokeRuleList
(
RuleItem
.
DEFAULT
,
target
,
order
);
}
catch
(
Exception
ex
)
{
DCR
.
emptyDefaultQueue
();
throw
new
RuleExecuteException
(
"Rule执行异常"
,
ex
);
}
finally
{
throw
new
RuleExecuteException
(
"Rule执行异常"
,
ex
);
}
finally
{
}
return
result
;
}
//执行Post 的default,因为它需要验证复合声明的头
public
boolean
executePostDefault
(
String
target
){
return
invokeRuleList
(
RuleItem
.
DEFAULT
,
target
,-
1
,
true
);
public
boolean
executePostDefault
(
String
target
)
{
return
invokeRuleList
(
RuleItem
.
DEFAULT
,
target
,
-
1
,
true
);
}
public
String
getModuleName
(){
public
String
getModuleName
()
{
return
relatedTransaction
().
getCanonicalName
();
}
@Override
public
Map
<
String
,
Integer
>
getDefaultQueue
()
{
Map
<
String
,
Integer
>
defaultQueue
=
super
.
getDefaultQueue
();
if
(
defaultQueue
.
isEmpty
())
{
synchronized
(
defaultQueue
){
if
(
defaultQueue
.
isEmpty
())
{
Map
<
String
,
Integer
>
defaultQueue
=
super
.
getDefaultQueue
();
if
(
defaultQueue
.
isEmpty
())
{
synchronized
(
defaultQueue
)
{
if
(
defaultQueue
.
isEmpty
())
{
String
moduleName
=
getModuleName
();
ModuleRuleContext
moduleRuleContext
=
ModuleAnnotationProcess
.
cache
.
get
(
moduleName
);
//设置默认的DefaultQueue,但要排除ModuleList
if
(
moduleRuleContext
!=
null
)
{
if
(
moduleRuleContext
!=
null
)
{
moduleRuleContext
.
getDefaultRule
().
entrySet
().
forEach
(
stringListEntry
->
{
if
(!(
stringListEntry
.
getValue
().
size
()
==
1
if
(!(
stringListEntry
.
getValue
().
size
()
==
1
&&
stringListEntry
.
getValue
().
get
(
0
).
getMethodName
().
equals
(
"executeDefault"
)))
{
defaultQueue
.
put
(
stringListEntry
.
getKey
(),
0
);
}
...
...
@@ -201,15 +213,16 @@ public abstract class AbstractAutoCompileEmitter extends AbstractRuleEmitter {
}
return
defaultQueue
;
}
@Override
public
boolean
executeDefaultAll
(){
public
boolean
executeDefaultAll
()
{
String
moduleName
=
getModuleName
();
ModuleRuleContext
moduleRuleContext
=
ModuleAnnotationProcess
.
cache
.
get
(
moduleName
);
if
(
moduleRuleContext
==
null
)
{
if
(
moduleRuleContext
==
null
)
{
return
false
;
}
moduleRuleContext
.
getDefaultRule
().
entrySet
().
forEach
(
stringListEntry
->
{
executeRuleList
(
RuleItem
.
DEFAULT
,
stringListEntry
.
getKey
(),
-
1
);
executeRuleList
(
RuleItem
.
DEFAULT
,
stringListEntry
.
getKey
(),
-
1
);
});
return
true
;
}
...
...
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractRuleEmitter.java
View file @
f1ae9ead
...
...
@@ -109,6 +109,9 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
protected
boolean
checkPathMatch
(
String
path
,
String
target
)
{
if
(
target
.
startsWith
(
"\\"
)){
target
=
target
.
substring
(
1
).
toLowerCase
();
}
int
targetLen
=
target
.
length
();
return
targetLen
==
0
||
(
path
.
startsWith
(
target
)
&&
(
path
.
length
()
==
targetLen
||
path
.
charAt
(
targetLen
)
==
'.'
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment