EJB µðÀÚÀο¡¼ÀÇ Ãß»ó ºñÁö´Ï½º, ±¸Çö, ¾ÖÇø®ÄÉÀÌ¼Ç ·ÎÁ÷
Brett
McLaughlin ÀÛ°¡/ÆíÁýÀÚ, O'Reilly and Associates 2002³â
10¿ù
¾ÖÇø®ÄÉÀÌ¼Ç Ç÷¡´×¿¡ ÀÖ¾î¼ °¡Àå º¹ÀâÇÑ ¹®Á¦ Áß Çϳª´Â
ºñÁî´Ï½º¿Í ±¸Çö Ƽ¾î(tier) »çÀ̸¦ ¹Ýµå½Ã ºÐ¸®ÇØ¾ß ÇÑ´Ù´Â Á¡ÀÌ´Ù. Business Delegate
ÆÐÅÏÀº ¾ÖÇø®ÄÉÀ̼ÇÀÇ À¯Áöº¸¼ö¿Í ¾÷±×·¹À̵带 ¾î·Æ°Ô ¸¸µå´Â Ä¿Çøµ(coupling)À»
¹æÁöÇÑ´Ù.
óÀ½ºÎÅÍ ÀÌ ½Ã¸®Á µû¶ó¿Ô´ø µ¶ÀÚ¶ó¸é ¾ÖÇø®ÄÉÀ̼ǰú ±¸Çö ·ÎÁ÷À» ºñÁö´Ï½º ·ÎÁ÷¿¡¼ ºÐ¸®ÇÏ´Â ¹®Á¦°¡ °è¼Ó
Àç±âµÇ°í ÀÖ´Ù´Â °ÍÀ» °¨ÁöÇßÀ» °ÍÀÌ´Ù. ¿¹¸¦ µé¾î, ù
¹ø°´Â ºóÀÇ ±¸ÇöÀ» ÀÎÅÍÆäÀ̽º¿¡¼ ºÐ¸®ÇÒ ¶§ ¿ø°Ý °´Ã¼ µðÀÚÀÎÀÇ ¾î·Á¿ò¿¡ ÃÊ÷À» ¸ÂÃè´Ù. ±× ¹®Á¦´Â
ºñÁö´Ï½º ÀÎÅÍÆäÀ̽º ÆÐÅÏ(Business Interface pattern)À¸·Î ÇØ°áÇß´Ù. ¸¶Áö¸·
±Û¿¡¼´Â ºó¼Ó¿¡ Æ÷ÇÔµÈ µ¥ÀÌÅÍ¿¡ »ç¿ëÀÚµéÀÌ ¾×¼¼½º ÇÒ ¼ö ÀÖµµ·Ï ÇÏ¸é¼ µ¿½Ã¿¡ ¿£ÅÍƼ ºóÀÌ ¾ÖÇø®ÄÉÀ̼Ç
·¹À̾ Á÷Á¢ ³ëÃâµÇ´Â °ÍÀ¸·ÎºÎÅÍ º¸È£ÇØ¾ß ÇÒ Çʿ伺¿¡ ´ëÇÑ ³íÀïÀ» ´Ù·ð´Ù.
µÎ °æ¿ì ¸ðµÎ, ÇÙ½É ¹®Á¦´Â ºñÁö´Ï½º ·ÎÁ÷ ±¸ÇöÀ» ±× ·ÎÁ÷À» »ç¿ëÇÏ´Â Äڵ忡¼ ÃßÃâÇÔÀ¸·Î¼ ÇØ°áµÇ¾ú´Ù.
ÀÌ·¯ÇÑ Á¾·ùÀÇ Ãß»óÈ(abstraction)´Â ÁÁÀº ¾ÖÇø®ÄÉÀÌ¼Ç µðÀÚÀÎÀÇ ±âº»ÀÌ´Ù. ƯÈ÷ EJB ±â¹Ý
¾ÖÇø®ÄÉÀÌ¼Ç µðÀÚÀο¡ À־ ƯÈ÷ ±×·¸´Ù. ¿©±â¿¡¼ ´Ù½ÃÇѹø ºñÁö´Ï½º ÀÎÅÍÆäÀ̽º ÆÐÅÏ°ú ¼¼¼Ç ºóÀ» ÀÌ¿ëÇÏ¿© À¥
Ƽ¾î¸¦ Enterprise JavaBeans ÄÄÆ÷³ÍÆ®¿¡ ¾à°áÇÕ ÇÏ´Â ¹æ¹ýÀ» ´Ù·ç°Ú´Ù.
ºñÁö´Ï½º ÀÎÅÍÆäÀ̽º ÆÐÅÏ(Business
Interface pattern) ºñÁö´Ï½º ÀÎÅÍÆäÀ̽º ÆÐÅÏ(Business
Interface pattern)À» ±¸ÇöÇÏ¿© ¼¼¼Ç ºó°ú ÀÎÅÍ·¢ÆÃÇÏ´Â ºñÁö´Ï½º ½ºÆÑÀÇ ÀÎÅÍÆäÀ̽º¸¦ Á¦°øÇÒ ¼ö
ÀÖ¾ú´Ù. Listing 1Àº ±× ÀÎÅÍÆäÀ̽ºÀÌ´Ù:
Listing 1. ¶óÀ̺귯¸® ºñÁö´Ï½º ÀÎÅÍÆäÀ̽º(Library
business interface)
package com.ibm.library;
import com.ibm.library.exceptions.NoSuchBookException;
import java.rmi.RemoteException;
import java.util.List;
public interface ILibrary {
public List getBooks() throws RemoteException;
public List getBooks(String category) throws RemoteException;
public Book getBook(String isbn)
throws NoSuchBookException, RemoteException;
public boolean checkout(Book book) throws RemoteException;
public boolean checkout(List books) throws RemoteException;
// And so on...
}
|
¶óÀ̺귯¸® ÀÎÅÍÆäÀ̽º(Library interface)´Â ¾î¶² EJB ±¸Á¶(semantics)µµ Æ÷ÇÔµÇÁö
¾Ê¾Ò´Ù´Â °ÍÀ» ÁÖ¸ñÇضó. ´ë½Å ¸ðµç ±¸Çö°ú EJB ¼¼ºÎ»çÇ×µéÀº ÀÎÅÍÆäÀ̽º¸¦ ±¸ÇöÇÑ ¼¼¼Ç ºó¿¡¼ ÇÚµéµÈ´Ù. ÀÌÁ¦,
¿£ÅÍÇÁ¶óÀÌÁî ¾ÖÇø®ÄÉÀ̼ÇÀÇ À¥ Ƽ¾î°¡ ¶óÀ̺귯¸® ÀÎÅÍÆäÀ̽º¿Í ¼¼¼Ç ºó¿¡ ¾×¼¼½ºÇÏ´Â ¹æ¹ýÀ» º¸ÀÚ:
Listing 2. ¶óÀ̺귯¸® ÀÎÅÍÆäÀ̽º »ç¿ëÇϱâ
LibraryHome libraryHome =
(LibraryHome)EJBHomeFactory.getInstance().
lookup("java:comp/env/ejb/LibraryHome",
LibraryHome.class);
ILibrary library = libraryHome.create();
|
Listing 2´Â ¿ì¸®¿¡°Ô Àͼ÷ÇÑ ¶Ç ´Ù¸¥ Ŭ·¡½º¸¦ »ç¿ëÇÑ´Ù.
EJBHomeFactory Ŭ·¡½º´Â Library ºó¿ë Ȩ
ÀÎÅÍÆäÀ̽º¸¦ ã¾Æ¼ ºñÁö´Ï½º¿Í ¾ÖÇø®ÄÉÀÌ¼Ç ·ÎÁ÷À» ºÐ¸®ÇÑ´Ù. Library ÀÎÅÍÆäÀ̽º
±¸ÇöÀº Ȩ ÀÎÅÍÆäÀ̽º¿¡¼ ¾ò¾îÁú ¼ö ÀÖ´Ù.
À§ ÄÚµå´Â ³ª»ÚÁö ¾Ê´Ù. ÀÌ°ÍÀº ºÐ¸í JNDI Ãʱâ ÄÜÅؽºÆ®¸¦ ·ÎµùÇÏ´Â °Íº¸´Ù ¹ßÀüÇÑ °ÍÀ¸·Î¼ Ȩ
ÀÎÅÍÆäÀ̽º¸¦ ¼öµ¿À¸·Î ¾ò°í ¿£ÅÍƼ ºóÀ» Á÷Á¢ ´Ù·é´Ù. ÇÏÁö¸¸ ¿©±â¿¡´Â ±Ùº»ÀûÀÎ ¾àÁ¡µµ ÀÖ´Ù. À¥ Ƽ¾î´Â ¿©ÀüÈ÷
EJB ÄÄÆ÷³ÍÆ®¿¡ ¹¿©ÀÖ°í Ưº°È÷ Library ¼¼¼ÇºóÀÌ ±×·¸´Ù. ¿£ÅÍƼ ºóÀ» ´Ü°èÀûÀ¸·Î
Á¤Áö½ÃÅ°°í Java Data Objects¸¦ »ç¿ëÇϰųª »õ·Î¿î EJB ½ºÆÑÀ» ¸¸µç´Ù¸é ¾ÖÇø®ÄÉÀÌ¼Ç Äڵ忡 ¾î¶²
ÀÏÀÌ ¹ß»ýÇÒ±î? ¾î¿ ¼ö ¾øÀÌ ±ò²ûÇÏ°Ô ºÐ¸®µÈ ½Ã½ºÅÛ ¾ÆÅ°ÅØÃÄ°¡ ÇÊ¿äÇÏ´Ù¸é? °°áÇÕ Äڵ带 ÀÛ¼ºÇÏ´Â °ÍÀÌ ´Ü±â
½ÇÇà¿¡¼ ´õ¿í ½±Áö¸¸ ±×·¸°Ô ÇÔÀ¸·Î¼ ¾ÖÇø®ÄÉÀ̼ÇÀÇ ¼ö¸íÀº °¨¼ÒÇÑ´Ù. ¹Ù·Î ÀÌ ºÎºÐ¿¡¼ Business
Delegate ÆÐÅÏÀÌ Àû¿ëµÉ ¼ö ÀÖ´Ù.
Áß°³ÀÚ: Business Delegate
ÆÐÅÏ Business Delegate ÆÐÅÏÀº Business Interface ÆÐÅÏ°ú´Â
´Ù¸£´Ù. Business Interface ÆÐÅÏÀº »ç¿ë °¡´ÉÇÑ ºñÁö´Ï½º ·ÎÁ÷À» Á¤ÀÇÇÏ´Â ¹Ý¸é, Business
Delegate´Â ±¸Çö ±â¼ú¿¡ ÀÇÁ¸ÇÏÁö ¾Ê°í ·ÎÁ÷¿¡ ¾×¼¼½º¸¦ Á¦°øÇÑ´Ù. ƯÈ÷ business delegate´Â
EJB ÄÁÅ×À̳ʷÎÀÇ ¿¬°á ¼¼ºÎ»çÇ×À» ÇÚµéÇÏ´Â ÇïÆÛ Å¬·¡½ºÀÌ´Ù, ¸ðµç ÇÊ¿äÇÑ ¸®¼Ò½º¸¦ ¾ò¾î ÇÊ¿äÇÒ ¶§ Á¦°øÇÑ´Ù.
Listing 3Àº ½ÃÀۺκп¡¼ Listing
1ÀÇ Library ÀÎÅÍÆäÀ̽º¸¦ »ç¿ëÇÑ´Ù. ÇÏÁö¸¸ »õ·Î¿î
LibraryDelegate Ŭ·¡½º¿Í ¸Þ¼Òµå°¡ µµÀԵǾú´Ù´Â °ÍÀ» ÁÖ¸ñÇ϶ó.
Listing 3. Library ºóÀ» À§ÇÑ business
delegate
package com.ibm.library;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.naming.NamingException;
public class LibraryDelegate implements ILibrary {
private ILibrary library;
public LibraryDelegate() {
init();
}
public void init() {
// Look up and obtain our session bean
try {
LibraryHome libraryHome =
(LibraryHome)EJBHomeFactory.getInstance().lookup(
"java:comp/env/ejb/LibraryHome", LibraryHome.class);
library = libraryHome.create();
} catch (NamingException e) {
throw new RuntimeException(e);
} catch (CreateException e) {
throw new RuntimeException(e);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
public List getBooks() throws ApplicationException {
try {
return library.getBooks();
} catch (RemoteException e) {
throw new ApplicationException(e);
}
}
public List getBooks(String category) throws ApplicationException {
try {
return library.getBooks(category);
} catch (RemoteException e) {
throw new ApplicationException(e);
}
}
public Book getBook(String isbn)
throws NoSuchBookException, ApplicationException {
try {
return library.getBook(isbn);
} catch (RemoteException e) {
throw new ApplicationException(e);
}
}
public boolean checkout(Book book) throws ApplicationException {
try {
return library.checkout(book);
} catch (RemoteException e) {
throw new ApplicationException(e);
}
}
public boolean checkout(List books) throws ApplicationException {
try {
return library.checkout(books);
} catch (RemoteException e) {
throw new ApplicationException(e);
}
}
// And so on...
public void destroy() {
// In this case, do nothing
}
}
|
LibraryDelegate Ŭ·¡½º¿¡¼, °¢°¢ÀÇ ¸Þ¼Òµå´Â ¼¼¼Ç ºóÀ¸·Î ÀÛµ¿¿äûÀ»
Àü´ÞÇÔÀ¸·Î¼ ÀÀ´äÇÑ´Ù. init() ¸Þ¼Òµå´Â ÃʱâÈ¿Í ¸®¼Ò½º ¸ðÀ½À» ÇÚµéÇÑ´Ù.
LibraryDelegate °¡ Àüü ¾ÖÇø®ÄÉÀ̼ÇÀÌ ÀÛµ¿ÇÏ´Â ¹æ½Ä¿¡ ¿µÇâÀ» ³¢Ä£´Ù.
¸í·á¼ºÀ» ÀÌ·èÇϱâ À§ÇÔÀÌ´Ù. Listing
2¿Í ¾Æ·¡ÀÇ ÄÚµåÀÇ Â÷ÀÌÁ¡À» »ý°¢Çغ¸ÀÚ:
ILibrary library = new LibraryDelegate();
|
LibraryDelegate À» µµÀÔÇÔÀ¸·Î¼ ¾ÖÇø®ÄÉÀ̼ÇÀÇ À¥ Ƽ¾î¿¡°Ô¼ ¸ðµç ±â¼ú
ÀÇÁ¸¼ºÀ» Á¦°ÅÇß´Ù. °á°ú°¡ ¸í·áÇÏ°í ¾ÈÁ¤µÈ ¾ÖÇø®ÄÉÀÌ¼Ç ÄÚµå´Â ¹°·Ð ¾ÖÇø®ÄÉÀÌ¼Ç º¯È°¡ ºÎµå·´°Ô ÀÌ·ç¾îÁ³´Ù.
¿¹¸¦ µé¾î, EJB ±â¼ú¿¡¼ ¼ø¼öÇÑ JDBC Ŭ·¡½º·Î ¸¶À̱׷¹À̼ÇÀ» ¿øÇÑ´Ù¸é »õ·Î¿î JDBC Ŭ·¡½º·Î
business delegate¸¦ ÀçÀÛ¼ºÇÒ ¼ö ÀÖ´Ù. À¥ Ƽ¾î´Â ±× Â÷ÀÌÁ¡À» ¸ð¸£°í ÀçÄÄÆÄÀÏ ÇÒ ÇÊ¿äµµ
¾ø´Ù.
Âü°íÀÚ·á
|