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. 정말 재미있게 잘 보았습니다..^^
    ROO 받아놓고 그저 멍하게 바라보고 있다가 이렇게
    자상하게 설명을 해주시니 이해가 쏙쏙 됩니다.
    AOP를 이렇게 적극적이고 창의적으로 사용하다니 정말 놀랍습니다.
    무엇보다 기타기능과 도메인,컨트롤러를 완전히 분리한 것을 보니
    다른 기능도 얼마든지 분리해서 쉽게 추가할수 있을 것 같습니다.

  2. 3년전에 컨퍼런스 다녀와서 뜯어 고쳐야겠다고 했던게 이거 때문이였군. 대박이네.

  3. RoR 장점이 모두 녹아 있는 것 같습니다.
    자동 setter/getter생성, 테이블 생성, 자동 finder메소드 생성
    그리고 RoR과 흡사한 command기반의 메소드 설치 과정도 눈부십니다.
    이거 진짜로 대박인데요~

  4. JPA QL이요..
    이미 생성된 소스에 자동 생성 툴을 적용할 수 있다니..
    기존에 자동 생성이 갖는 단점을 극복해주네요..

  5. JHecAK xdbvsrpyaxws, [url=http://pyatgigassln.com/]pyatgigassln[/url], [link=http://slajommzbxev.com/]slajommzbxev[/link], http://kiuwibhjanuj.com/

  6. This is a message to the webmaster. Your website is missing out on at least 300 visitors per day. I have found a company which offers to dramatically increase your traffic to your website: http://nsru.net/lpti They offer 1,000 free visitors during their free trial period and I managed to get over 30,000 visitors per month using their services, you could also get lot more targeted traffic than you have now. Hope this helps :) Take care.

  7. You need targeted traffic to your website so why not get some for free? There is a VERY POWERFUL and POPULAR company out there who now lets you try their website traffic service for 7 days free of charge. I am so glad they opened their traffic system back up to the public! Sign up before it is too late: http://nsru.net/059a

  8. PWmY1x zfgyvcwhkdfo, [url=http://pvrpiisppbyc.com/]pvrpiisppbyc[/url], [link=http://bteclcyzerww.com/]bteclcyzerww[/link], http://awdrrvmtqvqa.com/

  9. free trial viagra free trial viagra

  10. Traffic is the key to any website business. I found a company that has been an awesome resource in building our traffic and the communication back and forth has been great. I use most of the services offered by this site and I am now getting hundreds of targeted visitors to my website every day. Take a look here: http://gmbal.com/511c

  11. mbt swiss shoes Spring ROO 대충대충 분석 (3) ROO의 Inter-type declaration » Toby’s Epril

  12. We have decided to open our POWERFUL and PRIVATE website traffic system to the public for a limited time! You can sign up for our UP SCALE network with a free trial as we get started with the public’s orders. Imagine how your bank account will look when your website gets the traffic it deserves. Visit us today: http://2hams.com/612b

  13. you’re really a excellent webmaster. The website loading velocity is
    amazing. It sort of feels that you’re doing any unique trick.
    Moreover, The contents are masterpiece. you have performed a wonderful task in this topic!

  14. There is perceptibly a bundle to identify about this.
    I think you made some nice points in features
    also.

  15. It’s not my first time to go to see this web site, i am visiting this website dailly and get nice data from here
    daily.

    My blog … http://forskolinketovit.net/

  16. sağa sola gotunu vurduruyormussun

  17. Web Tasarim ve SEO hizmetlerinde web macaw Kurumsal web tasarim firmasi MediaClick Istanbul, SEO ve mobil uyumlu profesyonel web site tasarimlari, web yazilimlari ile web sitesi tasarim. Grimor, kurulusundan beri sizlere özel tasarim ve web hizmetleri vermektedir. Web tasarim ihtiyaçlariniz için en dogru adres Grimor.com Web tasarim Istanbul’da en kaliteli firmalarin basinda gelen firmamiz sadece web tasarim degil ayni zamanda Istanbul Seo Firmasi olarak da hizmet vermekte. Profesyonel web tasarim hizmetleri sunan, Biltek Web Tasarim sirketi ile kusursuz bir web sitesi tasarimina sahip olacaksiniz.

  18. Hello there! This article couldn’t be written any better!
    Looking at this post reminds me of my previous roommate!
    He continually kept talking about this. I am going to forward
    this article to him. Fairly certain he’s going to have a great read.

    Thank you for sharing!

  19. Yerli yangın kapısı denince aklınıza biz geliriz tıkla göre

  20. You made some good points there. I did a search on the topic and found most individuals will agree with your blog.

  21. Short Haircuts Models, There’s no going back once you commit to the short hairstyle so how are you. Celebrity inspired short haircuts and hairstyles to try. https://shorthaircutsmodels.com/ Our short hairstyles and short haircuts to inspire your next salon. Top model Maria Borges stunned in this sleek straight crop at the. From to Moss see the models who have made a career statement with short hair. The model approved haircuts were made for standing out. Check out our edit of the best celeb hairstyles for short hair for all the. Seriously short and peroxide blonde looks epic on model. These are the best short haircuts for men to get in 2019. We cover all types of fade haircuts crop haircuts classic short haircuts for men and cool quiff haircuts.

  22. Short Haircuts Models, There’s no going back once you commit to the short hairstyle so how are you. Celebrity inspired short haircuts and hairstyles to try. https://shorthaircutsmodels.com/ Our short hairstyles and short haircuts to inspire your next salon. Top model Maria Borges stunned in this sleek straight crop at the. From to Moss see the models who have made a career statement with short hair. The model approved haircuts were made for standing out. Check out our edit of the best celeb hairstyles for short hair for all the. Seriously short and peroxide blonde looks epic on model. These are the best short haircuts for men to get in 2019. We cover all types of fade haircuts crop haircuts classic short haircuts for men and cool quiff haircuts.

  23. Short Haircuts Models, There’s no going back once you commit to the short hairstyle so how are you. Celebrity inspired short haircuts and hairstyles to try. https://shorthaircutsmodels.com/ Our short hairstyles and short haircuts to inspire your next salon. Top model Maria Borges stunned in this sleek straight crop at the. From to Moss see the models who have made a career statement with short hair. The model approved haircuts were made for standing out. Check out our edit of the best celeb hairstyles for short hair for all the. Seriously short and peroxide blonde looks epic on model. These are the best short haircuts for men to get in 2019. We cover all types of fade haircuts crop haircuts classic short haircuts for men and cool quiff haircuts.

  24. Yangın kapısı Tekirdağ, yangın merdiveni kapısı ıkarak bilinen özel kapı Tekirdağ için önem arz eden bir kapıdır. Türkiyenin dünyanın en büyük yangın kapısı firması olmayı hayel ve arzu ediyoruz. Çünkü biz yangın yönetmeliğine ait bilgileri bilmekteyiz. Yangın merdiveni kapısı Tekirdağ için ve tüm dünya için panik barlı yangın çıkış kapısıdır. Ucuz yangın kapılarının amacı en ucuz olmasıdır. ama yangın kapısının ucuz olması demek iyi olduğu manasına gelmemektedir. Yangın çıkış kapısı Tekirdağ firması olarak istanbuldan tüm türkiyeye aynı günde stok yangın merdiveni kapısı gönderimi yapmaktayz. Ucuz Yangın kapısı firmasıyız.

  25. Today, I went to the beach front with my kids. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear and
    screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is entirely off topic but I had to tell someone!

  26. Gotune 50mm delik acmaya geliyorum ammina kodugum

  27. Howdy this is kind of of off topic but I was wondering if
    blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding knowledge so I wanted to get advice from someone
    with experience. Any help would be enormously appreciated!

  28. Levitra bayer
    Should you suffer from ringing in the ears, it is crucial that you stay away from pressure as much as humanly feasible. Stress is extremely harmful to your whole body and contains a negative result on all conditions, tinnitus included. Make time to walk and meditate, pay attention to peaceful music, or participate in any activity that you just get pleasure from and look for calming.
    levitra générique
    Would you like hearing tunes although operating? This really is fine, but avoid headsets that can keep you from hearing noises which may be needed for your security as well as your task, too.
    dapoxetin schweiz
    Allow yourself a smaller face treatment utilizing a mask created from an egg white colored and a dash of fresh lemon juice. Abandon the mask on for about two moments, then rinse off. This provides your skin an instant tightening up result and is perfect to accomplish about one hour well before an evening hours out around town.
    propecia preço

  29. viagra generico
    Acne is not a one time condition, but is quite a long-term genetic and hormonal issue that will last properly into the adult years. Utilize a everyday servicing software even though you may usually are not struggling with an acne breakouts breakout so that you can help ensure your epidermis remains to be pimples free of charge so long as possible.
    viagra comprar
    While weight lifters typically pinpoint the intake of proteins inside their diet, fruits and vegetables may also be important. Many nutritional vitamins are misplaced via perspire while in workouts. Vegetables and fruit do not put plenty of calorie consumption on the diet program, but do replace these nutrients while also incorporating fibers.
    viagra belgique
    For those who have numerous a credit card for different retailers, put them in the zippered sandwich travelling bag filled up with water, then lock the case inside your fridge. This helps you to refrain from attraction by producing several challenges to a usually impulsive investing spree. Not only will you need to wait for ice-cubes to thaw, but you could also wind up making a clutter – a fantastic deterrent.
    viagra wirkung

  30. kamagra prezzo
    When you achieve the delighted day time where your home loan is ultimately repaid, be sure you benefit from the insurance coverage positive aspects. The monthly premiums for homeowner’s insurance policy are drastically decrease for a residence you hold completely than first you happen to be continue to paying off. Insurance firms are betting,with good justification, that you simply can take better care of a residence that may be all your own property.
    priligy fass
    Even when you may have significant practical experience on the planet of entrepreneurship, you ought to never assume that you could “quick way” your way to success with your new endeavor. Surely, your experience in real life will remain you in good stead when it comes to advertising and marketing, buyer interaction and the like, nevertheless, you must start along with your clear page of document whenever.
    propecia generico
    In case you are jogging reduced on dollars or want some thing unique, you do not have to acquire an actual gown made for the woman at the wedding ceremony. Check out a few of the several types of bridesmaid or mall gowns, which will give you an attractive alternative at a small part of the cost.
    kamagra jelly

  31. Viagra pris
    For those who are living in an apartment sophisticated, plumbing related is normally forgotten about. The very first time they transfer to a residence they are unable to take care of any minimal domestic plumbing problems, because they have by no means addressed this type of thing. It is great to have a fundamental understanding when stepping into the first property.
    cialis senza ricetta
    While you are along the way of shedding weight, it is advisable to buy clothes at thrift shops and low cost stores. Simply because you wish to avoid paying lots of money on apparel on your weight loss strategy which will quickly be too big to suit your needs.
    levitra générique
    When you find it difficult getting your eyeliner to remain put, you may use eyeshadow once you wear eyeliner. You must casually set your shadow over your eyeliner having a pure cotton soccer ball. This will likely seal the application of eyeliner and it will keep going longer and never run.
    kamagra kopen

  32. cialis zonder voorschrift
    Make sure to take the time to check out the firm that you are currently contemplating obtaining your homeowners insurance through. You are going to want to make sure that there are not a number of complaints about payment instances and denials of statements. In the event the organization usually takes a long time to spend out or rejects claims, you may find it beneficial for you to maintain hunting.
    acheter levitra
    Some people might have grey your hair in the beginning, nevertheless most people encounter acquiring grey head of hair since they age group. A lot of people prefer to just go greyish and others want to conceal greyish head of hair. If you are not sure about long lasting locks colors you will find items that are temporary and you may try out those out initial prior to investing in a lasting coloring product or service.
    dapoxetin schweiz
    Maybe you’ve been at the job hunt for quite a while now, or maybe you are merely starting up. Either way, you may benefit from using the advice in this article ro direct you towards your pursuit for work. You will need to invest efforts and conscientious energy into the efforts, but it will likely be well worth it in the long run!All That You Should Know About Fund In Your Work
    viagra 100mg

Leave a Reply to yangın Kapısı Cancel 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