⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 driverdao.java

📁 车辆管理系统是OA系统中一部分。 单独使用。 提高车辆的有效管理
💻 JAVA
字号:
package org.langsin.car.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.langsin.car.dao.IDriverDAO;
import org.langsin.car.vo.Driver;
import org.langsin.car.vo.User;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * Data access object (DAO) for domain model class Driver.
 * @see org.langsin.car.vo.Driver
 * @author MyEclipse - Hibernate Tools
 */
public class DriverDAO extends HibernateDaoSupport implements IDriverDAO{

    private static final Log log = LogFactory.getLog(DriverDAO.class);

	//property constants
	public static final String DRIVERTYPE = "drivertype";
	public static final String MEMO = "memo";

	protected void initDao() {
		//do nothing
	}
    
    public void save(Driver driver) {
        log.debug("saving Driver instance");
        try {
            getHibernateTemplate().save(driver);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(Driver persistentInstance) {
        log.debug("deleting Driver instance");
        try {
            getHibernateTemplate().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public Driver findById( java.lang.Integer id) {
        log.debug("getting Driver instance with id: " + id);
        try {
            Driver instance = (Driver) getHibernateTemplate()
                    .get("org.langsin.car.vo.Driver", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(Driver instance) {
        log.debug("finding Driver instance by example");
        try {
            List results = getHibernateTemplate().findByExample(instance);
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding Driver instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from Driver as model where model." 
         						+ propertyName + "= ?";
		 return getHibernateTemplate().find(queryString, value);
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByDrivertype(Object drivertype) {
		return findByProperty(DRIVERTYPE, drivertype);
	}
	
	public List findByMemo(Object memo) {
		return findByProperty(MEMO, memo);
	}
	
    public Driver merge(Driver detachedInstance) {
        log.debug("merging Driver instance");
        try {
            Driver result = (Driver) getHibernateTemplate()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Driver instance) {
        log.debug("attaching dirty Driver instance");
        try {
            getHibernateTemplate().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(Driver instance) {
        log.debug("attaching clean Driver instance");
        try {
            getHibernateTemplate().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

	public static DriverDAO getFromApplicationContext(ApplicationContext ctx) {
    	return (DriverDAO) ctx.getBean("DriverDAO");
	}

	public List findAllDriver() {
		log.info("查出所有的驾驶员相关信息");
	    Session session=this.getHibernateTemplate().getSessionFactory().openSession();
	    Query query=session.createQuery("FROM Driver d");
	     List drivers=query.list();
		return drivers;
	}

	public void deleteId(Integer driverId) {
				log.info("UserDAO中删除的方法被执行");
			Driver instance = (Driver) getHibernateTemplate().get(
					"org.langsin.car.vo.Driver", driverId);
			getHibernateTemplate().delete(instance);
			
		
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -