0 Replies Latest reply: Jan 15, 2014 7:35 AM by Eduardo Royer RSS

    Execute batch job (JSR 352) on startup

    Eduardo Royer

      I have a batchjob and need to run it up the application. He makes the call for the job, but the job does not reach the method.

      BatchRuntime.getJobOperator().start(JOB_NAME, new Properties());

      Throws no errors. So it seems that he is looking for the resource that indicates which class Implementing this job, but not yet loaded. Any idea?

      package com.royer.batch.update.schema;
      
      public interface UpdateSchemaBatch { void 
                initJob(); 
      }
      

       

      package com.royer.batch.update.schema.impl;
      
      import java.util.Properties;
      import javax.batch.runtime.BatchRuntime;
      import javax.batch.runtime.BatchStatus;
      import javax.batch.runtime.JobExecution;
      import com.royer.batch.update.schema.UpdateSchemaBatch;
      
      public class UpdateSchemaBatchImpl implements UpdateSchemaBatch {
      
      
        private static final String JOB_NAME = "update-schema-job";
      
        @Override
        public void initJob() {
          BatchRuntime.getJobOperator().start(JOB_NAME, new Properties());     
         }
      }
      

       

       

      package com.royer.batch.controller.schema;
      
      import javax.batch.api.Batchlet;
      import javax.batch.runtime.BatchStatus;
      import javax.batch.runtime.context.JobContext;
      import javax.inject.Inject;
      import javax.inject.Named;
      
      @Named
      public class UpdateSchemaBatchlet implements Batchlet {
      
        @Inject
        private JobContext jobContext;
      
        public JobContext getJobContext() {
        return jobContext;
        }
      
        public void setJobContext(JobContext jobContext) {
        this.jobContext = jobContext;
        }
      
        @Override
        public String process() throws Exception {
             System.out.println("TESTE-ROYER");
             return BatchStatus.COMPLETED.name();
        }
      
        public void stop() throws Exception {
        }
      }
      
      package com.royer.batch.controller.startup;
      
      import javax.annotation.PostConstruct;
      import javax.ejb.Singleton;
      import javax.ejb.Startup;
      import javax.inject.Inject;
      import com.royer.batch.update.schema.UpdateSchemaBatch;
      
      @Startup
      @Singleton
      public class UpdateDBController {
      
        @Inject
        private UpdateSchemaBatch updateSchemaBatch;
      
        public UpdateSchemaBatch getUpdateSchemaBatch() {
        return updateSchemaBatch;
        }
      
        public void setUpdateSchemaBatch(UpdateSchemaBatch updateSchemaBatch) {
        this.updateSchemaBatch = updateSchemaBatch;
        }
      
      @PostConstruct
        public void init() {
             getUpdateSchemaBatch().initJob();
        }
      }
      

       

       

      It is a bug?