Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static variable for metadata table string path #4587

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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