Skip to content

Commit

Permalink
Add static variable for metadata table string path
Browse files Browse the repository at this point in the history
  • Loading branch information
spring0913 committed May 5, 2024
1 parent f6dcea8 commit d76a4e1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.resource.DatabaseResource;
import org.springframework.batch.core.scope.context.JobContext;
import org.springframework.batch.core.scope.context.StepContext;
import org.springframework.batch.item.Chunk;
Expand All @@ -83,7 +84,7 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
"java.util.concurrent.ConcurrentHashMap$Segment");

// resource hints
hints.resources().registerPattern("org/springframework/batch/core/schema-h2.sql");
hints.resources().registerPattern(DatabaseResource.SCHEMA_H2);
hints.resources().registerPattern("org/springframework/batch/core/schema-derby.sql");
hints.resources().registerPattern("org/springframework/batch/core/schema-hsqldb.sql");
hints.resources().registerPattern("org/springframework/batch/core/schema-sqlite.sql");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.springframework.batch.core.resource;

public class DatabaseResource {

public static final String SCHEMA_H2 = "/org/springframework/batch/core/schema-h2.sql";
public static final String SCHEMA_DROP_H2 = "/org/springframework/batch/core/schema-drop-h2.sql";

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.resource.DatabaseResource;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -70,8 +71,8 @@ public Job job(JobRepository jobRepository, PlatformTransactionManager transacti
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
.addScript("/org/springframework/batch/core/schema-drop-h2.sql")
.addScript("/org/springframework/batch/core/schema-h2.sql")
.addScript(DatabaseResource.SCHEMA_DROP_H2)
.addScript(DatabaseResource.SCHEMA_H2)
.generateUniqueName(true)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.core.resource.DatabaseResource;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -203,7 +204,7 @@ public Job job(JobRepository jobRepository, Step step) {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
.addScript("/org/springframework/batch/core/schema-h2.sql")
.addScript(DatabaseResource.SCHEMA_H2)
.generateUniqueName(true)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.resource.DatabaseResource;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
Expand Down Expand Up @@ -76,7 +77,7 @@ private static DataSource buildDataSource(ModeEnum compatibilityMode) {
UUID.randomUUID(), compatibilityMode);
var dataSource = new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", "");
var populator = new ResourceDatabasePopulator();
var resource = new DefaultResourceLoader().getResource("/org/springframework/batch/core/schema-h2.sql");
var resource = new DefaultResourceLoader().getResource(DatabaseResource.SCHEMA_H2);
populator.addScript(resource);
DatabasePopulatorUtils.execute(populator, dataSource);
return dataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.resource.DatabaseResource;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -74,7 +75,7 @@ static class TestConfiguration {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
.addScript("/org/springframework/batch/core/schema-h2.sql")
.addScript(DatabaseResource.SCHEMA_H2)
.generateUniqueName(true)
.build();
}
Expand Down

0 comments on commit d76a4e1

Please sign in to comment.