Platinum Partner
java,frameworks

Now you can choose ActiveRecord or Service/Repo for Roo 1.2

Check it out!  Now you can install services and repositories, and when you scaffold the project automatically generates calls to the service layer rather than to the Active Record pattern.

I think personally it's a huge win for Roo to be able to support both approaches, since having to switch tools based on a difference in one pattern approach to me feels wrongheaded.  Here's a screenshot from IntelliJ:


Here is a snippet of the code written in the CourseController_Roo_Controller.aj file proving the nice integration:

privileged aspect CourseController_Roo_Controller {
  
  @Autowired
  CourseService CourseController.courseService;
  
  @RequestMapping(method = RequestMethod.POST)
  public String CourseController.create(@Valid Course course, 
       BindingResult bindingResult, Model uiModel, 
       HttpServletRequest httpServletRequest) {
    if (bindingResult.hasErrors()) {
        uiModel.addAttribute("course", course);
        return "courses/create";
    }
    uiModel.asMap().clear();
    courseService.saveCourse(course);
    return "redirect:/courses/" + 
         encodeUrlPathSegment(
            course.getId().toString(), httpServletRequest);
  }
  
  @RequestMapping(params = "form", method = RequestMethod.GET)
  public String CourseController.createForm(Model uiModel) {
      uiModel.addAttribute("course", new Course());
      return "courses/create";
  }
  
  @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  public String CourseController.show(
      @PathVariable("id") Long id, Model uiModel) {
    uiModel.addAttribute("course", courseService.findCourse(id));
    uiModel.addAttribute("itemId", id);
    return "courses/show";
  } 
...
}

To try it out, head over to the nightly builds page and download the latest nightly.  (Do NOT unzip this over a working 1.1 or earlier 1.2 or you'll be crying a sweater of tears).  Then, make your /usr/bin/roo or /usr/bin/roo12 symbolic link (my angle as during the writing of the book I've been testing things against roo 1.1, 1.2, etc).  Create your project and you'll see the options.

You can build this if you put the snapshot repository into your list of repositories in your pom.xml file:

<repository>
    <id>spring-roo-internal-repo</id>
    <name>Spring Roo Internal Snapshot Repo</name>
    <url>http://spring-roo-repository.springsource.org/snapshot</url>
</repository>

Best of luck, and enjoy playing with the upcoming Roo features. I'm also going to check out some newer add-ons, such as JSF and the newly updated Flex (by Roo forum contributor working with the team on a patch) and GWT addons in future blog entries. For now, though, it's back to my add-ons chapter, which is coming soon.

From http://www.rimple.com/tech/2011/8/21/now-you-can-choose-activerecord-or-servicerepo-for-roo-12.html

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}