2.实验室设备管理系统---JSF(Tomahawk)+Spring2.0+Hibernate3.2
我设计的部分超类:
/*
* EntityManagerDAOImpl.java
*
* Created on 2007年10月6日, 下午2:29
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package org.dgut.lab.model.dao.impl;
import java.sql.SQLException;
import java.util.List;
import org.dgut.lab.model.dao.EntityManagerDAO;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
/**
*
* @author LinChunyu
*/
public class EntityManagerDAOImpl implements EntityManagerDAO{
private HibernateTemplate hibernateTemplate;
/** Creates a new instance of EntityManagerDAOImpl */
public EntityManagerDAOImpl() {
}
public void delete(Object persistentInstance) {
hibernateTemplate.delete(persistentInstance);
}
public Object findById(Class cl,int id) {
return hibernateTemplate.get(cl, id);
}
public Object merge(Object detachedInstance) {
return hibernateTemplate.merge(detachedInstance);
}
public void persist(Object transientInstance) {
hibernateTemplate.persist(transientInstance);
}
public List execute(final String qry,final Object[] p) {
List list=(List)hibernateTemplate.execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
List list = null;
Query q = session.createQuery(qry);
if(p!=null){
for (int i = 0; i < p.length; i++) {
q.setParameter(i, p[i]);
}
}
return list = q.list();
}
});
return list;
}
public List execute(final String qry,final Object[] p,final int batchSize,final int firstItem) {
List list=(List)hibernateTemplate.execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
List list = null;
Query q = session.createQuery(qry);
if(p!=null){
for (int i = 0; i < p.length; i++) {
q.setParameter(i, p[i]);
}
}
q.setMaxResults(batchSize);
q.setFirstResult(firstItem);
return list = q.list();
}
});
return list;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
}
}
package org.dgut.lab.view.controller;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.dgut.lab.model.servicelocator.ServiceLocator;
public class BaseController {
protected ServiceLocator serviceLocator;
protected final Logger log = Logger.getLogger(this.getClass().getName());
private int command=0;
protected int pageNo=1;
protected long itemCount;
protected int totalPage;
protected int batchSize=4;
public BaseController() {
}
public void init() {
}
public void setServiceLocator(ServiceLocator newServiceLocator) {
this.serviceLocator = newServiceLocator;
init();
}
public static void addErrorMessage(String msg1) {
String msg=getMessageString(msg1);
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR,
msg, msg);
FacesContext fc = FacesContext.getCurrentInstance();
fc.addMessage(null, facesMsg);
}
public static void addSuccessMessage(String msg1) {
String msg=getMessageString(msg1);
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO,
msg, msg);
FacesContext fc = FacesContext.getCurrentInstance();
fc.addMessage("successInfo", facesMsg);
}
public static String getMessageString(String name) {
String str = "";
FacesContext facesContext = FacesContext.getCurrentInstance();
String bundleName = facesContext.getApplication().getMessageBundle();
if (bundleName != null) {
Locale locale = facesContext.getViewRoot().getLocale();
/*ResourceBundle bundle = ResourceBundle.getBundle(bundleName,
locale, getCurrentClassLoader(params));*/
ResourceBundle bundle = ResourceBundle.getBundle(bundleName,
locale);
/*ResourceBundle bundle = ResourceBundle.getBundle(bundleName,
locale, getCurrentClassLoader(params));*/
str = bundle.getString(name);
}
return str;
}
private static ClassLoader getCurrentClassLoader(Object params) {
return params.getClass().getClassLoader();
}
public long getItemCount() {
return this.itemCount;
}
public int getPageNo() {
return pageNo;
}
public int getTotalPage() {
long totalPage1 = getItemCount() % 20 == 0 ? getItemCount() /batchSize
: getItemCount() / batchSize + 1;
totalPage=Integer.parseInt(String.valueOf(totalPage1));
return this.totalPage;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public void setItemCount(long itemCount) {
this.itemCount = itemCount;
}
public int getCommand() {
return command;
}
public void setCommand(int command) {
this.command = command;
}
}
Spring配置文件
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
org.hibernate.dialect.MySQLDialect
true
3.数据库查询分析处理器---RMI+JDBC+Swing