/** @see JdbcJobExecutionDao#afterPropertiesSet() */
  @Override
  public void afterPropertiesSet() throws Exception {

    Assert.state(dataSource != null, "DataSource must be provided");

    if (getJdbcTemplate() == null) {
      setJdbcTemplate(new JdbcTemplate(dataSource));
    }
    setJobExecutionIncrementer(
        new AbstractDataFieldMaxValueIncrementer() {
          @Override
          protected long getNextKey() {
            return 0;
          }
        });

    allExecutionsPagingQueryProvider = getPagingQueryProvider();
    byJobNamePagingQueryProvider = getPagingQueryProvider("I.JOB_NAME=?");

    super.afterPropertiesSet();
  }
  /**
   * This method reads all the task from an xml file and registers them with the MifosScheduler
   *
   * @param document Task configuration document
   * @throws TaskSystemException when something goes wrong
   */
  @Deprecated
  private void registerTasksOldConfigurationFile(Document document) throws TaskSystemException {
    try {
      logger.warn(
          "Old format task.xml configuration file is deprecated. Please configure scheduler using spring managed beans.");
      NodeList rootSchedulerTasks =
          document.getElementsByTagName(SchedulerConstants.SCHEDULER_TASKS);
      Element rootNodeName = (Element) rootSchedulerTasks.item(0);
      NodeList collectionOfScheduledTasks =
          rootNodeName.getElementsByTagName(SchedulerConstants.SCHEDULER);

      DataSource dataSource =
          SessionFactoryUtils.getDataSource(StaticHibernateUtil.getSessionFactory());
      SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);

      JobRegistry jobRegistry = new MapJobRegistry();
      this.jobLocator = jobRegistry;

      JdbcJobInstanceDao jobInstanceDao = new JdbcJobInstanceDao();
      jobInstanceDao.setJdbcTemplate(jdbcTemplate);
      jobInstanceDao.setJobIncrementer(
          new MySQLMaxValueIncrementer(dataSource, "BATCH_JOB_SEQ", "id"));
      jobInstanceDao.afterPropertiesSet();

      JdbcJobExecutionDao jobExecutionDao = new JdbcJobExecutionDao();
      jobExecutionDao.setJdbcTemplate(jdbcTemplate);
      jobExecutionDao.setJobExecutionIncrementer(
          new MySQLMaxValueIncrementer(dataSource, "BATCH_JOB_EXECUTION_SEQ", "id"));
      jobExecutionDao.afterPropertiesSet();

      JdbcStepExecutionDao stepExecutionDao = new JdbcStepExecutionDao();
      stepExecutionDao.setJdbcTemplate(jdbcTemplate);
      stepExecutionDao.setStepExecutionIncrementer(
          new MySQLMaxValueIncrementer(dataSource, "BATCH_STEP_EXECUTION_SEQ", "id"));
      stepExecutionDao.afterPropertiesSet();

      JdbcExecutionContextDao executionContextDao = new JdbcExecutionContextDao();
      executionContextDao.setJdbcTemplate(jdbcTemplate);
      executionContextDao.afterPropertiesSet();

      JobRepository jobRepository =
          new SimpleJobRepository(
              jobInstanceDao, jobExecutionDao, stepExecutionDao, executionContextDao);
      this.jobRepository = jobRepository;

      SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
      jobLauncher.setJobRepository(jobRepository);
      jobLauncher.setTaskExecutor(new SyncTaskExecutor());
      jobLauncher.afterPropertiesSet();
      this.jobLauncher = jobLauncher;

      JobExplorer jobExplorer =
          new SimpleJobExplorer(
              jobInstanceDao, jobExecutionDao, stepExecutionDao, executionContextDao);
      this.jobExplorer = jobExplorer;

      Map<String, Object> jobData = new HashMap<String, Object>();
      jobData.put("jobLocator", jobRegistry);
      jobData.put("jobLauncher", jobLauncher);
      jobData.put("jobExplorer", jobExplorer);
      jobData.put("jobRepository", jobRepository);

      JobRegistryBeanPostProcessor jobRegistryProcessor = new JobRegistryBeanPostProcessor();
      jobRegistryProcessor.setJobRegistry(jobRegistry);
      ResourcelessTransactionManager transactionManager = new ResourcelessTransactionManager();

      Date loanArrearsTaskInitialTime = null;
      Long loanArrearsTaskDelayTime = null;
      boolean portfolioAtRiskTaskExists = false;

      for (int i = 0; i < collectionOfScheduledTasks.getLength(); i++) {
        Element scheduledTask = (Element) collectionOfScheduledTasks.item(i);
        Element subNodeName1 =
            (Element)
                scheduledTask.getElementsByTagName(SchedulerConstants.TASK_CLASS_NAME).item(0);
        String taskName = ((Text) subNodeName1.getFirstChild()).getData().trim();
        Element subNodeName2 =
            (Element) scheduledTask.getElementsByTagName(SchedulerConstants.INITIAL_TIME).item(0);
        String initialTime = ((Text) subNodeName2.getFirstChild()).getData().trim();
        Element subNodeName3;
        String delayTime = null;
        if ((scheduledTask.getElementsByTagName(SchedulerConstants.DELAY_TIME)) != null) {
          subNodeName3 =
              (Element) scheduledTask.getElementsByTagName(SchedulerConstants.DELAY_TIME).item(0);
          if (subNodeName3.getFirstChild() != null) {
            delayTime = ((Text) subNodeName3.getFirstChild()).getData().trim();
          }
        }
        if (Long.parseLong(delayTime) < 86400) {
          throw new IllegalArgumentException("Please specify the delay time >= 86400(1 day)");
        }
        if (scheduler.getJobDetail(taskName, Scheduler.DEFAULT_GROUP) != null) {
          scheduler.unscheduleJob(taskName, Scheduler.DEFAULT_GROUP);
        }
        if ("LoanArrearsTask".equals(taskName)) {
          loanArrearsTaskInitialTime = parseInitialTime(initialTime);
          loanArrearsTaskDelayTime = Long.parseLong(delayTime) * 1000;
          continue;
        }
        if ("PortfolioAtRiskTask".equals(taskName)) {
          portfolioAtRiskTaskExists = true;
          continue;
        }
        schedule(
            taskName,
            parseInitialTime(initialTime),
            Long.parseLong(delayTime) * 1000,
            jobRegistry,
            jobRepository,
            jobData,
            transactionManager);
      }
      if (loanArrearsTaskInitialTime != null) {
        if (portfolioAtRiskTaskExists) {
          scheduleLoanArrearsAndPortfolioAtRisk(
              loanArrearsTaskInitialTime,
              loanArrearsTaskDelayTime,
              jobRegistry,
              jobRepository,
              jobData,
              transactionManager);
        } else {
          schedule(
              "LoanArrearsTask",
              loanArrearsTaskInitialTime,
              loanArrearsTaskDelayTime,
              jobRegistry,
              jobRepository,
              jobData,
              transactionManager);
        }
      }
    } catch (Exception e) {
      throw new TaskSystemException(e);
    }
  }