我新闻发布系统和实验室设备管理系统截图
1.新闻发布系统截图---JSF+EJB3.0
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*); } } 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*); } } 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配置文件
<!-- ****************** DataSource ********************* -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="jdbcUrl">
<value>jdbc:mysql://localhost:3306/devicemanage</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value>123456</value>
</property>
<property name="initialPoolSize"><value>10</value></property>
<property name="minPoolSize"><value>5</value></property>
<property name="maxPoolSize"><value>30</value></property>
<property name="acquireIncrement"><value>5</value></property>
<property name="maxIdleTime"><value>10</value></property>
<property name="maxStatements"><value>0</value></property>
</bean>
<!-- ****************** SessionFactory ********************* -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">
true
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/dgut/lab/model/entity/Voucher.hbm.xml</value>
<value>org/dgut/lab/model/entity/Device.hbm.xml</value>
<value>org/dgut/lab/model/entity/User.hbm.xml</value>
<value>org/dgut/lab/model/entity/VoucherDevice.hbm.xml</value>
<value>org/dgut/lab/model/entity/ManageLog.hbm.xml</value>
<value>org/dgut/lab/model/entity/Country.hbm.xml</value>
<value>org/dgut/lab/model/entity/PowerList.hbm.xml</value>
</list>
</property>
</bean>
<!-- ****************** Transaction ********************* -->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true" />
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="fooServiceOperation"
expression="execution(* org.dgut.lab.model.service.*Service.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="fooServiceOperation" />
</aop:config>
<!-- ****************** Service Locator ********************* -->
<bean id="serviceLocator"
class="org.dgut.lab.model.servicelocator.ServiceLocatorImpl">
<property name="userService">
<ref bean="userService" />
</property>
<property name="loanService">
<ref bean="loanService" />
</property>
<property name="deviceService">
<ref bean="deviceService" />
</property>
</bean>
<!-- ****************** DAO ********************* -->
<bean id="entityManagerDAO"
class="org.dgut.lab.model.dao.impl.EntityManagerDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- ****************** Service ********************* -->
<bean id="deviceService"
class="org.dgut.lab.model.service.impl.DeviceServiceImpl">
<property name="entityManagerDAO">
<ref bean="entityManagerDAO" />
</property>
</bean>
<bean id="loanService"
class="org.dgut.lab.model.service.impl.LoanServiceImpl">
<property name="entityManagerDAO">
<ref bean="entityManagerDAO" />
</property>
</bean>
<bean id="userService"
class="org.dgut.lab.model.service.impl.UserServiceImpl">
<property name="entityManagerDAO">
<ref bean="entityManagerDAO" />
</property>
</bean>
3.数据库查询分析处理器---RMI+JDBC+Swing