Results 1 to 6 of 6

Thread: Control Transactions with Java 5.0 Attributes

  1. #1
    Join Date
    Feb 2005
    Posts
    9

    Default Control Transactions with Java 5.0 Attributes

    Hello,

    Perhaps this really belongs in the AOP forum, but the motivation behind it for me is persistence.

    It looks like Spring only comes with an Apache Commons-Attributes implementation for letting attributes drive transactions. I had this working for a while, but then I decided to start using Java 1.5/5.0. Sadly, the attribute compiler for commons-attributes doesn't understand generics syntax, so I could no longer compile my attributes. I decided to switch from Apache attributes to Java 5 attributes. To do that, I had to write a Java 5-based implementation of Spring's org.springframework.metadata.Attributes interface. I would like to contribute this code. It seems I can't attach a tarball to this post, so please let me know how I can get this code to you, if you're interested.

    This whole issue makes me think that Apache attributes are much better than Java 5 annotations. The biggest problem I found was that Java 5 annotations are not real Java classes. Therefore I couldn't use Spring's DefaultTransactionAttribute to "be" an annotation. I had to write an Annotation that represented that attribute, and then convert it to a DefaultTransactionAttribute in my implementation of the Attributes interface. Even worse, Annotations don't seem capable of defining methods (or much of anything else). Suppose I wrote a DefaultTransactionAnnotation. It would be great if I could have given it a method "asSpring" that returned a DefaultTransactionAttribute. Nope! As far as I can tell, you cannot define methods on an Annotation. Therefore, I ended up writing a separate class that converts Annotations to Spring classes. This is the big, glaring hack in my implementation. If there is any fix for it, I'd like to know!

    So far I have only written code for the DefaultTransactionAttribute class, but I believe adding the others would be easy now. I just don't know them very well, because so far DefaultTransactionAttribute is all I've needed for my own project. If someone can tell me which classes control transactions, I can try writing Java 5 annotations for them. The list I see so far is RuleBasedTransactionAttribute, RollbackRuleAttribute, and NoRollbackRuleAttribute.

    Anyway, please let me know how I can deliver this code. You are welcome to rename packages, classes, etc. and use it however you like.

    Thanks,
    Paul

  2. #2
    Join Date
    Feb 2005
    Posts
    9

    Default

    I found a fix to my apache-attributes-and-java-5 problem. The apache attributes compiler users xjavadoc to read the source files. People have been clamoring for XDoclet to support Java 5 for a long time, and someone posted a patched xjavadoc.jar that reads (and ignores, I think) java 5 syntax like generics and enums. I dropped this into $ANT_HOME/lib and tried building. I also had to replace ant's commons-logging jar with the 1.0.4 version. (I'm using ant 1.6.2, so I'm surprised it has an apparently older jar.) After that, everything worked fine. So you can use apache-attributes for spring-managed transactions even with java 5. Hooray!

    That code to let spring use java 5 annotations still might be useful, though, so if you would like it, please let me know how to post it somewhere.

  3. #3
    Join Date
    Feb 2005
    Posts
    9

    Default

    Oops, I forgot the link to that xjavadoc.jar file:

    http://opensource.atlassian.com/proj.../browse/XJD-41

  4. #4
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    We will release native support for Java 5.0 annotations in Spring 1.2 next month.
    This whole issue makes me think that Apache attributes are much better than Java 5 annotations. The biggest problem I found was that Java 5 annotations are not real Java classes.
    I must agree that the limitations regarding annotations, and the resulting code duplication, are disappointing.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  5. #5
    Join Date
    Feb 2005
    Posts
    9

    Default

    Okay, thanks for the update.

    People use Log4j instead of the JFC logging framework. Perhaps they'll use commons-attributes as well. . . .

  6. #6

    Default

    Quote Originally Posted by pjungwir
    Okay, thanks for the update.

    People use Log4j instead of the JFC logging framework. Perhaps they'll use commons-attributes as well. . . .
    not me ....

    --b

Similar Threads

  1. HibernateTemplate and transactions
    By Simon Brunning in forum Data
    Replies: 4
    Last Post: Mar 9th, 2009, 12:37 AM
  2. MethodSecurityInterceptor not working?
    By asarco in forum Security
    Replies: 14
    Last Post: Mar 31st, 2008, 09:59 AM
  3. JDO Transactions and JUnit testing
    By markds75 in forum Data
    Replies: 2
    Last Post: Sep 17th, 2005, 01:46 AM
  4. Replies: 12
    Last Post: May 5th, 2005, 09:01 AM
  5. Replies: 8
    Last Post: Dec 7th, 2004, 06:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •