Announcement Announcement Module
Collapse
No announcement yet.
Spring ROO - Generate jspx files for custom finders Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring ROO - Generate jspx files for custom finders

    I have a class called Payment that was generated by spring ROO, and I would like to create a "custom" finder ("complex" finder that returns aggregated results) and use Spring ROO's mechanism to generate the jspx files etc. Is this possible?

    My code (modified for the question):
    Code:
    package com.mystuff.orm;
    ...
    @RooJavaBean
    @RooToString
    public class Payment {
    
       private Double someValue;
        ...
    
        // My Custom finder!!
       public static TypedQuery<PaymentSummary> findPaymentStatistics(Calendar fromDate, Calendar toDate) {
        if (fromDate == null || toDate == null)
            throw new IllegalArgumentException("Date period argument is required");
        EntityManager em = Payment.entityManager();
        TypedQuery<PaymentSummary> q = em.createQuery("select new com.mystuff.data.PaymentSummary(sum(o.someValue)) from Payment o where o.startDate >= :startDate and o.endDate <= :endDate", PaymentSummary.class);
        q.setParameter("startDate", fromDate);
        q.setParameter("endDate", toDate);
        return q;
       }
    
    }
    How can I generate jspx files for this query? Whenever I try to run "finder add --finderName findPaymentStatistics" I get an error message:

    Dynamic finder is unable to match 'findPaymentStatistics' token of 'findPaymentStatistics' finder definition in Payment.java
    Thanks for the help,
    Li

  • #2
    Please use the 'finder list' command to see which exact finder names are acceptable for Roo.

    HTH,
    Stefan

    Comment


    • #3
      Thanks Stefan,

      I know that my finder is not in the finders list, but I was still wondering if there is a way to handle custom finders that were not generate by roo or a way to add my finder to the finders list.

      Thanks,
      Lin

      Comment


      • #4
        Roo needs to use the finder names it can reason about so it can generate the correct forms for it. So you can't just add a custom finder name and hope Roo can do black magic . However, you can use a known finder name (findBy..DateBetween) which Roo can offer views for and then push it in to customize the SQL statement.

        Alternatively, you can create your own jspx (using Roos tags if you want) to get your custom finder working.

        -Stefan

        Comment


        • #5
          Thanks Stefan, I'll do as you suggested.

          Comment


          • #6
            How come when using the finder add and supplying a finder name from the list, sometimes it creates it properly with the aspect, and sometimes it just updates the Entity and does not create the aspect. It seems sproadic.

            Comment


            • #7
              Can you please try one of the latest snapshot releases to see if this behaviour is still present? http://static.springsource.org/downl...hp?project=ROO

              We recently made a number of changes to address this issue. If the problem still persists, please open a Jira bug ticket.

              Comment


              • #8
                Well, I downloaded it and unzipped it. Added the version to the Spring Roo Support Workspace settings. Getting these pom errors:
                2/3/11 4:06:41 PM MST: [WARN] The POM for org.springframework.roo:org.springframework.roo.an notations:jar:1.1.2.BUILD-SNAPSHOT is missing, no dependency information available
                2/3/11 4:06:41 PM MST: Maven Builder: AUTO_BUILD
                2/3/11 4:08:20 PM MST: [WARN] The POM for org.springframework.roo:org.springframework.roo.an notations:jar:1.1.2.BUILD-SNAPSHOT is missing, no dependency information available
                2/3/11 4:08:20 PM MST: Missing artifact org.springframework.roo:org.springframework.roo.an notations:jar:1.1.2.BUILD-SNAPSHOTrovided
                2/3/11 4:08:21 PM MST: Maven Builder: AUTO_BUILD

                Comment


                • #9
                  Had to change the pom file annotations version to: 1.1.1.RELEASE

                  Comment


                  • #10
                    Had to update the pom file <artifactId>org.springframework.roo.annotations</artifactId>
                    <version>1.1.1.RELEASE</version>

                    It seems to have removed all the current finders and does nothing when doing a finder add or a finder list.

                    Comment

                    Working...
                    X