1 /*** $Id: DAOTester.java,v 1.1.1.1 2004/05/18 10:50:23 mochoa Exp $*/ 2 package cmd_dao.sample.common.tester; 3 4 //sql 5 import java.sql.*; 6 //dao 7 import org.j2ee.dao.*; 8 //employee_old-dao 9 import cmd_dao.sample.common.dao.employee.InsertEmployeeRecord; 10 import cmd_dao.sample.common.dao.employee.UpdateEmployeeRecord; 11 import cmd_dao.sample.common.dao.employee.DeleteEmployeeRecord; 12 import cmd_dao.sample.common.dao.employee.FindEmployeeByPK; 13 //dto 14 import cmd_dao.sample.common.dto.EmployeeTO; 15 import cmd_dao.sample.common.tester.CRUDTester; 16 import org.j2ee.dao.DAOJdbcActionProcessorImpl; 17 18 /*** 19 * Last modified $Date: 2004/05/18 10:50:23 $ 20 * @version $Revision: 1.1.1.1 $ 21 * @author jvlio (jvlio@users.sourceforge.net) - 17/10/2002 - 02:42:53 22 */ 23 public class DAOTester implements CRUDTester { 24 public static String INSERT_EMP_REC = "ins_emp_rec"; 25 public static String FINDPK_EMP_REC = "findpk_emp_rec"; 26 public static String UPDATE_EMP_REC = "up_emp_rec"; 27 public static String DELETE_EMP_REC = "del_emp_rec"; 28 29 public TuneData insert(Connection con, int count, DataSetter ds) throws DAOException { 30 DAOActionProcessor p = new DAOJdbcActionProcessorImpl(); 31 p.setConnection(con); 32 33 EmployeeTO emp = new EmployeeTO(); 34 //InsertEmployeeRecord action = new InsertEmployeeRecord(emp); 35 InsertEmployeeRecord action = (InsertEmployeeRecord)DAOFactory.getDAOFactory().getAction(INSERT_EMP_REC); //new InsertEmployeeRecord(emp); 36 action.setEmployee(emp); 37 action.setCaching(true); 38 39 long begin = 0; 40 long time = 0; 41 long stime = 0; 42 for(int i=0; i<count; i++) { 43 emp = (EmployeeTO)ds.set(i,emp); 44 begin = System.currentTimeMillis(); 45 action.execute(p); 46 time = System.currentTimeMillis()-begin; 47 stime += time; 48 } 49 50 try { 51 if (action.getPreparedStatement()!=null) action.getPreparedStatement().close(); 52 } catch (Exception ex) { 53 ex.printStackTrace(System.err); 54 } 55 56 TuneData tunning = new TuneData(); 57 tunning.setProcesedTime(stime); 58 return tunning; 59 } 60 61 62 public TuneData find(Connection con, int count, DataSetter ds) throws DAOException { 63 DAOActionProcessor p = new DAOJdbcActionProcessorImpl(); 64 p.setConnection(con); 65 66 EmployeeTO emp = new EmployeeTO(); 67 //FindEmployeeByPK action = new FindEmployeeByPK(emp); 68 FindEmployeeByPK action = (FindEmployeeByPK)DAOFactory.getDAOFactory().getAction(FINDPK_EMP_REC); 69 action.setEmployee(emp); 70 action.setCaching(true); 71 72 long begin = 0; 73 long time = 0; 74 long stime = 0; 75 for(int i=0; i<count; i++) { 76 emp = (EmployeeTO)ds.set(i,emp); 77 begin = System.currentTimeMillis(); 78 action.execute(p); 79 time = System.currentTimeMillis()-begin; 80 stime += time; 81 if (!action.isFound()) System.out.println("dao find error pk=("+i+")"); 82 } 83 84 try { 85 if (action.getPreparedStatement()!=null) action.getPreparedStatement().close(); 86 } catch (Exception ex) { 87 ex.printStackTrace(System.err); 88 } 89 90 91 TuneData tunning = new TuneData(); 92 tunning.setProcesedTime(stime); 93 return tunning; 94 } 95 96 97 public TuneData update(Connection con, int count, DataSetter ds) throws DAOException { 98 DAOActionProcessor p = new DAOJdbcActionProcessorImpl(); 99 p.setConnection(con); 100 101 EmployeeTO emp = new EmployeeTO(); 102 //UpdateEmployeeRecord action = new UpdateEmployeeRecord(emp); 103 UpdateEmployeeRecord action = (UpdateEmployeeRecord)DAOFactory.getDAOFactory().getAction(UPDATE_EMP_REC); 104 action.setEmployee(emp); 105 action.setCaching(true); 106 107 long begin = 0; 108 long time = 0; 109 long stime = 0; 110 for(int i=0; i<count; i++) { 111 emp = (EmployeeTO)ds.set(i,emp); 112 begin = System.currentTimeMillis(); 113 action.execute(p); 114 time = System.currentTimeMillis()-begin; 115 stime += time; 116 } 117 118 try { 119 if (action.getPreparedStatement()!=null) action.getPreparedStatement().close(); 120 } catch (Exception ex) { 121 ex.printStackTrace(System.err); 122 } 123 124 125 TuneData tunning = new TuneData(); 126 tunning.setProcesedTime(stime); 127 return tunning; 128 } 129 130 131 132 public TuneData delete(Connection con, int count, DataSetter ds) throws DAOException { 133 DAOActionProcessor p = new DAOJdbcActionProcessorImpl(); 134 p.setConnection(con); 135 136 EmployeeTO emp = new EmployeeTO(); 137 //DeleteEmployeeRecord action = new DeleteEmployeeRecord(emp); 138 DeleteEmployeeRecord action = (DeleteEmployeeRecord)DAOFactory.getDAOFactory().getAction(DELETE_EMP_REC); 139 action.setEmployee(emp); 140 action.setCaching(true); 141 142 long begin = 0; 143 long time = 0; 144 long stime = 0; 145 for(int i=0; i<count; i++) { 146 emp = (EmployeeTO)ds.set(i,emp); 147 begin = System.currentTimeMillis(); 148 action.execute(p); 149 time = System.currentTimeMillis()-begin; 150 stime += time; 151 } 152 153 try { 154 if (action.getPreparedStatement()!=null) action.getPreparedStatement().close(); 155 } catch (Exception ex) { 156 ex.printStackTrace(System.err); 157 } 158 159 160 TuneData tunning = new TuneData(); 161 tunning.setProcesedTime(stime); 162 return tunning; 163 } 164 }

This page was automatically generated by Maven