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

📄 eventbo.java

📁 使用eclipse开发的web程序
💻 JAVA
字号:
package com.wrox.tourism.business;import com.wrox.tourism.entity.Event;import com.wrox.tourism.db.EventDAO;import com.wrox.tourism.db.AttractionDAO;import com.wrox.tourism.db.CreateException;import com.wrox.tourism.db.FinderException;import com.wrox.tourism.db.util.ConnectionPool;import java.sql.SQLException;import java.sql.Connection;public class EventBO {  private ConnectionPool pool;  public EventBO() {    pool = ConnectionPool.getInstance();  }  public void createEvent(Event event) throws EventException {    validateEvent(event);    Connection con = null;    try {      con = pool.getConnection();      AttractionDAO attractionDAO = new AttractionDAO(con);      attractionDAO.findByPrimaryKey(event.getUserId());      EventDAO eventDAO = new EventDAO(con);      eventDAO.create(event);      con.commit();    } catch (Exception e) {      try {        if (con != null) {          con.rollback();          throw new EventException(e.getMessage());        }      } catch (SQLException sqle) {        e.printStackTrace();        throw new RuntimeException("error.unexpected");      }    } finally {      try {        if (con != null) {          con.close();        }      } catch (SQLException sqle) {        sqle.printStackTrace();        throw new RuntimeException("error.unexpected");      }    }  }  public void updateEvent(Event event) throws EventException {    validateEvent(event);    Connection con = null;    try {      con = pool.getConnection();      EventDAO eventDAO = new EventDAO(con);      eventDAO.update(event);      con.commit();    } catch (Exception e) {      try {        if (con != null) {          con.rollback();          throw new EventException(e.getMessage());        }      } catch (SQLException sqle) {        e.printStackTrace();        throw new RuntimeException("error.unexpected");      }    } finally {      try {        if (con != null) {          con.close();        }      } catch (SQLException sqle) {        sqle.printStackTrace();        throw new RuntimeException("error.unexpected");      }    }  }  public void removeEvent(int eventId)    throws EventException {    Connection con = null;    try {      con = pool.getConnection();      EventDAO eventDAO = new EventDAO(con);      eventDAO.remove(eventId);      con.commit();    } catch (Exception e) {      try {        if (con != null) {          con.rollback();          throw new EventException(e.getMessage());        }      } catch (SQLException sqle) {        e.printStackTrace();        throw new RuntimeException("error.unexpected");      }    } finally {      try {        if (con != null) {          con.close();        }      } catch (SQLException sqle) {        sqle.printStackTrace();        throw new RuntimeException("error.unexpected");      }    }  }  private void validateEvent(Event event) throws EventException {    if (event.getName().trim().equals("")) {      throw new EventException("error.missing.name");    }    if (event.getDescription().trim().equals("")) {      throw new EventException("error.missing.description");    }    if (event.getTicketPrice() < 0) {      throw new EventException("error.missing.ticketPrice");    }  }}

⌨️ 快捷键说明

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