Announcement Announcement Module
Collapse
No announcement yet.
Control Transactions with Java 5.0 Attributes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


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

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

      Comment


      • #4
        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.

        Comment


        • #5
          Okay, thanks for the update.

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

          Comment


          • #6
            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

            Comment

            Working...
            X