2

実装したい検証に苦労しています。update で始まる Service のすべてのメソッドに @Transactional アノテーションが必要であることを確認したいと思います。ここまでで、update で始まるサービス クラスのメソッド (updateInvoice など) を提供する概念を作成しました。しかし、 @Transaction アノテーションのないメソッドを選択する制約を作成する方法がわかりません。

4

2 に答える 2

3

重要な要素を表すいくつかの概念を定義して、それらに制約を定義することをお勧めします。

あなたのサービス:

<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 >

このアプローチにはいくつかの利点があります。

  • より多くのルールが得られますが、設計のために定義した用語を使用しているため、それぞれのルール (特に制約) ははるかに読みやすくなっています。
  • 他の制約についても「サービス」と「トランザクション」の概念が必要になる可能性が非常に高いです。ラベルを使用するだけです。
  • Maven サイトを作成している場合、設計のすべての概念に関するレポートを取得します (つまり、現在存在するサービス実装)
于 2015-10-01T07:13:43.237 に答える
1

以下はうまくいくようです:

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
于 2015-09-30T17:09:20.977 に答える