java - Discover methods without @Transaction? -
i'm struggling validation implement. verify every methods service start update must have @transactional annotation. far have made concept gives me methods service class start update (e.g. updateinvoice). have no idea how build constraint select methods wich have no @transaction annotation.
i'd recommend define concepts representing key elements define constraints on them, i.e.
your services:
<concept id="service:serviceclass"> <description>adds label "service" every class annotated "@com.mycompany.services.service"</description> <cypher><![cdata[ match (service:type:class)-[:annotated_by]->()-[:of_type]->(serviceannotationtype) set service:service serviceannotationtype.fqn = "com.mycompany.services.service" return service ]]> </cypher> </concept> your transacted methods:
<concept id="service:transactmethod"> <description>adds label "transact" every method annotated "@com.mycompany.services.transact"</description> <cypher><![cdata[ match (method:method)-[:annotated_by]->()-[:of_type]->(transactannotationtype) set method:transact transactannotationtype.fqn = "com.mycompany.services.transact" return method ]]> </cypher> </concept> your constraint:
<constraint id="service:allupdatemethodsmustbetransacted"> <requiresconcept refid="service:serviceclass" /> <requiresconcept refid="service:transactmethod" /> <description>all update methods must transacted</description> <cypher><![cdata[ match (service:service:class)-[:declares]->(updatemethod:method) updatemethod.name =~ "update.*" // extracted concept , not updatemethod:transact return updatemethod ]]> </cypher> </constraint > this approach has several advantages:
- you're getting more rules each of them better readable (especially constaint), because you're using terms defined design
- it's need concepts "service" , "transact" other constraints - use labels
- if you're creating maven site report concepts in design (i.e. wich service implementations exist)
Comments
Post a Comment