computer 版 (精华区)

发信人: random (arboreal), 信区: program
标  题: <<EJB Pattern>> Wrap entities with sessions
发信站: 听涛站 (2001年12月02日21:37:57 星期天), 站内信件

<<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()
            {
                ...
            }
        }

大家一定要多讨论啊,类似的思想,在其他地方也可以借用的。

--
                      

                           记得到 program 灌水啊!
※ 来源:·听涛站 tingtao.dhs.org·[FROM: 匿名天使的家] 
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:0.903毫秒