EJB Entity Bean

package hrm.ejb.data;
import javax.sql.*;
import java.sql.*;
import java.util.*;
import javax.naming.*;
import java.io.*;
import hrm.common.dto.*;
/**
<pre>
   Program Name : Hrm_cp_house_listBean
   Description  : Hrm_cp_house Table의 자료를 Multi로 관리하는 Entity Bean 이다.
   Create Date  : 2011.10.11
   History      : 2011.10.11 Initial created by
</pre>
@version  1.0.0.1
@author
*/
public class Hrm_cp_house_listBean implements Serializable{
   // 시스템으로 부터 얻어 온 데이터 소스
   private javax.sql.DataSource ds;
   // 데이터 소스로 부터 얻어 온 커넥션 객체
   private java.sql.Connection conn;
   // Statement
   private CallableStatement stmt = null;
   // ResultSet
   private ResultSet rset = null;
   // Execute SQL
   private String sqlString = "";
   private String dong;     //동
   private String ho;     //호
   private String room;     //룸
   private String note;     //비고

   private static final String insertStatement =
      " insert into hrm_cp_house ( "
      +"     dong, ho, room, note, mod_emp_id"
      +"   , mod_date"
      +"   ) "
      +" values( ?, ?, ?, ?, ?, sysdate) ";
   private static final String updateStatement =
      " update hrm_cp_house "
      +"   set note = ? "
      +"     , mod_emp_id = ? "
      +"     , mod_date = sysdate "
      +" where dong = ? "
      +"   and ho = ? "
      +"   and room = ? " ;
   private static final String deleteStatement =
      " delete from hrm_cp_house where dong = ? "
      +"   and ho = ? "
      +"   and room = ? " ;
   private static final String findByPKStatement =
      " select * from hrm_cp_house where dong = ? "
      +"   and ho = ? "
      +"   and room = ? " ;
   public Hrm_cp_house_listBean() throws Exception{
   }
   /**
    * Create Date : 2011.10.11
    * Description : closeConnection은 현재 연결되어 있는 Connection 을 닫는다
    * @param      : 없음
    * @return     : 없음
    * @exception  : 없음
    * History     : 2011.10.11 최초 작성
    * */
   private void closeConnection(){
      try{
         if(stmt != null){
            stmt.close();
         }
         if(conn != null){
            conn.close();
         }
      }catch(Exception e){
         e.printStackTrace();
      }
   }
   /**
    * Create Date : 2011.10.11
    * Description : excuteUpdate()는 SQL을 수행하고, 결과 값(실행 수)을 리턴한다.
    * @param  : 없음
    * @return  : 없음
    * @exception : SQLException, SQL의 수행이 올바르게 되지 않을 경우 SQLException을 발생한다
    * History  : 2011.10.11 최초 작성
    * */
   private  int executeUpdate()throws SQLException{
      try{
         return stmt.executeUpdate();
      }catch(SQLException se){
         throw new SQLException(se.getMessage());
      }
   }
   /**
    * Create Date : 2011.10.11
    * Description : excute()는 현재 SQL을  수행하고, ResultSet을 리턴한다.
    * @param  : 없음
    * @return  : 없음
    * @exception : SQLException, SQL의 수행이 올바르게 되지 않을 경우 SQLException을 발생한다
    * History  : 2011.10.11최초 작성
    * */
   private  ResultSet execute()throws SQLException{
      try{
         rset = stmt.executeQuery();
         return rset;
      }catch(SQLException se){
         throw new SQLException(se.getMessage());
      }
   }
   public void modifyHrm_cp_house_list(Hrm_cp_houseDTO[] arrDto) throws Exception {
      /* 
      Hashtable parms = new Hashtable();
      parms.put(Context.INITIAL_CONTEXT_FACTORY,
      "com.ibm.websphere.naming.WsnInitialContextFactory");
      InitialContext ctx = new InitialContext(parms);
      */
      InitialContext ctx = new InitialContext();
      ds = (DataSource)ctx.lookup("hrmsDataSource");
      conn = ds.getConnection();
      try{
         for (int i=0; i < arrDto.length; i++) {
            if (arrDto[i].getFlag().equals("I")) {
               newHrm_cp_house(arrDto[i]);
            } else if (arrDto[i].getFlag().equals("U")) {
               setHrm_cp_house(arrDto[i]);
            } else if (arrDto[i].getFlag().equals("D")) {
               deleteHrm_cp_house(arrDto[i]);
            }
         }
      } catch (Exception e){
         e.printStackTrace();
         throw new Exception(e.toString());
      } finally {
         if(conn != null){
            closeConnection();
         }
      }
   }
   public void newHrm_cp_house(Hrm_cp_houseDTO dto) throws SQLException {
      try {
         sqlString = insertStatement;
         stmt = conn.prepareCall(sqlString);
         stmt.setString(1, dto.getDong());
         stmt.setString(2, dto.getHo());
         stmt.setString(3, dto.getRoom());
         stmt.setString(4, dto.getNote());
         stmt.setString(5, dto.getMod_emp_id());
         executeUpdate();
      }catch(Exception e) {
         throw new SQLException();
      } finally {
         if (stmt != null) stmt.close();
      }
   }
   public void setHrm_cp_house(Hrm_cp_houseDTO dto) throws SQLException {
      try {
         sqlString = findByPKStatement;
         stmt = conn.prepareCall(sqlString);
         stmt.setString(1, dto.getDong());
         stmt.setString(2, dto.getHo());
         stmt.setString(3, dto.getRoom());
         rset = execute();
         if (rset.next()) {
            this.dong = rset.getString(1);     // 동
            this.ho = rset.getString(2);     // 호
            this.room = rset.getString(3);     // 룸
            this.note = rset.getString(4);     // 비고
              }
         if (rset != null) rset.close();
         if (stmt != null) stmt.close();
         // Argument Setting
         if (dto.getNote() != null)  setNote(dto.getNote());     // 비고
         if (dto.getMod_emp_id() != null)  setMod_emp_id(dto.getMod_emp_id());     // 변경사번
         if (dto.getMod_date() != null)  setMod_date(dto.getMod_date());     // 변경일시
         // 자료를 Update
         sqlString = updateStatement;
         stmt = conn.prepareCall(sqlString);
         stmt.setString(1, note);
         stmt.setString(2, mod_emp_id);
         stmt.setString(3, dong);
         stmt.setString(4, ho);
         stmt.setString(5, room);
         executeUpdate();
      }catch(Exception e) {
         throw new SQLException();
      } finally {
         if (rset != null) rset.close();
         if (stmt != null) stmt.close();
      }
   }
   public void deleteHrm_cp_house(Hrm_cp_houseDTO dto) throws SQLException {
      try {
         sqlString = deleteStatement;
         stmt = conn.prepareCall(sqlString);
         stmt.setString(1, dto.getDong());
         stmt.setString(2, dto.getHo());
         stmt.setString(3, dto.getRoom());
         executeUpdate();
      }catch(Exception e) {
         throw new SQLException();
      } finally {
         if (stmt != null) stmt.close();
      }
   }
   public void setDong(String dong) {      // 동
      this.dong = dong;
   }
   public void setHo(String ho) {      // 호
      this.ho = ho;
   }
   public void setRoom(String room) {      // 룸
      this.room = room;
   }
   public void setNote(String note) {      // 비고
      this.note = note;
   }
}

댓글

이 블로그의 인기 게시물

jquery css

Struts2의 작동 원리

JSP/Servlet 한글 깨짐 처리 ?