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

📄 transitinfodaoimpl.java

📁 一个关于物流的管理系统
💻 JAVA
字号:
package com.shunshi.ssh.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.shunshi.ssh.entity.Agent;
import com.shunshi.ssh.entity.StorageInfo;
import com.shunshi.ssh.entity.Transitinfo;
import com.shunshi.ssh.exception.AgentDaoException;
import com.shunshi.ssh.exception.TransitinfoDaoException;

public class TransitinfoDaoImpl extends HibernateDaoSupport implements
		 ITransitinfoDao{

	public void add(Transitinfo Transitinfo) throws TransitinfoDaoException {
		try{
			getHibernateTemplate().save(Transitinfo);
		}catch(RuntimeException e){
			throw new TransitinfoDaoException(e.getMessage());
		}

	}

	public void delete(int id) throws TransitinfoDaoException {
		try{
			Transitinfo t=this.findById(id);
			if(t!=null){
				getHibernateTemplate().delete(t);
			}
			
		}catch(RuntimeException e){
			throw new TransitinfoDaoException(e.getMessage());
		}
		
	}

	public List findAll() throws TransitinfoDaoException {
		
		return null;
	}

	public Transitinfo findById(int id) throws TransitinfoDaoException {
		try{
			return (Transitinfo)getHibernateTemplate().find("from Transitinfo t where t.id=?", id).get(0);
		
		}catch(RuntimeException e){
			throw new TransitinfoDaoException(e.getMessage());
		}
	}

	public List findByUserId(int uid) throws TransitinfoDaoException {
		try{
			return getHibernateTemplate().find("from Transitinfo t where t.userId=?", uid);
		}catch(RuntimeException e){
			throw new TransitinfoDaoException(e.getMessage());
		}
	}

	public void updateState(int id, int state) throws TransitinfoDaoException {
		try{
			Transitinfo t=this.findById(id);
			if(t!=null){
				t.setState(state);
			}
			getHibernateTemplate().saveOrUpdate(t);
		}catch(RuntimeException e){
			throw new TransitinfoDaoException(e.getMessage());
		}
		
	}

	public void updateTransitinfo(Transitinfo t) throws TransitinfoDaoException {
		try{
			getHibernateTemplate().saveOrUpdate(t);
		}catch(RuntimeException e){
			throw new TransitinfoDaoException(e.getMessage());
		}
		
	}

	public List findByState(final int state, final  int start, final int max)
			throws TransitinfoDaoException {

		try{
		List transitinfos=(List) getHibernateTemplate().execute(new HibernateCallback(){

			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query q=session.createQuery("from Transitinfo t where t.state=:state");
					q.setInteger("state", state);
					q.setFirstResult(start);
					q.setMaxResults(max);
					List<Transitinfo> l=q.list();
					return l;
					
			}
			
			
		});
		return transitinfos;
		}catch(RuntimeException e){
			throw new TransitinfoDaoException(e.getMessage());
		}
	
	}

	public Long getTotalRowsByState(int state) throws TransitinfoDaoException {
		try{
			return (Long)(getHibernateTemplate().find("select count(*) from Transitinfo t where t.state=?",state)).get(0);
		}catch(RuntimeException e){
			throw new TransitinfoDaoException(e.getMessage());
		}
	}

	public Transitinfo findByMaxId() throws TransitinfoDaoException {
		String hql="select Max(id) from Transitinfo transitinfo";
		Integer id=(Integer)getHibernateTemplate().find(hql).get(0);
		Transitinfo transitinfo=null;
		try {
			transitinfo=findById(id.intValue());
		} catch (TransitinfoDaoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return transitinfo;
	}
	


}

⌨️ 快捷键说明

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