发现没有@Transaction 的方法?
Discover methods without @Transaction?
我正在为我想要实施的验证而苦苦挣扎。我想验证以更新开头的服务中的每个方法都必须具有 @Transactional 注释。到目前为止,我已经提出了一个概念,它为我提供了从我的服务 class 以更新开始的方法(例如 updateInvoice)。但我不知道如何建立一个约束,select 没有@Transaction 注释的方法。
以下似乎有效:
match
(aType:Type:Class)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(anAnnotationType:Type),
(aType:Type)-[:DECLARES]->(aMethod:Method)
optional match
(aMethod)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(tType:Type)
with anAnnotationType, aMethod, tType
where
anAnnotationType.fqn = "com.mycompany.services.Service"
and aMethod.name =~ "update.*"
and ((tType is null) or not (tType.fqn = "com.mycompany.services.Transact"))
return
aMethod.name, tType
我建议定义一些代表你的关键元素的概念来定义对它们的约束,即
您的服务:
<concept id="service:ServiceClass">
<description>Adds a label "Service" to every class annotated by "@com.mycompany.services.Service"</description>
<cypher><![CDATA[
MATCH
(service:Type:Class)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(serviceAnnotationType)
SET
service:Service
WHERE
serviceAnnotationType.fqn = "com.mycompany.services.Service"
RETURN
service
]]>
</cypher>
</concept>
您的交易方式:
<concept id="service:TransactMethod">
<description>Adds a label "Transact" to every method annotated by "@com.mycompany.services.Transact"</description>
<cypher><![CDATA[
MATCH
(method:Method)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(transactAnnotationType)
SET
method:Transact
WHERE
transactAnnotationType.fqn = "com.mycompany.services.Transact"
RETURN
method
]]>
</cypher>
</concept>
您的限制条件:
<constraint id="service:AllUpdateMethodsMustBeTransacted">
<requiresConcept refId="service:ServiceClass" />
<requiresConcept refId="service:TransactMethod" />
<description>All update methods must be transacted</description>
<cypher><![CDATA[
MATCH
(service:Service:Class)-[:DECLARES]->(updateMethod:Method)
WHERE
updateMethod.name =~ "update.*" // even this could be extracted to a concept
and not updateMethod:Transact
RETURN
updateMethod
]]>
</cypher>
</constraint >
这种方法有几个优点:
- 您现在获得了更多规则,但每条规则的可读性都更好(尤其是约束),因为您使用的是为设计定义的术语
- 对于其他约束,您很可能还需要概念 "Service" 和 "Transact" - 现在只需使用标签
- 如果您正在创建 Maven 站点,您会收到一份关于设计中所有概念的报告(即当前存在的服务实现)
我正在为我想要实施的验证而苦苦挣扎。我想验证以更新开头的服务中的每个方法都必须具有 @Transactional 注释。到目前为止,我已经提出了一个概念,它为我提供了从我的服务 class 以更新开始的方法(例如 updateInvoice)。但我不知道如何建立一个约束,select 没有@Transaction 注释的方法。
以下似乎有效:
match
(aType:Type:Class)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(anAnnotationType:Type),
(aType:Type)-[:DECLARES]->(aMethod:Method)
optional match
(aMethod)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(tType:Type)
with anAnnotationType, aMethod, tType
where
anAnnotationType.fqn = "com.mycompany.services.Service"
and aMethod.name =~ "update.*"
and ((tType is null) or not (tType.fqn = "com.mycompany.services.Transact"))
return
aMethod.name, tType
我建议定义一些代表你的关键元素的概念来定义对它们的约束,即
您的服务:
<concept id="service:ServiceClass">
<description>Adds a label "Service" to every class annotated by "@com.mycompany.services.Service"</description>
<cypher><![CDATA[
MATCH
(service:Type:Class)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(serviceAnnotationType)
SET
service:Service
WHERE
serviceAnnotationType.fqn = "com.mycompany.services.Service"
RETURN
service
]]>
</cypher>
</concept>
您的交易方式:
<concept id="service:TransactMethod">
<description>Adds a label "Transact" to every method annotated by "@com.mycompany.services.Transact"</description>
<cypher><![CDATA[
MATCH
(method:Method)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(transactAnnotationType)
SET
method:Transact
WHERE
transactAnnotationType.fqn = "com.mycompany.services.Transact"
RETURN
method
]]>
</cypher>
</concept>
您的限制条件:
<constraint id="service:AllUpdateMethodsMustBeTransacted">
<requiresConcept refId="service:ServiceClass" />
<requiresConcept refId="service:TransactMethod" />
<description>All update methods must be transacted</description>
<cypher><![CDATA[
MATCH
(service:Service:Class)-[:DECLARES]->(updateMethod:Method)
WHERE
updateMethod.name =~ "update.*" // even this could be extracted to a concept
and not updateMethod:Transact
RETURN
updateMethod
]]>
</cypher>
</constraint >
这种方法有几个优点:
- 您现在获得了更多规则,但每条规则的可读性都更好(尤其是约束),因为您使用的是为设计定义的术语
- 对于其他约束,您很可能还需要概念 "Service" 和 "Transact" - 现在只需使用标签
- 如果您正在创建 Maven 站点,您会收到一份关于设计中所有概念的报告(即当前存在的服务实现)