패키지: com.batch.dao
1 2 3 4 5 6 7 8 9 | public interface TruncTableDao { /** * sample insert * @return * @throws DataAccessException * @throws Exception */ public void truncateTable() throws DataAccessException, Exception; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | public class TruncTableDaoImpl extends SqlMapClientDaoSupport implements TruncTableDao { @SuppressWarnings({ "rawtypes", "unchecked" }) public void truncateTable() throws DataAccessException, Exception { SqlMapClient smc = getSqlMapClient(); int errCd = 0; String rstMsg = ""; String modDt = ""; // 등록 날짜 String modDt2 = ""; String errDtl = ""; JrConfigManager configMng = JrConfigManager.getInstance(); String targetDir = configMng.getProperty("config.job.temp.dir"); String fileName = configMng.getProperty("config.job.temp.file");; String targetFileName = targetDir + "/" + fileName; File fileTmp = new File(targetDir); try{ if(fileTmp.exists() == false){ fileTmp.mkdirs(); FileUtil.fileMake(targetFileName); System.out.println("FIRST - 1"); BufferedWriter writer = new BufferedWriter(new FileWriter(targetFileName)); writer.write("1"); writer.close(); smc.startTransaction(); loggingCat.info("Query Call ID : JOB.truncateTable"); smc.update("JOB.truncateTable"); smc.commitTransaction(); }else{ File files = new File(targetFileName); if(files.exists() == false){ FileUtil.fileMake(targetFileName); }else{ FileReader fileReader = new FileReader(files); BufferedReader reader = new BufferedReader(fileReader); String number = null; int cnt = 0; while((number = reader.readLine()) != null ){ cnt = Integer.parseInt(number); if(Integer.parseInt(number) == 1){ BufferedWriter writer = new BufferedWriter(new FileWriter(targetFileName)); writer.write("2"); writer.close(); smc.startTransaction(); loggingCat.info("Query Call ID : JOB.truncateTable"); smc.update("JOB.truncateTable"); smc.commitTransaction(); }else if(Integer.parseInt(number) == 2){ BufferedWriter writer = new BufferedWriter(new FileWriter(targetFileName)); writer.write("1"); writer.close(); smc.startTransaction(); loggingCat.info("Query Call ID : JOB.truncateTable2"); smc.update("JOB.truncateTable2"); smc.commitTransaction(); } } reader.close(); if(cnt == 0){ System.out.println("FIRST - 2"); BufferedWriter writer = new BufferedWriter(new FileWriter(targetFileName)); writer.write("1"); writer.close(); smc.startTransaction(); loggingCat.info("Query Call ID : JOB.truncateTable"); smc.update("JOB.truncateTable"); smc.commitTransaction(); } } } }catch (Exception e){ system.out.println(s.printStackTrace()); }finally{ smc.endTransaction(); } } } |
config.job.temp.dir = c:/temp
config.job.temp.file = trunc
여기서 c:/temp/trunc 파일에 1과 2를 반복하면서 파일에 쓴다.
1일 때는 파일에 2를 쓰고 SESSION 테이블을 TRUNCATE 하겠다는 것이고,
2일 때는 파일에 1를 쓰고 SESSION2 테이블을 TRUNCATE 하겠다는 것이다.
다음 패키지를 생성하고 쿼리를 만들어 준다.
패키지: com.batch.sqlmap
파일명: JOB_oracle.xml
1 2 3 4 5 6 7 8 9 10 11 12 | <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"> <sqlMap namespace="JOB"> <update id="truncateTable"> TRUNCATE TABLE SESSION </update> <update id="truncateTable2"> TRUNCATE TABLE SESSION2 </update> </sqlMap> |
댓글 없음:
댓글 쓰기