I was born in Cuba, and live in Argentina since January 2009. I'm a self-learned software developer and currently I'm working with the NetBeans IDE and platform. I've also participated in NetCAT68, NetCAT69, NetCAT70, NetCAT71, NetCAT72, NetCAT73 and NetCAT74. I am currently Java back-ender Software Developer at Globant Rosario. Almost obsessed to code quality; I can be annoying in this subject. Alied has posted 10 posts at DZone. You can read more from them at their website. View Full User Profile

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

  • submit to reddit

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.

Your rating: None
Published at DZone with permission of its author, Alied Pérez.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Marc Stock replied on Thu, 2012/01/05 - 4:53pm

You can do this pretty easily with IntelliJ's structural search (and replace). The following template will find all public methods missing the @Transactional:
class $Class$ {
public $MethodType$ $MethodName$($ParameterType$ $ParameterName$);

Of course, you have to set what those vars mean but this is just a built in template in IntelliJ so it only takes a minute to do.
Sorry but the code tag isn't working for some reason.

Alied Pérez replied on Fri, 2012/01/06 - 2:40pm in response to: Marc Stock

Yes, of course, unless you are not using InteljiJ :-)

I tried to use Netbean's custom hints, but I know even less about it than I know on regexp; (and at least I have some one to ask just 2m from me :-) when it comes to regexp)

 Anyway, thanks for sharing your tip.

Gábor Lipták replied on Thu, 2012/02/02 - 4:35pm

Annotations are not supported as I saw, but source code "query" tools king in my opinion is The Browse-By-Query Query with eclipse integration. The only problem is that the query language is far from trivial.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.