From 00ad8f96c63b912019e7f7c479caa945dbad2309 Mon Sep 17 00:00:00 2001 From: WiredNerd Date: Mon, 14 Feb 2022 17:19:27 -0600 Subject: [PATCH 1/3] Compatible with spring-data-mongodb:3.2.8 (spring boot 2.5) --- spring-batch-mongo-example/build.gradle | 4 ++-- spring-batch-mongo-example/src/main/resources/application.yml | 2 +- spring-batch-mongo/build.gradle | 4 ++-- .../springbatch/mongo/explore/MongodbJobExplorer.java | 2 +- .../springbatch/mongo/repository/MongodbJobRepository.java | 2 +- .../mongo/repository/MongodbJobRepositoryTest.java | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spring-batch-mongo-example/build.gradle b/spring-batch-mongo-example/build.gradle index e7a7c2b..3339b39 100644 --- a/spring-batch-mongo-example/build.gradle +++ b/spring-batch-mongo-example/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'org.springframework.boot' version '2.6.3' + id 'org.springframework.boot' version '2.5.9' id "io.freefair.lombok" version "6.4.0" } @@ -16,7 +16,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-batch' - implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' +// implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' implementation project(":spring-batch-mongo") diff --git a/spring-batch-mongo-example/src/main/resources/application.yml b/spring-batch-mongo-example/src/main/resources/application.yml index 8065a21..4ab3a94 100644 --- a/spring-batch-mongo-example/src/main/resources/application.yml +++ b/spring-batch-mongo-example/src/main/resources/application.yml @@ -2,7 +2,7 @@ spring: data: mongodb: uri: mongodb://localhost:27017/?replicaSet=rs0 - database: Test + database: test batch: job: enabled: false diff --git a/spring-batch-mongo/build.gradle b/spring-batch-mongo/build.gradle index 46ecc69..afce6b7 100644 --- a/spring-batch-mongo/build.gradle +++ b/spring-batch-mongo/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'java' + id 'java-library' id "io.freefair.lombok" version "6.4.0" // id 'jacoco' id 'pmd' @@ -19,7 +19,7 @@ repositories { dependencies { implementation 'org.springframework.batch:spring-batch-core:4.3.4' - implementation 'org.springframework.data:spring-data-mongodb:3.3.1' + implementation 'org.springframework.data:spring-data-mongodb:3.2.8' implementation 'org.netbeans.api:org-netbeans-api-annotations-common:RELEASE126' testImplementation 'org.junit.jupiter:junit-jupiter' diff --git a/spring-batch-mongo/src/main/java/io/github/wirednerd/springbatch/mongo/explore/MongodbJobExplorer.java b/spring-batch-mongo/src/main/java/io/github/wirednerd/springbatch/mongo/explore/MongodbJobExplorer.java index 5c5db40..cb1f363 100644 --- a/spring-batch-mongo/src/main/java/io/github/wirednerd/springbatch/mongo/explore/MongodbJobExplorer.java +++ b/spring-batch-mongo/src/main/java/io/github/wirednerd/springbatch/mongo/explore/MongodbJobExplorer.java @@ -256,7 +256,7 @@ public JobExecution getLastJobExecution(JobInstance jobInstance) { public Set findRunningJobExecutions(String jobName) { return mongoTemplate.find(Query.query(Criteria.where(JOB_NAME).is(jobName)) .addCriteria(Criteria.where(START_TIME).ne(null)) - .addCriteria(Criteria.where(END_TIME).isNull()) + .addCriteria(Criteria.where(END_TIME).is(null)) .with(Sort.by(JOB_EXECUTION_ID).descending()), Document.class, jobCollectionName) .stream().map(JobExecutionConverter::convert) diff --git a/spring-batch-mongo/src/main/java/io/github/wirednerd/springbatch/mongo/repository/MongodbJobRepository.java b/spring-batch-mongo/src/main/java/io/github/wirednerd/springbatch/mongo/repository/MongodbJobRepository.java index 023c54a..65fa10a 100644 --- a/spring-batch-mongo/src/main/java/io/github/wirednerd/springbatch/mongo/repository/MongodbJobRepository.java +++ b/spring-batch-mongo/src/main/java/io/github/wirednerd/springbatch/mongo/repository/MongodbJobRepository.java @@ -324,7 +324,7 @@ private JobExecution insertNewJobExecution(JobExecution jobExecution) { mongoTemplate.upsert(new Query() .addCriteria(Criteria.where(JOB_NAME).is(jobExecution.getJobInstance().getJobName())) .addCriteria(Criteria.where(JOB_KEY).is(jobKeyGenerator.generateKey(jobExecution.getJobParameters()))) - .addCriteria(Criteria.where(JOB_EXECUTION_ID).isNull()), + .addCriteria(Criteria.where(JOB_EXECUTION_ID).is(null)), Update.fromDocument(JobExecutionConverter.convert(jobExecution)), jobCollectionName); return jobExecution; diff --git a/spring-batch-mongo/src/test/java/io/github/wirednerd/springbatch/mongo/repository/MongodbJobRepositoryTest.java b/spring-batch-mongo/src/test/java/io/github/wirednerd/springbatch/mongo/repository/MongodbJobRepositoryTest.java index 4e71830..44d5142 100644 --- a/spring-batch-mongo/src/test/java/io/github/wirednerd/springbatch/mongo/repository/MongodbJobRepositoryTest.java +++ b/spring-batch-mongo/src/test/java/io/github/wirednerd/springbatch/mongo/repository/MongodbJobRepositoryTest.java @@ -192,12 +192,12 @@ void createJobExecutionWithConfigName() { void createJobExecutionWithConfigName_replaceJobInstance() { var jobInstance = repository.createJobInstance("New Job", jobExecution.getJobParameters()); - assertEquals(1, mongoTemplate.find(new Query(Criteria.where("jobInstanceId").is(jobInstance.getId())).addCriteria(Criteria.where(JOB_EXECUTION_ID).isNull()), Document.class, jobCollectionName).size()); + assertEquals(1, mongoTemplate.find(new Query(Criteria.where("jobInstanceId").is(jobInstance.getId())).addCriteria(Criteria.where(JOB_EXECUTION_ID).is(null)), Document.class, jobCollectionName).size()); assertEquals(0, mongoTemplate.find(new Query(Criteria.where("jobInstanceId").is(jobInstance.getId())).addCriteria(Criteria.where(JOB_EXECUTION_ID).gte(0L)), Document.class, jobCollectionName).size()); var jobExecution = repository.createJobExecution(jobInstance, this.jobExecution.getJobParameters(), this.jobExecution.getJobConfigurationName()); - assertEquals(0, mongoTemplate.find(new Query(Criteria.where("jobInstanceId").is(jobInstance.getId())).addCriteria(Criteria.where(JOB_EXECUTION_ID).isNull()), Document.class, jobCollectionName).size()); + assertEquals(0, mongoTemplate.find(new Query(Criteria.where("jobInstanceId").is(jobInstance.getId())).addCriteria(Criteria.where(JOB_EXECUTION_ID).is(null)), Document.class, jobCollectionName).size()); assertEquals(1, mongoTemplate.find(new Query(Criteria.where("jobInstanceId").is(jobInstance.getId())).addCriteria(Criteria.where(JOB_EXECUTION_ID).is(jobExecution.getId())), Document.class, jobCollectionName).size()); } From 6c50db2f1c816a7e530baac61333fa9020780cd9 Mon Sep 17 00:00:00 2001 From: Peter Busch <97931970+WiredNerd@users.noreply.github.com> Date: Mon, 14 Feb 2022 17:21:23 -0600 Subject: [PATCH 2/3] Update gradle.properties --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 35f6434..53bf690 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=io.github.wirednerd -version=1.0.0 \ No newline at end of file +version=1.0.1 From 58c4b1ed772f6de3c8571e7babaccc38ca1ef98b Mon Sep 17 00:00:00 2001 From: WiredNerd Date: Mon, 14 Feb 2022 17:22:58 -0600 Subject: [PATCH 3/3] dependency in example project --- spring-batch-mongo-example/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-batch-mongo-example/build.gradle b/spring-batch-mongo-example/build.gradle index 3339b39..3208d88 100644 --- a/spring-batch-mongo-example/build.gradle +++ b/spring-batch-mongo-example/build.gradle @@ -16,7 +16,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-batch' -// implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' + implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' implementation project(":spring-batch-mongo")