BBS水木清华站∶精华区

发信人: gty (红烧鸡翅), 信区: Java        
标  题: <<EJB Pattern>> Wrap entities with sessions 
发信站: BBS 水木清华站 (Wed Oct 25 19:27:19 2000) 
 
<<EJB Pattern>>  Wrap entities with sessions 
 
Motivation 
        -- 调用EJB,特别是Entity Bean,代价非常高。(见 
           <<EJB Pattern>> Value Object) 
           
        -- Value Object解决了对单个Entity Bean的多次访问问题。 
         
        -- 如果用户的一次查询,返回多个Entity Bean,远程访问 
           次数还是很多,性能仍然较低。 
         
        ? 你希望一次远程访问,就可以返回需要的所有结果。 
 
Solution 
        -- 利用Session Bean。在中间层,得到Entity Bean集合后, 
           将它们转化为Value Object集合,送回表现层。 
 
Advantage 
        -- 减少了网络传输 
        -- 减少了事务处理和同步处理 
 
Example 
        <<Session Bean>> 
        Public class ProductManager implements javax.ejb.SessionBean { 
             
            ... 
             
            public Collection getAllProduct() 
            { 
                Vector productValues = new Vector();; 
                ... 
                Collection products = productHome.findAllProduct(); 
                 
                Product product; 
                Iterator itProduct = products.iterate(); 
                while( itProduct.hasNext()) 
                { 
                    product = (Product)itProduct.next(); 
                    productValues.add(product.getDetail()); 
                } 
                 
                return productValues; 
            } 
        } 
         
        <<Entity Bean>> 
        public class ProductEJB implements javax.ejb.EntityBean { 
            public String name; 
            public double price; 
             
            ... 
             
            public ProductValue getDetail()  
            { 
                return new ProductValue(this.name,this.price); 
            } 
             
            public Collection ejbFindAllProduct() 
            { 
                ... 
            } 
        } 
         
大家一定要多讨论啊,类似的思想,在其他地方也可以借用的。 
 
-- 
 
※ 来源:·BBS 水木清华站 smth.org·[FROM: 211.100.7.50] 

BBS水木清华站∶精华区