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

📄 facade.java

📁 航空订票系统,可实现航空订票的主要功能.
💻 JAVA
字号:
package facade;

import hibernate.HibernateSessionFactory;
import hibernate.Reservation;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;


public class Facade
{
	
	//获取所有航班信息
	public static List getAllFlightSchedule() throws FacadeException
	{
		try
		{
			Session s=HibernateSessionFactory.currentSession();

				//Configuration cf=new Configuration().configure();
				//SessionFactory sf=cf.buildSessionFactory();
				//Session s=sf.openSession();
				
			Transaction t=s.beginTransaction();
			
			//Query q=s.createQuery("from FlightSchedule as fsl join Fare as fare where fsl.route_code=fare.route_code");
			Query q=s.createQuery("from FlightSchedule as fsl");
			List l=q.list();
			if(l != null && l.size()>0)
			{
					t.commit();
					return l;
			}
			else
			{
				throw new FacadeException("空航班信息错误!");
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new FacadeException("获取航班信息错误:" + e.getMessage());
		}
		finally
		{
			//HibernateSessionFactory.closeSession();
		}
	}
	
//	根据目的地获取航班信息
	public static List getFlightScheduleByDestination(String dest) throws FacadeException
	{
		try
		{
			Session s=HibernateSessionFactory.currentSession();
			Transaction t=s.beginTransaction();
			Query q=s.createQuery("from FlightSchedule as fsl where fsl.fare.destination=:dest");
			q.setString("dest",dest);
			
			List l=q.list();
			if(l != null && l.size()>0)
			{
					t.commit();
					return l;
			}
			else
			{
				throw new FacadeException("空航班信息错误!");
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new FacadeException("获取航班信息错误:" + e.getMessage());
		}
	}
	
//	根据航班编号获取航班信息
	public static List getFlightScheduleByFlightno(String flightno) throws FacadeException
	{
		try
		{
			Session s=HibernateSessionFactory.currentSession();
			Transaction t=s.beginTransaction();
			Query q=s.createQuery("from FlightSchedule as fsl where flightno=:flightno");
			q.setString("flightno",flightno);
			
			List l=q.list();
			if(l != null && l.size()>0)
			{
					t.commit();
					return l;
			}
			else
			{
				throw new FacadeException("空航班信息错误!");
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new FacadeException("获取航班信息错误:" + e.getMessage());
		}
	}
	
//	获取所有票价信息
	public static List getAllFare() throws FacadeException
	{
		try
		{
			Session s=HibernateSessionFactory.currentSession();
			Transaction t=s.beginTransaction();
			Query q=s.createQuery("from Fare");
			List l=q.list();
			if(l!=null && l.size()>0)
			{
				t.commit();
				return l;
			}
			else
			{
				throw new FacadeException("获取票价信息错误!");
			}
		
		}
		catch(Exception e)
		{
			e.getStackTrace();
			throw new FacadeException("获取票价信息错误:" + e.getMessage());
		}
	}
	
//	获取所有订票信息
	public static List getAllReservation() throws FacadeException
	{
		try
		{
			Session s=HibernateSessionFactory.currentSession();
			Transaction t=s.beginTransaction();
			Query q=s.createQuery("from Reservation");
			List l=q.list();
			if(l!=null && l.size()>0)
			{
				t.commit();
				return l;
			}
			else
			{
				throw new FacadeException("获取订票信息错误!");
			}
		
		}
		catch(Exception e)
		{
			e.getStackTrace();
			throw new FacadeException("获取订票信息错误:" + e.getMessage());
		}
	}
	
//	增加一条订票记录
	public static void AddReservation(Reservation r) throws FacadeException
	{
		try
		{
			Session s=HibernateSessionFactory.currentSession();
			Transaction t=s.beginTransaction();
			s.save(r);
			t.commit();		
		}
		catch(Exception e)
		{
			e.getStackTrace();
			throw new FacadeException("增加订票记录错误:" + e.getMessage());
		}
	}
	
//	更新一条订票记录
	public static void UpdateReservation(Reservation r) throws FacadeException
	{
		try
		{
			Session s=HibernateSessionFactory.currentSession();
			Transaction t=s.beginTransaction();
			s.update(r);
			t.commit();		
		}
		catch(Exception e)
		{
			e.getStackTrace();
			throw new FacadeException("更新订票记录错误:" + e.getMessage());
		}
	}
}

⌨️ 快捷键说明

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