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

📄 attractionbo.java

📁 使用eclipse开发的web程序
💻 JAVA
字号:
package com.wrox.tourism.business;import com.wrox.tourism.entity.Attraction;import com.wrox.tourism.entity.Event;import com.wrox.tourism.entity.UserRole;import com.wrox.tourism.db.EventDAO;import com.wrox.tourism.db.AttractionDAO;import com.wrox.tourism.db.UserRoleDAO;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;import java.util.Iterator;public class AttractionBO {  private ConnectionPool pool;  public AttractionBO() {    pool = ConnectionPool.getInstance();  }  public void registerAttraction(Attraction attraction)    throws AttractionException {    validateAttraction(attraction);    Connection con = null;    try {      con = pool.getConnection();      AttractionDAO attractionDAO = new AttractionDAO(con);      attractionDAO.create(attraction);      UserRoleDAO userRoleDAO = new UserRoleDAO(con);      UserRole userRole = new UserRole();      userRole.setUserId(attraction.getUserId());      userRole.setRoleName(Role.ATTRACTION);      userRoleDAO.create(userRole);      con.commit();    } catch (Exception e) {      try {        if (con != null) {          con.rollback();          throw new AttractionException(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 updateAttraction(Attraction attraction)    throws AttractionException {    validateAttraction(attraction);    Connection con = null;    try {      con = pool.getConnection();      AttractionDAO attractionDAO = new AttractionDAO(con);      attractionDAO.update(attraction);      con.commit();    } catch (Exception e) {      try {        if (con != null) {          con.rollback();          throw new AttractionException(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 deregisterAttraction(String userId)    throws AttractionException {    Connection con = null;    try {      con = pool.getConnection();      AttractionDAO attractionDAO = new AttractionDAO(con);      attractionDAO.remove(userId);      UserRoleDAO userRoleDAO = new UserRoleDAO(con);      userRoleDAO.remove(userId,Role.ATTRACTION);      EventDAO eventDAO = new EventDAO(con);      Iterator it = eventDAO.findAll(userId).iterator();      while(it.hasNext()) {        Event event = (Event)it.next();        eventDAO.remove(event.getEventId());      }      con.commit();    } catch (Exception e) {      try {        if (con != null) {          con.rollback();          throw new AttractionException(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 validateAttraction(Attraction attraction)    throws AttractionException {    if (attraction.getUserId().trim().equals("")) {      throw new AttractionException("error.missing.userId");    }    if (attraction.getPassword().trim().equals("")) {      throw new AttractionException("error.missing.password");    }    if (attraction.getName().trim().equals("")) {      throw new AttractionException("error.missing.name");    }    if (attraction.getDescription().trim().equals("")) {      throw new AttractionException("error.missing.description");    }    if (attraction.getWebSite().trim().equals("")) {      throw new AttractionException("error.missing.webSite");    }    if (attraction.getAddress().trim().equals("")) {      throw new AttractionException("error.missing.address");    }  }}

⌨️ 快捷键说明

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