1 22 23 package org.webdocwf.util.loader; 24 25 import java.sql.*; 26 import java.math.BigDecimal ; 27 import org.webdocwf.util.loader.logging.*; 28 29 35 public class DataTransmition { 36 private ImportDefinitionElement importDefinitionElement; 37 private Logger logger; 38 39 public DataTransmition(ImportDefinitionElement importDefinitionElement) { 40 this.importDefinitionElement = importDefinitionElement; 41 } 42 43 48 public void createRestartCounterTable(Connection conn) throws 49 LoaderException { 50 51 this.logger.write("full", "\tcreateRestartCounterTable method is started."); 52 try { 53 Statement stmt; 54 stmt = conn.createStatement(); 55 56 String sqlStmt = "create table " + 57 this.importDefinitionElement.strRestartCounterTableName 58 + " (" + 59 this.importDefinitionElement.strRestartCounterImportDefinitionName + 60 " VARCHAR(50) NOT NULL, " 61 + this.importDefinitionElement.strRestartCounterValue + " DECIMAL(19,0));"; 62 63 this.logger.write("full","\tQuery '" + sqlStmt + "' will be executed"); 64 stmt.execute(sqlStmt); 65 this.importDefinitionElement.bRestartAutoCreate = false; 66 conn.commit(); 67 stmt.close(); 68 } 69 catch (SQLException e) { 70 LoaderException le = new LoaderException("SQLException: ", (Throwable )e); 71 this.logger.write("normal", le.getCause().toString()); 72 throw le; 73 } 74 this.logger.write("full", "\tcreateRestartCounterTable method is finished."); 75 } 76 77 86 public BigDecimal checkDataTransmition(Connection c, 87 ResultSet rset, String jobName, int iTargetFirstColumnResult) throws SQLException { 88 89 String strQuery = ""; 90 BigDecimal bdecRestartCounter = null; 91 String valueOfRestartColumn = ""; 92 93 this.logger.write("full", "\tcheckDataTransmition method is started."); 94 95 if (jobName.equalsIgnoreCase("importDefinition")) { 96 valueOfRestartColumn = this.importDefinitionElement.strImportDefinitionName; 97 } else if (jobName.equalsIgnoreCase("copyTable")) { 98 valueOfRestartColumn = this.importDefinitionElement.strCopyTableName; 99 } 100 101 try { 102 strQuery = "SELECT " + this.importDefinitionElement.strRestartCounterValue + 103 " FROM " + 104 this.importDefinitionElement.strRestartCounterTableName + " WHERE " + 105 this.importDefinitionElement.strRestartCounterImportDefinitionName 106 + " = '" + valueOfRestartColumn + "'"; 107 108 this.logger.write("full", "\tQuery '" + strQuery + "' will be executed"); 109 Statement stmtCountT = c.createStatement(); 110 ResultSet rsetCountT = stmtCountT.executeQuery(strQuery); 111 112 if (!rsetCountT.next()) { 114 strQuery = "INSERT into " + 115 this.importDefinitionElement.strRestartCounterTableName 116 + " (" + 117 this.importDefinitionElement.strRestartCounterImportDefinitionName 118 + ", " + this.importDefinitionElement.strRestartCounterValue + ") " + 119 " VALUES ('" 120 + valueOfRestartColumn + "', null)"; 121 this.logger.write("full", "\tQuery '" + strQuery + "' will be executed"); 122 stmtCountT.executeUpdate(strQuery); 123 c.commit(); 124 bdecRestartCounter = null; 125 126 } else { if (iTargetFirstColumnResult == 1) { 128 bdecRestartCounter = new BigDecimal (Integer.parseInt(rsetCountT.getString(1))); 129 } else { bdecRestartCounter = new BigDecimal (Integer.parseInt(rsetCountT.getString(0))); 131 } 132 if (false) { 133 rset.relative(bdecRestartCounter.intValue()); 134 } else { 135 BigDecimal kl = new BigDecimal (0); 136 while (kl.compareTo(bdecRestartCounter) == -1) { 137 rset.next(); 138 kl = kl.add(new BigDecimal (1)); 139 } 140 } 141 } 142 rsetCountT.close(); 143 stmtCountT.close(); 144 } 145 catch (SQLException ex) { 146 ex.printStackTrace(); 147 } 148 return bdecRestartCounter; 149 } 150 151 159 public void insertCounter(String jobName, BigDecimal bdecCount, 160 Connection conn) throws SQLException { 161 162 String valueOfRestartColumn = ""; 163 164 this.logger.write("full", "\tinsertCounter method is started."); 165 166 if (jobName.equalsIgnoreCase("importDefinition")) { 167 valueOfRestartColumn = this.importDefinitionElement.strImportDefinitionName; 168 } else if (jobName.equalsIgnoreCase("copyTable")) { 169 valueOfRestartColumn = this.importDefinitionElement.strCopyTableName; 170 } 171 172 String strQueryUpdate = "update " + 173 this.importDefinitionElement.strRestartCounterTableName 174 + " set " + this.importDefinitionElement.strRestartCounterValue + " = " + 175 bdecCount 176 + " where " + 177 this.importDefinitionElement.strRestartCounterImportDefinitionName + 178 " = '" + valueOfRestartColumn + "'"; 179 180 try { 181 this.logger.write("full", "\tQuery '" + strQueryUpdate + "' will be executed"); 182 Statement stmtChange = conn.createStatement(); 183 int num = stmtChange.executeUpdate(strQueryUpdate); 184 stmtChange.close(); 185 conn.commit(); 186 } 187 catch (SQLException ex) { 188 throw ex; 189 } 190 this.logger.write("full", "\tinsertCounter method is finished."); 191 } 192 193 200 public void resetRestartCounter(Connection conn, String jobName) throws SQLException { 201 202 String valueOfRestartColumn = ""; 203 204 this.logger.write("full", "\tresetRestartCounter method is started."); 205 206 if (jobName.equalsIgnoreCase("importDefinition")) { 207 valueOfRestartColumn = this.importDefinitionElement.strImportDefinitionName; 208 } else if (jobName.equalsIgnoreCase("copyTable")) { 209 valueOfRestartColumn = this.importDefinitionElement.strCopyTableName; 210 } 211 212 String strQueryReset = "update " + 213 this.importDefinitionElement.strRestartCounterTableName + 214 " set " + this.importDefinitionElement.strRestartCounterValue + 215 " = 0 where " + 216 this.importDefinitionElement.strRestartCounterImportDefinitionName 217 + " = '" + valueOfRestartColumn + "'"; 218 try { 219 Statement stmtReset = conn.createStatement(); 220 this.logger.write("full", "\tQuery '" + strQueryReset + "' will be executed"); 221 int num = stmtReset.executeUpdate(strQueryReset); 222 stmtReset.close(); 223 conn.commit(); 224 } 225 catch (SQLException ex) { 226 throw ex; 227 } 228 this.logger.write("full", "\tresetRestartCounter method is finished."); 229 } 230 231 235 public void setLogger(Logger logger) { 236 this.logger = logger; 237 } 238 239 } | Popular Tags |