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

Use LocalDataSourceJobStore only if one is not specified via Quartz properties #27560

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -570,7 +570,7 @@ private void initSchedulerFactory(StdSchedulerFactory schedulerFactory) throws S

CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps);
if (this.dataSource != null) {
mergedProps.setProperty(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
mergedProps.putIfAbsent(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
}

// Determine scheduler name across local settings and Quartz properties...
Expand Down
Expand Up @@ -18,6 +18,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.sql.DataSource;

Expand All @@ -30,6 +31,7 @@
import org.quartz.SchedulerFactory;
import org.quartz.impl.JobDetailImpl;
import org.quartz.impl.SchedulerRepository;
import org.quartz.impl.jdbcjobstore.JobStoreTX;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
Expand All @@ -40,6 +42,8 @@
import org.springframework.core.task.TaskExecutor;
import org.springframework.core.testfixture.EnabledForTestGroups;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
Expand Down Expand Up @@ -396,6 +400,29 @@ public void schedulerWithHsqlDataSource() throws Exception {
}
}

@Test
public void schedulerFactoryBeanWithCustomJobStore() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();

final String dbName = "mydb";
final EmbeddedDatabase database = new EmbeddedDatabaseBuilder().setName(dbName).build();

final Properties properties = new Properties();
properties.setProperty("org.quartz.jobStore.class", JobStoreTX.class.getName());
properties.setProperty("org.quartz.jobStore.dataSource", dbName);

BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(SchedulerFactoryBean.class)
.addPropertyValue("autoStartup", false)
.addPropertyValue("dataSource", database)
.addPropertyValue("quartzProperties", properties)
.getBeanDefinition();
context.registerBeanDefinition("scheduler", beanDefinition);

Scheduler bean = context.getBean("scheduler", Scheduler.class);

assertThat(bean.getMetaData().getJobStoreClass()).isEqualTo(JobStoreTX.class);
}

private ClassPathXmlApplicationContext context(String path) {
return new ClassPathXmlApplicationContext(path, getClass());
}
Expand Down