实例介绍
【实例简介】
随着对外开发政策的不断扩展,国与国之间的商品贸易越来越普遍,对于港口集装箱物流商品的处理也变得越来越紧张和复杂,港口集装箱物流货物存运设备应急调度管理系统是集商品信息,车辆调度,仓库调度,人员调度为一体的综合应急调度管理系统,通过合理的调度安排,使原本复杂的调度工作变得越来越简单,高效,智能,节能。
【实例截图】
【核心代码】
package common.exception;
public class MotorCarException extends Exception {
public MotorCarException() {
super();
// TODO Auto-generated constructor stub
}
public MotorCarException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
public MotorCarException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
public MotorCarException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
}
package common.exception;
public class UserException extends Exception {
public UserException() {
super();
// TODO Auto-generated constructor stub
}
public UserException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
public UserException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
public UserException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
}
package common.transaction;
import org.hibernate.Session;
import common.util.HibernateSessionFactory;
public class HibernateTransaction implements Transaction {
private org.hibernate.Transaction transaction;
public void beginTransaction() {
Session session = HibernateSessionFactory.getSession();
transaction = session.beginTransaction();
}
public void commit() {
if (transaction != null)
transaction.commit();
}
public void rollback() {
if (transaction != null)
transaction.rollback();
}
}
package common.transaction;
public interface Transaction {
void beginTransaction();
void commit();
void rollback();
}
package common.util;
import service.IMotorCarService;
import service.IUserService;
import service.impl.MotorCarServiceImpl;
import service.impl.UserServiceImpl;
import dao.IMotorCarDao;
import dao.IUserDao;
import dao.impl.MotorCarDaoImpl;
import dao.impl.UserDaoImpl;
public class BeanFactory {
private static IUserDao userDao;
private static IUserService userService;
private static IMotorCarDao motorcarDao;
private static IMotorCarService motorcarService;
public static Object getBean(String beanName) {
if (beanName.equals("userDao")) {
userDao = getUserDao();
return userDao;
}
if (beanName.equals("userService")) {
userService = getUserService();
return userService;
}
if (beanName.equals("motorcarDao")) {
motorcarDao = getMotorCarDao();
return motorcarDao;
}
if (beanName.equals("motorcarService")) {
motorcarService = getMotorCarService();
return motorcarService;
}
return null;
}
synchronized private static IUserDao getUserDao() {
if (userDao == null)
userDao = new UserDaoImpl();
return userDao;
}
synchronized private static IUserService getUserService() {
if (userService == null)
userService = new UserServiceImpl();
return userService;
}
synchronized private static IMotorCarDao getMotorCarDao() {
if (motorcarDao == null)
motorcarDao = new MotorCarDaoImpl();
return motorcarDao;
}
synchronized private static IMotorCarService getMotorCarService() {
if (motorcarService == null)
motorcarService = new MotorCarServiceImpl();
return motorcarService;
}
}
package common.util;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
* pattern, see {@link http://hibernate.org/42.html }.
*/
public class HibernateSessionFactory {
/**
* Location of hibernate.cfg.xml file.
* Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file.
* The default classpath location of the hibernate config file is
* in the default package. Use #setConfigFile() to update
* the location of the configuration file for the current session.
*/
private static String CONFIG_FILE_LOCATION = "/common/util/hibernate.cfg.xml";
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}
/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}
return session;
}
/**
* Rebuild hibernate session factory
*
*/
public static void rebuildSessionFactory() {
try {
System.out.println(" ");
configuration.configure(configFile);
System.out.println("*****************");
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论