完美的组合tomahawk+spring2.0+hibernate3.2

相对于struts1.2 mvc,spring mvc,struts2.0 mvc!我已经决定了用jsf.
前一段时间由于遇到性能问题,比如数据库的数据量很大,这样的情况下.怎么办呢!有两处方案可以选!
1.EJB3.0.
如果用EJB3.0解决,但是已经试验过,EJB3.0跟tomahawk不兼容,tomahawk里面有很多现成的jsf组件...文件上传,日期选框,html文本编辑器,树形菜单...
2.Spring+hibernate.

如果用spring+hibernate,跟spring+Hiberante集成较好,性能怎么解决呢,很简单,使用缓冲池就行了,dbcp或者c3p0,我目前是选择c3p0,效果非常好.
3.近来也学习了Seam,跟jsf的无缝集成,还更好地支持ajax,jsf的backBean已经放在业务类里了,验证已经放到entity Bean里,这样少写了很多类,因此,系统运行时,构建的对象是最少的,效率当然很高.不过,深入一些学习,发现存在一些难以解决的问题,
1.对国际化的支持,因为它的验证放到entity bean里了,要支持国际化,目前我还没有想到有效的解决办法.
2.对业务层的测试,因为Seam的业务层已经跟jsf混在一起来减少很多类了,测试业务层就离不开了Web容器,测试不如spring+hibernate方便.
3.jsp代码要比tomahawk写得多,tomahawk(myface)的界面用了Tiles之后,代码写得是最少了,facelets写得代码还要比它多.

开发周期和代码的移植性:
经过一段时间的技术选择和测试,我已经得到结论:
开发周期来说,spring+hiberante+tomahawk花的时间是最少的!
代码可移植性,也是它最好的!

看一下我的代码片段:
package org.dgut.lab.view.controller;

import java.util.ArrayList;
import java.util.List;

import org.dgut.lab.model.entity.Country;
import org.dgut.lab.view.builder.CountryBuilder;
import org.dgut.lab.view.util.FacesUtils;
/**
*
* @authors林春宇. 2008年6月毕业于东莞理工学院软件工程专业 QQ:445104284 电子邮箱:[email protected]
*              Blog: http://oak2008.iteye.com/
*/
public class CountryListBean extends BaseController {
   
    /** Creates a new instance of CountryController */
    public CountryListBean() {
        this.countryBeans = new ArrayList();
    }
   
    private int command=0;
   
    private int pageNo=1;
   
    private long itemCount;
   
    private long totalPage;
   
    private int batchSize=10;
   
    private String name;
   
    private List countrys;
   
    private List countryBeans;
   
   
    public void init() {
        List countrys = this.serviceLocator.getCountryService().getCountryAndPage(batchSize,0);
        setItemCount(serviceLocator.getCountryService().getCountryAllCount());
        for (int i = 0; i < countrys.size(); i++) {
            Country country = (Country) countrys.get(i);
           
            CountryBean countryBean = CountryBuilder.createCountryBean(country);
           
            countryBean.setServiceLocator(this.serviceLocator);
           
            this.getCountryBeans().add(countryBean);
           
        }
       
       
    }
   
    public String findCountryByName() {
        command=1;
        countrys = serviceLocator.getCountryService().getCountryByNameAndPage(name,batchSize,0);
        setItemCount(serviceLocator.getCountryService().getCountryCountByName(name));
        pageNo=1;
        countryBeans.clear();
        for (int i = 0; i < countrys.size(); i++) {
            Country country = (Country) countrys.get(i);
           
            CountryBean countryBean = CountryBuilder.createCountryBean(country);
           
            countryBean.setServiceLocator(this.serviceLocator);
           
            countryBeans.add(countryBean);
        }
       
        return "country_list";
       
    }
   
    public String getAllCountryAndPage() {
        // FacesUtils.resetManagedBean("countryListBean");
        command=0;
        countryBeans.clear();
        List countrys = this.serviceLocator.getCountryService().getCountryAndPage(batchSize,0);
        setItemCount(serviceLocator.getCountryService().getCountryAllCount());
        pageNo=1;
        for (int i = 0; i < countrys.size(); i++) {
            Country country = (Country) countrys.get(i);
           
            CountryBean countryBean = CountryBuilder.createCountryBean(country);
           
            countryBean.setServiceLocator(this.serviceLocator);
           
            countryBeans.add(countryBean);
        }
       
       
        return "country_list";
       
    }
   
    public String toPage() {
        int p = getPageNo();
        this.pageNo=p;
       
        if(command==0){
            countryBeans = serviceLocator.getCountryService().getCountryAndPage(batchSize,(p-1)*batchSize);
        } else{
            countryBeans = serviceLocator.getCountryService().getCountryByNameAndPage(name,batchSize,(p-1)*batchSize);
        }
        return "country_list";
    }
   
    public String next() {
       
        int p = getPageNo() + 1;
        this.pageNo=p;
        if(command==0){
            countryBeans = serviceLocator.getCountryService().getCountryAndPage(batchSize,(p-1)*batchSize);
        } else{
            countryBeans = serviceLocator.getCountryService().getCountryByNameAndPage(name,batchSize,(p-1)*batchSize);
        }
        return "country_list";
    }
   
    public String prev() {
        int p = getPageNo() - 1;
        if(p<=0)
            this.pageNo=1;
        else{
            this.pageNo=p;
        }
        if(command==0){
            countryBeans = serviceLocator.getCountryService().getCountryAndPage(batchSize,(p-1)*batchSize);
        }else{
            countryBeans = serviceLocator.getCountryService().getCountryByNameAndPage(name,batchSize,(p-1)*batchSize);
        }
       
        return "country_list";
    }
   
    public String getName() {
        return name;
    }
   
    public void setName(String name) {
        this.name = name;
    }
   
    public long getItemCount() {
        return this.itemCount;
    }
   
    public int getPageNo() {
        return pageNo;
    }
   
    public long getTotalPage() {
        this.totalPage = getItemCount() % 20 == 0 ? getItemCount() / 10
                : getItemCount() / 10 + 1;
        log.info("***ResourceBundle"+this.getMessageString("uT",new String("code")));
        return this.totalPage;
    }
   
    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }
   
    public List getCountryBeans() {
        return countryBeans;
    }
   
    public void setItemCount(long itemCount) {
        this.itemCount = itemCount;
    }
   
}

我的这个项目,到现在已经完全进入了编码阶段,理论上,很快会完成的.

由于时间的仓促,这篇文章就写到这里,不足之处,还望多多交流.
我的qq:445104284

你可能感兴趣的:(spring,Hibernate,mvc,JSF,seam)