ROO가 inter-type declaration방식을 써서 도메인객체와 컨트롤러에 적용한 것들을 좀 살펴보자.

 

도메인 객체용 Inter-type delcaration

도메인 객체에는 5가지의 Inter-type declaration가 적용되어있다.

  • Configurable
  • Entity
  • JavaBean
  • Plural
  • ToString

 

ROO_Configurable

 

Pet_Roo_Configurable.aj를 보자. ROO가 생성한 inter-type declaration은 모두 _Roo_가 붙어있다. 이는 IDE(Eclipse)에서 filtering을 통해서 개발자들에게 코드를 감추는데 효과적으로 활용된다. 개발자들은 이 코드들을 안보고 개발할 수 있다.

privileged aspect Pet_Roo_Configurable {
    declare @type: Pet: @org.springframework.beans.factory.annotation.Configurable;   
}

간단한 내용이다. Pet클래스에 @Configurable을 추가시키는 것이다. @Configurable은 하이버네이트와 같은 3-rd party 제품에서 new로 생성할 때 DI를 적용시키기 위한 기술이다.

DDD개발방법에서는 보통 도메인객체와 Repository를 구분하는데 ROO는 이를 단순화 해서 일체형으로 만들었다. 즉 Pet은 Mixin이 만들어지고 나면 Pet+Pet Repository(DAO)의 기능을 모두 가지게 된다. 그래서 Domain –> Repository의 DI는 필요없지만 대신 JPA를 사용하니 EntityManager를 가져와야 한다. 그 외에 다른 DI가 필요할 수도 있으니 @Configurable을 적용하는데, 그것을 개발자코드에서는 감추고 여기서 자동으로 추가하게 해준다.

 

ROO_Entity

 

ROO Entity는 JPA(Hibernate)를 이용한 Geneirc DAO를 만들어주는 것이라고 보면 된다. EntityManager(SessionFactory 같은..)를 정의해주고 JPA스타일의 CRUD기본 메소드를 등록해준다. 그 외에 Id나 Version같은 것, relation(M2O 따위)이 정의될 수 있다.

privileged aspect Pet_Roo_Entity {
    @javax.persistence.PersistenceContext   
    transient javax.persistence.EntityManager Pet.entityManager;   
    @javax.persistence.Id   
    @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)   
    @javax.persistence.Column(name = "id")   
    private java.lang.Long Pet.id;   
    @javax.persistence.Version   
    @javax.persistence.Column(name = "version")   
    private java.lang.Integer Pet.version;   
    public java.lang.Long Pet.getId() {   
        return this.id;       
    }   

   …
    @org.springframework.transaction.annotation.Transactional   
    public void Pet.persist() {   
        if (this.entityManager == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");       
        this.entityManager.persist(this);       
    }   
    @org.springframework.transaction.annotation.Transactional   
    public void Pet.remove() {   
        if (this.entityManager == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");       
        this.entityManager.remove(this);       
    }

  …  

 

ROO_JavaBean

 

이건 getter/setter를 제공해서 javabean 스펙을 요구하는 SpringMVC등에 적용하도록 만들어주는 것이다. 이 덕분에 Pet 도메인 객체에는 지저분하게 보이기도 하는 getter/setter가 없다.

privileged aspect Pet_Roo_JavaBean {
    public java.lang.String Pet.getContactEmails() {   
        return this.contactEmails;       
    }   
    public void Pet.setContactEmails(java.lang.String contactEmails) {   
        this.contactEmails = contactEmails;       
    }   
    public java.lang.Boolean Pet.getSendReminders() {   
        return this.sendReminders;       
    }   
    public void Pet.setSendReminders(java.lang.Boolean sendReminders) {   
        this.sendReminders = sendReminders;       
    }   

  …

 

ROO_Finder

 

Finder는 CRUD외에 검색용 DAO 메소드를 말한다. Finder는 코드 생성에서 바로 만들 수 있는데, HSQL 같은(JPA에서는 머라고 하더라..) 로우레벨의 코드를 안쓰고도 필드 조건만 정의해주면 자동으로 만들어진다.

 

이름과 무게로 Pet을 검색하는 finder의 추가는 코드생성기에서

install finder -class ~.domain.Pet -finderName findPetsByNameAndWeight

라고 하면 된다. RoR에서와 비슷하게 이름을 가지고 검색조건을 자동으로 인식해서 만들어 준다.

이에 의해서 생성되는 코드는 아래와 같다.

privileged aspect Pet_Roo_Finder {
    public static javax.persistence.Query Pet.findPetsByNameAndWeight(java.lang.String name, java.lang.Float weight) {   
        if (name == null) throw new IllegalArgumentException("The name argument is required");       
        if (weight == null) throw new IllegalArgumentException("The weight argument is required");       
        javax.persistence.EntityManager em = new Pet().entityManager;       
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");       
        javax.persistence.Query q = em.createQuery("FROM Pet AS pet WHERE pet.name = :name AND pet.weight = :weight");       
        q.setParameter("name", name);       
        q.setParameter("weight", weight);       
        return q;       
    }

 

검색조건을 확인하는 것까지 포함해서 JPA의 Query를 만들어 준다.

 

ROO_Plural

 

이건 RoR스타일의 테이블 이름 자동 추정기능을 활용하기 위해서이다. 요즘 나오는 대부분의 프레임워크들이 그렇지만 ROO도 RoR의 영향을 많이 받았다. 자바로 만든 RoR을 지향하는 것일지도.

Plural은 테이블 명으로 사용되며, 기본적으로 자동으로 정의되지만 바꿀 수 있다. JPA이므로 테이블 자동 생성기능도 지원 가능할 것이다.

privileged aspect Pet_Roo_Plural {
    public static java.lang.String Pet.getPluralName() {   
        return "Pets";       
    }   
}

 

ROO_ToString

 

로깅이나 여타 경우에 사용가능한 ToString을 자동으로 만들어준다. 이건 보너스~

privileged aspect Pet_Roo_ToString {
    public java.lang.String Pet.toString() {   
        StringBuilder sb = new StringBuilder();       
        sb.append("id: ").append(getId()).append(", ");       
        sb.append("version: ").append(getVersion()).append(", ");       

       …
        return sb.toString();       
    }   
}

 

자, 이렇게 해서 5가지 Inter-type declaration이 Pet과 결합해서 Pet Mixin을 만들어낸다. 모두 30여개의 새로운 메소드와 필드, 선언들이 추가된다.

 

이것이 역시 CRUD를 모두 지원하는(RoR의 Scaffolding과 비슷하다) Controller와 결합해서 동작하게 되어있다. 관심있는 분들은 Controller부분은 샘플을 한번 만들어서 직접 보도록.

Related posts:

  1. 테스트 할 수 없는 것을 테스트 하기. Spring ROO와 static method mocking.
  2. Spring ROO 대충대충 분석 (4) ROO의 미래와 의의
  3. Spring 3.0 (11) Aspects 모듈의 선택 라이브러리 분석
  4. Spring 3.0 (17) Orm 모듈의 선택 라이브러리 분석
  5. Spring 3.0 (13) Context 모듈의 선택 라이브러리 분석
  6. S1A 2008 셋째날 – Spring JavaConfig
  7. Spring 3.0 (21) Web 모듈의 선택 라이브러리 분석
  8. 미리 보는 Spring 3.0.1의 변경사항
  9. Spring 3.0 EL (Spel)을 이용한 AssertThrows 확장 (1)
  10. Spring 3.0 (56) @Bean 사용의 주의사항
  11. Spring Expressions(SpEL)를 이용한 Mockito Argument Matcher 만들기
  12. Spring 3.0 EL (Spel)을 이용한 AssertThrows 확장 (3)
  13. Spring 3.0 (28) R-669 Update
  14. Spring 3.0 (20) Transaction 모듈의 선택 라이브러리
  15. Spring 3.0 (52) 반쪽짜리 3.0 RC1 공개

Facebook comments:

to “Spring ROO 대충대충 분석 (3) ROO의 Inter-type declaration”

  1. Thank you for every other informative website. Where else could I get that type of info written in such a perfect means? I’ve a mission that I’m just now operating on, and I’ve been at the look out for such info.

  2. I like this post, enjoyed this one thank you for putting up. “The universe is not hostile, nor yet is it unfriendly. It is simply indifferent.” by John Andrew Holmes.

  3. Lovely website! I am loving it!! Will come back again. I am bookmarking your feeds also

  4. I’ve recently started a blog, the info you offer on this web site has helped me greatly. Thanks for all of your time & work.

  5. bad credits can happen at any point in your life so be prepared to always get some extra income.

  6. Thank you, I have recently been looking for information approximately this topic for ages and yours is the best I’ve discovered so far. But, what about the conclusion? Are you sure concerning the source?

  7. Thanks for your write-up on the vacation industry. I will also like to add that if your senior taking into consideration traveling, it can be absolutely imperative that you buy traveling insurance for seniors. When traveling, senior citizens are at greatest risk of having a healthcare emergency. Obtaining right insurance policy package for your age group can protect your health and give you peace of mind.

  8. One thing is that when you are searching for a education loan you may find that you will need a co-signer. There are many circumstances where this is correct because you might find that you do not have a past credit rating so the mortgage lender will require that you have someone cosign the credit for you. Great post.

  9. Heya! I’m at work surfing around your blog from my new iphone 4! Just wanted to say I love reading your blog and look forward to all your posts! Keep up the outstanding work!

  10. Nice blog here! Also your website loads up fast! What host are you using? Can I get your affiliate link to your host? I wish my site loaded up as quickly as yours lol

  11. Hi! Do you use Twitter? I’d like to follow you if that would be okay. I’m definitely enjoying your blog and look forward to new posts.

  12. hi and thanks for the actual blog post ive recently been searching regarding this specific advice on-line for sum hours these days as a result thanks

  13. It’s in point of fact a great and useful piece of information. I am glad that you shared this useful info with us. Please stay us up to date like this. Thanks for sharing.

  14. Howdy! Quick question that’s entirely off topic. Do you know how to make your site mobile friendly? My web site looks weird when browsing from my iphone4. I’m trying to find a theme or plugin that might be able to fix this problem. If you have any recommendations, please share. Thank you!

  15. Wonderful beat ! I wish to apprentice whilst you amend your
    web site, how can i subscribe for a blog web site? The account aided me a
    acceptable deal. I have been tiny bit familiar of this your
    broadcast provided shiny transparent idea.

    Here is my site … Nature Active Keto Diet

  16. What i do not realize is actually how you are
    now not actually a lot more well-preferred than you
    might be right now. You’re so intelligent. You recognize
    therefore considerably when it comes to this matter,
    produced me for my part consider it from so many varied angles.
    Its like women and men are not interested unless it’s something to do with Lady gaga!
    Your individual stuffs nice. Always deal with it up!

  17. Wonderful web site. Plenty of useful info here. I’m sending it to several friends ans also sharing in delicious. And naturally, thanks for your effort!

  18. I think your blog is getting more and more visitors.’-”;.

  19. Thanks so much for giving my family an update on this issue on your web page.
    Please realize that if a completely new post appears or in the event any improvements occur with the current article, I would
    be interested in reading a lot more and knowing how to make good usage of those techniques you talk about.
    Thanks for your efforts and consideration of other men and women by making this blog available.

    My web site :: Wild Things Hair Growth Reviews

  20. Hello there. I found your web site by the use of Google while searching for a comparable topic, your website got here up. It appears great. I have bookmarked it in my google bookmarks to come back then.

  21. When someone writes an piece of writing he/she keeps the idea of a user in his/her mind that how a user can be aware of it.
    Thus that’s why this piece of writing is outstdanding.
    Thanks!

  22. Hey there. I discovered your blog via Google while searching for a comparable subject, your site got here up. It appears to be great. I’ve bookmarked it in my google bookmarks to visit then.

  23. Hiya, I am really glad I’ve found this info. Nowadays bloggers publish just about gossip and internet stuff and this is really frustrating. A good web site with interesting content, that is what I need. Thank you for making this web site, and I will be visiting again. Do you do newsletters by email?

  24. Hiya, I’m really glad I have found this information. Today bloggers publish only about gossip and net stuff and this is really annoying. A good website with interesting content, this is what I need. Thank you for making this web site, and I’ll be visiting again. Do you do newsletters by email?

  25. After I originally left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get 4 emails with the same comment. Perhaps there is a way you are able to remove me from that service? Appreciate it.

  26. Hiya, I’m really glad I have found this info. Nowadays bloggers publish just about gossip and net stuff and this is really irritating. A good site with exciting content, that’s what I need. Thank you for making this web-site, and I will be visiting again. Do you do newsletters by email?

  27. Hiya, I am really glad I have found this information. Nowadays bloggers publish only about gossip and internet stuff and this is actually annoying. A good site with exciting content, this is what I need. Thank you for making this web site, and I’ll be visiting again. Do you do newsletters by email?

  28. Hiya, I’m really glad I’ve found this info. Nowadays bloggers publish only about gossip and net stuff and this is really annoying. A good web site with exciting content, that’s what I need. Thank you for making this web site, and I will be visiting again. Do you do newsletters by email?

  29. Hi there. I discovered your site by the use of Google while searching for a similar matter, your web site came up. It looks good. I’ve bookmarked it in my google bookmarks to come back then.

  30. Awesome post. I’m a normal visitor of your site and appreciate you taking the time to maintain the nice site. I will be a regular visitor for a long time.

  31. Awesome write-up. I am a normal visitor of your site and appreciate you taking the time to maintain the excellent site. I will be a frequent visitor for a really long time.

  32. Awesome write-up. I am a regular visitor of your web site and appreciate you taking the time to maintain the excellent site. I’ll be a frequent visitor for a long time.

  33. Hi there. I found your web site by way of Google at the same time as searching for a similar matter, your site got here up. It appears great. I’ve bookmarked it in my google bookmarks to come back then.

  34. Hello there. I discovered your web site by the use of Google at the same time as searching for a related matter, your site came up. It appears to be great. I’ve bookmarked it in my google bookmarks to visit then.

  35. Hello there. I discovered your blog by the use of Google even as searching for a similar matter, your web site came up. It looks good. I’ve bookmarked it in my google bookmarks to visit then.

  36. Awesome write-up. I am a normal visitor of your blog and appreciate you taking the time to maintain the excellent site. I will be a frequent visitor for a long time.

  37. Hiya, I am really glad I’ve found this information. Nowadays bloggers publish just about gossip and net stuff and this is actually frustrating. A good site with exciting content, this is what I need. Thank you for making this web site, and I’ll be visiting again. Do you do newsletters by email?

  38. Awesome post. I am a normal visitor of your web site and appreciate you taking the time to maintain the nice site. I will be a frequent visitor for a really long time.

  39. Hiya, I am really glad I have found this information. Today bloggers publish only about gossip and internet stuff and this is actually frustrating. A good site with exciting content, this is what I need. Thanks for making this web site, and I’ll be visiting again. Do you do newsletters by email?

  40. Hiya, I am really glad I have found this information. Nowadays bloggers publish just about gossip and net stuff and this is actually frustrating. A good site with interesting content, that is what I need. Thanks for making this website, and I’ll be visiting again. Do you do newsletters by email?

  41. Awesome write-up. I am a regular visitor of your site and appreciate you taking the time to maintain the nice site. I will be a frequent visitor for a long time.

  42. Hello there. I discovered your web site by means of Google even as searching for a similar subject, your website got here up. It looks good. I’ve bookmarked it in my google bookmarks to visit then.

  43. Great info. Lucky me I discovered your blog by accident (stumbleupon). I have saved it for later!

  44. Awesome write-up. I am a normal visitor of your website and appreciate you taking the time to maintain the excellent site. I’ll be a frequent visitor for a really long time.

  45. Awesome post. I’m a normal visitor of your web site and appreciate you taking the time to maintain the excellent site. I’ll be a frequent visitor for a really long time.

  46. Hiya, I’m really glad I have found this info. Today bloggers publish only about gossip and internet stuff and this is really irritating. A good web site with interesting content, this is what I need. Thank you for making this website, and I’ll be visiting again. Do you do newsletters by email?

  47. Hiya, I am really glad I have found this information. Today bloggers publish just about gossip and internet stuff and this is actually frustrating. A good website with interesting content, that’s what I need. Thanks for making this web-site, and I will be visiting again. Do you do newsletters by email?

  48. Hello there. I discovered your website by the use of Google whilst searching for a related subject, your site got here up. It appears good. I’ve bookmarked it in my google bookmarks to come back then.

  49. Awesome post. I am a normal visitor of your blog and appreciate you taking the time to maintain the excellent site. I will be a regular visitor for a long time.

  50. Awesome write-up. I am a normal visitor of your site and appreciate you taking the time to maintain the excellent site. I’ll be a frequent visitor for a long time.

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2017 Toby's Epril Suffusion theme by Sayontan Sinha