1 32 33 package com.knowgate.scheduler; 34 35 import java.sql.ResultSet ; 36 import java.sql.ResultSetMetaData ; 37 import java.sql.SQLException ; 38 import java.sql.Connection ; 39 import java.sql.Statement ; 40 import java.sql.PreparedStatement ; 41 import java.sql.Types ; 42 43 import java.util.HashMap ; 44 45 import com.knowgate.jdc.JDCConnection; 46 import com.knowgate.dataobjs.DB; 47 import com.knowgate.dataobjs.DBPersist; 48 import com.knowgate.debug.DebugFile; 49 import com.knowgate.misc.Gadgets; 50 51 57 public class Atom extends DBPersist { 58 59 89 public Atom(ResultSet oRow, ResultSetMetaData oMetaData) throws SQLException { 90 super(DB.k_job_atoms, "Atom"); 91 92 int iCols = oMetaData.getColumnCount(); 93 String sCol; 94 Object oCol; 95 96 for (int c=1; c<=iCols; c++) { 97 98 sCol = oMetaData.getColumnName(c); 99 oCol = oRow.getObject(c); 100 101 if (!oRow.wasNull()) { 102 103 if (sCol.equalsIgnoreCase(DB.tx_name)) { 104 105 put(DB.tx_name, oRow.getString(c)); 106 put("Data.Name", oRow.getString(c)); 107 put("Datos.Nombre", oRow.getString(c)); 108 } 109 else if (sCol.equalsIgnoreCase(DB.tx_surname)) { 110 111 put(DB.tx_surname, oRow.getString(c)); 112 put("Data.Surname", oRow.getString(c)); 113 put("Datos.Apellidos", oRow.getString(c)); 114 } 115 else if (sCol.equalsIgnoreCase(DB.tx_salutation)) { 116 117 put(DB.tx_salutation, oRow.getString(c)); 118 put("Data.Salutation", oRow.getString(c)); 119 put("Datos.Saludo", oRow.getString(c)); 120 } 121 else if (sCol.equalsIgnoreCase(DB.nm_commercial)) { 122 123 put(DB.nm_commercial, oRow.getString(c)); 124 put("Data.Legal_Name", oRow.getString(c)); 125 put("Datos.Razon_Social", oRow.getString(c)); 126 } 127 else if (sCol.equalsIgnoreCase(DB.tx_email)) { 128 129 put(DB.tx_email, oRow.getString(c)); 130 put("Address.EMail", oRow.getString(c)); 131 put("Direccion.EMail", oRow.getString(c)); 132 } 133 else if (sCol.equalsIgnoreCase(DB.tp_street)) { 134 135 put(DB.tp_street, oRow.getString(c)); 136 put("Address.Street_Type", oRow.getString(c)); 137 put("Direccion.Tipo_Via", oRow.getString(c)); 138 } 139 else if (sCol.equalsIgnoreCase(DB.nm_street)) { 140 141 put(DB.nm_street, oRow.getString(c)); 142 put("Address.Street_Name", oRow.getString(c)); 143 put("Direccion.Nombre_Via", oRow.getString(c)); 144 } 145 else if (sCol.equalsIgnoreCase(DB.nu_street)) { 146 147 put(DB.nu_street, oRow.getString(c)); 148 put("Address.Street_Num", oRow.getString(c)); 149 put("Direccion.Numero_Via", oRow.getString(c)); 150 } 151 else if (sCol.equalsIgnoreCase(DB.tx_addr1)) { 152 153 put(DB.tx_addr1, oRow.getString(c)); 154 put("Address.Line1", oRow.getString(c)); 155 put("Direccion.Linea1", oRow.getString(c)); 156 } 157 else if (sCol.equalsIgnoreCase(DB.tx_addr2)) { 158 159 put(DB.tx_addr2, oRow.getString(c)); 160 put("Address.Line2", oRow.getString(c)); 161 put("Direccion.Linea2", oRow.getString(c)); 162 } 163 else if (sCol.equalsIgnoreCase(DB.nm_country)) { 164 165 put(DB.nm_country, oRow.getString(c)); 166 put("Address.Country", oRow.getString(c)); 167 put("Direccion.Pais", oRow.getString(c)); 168 } 169 else if (sCol.equalsIgnoreCase(DB.nm_state)) { 170 171 put(DB.nm_state, oRow.getString(c)); 172 put("Address.State", oRow.getString(c)); 173 put("Direccion.Provincia", oRow.getString(c)); 174 } 175 else if (sCol.equalsIgnoreCase(DB.mn_city)) { 176 177 put(DB.mn_city, oRow.getString(c)); 178 put("Address.City", oRow.getString(c)); 179 put("Direccion.Ciudad", oRow.getString(c)); 180 } 181 else if (sCol.equalsIgnoreCase(DB.zipcode)) { 182 183 put(DB.zipcode, oRow.getString(c)); 184 put("Address.Zipcode", oRow.getString(c)); 185 put("Direccion.Codigo_Postal", oRow.getString(c)); 186 } 187 else if (sCol.equalsIgnoreCase(DB.work_phone)) { 188 189 put(DB.work_phone, oRow.getString(c)); 190 put("Address.Proffesional_Phone", oRow.getString(c)); 191 put("Direccion.Telf_Profesional", oRow.getString(c)); 192 } 193 else if (sCol.equalsIgnoreCase(DB.fax_phone)) { 194 195 put(DB.fax_phone, oRow.getString(c)); 196 put("Address.Fax_Phone", oRow.getString(c)); 197 put("Direccion.Telf_Fax", oRow.getString(c)); 198 } 199 else if (sCol.equalsIgnoreCase(DB.mov_phone)) { 200 201 put(DB.mov_phone, oRow.getString(c)); 202 put("Address.Mobile_Phone", oRow.getString(c)); 203 put("Direccion.Telf_Movil", oRow.getString(c)); 204 } 205 else if (sCol.equalsIgnoreCase(DB.tx_parameters)) 206 207 parseParameters(oRow.getString(c)); 211 212 else 213 put(oMetaData.getColumnName(c).toLowerCase(), oRow.getObject(c)); 214 215 } } } 218 219 221 private void parseParameters(String sTxParams) { 222 String aVariable[]; 223 String aParams[] = Gadgets.split(sTxParams, ","); 224 225 for (int p=0; p<aParams.length; p++) { 226 aVariable = Gadgets.split(aParams[p], ":"); 227 put(aVariable[0], aVariable[1]); 228 } 230 } 232 234 239 public void archive(JDCConnection oConn) throws SQLException { 240 final String COLUMNS_LIST = DB.gu_job + "," + DB.pg_atom + "," + DB.dt_execution + "," + DB.id_status + "," + DB.id_format + "," + DB.gu_company + "," + DB.gu_contact + "," + DB.tx_email + "," + DB.tx_name + "," + DB.tx_surname + "," + DB.tx_salutation + "," + DB.nm_commercial + "," + DB.tp_street + "," + DB.nm_street + "," + DB.nu_street + "," + DB.tx_addr1 + "," + DB.tx_addr2 + "," + DB.nm_country + "," + DB.nm_state + "," + DB.mn_city + "," + DB.zipcode + "," + DB.work_phone + "," + DB.direct_phone + "," + DB.home_phone + "," + DB.mov_phone + "," + DB.fax_phone + "," + DB.other_phone + "," + DB.po_box + "," + DB.tx_log; 241 String sWhere, sSQL; 242 Statement oStmt; 243 244 if (DebugFile.trace) { 245 DebugFile.writeln("Begin Atom.archive([Connection])"); 246 DebugFile.incIdent(); 247 } 248 249 oStmt = oConn.createStatement(); 250 251 sWhere = " WHERE gu_job='" + getString(DB.gu_job) + "' AND pg_atom=" + String.valueOf(getInt(DB.pg_atom)); 252 253 sSQL = "UPDATE " + DB.k_job_atoms + " SET " + DB.id_status + "=" + String.valueOf(Atom.STATUS_FINISHED) + "," + DB.tx_log + "=NULL " + sWhere; 254 255 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(" + sSQL + ")"); 256 257 oStmt.executeUpdate(sSQL); 258 259 sSQL = "INSERT INTO " + DB.k_job_atoms_archived + " (" + COLUMNS_LIST + ") " + 260 "SELECT " + COLUMNS_LIST + " FROM " + DB.k_job_atoms + sWhere; 261 262 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(" + sSQL + ")"); 263 264 oStmt.executeUpdate(sSQL); 265 266 sSQL = "DELETE FROM " + DB.k_job_atoms + sWhere; 267 268 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(" + sSQL + ")"); 269 270 oStmt.executeUpdate(sSQL); 271 272 oStmt.close(); 273 274 if (DebugFile.trace) { 275 DebugFile.decIdent(); 276 DebugFile.writeln("End Atom.archive()"); 277 } 278 279 } 281 283 292 public void setStatus (JDCConnection oConn, short iStatus, String sLog) 293 throws SQLException , NullPointerException ,NumberFormatException { 294 295 if (isNull(DB.gu_job)) 296 throw new NullPointerException ("Atom.setStatus() Job GUID not set"); 297 if (isNull(DB.pg_atom)) 298 throw new NullPointerException ("Atom.setStatus() Atom ordinal not set"); 299 300 int iPgAtom = getInt(DB.pg_atom); 301 302 PreparedStatement oStmt = oConn.prepareStatement("UPDATE "+DB.k_job_atoms+" SET "+DB.id_status+"=?,"+DB.tx_log+"=? WHERE "+DB.gu_job+"=? AND "+DB.pg_atom+"=?"); 303 oStmt.setShort(1, iStatus); 304 if (null==sLog) 305 oStmt.setNull(2, Types.VARCHAR); 306 else 307 oStmt.setString(2, Gadgets.left(sLog,254)); 308 oStmt.setString(3, getString(DB.gu_job)); 309 oStmt.setInt(4, iPgAtom); 310 oStmt.executeUpdate(); 311 oStmt.close(); 312 313 replace(DB.id_status, iStatus); 314 } 316 318 public static final short STATUS_ABORTED = Job.STATUS_ABORTED; 319 public static final short STATUS_FINISHED = Job.STATUS_FINISHED; 320 public static final short STATUS_PENDING = Job.STATUS_PENDING; 321 public static final short STATUS_SUSPENDED = Job.STATUS_SUSPENDED; 322 public static final short STATUS_RUNNING = Job.STATUS_RUNNING; 323 public static final short STATUS_INTERRUPTED = Job.STATUS_INTERRUPTED; 324 325 } | Popular Tags |