달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2007. 10. 25. 09:55

JSP & Servlet 교육 Day 4th. 그거/Seminar2007. 10. 25. 09:55


장소 : 썬 교육센터
날짜 : 10.22 ~ 10.26
시간 : 09:30 ~ 17:30
내용 : Web Component Developement with Servlet and JSP Technologies

# Day 4

# Web Application 에서 EJB 사용하기

<%@ page contentType="text/html; charset=euc-kr" %>
<%@ page import="javax.rmi.*" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.transaction.*" %>
<%@ page import="kr.co.ejb.examples.*" %>

<%
 Context ctx = null;

 try {
  ctx = new InitialContext();
  Object h = ctx.lookup("HelloWorldBean");
  HelloWorldHome home = (HelloWorldHome)PortableRemoteObject.narrow(h, HelloWorldHome.class);
  HelloWorld helloWorld = home.create();

  out.println(helloWorld.helloWorld());
 } catch(Exception e) {
  out.println(e);
 }
%>


1. 위 내용의 jsp 파일을 생성하여 web application 디렉토리 위치(C:\bea\user_projects\domains\mydomain\applications\webtest)에 복사한다.
2. jsp 페이지에서 helloworld.jar 내용을 import하여 사용하기 위해서
   helloworld.jar 파일을 C:\bea\user_projects\domains\mydomain\applications\webtest\WEB-INF\lib 에 복사한다.
   (classpath 잡아주기 귀찮으니까 WebLogic 서버가 시작하면서 알아서 jar 파일 물고 올라오도록 설정한 것이다.)


## 엔티티 빈
  Home Interface
    javax.ejb.EJBHome 또는 javax.ejb.EJBLocalHome 를 상속받는다.
    빈 클래스를 생성, 검색, 삭제할 수 있는 메소드를 선언한다.

    public interface XXX extends EJBHome {
      // insert 담당
      public XXX create(xx) throws CreateException, RemoteException;  
      // PK를 이용하여 table에서 한 row 가져옴
      public XXX findByPrimaryKey(xx) throws FinderException, RemoteException;
    }


  Remote Interface
    javax.ejb.EJBObject 또는 javax.ejb.EJBLocalObject를 상속받는다.
    클라이언트가 호출할 비즈니스 메소드를 정의하고 있다.

    public interface XXX extends EJBObject {
      // Table의 특정 column에 대해 접근할 수 있도록 하는 getter/setter
      public XXX getXX() throws RemoteException;
      public void setXX(xx) throws RemoteException;
    }


  Bean class
    javax.ejb.SessionBean 인터페이스를 구현한다.
    원격 인터페이스에서 선언한 비즈니스 메소드를 구현해야 한다.
    (EJB 클래스는 원격 인터페이스를 구현하지 않는다.)

    public abstract class XXX implements EntityBean {
      private EntityContext context;
      // Home Interface에 있는 getter/setter method 추상화 선언
      public abstract XXX getXX() throws RemoteException;
      public abstract void setXX(xx) throws RemoteException;

      // Table에 한 row를 insert 하는 역할을 담당
      public String ejbCreate(xx) throws CreateException {
        setXX(xx);
      }

      // CMP 에서는 method의 몸체 없이 정의, BMP 에서는 각 method 몸체 구현
      // ejbCreate, ejbPostCreate -> insert 구현
      // ejbRemove -> delete 구현
      // ejbStore -> update 구현
      // ejbLoad -> where 조건을 이용한 특정 한 row select 구현
      // ejbFindByPrimaryKey -> PK를 이용한 특정 한 row select 구현
      public void ejbPostCreate(XX) throws CreateException {}
      public void ejbStore() {}
      public void ejbLoad() {}
      public void ejbRemove() {}

      public void ejbActivate() {}
      public void ejbPassivate() {}
      public void setEntityContext(EntityContext ctx) { context = ctx; }
      public void unsetEntityContext() { context = null; }
    }


  CMP 개발 (Container Managed Persistence)
    Source에 SQL 이 보이지 않는다.
    create(), findByPrimaryKey() method 등 Spec에 정의된 사항을 이용하여 DB 작업을 한다.
    WebLogic Builder에서의 설정
      1. Persistence 설정
      2. CMP fields 각각에 대해서 type 설정
      ( 3. Resources -> Resource References에 Add를 해줘야 한다는데, 안해도 잘된다.
           이유....는 나도 모른다 -_-;
           물어보니... 소스에 해당 resource에 대해서 lookup이 박혀있음 안해도 된단다.
           그래도 모르겠다 ㅜㅜ.
      )
      3. 저장하여 descriptor 파일 생성
      4. jar cvf xxxx.jar * 해서 class 파일과 META-INF 디렉토리를 jar로 압축

  BMP 개발 (Bean Managed persistence)
    Source(Bean)에 SQL을 직접 사용한다.
    WebLogic Builder에서의 설정
      1. Persistence 설정
      2. CMP fields 각각에 대해서 type 설정
      ( 3. Resources -> Resource References에 Add를 해줘야 한다는데, 안해도 잘된다.
        이유....는 나도 모른다 -_-; )
      3. 저장하여 descriptor 파일 생성
      4. jar cvf xxxx.jar * 해서 class 파일과 META-INF 디렉토리를 jar로 압축


  * EntityBean 에는 Persistence Data 그 자체에 대해서만 구현
    SessionBean 에는 EntityBean에서의 Data에대한 가공 및
    각종 Business Logic 을 구현
  * EJB 는 MVC 패턴에서 Model 이다.
    Model 은 Data와 Business Logic 역할로 구성되어 있다.

## 메세지 드리븐 빈
    Source(Bean)에 SQL을 직접 사용한다.
    WebLogic Builder에서의 설정
      1. Persistence 설정
      2. CMP fields 각각에 대해서 type 설정
      ( 3. Resources -> Resource References에 Add를 해줘야 한다는데, 안해도 잘된다.
        이유....는 나도 모른다 -_-; )
      3. MessageDrivenBean에 대해서 Destination Type & JNDI Name을 설정한다.
      4. MessageDrivenBean에 대해서 Resource -> EJB Refs 설정
      5. 저장하여 descriptor 파일 생성
      6. jar cvf xxxx.jar * 해서 class 파일과 META-INF 디렉토리를 jar로 압축
   
   


EJB 복잡하다.. 헷갈린다..  해야 될 것들이 너무 많다..
SessionBean, EntityBean, MessageDrivenBean
대체 이런건 왜 만든거여. -_-; ㅜㅜ
어흑. 먼 Spec이 이모양이야!!!!!!!!!!!!!!!!!
메세지 드리븐 빈은 더 복잡하네 -_-;

'그거 > Seminar' 카테고리의 다른 글

제9회 한국 Java 개발자 컨퍼런스  (0) 2008.01.22
JSP & Servlet 교육 Day 5th.  (0) 2007.10.26
JSP & Servlet 교육 Day 3rd.  (0) 2007.10.24
JSP & Servlet 교육 Day 2nd.  (0) 2007.10.23
JSP & Servlet 교육 Day 1st.  (0) 2007.10.22
:
Posted by 뽀기