1 32 33 package com.knowgate.scheduler; 34 35 import java.util.Date ; 36 37 import java.sql.SQLException ; 38 import java.sql.Connection ; 39 import java.sql.PreparedStatement ; 40 import java.sql.Timestamp ; 41 42 import com.knowgate.jdc.JDCConnection; 43 import com.knowgate.dataobjs.DB; 44 import com.knowgate.debug.DebugFile; 45 46 51 public class AtomConsumer { 52 53 private AtomQueue oQueue; 54 private JDCConnection oConn; 55 private PreparedStatement oStmt; 56 57 59 65 public AtomConsumer(JDCConnection oConnection, AtomQueue oAtomQueue) throws SQLException { 66 oQueue = oAtomQueue; 67 oConn = oConnection; 68 69 if (DebugFile.trace) { 70 DebugFile.writeln("Connection.prepareStatement (UPDATE " + DB.k_job_atoms + " SET " + DB.id_status + "=" + String.valueOf(Atom.STATUS_RUNNING) + ", " + DB.dt_execution + "=? WHERE " + DB.gu_job + "=? AND " + DB.pg_atom + "=?)"); 71 } 72 73 oStmt = oConn.prepareStatement("UPDATE " + DB.k_job_atoms + " SET " + DB.id_status + "=" + String.valueOf(Atom.STATUS_RUNNING) + ", " + DB.dt_execution + "=? WHERE " + DB.gu_job + "=? AND " + DB.pg_atom + "=?"); 75 76 try { oStmt.setQueryTimeout(20); } catch (SQLException sqle) { } 77 } 78 79 81 public void close() { 82 if (null!=oStmt) 83 try { oStmt.close(); } catch (SQLException sqle) { } 84 oStmt = null; 85 } 86 87 89 94 95 public synchronized Atom next() throws SQLException { 96 97 if (DebugFile.trace) { 98 DebugFile.writeln("Begin AtomConsumer.next()"); 99 DebugFile.incIdent(); 100 } 101 102 Atom oAtm = oQueue.pop(); 103 104 if (oAtm!=null) { 105 106 if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setTimestamp(1, new Timestamp(new Date().getTime()))"); 107 108 oStmt.setTimestamp(1, new Timestamp (new Date ().getTime())); 109 110 if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setString(2, " + oAtm.getStringNull(DB.gu_job,"null") + ")"); 111 112 oStmt.setString(2, oAtm.getString(DB.gu_job)); 114 115 if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setInt(3, " + String.valueOf(oAtm.getInt(DB.pg_atom)) + ")"); 116 117 oStmt.setInt(3, oAtm.getInt(DB.pg_atom)); 118 119 if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate()"); 120 121 oStmt.executeUpdate(); 122 } 123 124 if (DebugFile.trace) { 125 DebugFile.decIdent(); 126 DebugFile.writeln("End AtomConsumer.next()"); 127 } 128 129 return oAtm; 130 } 132 134 public JDCConnection getConnection() { 135 return oConn; 136 } 137 138 } | Popular Tags |