Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Which public methods are NOT marked with @Transactional? Use a regex.

DZone's Guide to

Which public methods are NOT marked with @Transactional? Use a regex.

· Java Zone
Free Resource

Learn how to stop testing everything every sprint and only test the code you’ve changed. Brought to you by Parasoft.

Yesterday we were doing some code cleaning for a near to deploy project. There we realized that there were some methods which should be @Transactional but they weren't... How to know which ones in a whole project, without checking class by class? Thanks the Gods I had Rafael Darder, our Python guru (I my self am not a regexp connaiseur), next to me and pointed me to the right direction.

Anyway, this is what we came with:

(?<!\s*@Transactional\r?\n)(^\s*public +[\w\<\>\[\]]+\s+(\w+) *\([^\)]*\) *(\{?|[^;])$)

Scary, ah? then just wait when applied to your project... and go for a coffee...

Do you know a better/faster solution? I would like to know it.

Thanks for reading it. Waiting for your comments.

Get the top tips for Java developers and best practices to overcome common challenges. Brought to you by Parasoft.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}