public SJob fetchByPK(Integer jobId) throws DAOException {
if (jobId == null) {
throw new JobDAOException("jobId cannot be null");
}
SJob job= null;
PreparedStatement statement = null;
ResultSet result;
Connection connection = DAOHelper.getDBConnection();
try {
try
{
statement = connection.prepareStatement(FETCHBYPK_QRY);
statement.setInt(1, jobId.intValue());
result = statement.executeQuery();
if(result.next())
{
job = new SJob();
job.setObjId(result.getString("id"));
job.setObjClass(SJob.class.getName());
job.setStatus(result.getString("status"));
job.setUserId(result.getString("owner_id"));
job.setInstrumentId(result.getString("instrument_id"));
job.setDescr(result.getString("description"));
job.setRa(result.getBigDecimal("ra"));
job.setDec(result.getBigDecimal("dec"));
java.sql.Date curDate;
curDate = result.getDate("scheduled_begin");
if (curDate == null) {
job.setScheduledBeginDateTime(null);
}
else {
try {
job.setScheduledBeginDateTime
(new XSDateTime(new java.util.Date(curDate.getTime())));
}
catch (XmlStructException e) {
throw new JobDAOException(e.getMessage());
}
}
curDate = result.getDate("actual_begin");
if (curDate == null) {
job.setActualBeginDateTime(null);
}
else {
try {
job.setActualBeginDateTime
(new XSDateTime(new java.util.Date(curDate.getTime())));
}
catch (XmlStructException e) {
throw new JobDAOException(e.getMessage());
}
}
job.setImageUrl(result.getString("image_url"));
job.setUserComment(result.getString("user_comment"));
job.setObservatoryComment(result.getString("observatory_comment"));
if(result.next())
{
throw new JobDAOException("Multiple rows exists for jobId " + jobId.toString());
}
}