Announcement Announcement Module
Collapse
No announcement yet.
Duplicated code in auto-generated finders Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Duplicated code in auto-generated finders

    By default, the Pizza_Roo_Entity.aj file contains these two finders (among others):

    Code:
    public static List<Pizza> Pizza.findAllPizzas() {    
        return entityManager().createQuery("select o from Pizza o").getResultList();        
    }
        
    public static List<Pizza> Pizza.findPizzaEntries(int firstResult, int maxResults) {    
        return entityManager().createQuery("select o from Pizza o").setFirstResult(firstResult).setMaxResults(maxResults).getResultList();        
    }
    The JPQL is the same in both methods; it would be more DRY (with all the attendant benefits) if the "findAllXxx" finder was changed to read:

    Code:
    public static List<Pizza> Pizza.findAllPizzas() {    
        return findPizzaEntries(0, Integer.MAX_VALUE);        
    }
    This is not just stylistic nitpicking; if you always want to limit these two finders by some additional criteria (e.g. the Pizzas created by the currrent user*), then you have to push in and modify both the above finders, whereas if my suggestion were adopted, you would only have to push in and modify the "findPizzaEntries" finder. Repeated across multiple entities, this represents a lot of work saved. And Roo is all about productivity, right?

    * This is obviously a made-up example, but it mirrors a real-world requirement in the app I'm currently developing.
Working...
X