public void deleteJobEntry(JobEntry jobEntry) {
   if (jobEntry == null || jobEntry.getJobEntryId() == null) {
     log.warn(
         "User attempted to delete a job but provided insufficient information to identify it: "
             + jobEntry);
     return;
   }
   jobEntry = getJobEntry(jobEntry);
   if (jobEntry == null) {
     log.warn("User attempted to delete a job that was not found in the system.");
     return;
   }
   /*
           if (jobEntry.getLogEntries() != null) {
               for (JobEntryEventLog eventLog : jobEntry.getLogEntries()) {
                   getHibernateTemplate().delete(eventLog);
               }
               getHibernateTemplate().delete(jobEntry);
               getHibernateTemplate().flush();
           }
   */
   List<JobEntryEventLog> jobEntryEventLogs = getJobEntryEventLogs(jobEntry.getJobEntryId());
   for (JobEntryEventLog eventLog : jobEntryEventLogs) {
     getHibernateTemplate().delete(eventLog);
   }
   getHibernateTemplate().delete(jobEntry);
   getHibernateTemplate().flush();
 }
  public void logJobEntryEvent(JobEntry jobEntry, JobEntryEventLog eventLog) {
    if (jobEntry == null || jobEntry.getJobEntryId() == null) {
      log.warn(
          "User attempted to attempted to log an event against a job but provided insufficient "
              + "information to identify it: "
              + jobEntry);
      return;
    }

    JobEntry foundJobEntry = getJobEntry(jobEntry);
    if (foundJobEntry == null) {
      log.warn("User attempted to log a job event but the job was not found in the system.");
      return;
    }
    eventLog.setEventEntryEventLogId(null);
    eventLog.setJobEntry(foundJobEntry);
    foundJobEntry.getLogEntries().add(eventLog);

    getHibernateTemplate().saveOrUpdate(jobEntry);
    getHibernateTemplate().flush();
    if (log.isDebugEnabled()) {
      log.debug("Finished loggging an event against a job: " + foundJobEntry);
    }
  }
  @SuppressWarnings("unchecked")
  public JobEntry getJobEntry(JobEntry jobEntry) {
    List<JobEntry> entries =
        (List<JobEntry>)
            getHibernateTemplate()
                .find("from JobEntry e where e.jobEntryId = " + jobEntry.getJobEntryId());

    if (entries.size() == 0) {
      return null;
    }
    JobEntry entry = entries.get(0);
    getHibernateTemplate().evict(entry);
    Hibernate.initialize(entry);
    if (log.isDebugEnabled()) {
      log.debug("Loaded the jobEntry: " + entry);
    }
    return entry;
  }
  public JobEntry updateJobEntry(JobEntry jobEntry) {
    if (log.isDebugEnabled()) {
      log.debug("Updating jobEntry: " + jobEntry);
    }
    if (jobEntry == null || jobEntry.getJobEntryId() == null) {
      log.warn(
          "User attempted to update a job but provided insufficient information to identify it.");
      return jobEntry;
    }
    JobEntry foundJobEntry = getJobEntry(jobEntry);
    if (foundJobEntry == null) {
      log.warn("User attempted to update a job that was not found in the system.");
      return jobEntry;
    }

    // The user can only update these fields only.
    foundJobEntry.setDateCompleted(jobEntry.getDateCompleted());
    foundJobEntry.setItemsErrored(jobEntry.getItemsErrored());
    foundJobEntry.setItemsProcessed(jobEntry.getItemsProcessed());
    foundJobEntry.setItemsSuccessful(jobEntry.getItemsSuccessful());
    foundJobEntry.setJobDescription(jobEntry.getJobDescription());
    foundJobEntry.setJobStatus(jobEntry.getJobStatus());

    getHibernateTemplate().saveOrUpdate(foundJobEntry);
    getHibernateTemplate().flush();
    if (log.isDebugEnabled()) {
      log.debug("Finished updating the job: " + foundJobEntry);
    }
    return foundJobEntry;
  }