Skip to content

Commit c2459b4

Browse files
committed
Full Quartz 2.2 support, including LocalDataSourceJobStore
While we've had basic Quartz 2.2 support before, a few details were missing: * LocalDataSourceJobStore's ConnectionProvider adapters need to provide an empty implementation of Quartz 2.2's new initialize method. * SchedulerFactoryBean's "schedulerContextMap" needs to be explicitly declared with String keys, otherwise it can't be compiled against Quartz 2.2 (forward compatibility once we're dropping Quartz 1.x support). This doesn't hurt against older Quartz versions either, since the keys need to be Strings anyway. Issue: SPR-11284 (cherry picked from commit 38a8ace)
1 parent 4f24643 commit c2459b4

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalDataSourceJobStore.java

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
1818

1919
import java.sql.Connection;
2020
import java.sql.SQLException;
21-
2221
import javax.sql.DataSource;
2322

2423
import org.quartz.SchedulerConfigException;
@@ -108,14 +107,17 @@ public Connection getConnection() throws SQLException {
108107
public void shutdown() {
109108
// Do nothing - a Spring-managed DataSource has its own lifecycle.
110109
}
110+
/* Quartz 2.2 initialize method */
111+
public void initialize() {
112+
// Do nothing - a Spring-managed DataSource has its own lifecycle.
113+
}
111114
}
112115
);
113116

114117
// Non-transactional DataSource is optional: fall back to default
115118
// DataSource if not explicitly specified.
116119
DataSource nonTxDataSource = SchedulerFactoryBean.getConfigTimeNonTransactionalDataSource();
117-
final DataSource nonTxDataSourceToUse =
118-
(nonTxDataSource != null ? nonTxDataSource : this.dataSource);
120+
final DataSource nonTxDataSourceToUse = (nonTxDataSource != null ? nonTxDataSource : this.dataSource);
119121

120122
// Configure non-transactional connection settings for Quartz.
121123
setNonManagedTXDataSource(NON_TX_DATA_SOURCE_PREFIX + getInstanceName());
@@ -131,21 +133,24 @@ public Connection getConnection() throws SQLException {
131133
public void shutdown() {
132134
// Do nothing - a Spring-managed DataSource has its own lifecycle.
133135
}
136+
/* Quartz 2.2 initialize method */
137+
public void initialize() {
138+
// Do nothing - a Spring-managed DataSource has its own lifecycle.
139+
}
134140
}
135141
);
136142

137-
// No, if HSQL is the platform, we really don't want to use locks
143+
// No, if HSQL is the platform, we really don't want to use locks...
138144
try {
139-
String productName = JdbcUtils.extractDatabaseMetaData(dataSource,
140-
"getDatabaseProductName").toString();
145+
String productName = JdbcUtils.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName").toString();
141146
productName = JdbcUtils.commonDatabaseName(productName);
142-
if (productName != null
143-
&& productName.toLowerCase().contains("hsql")) {
147+
if (productName != null && productName.toLowerCase().contains("hsql")) {
144148
setUseDBLocks(false);
145149
setLockHandler(new SimpleSemaphore());
146150
}
147-
} catch (MetaDataAccessException e) {
148-
logWarnIfNonZero(1, "Could not detect database type. Assuming locks can be taken.");
151+
}
152+
catch (MetaDataAccessException ex) {
153+
logWarnIfNonZero(1, "Could not detect database type. Assuming locks can be taken.");
149154
}
150155

151156
super.initialize(loadHelper, signaler);

spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.springframework.core.io.ResourceLoader;
4444
import org.springframework.core.io.support.PropertiesLoaderUtils;
4545
import org.springframework.scheduling.SchedulingException;
46+
import org.springframework.util.Assert;
4647
import org.springframework.util.CollectionUtils;
4748

4849
/**
@@ -157,7 +158,7 @@ public static DataSource getConfigTimeNonTransactionalDataSource() {
157158
}
158159

159160

160-
private Class<?> schedulerFactoryClass = StdSchedulerFactory.class;
161+
private Class<? extends SchedulerFactory> schedulerFactoryClass = StdSchedulerFactory.class;
161162

162163
private String schedulerName;
163164

@@ -173,7 +174,7 @@ public static DataSource getConfigTimeNonTransactionalDataSource() {
173174
private DataSource nonTransactionalDataSource;
174175

175176

176-
private Map schedulerContextMap;
177+
private Map<String, ?> schedulerContextMap;
177178

178179
private ApplicationContext applicationContext;
179180

@@ -200,18 +201,16 @@ public static DataSource getConfigTimeNonTransactionalDataSource() {
200201

201202
/**
202203
* Set the Quartz SchedulerFactory implementation to use.
203-
* <p>Default is StdSchedulerFactory, reading in the standard
204+
* <p>Default is {@link StdSchedulerFactory}, reading in the standard
204205
* {@code quartz.properties} from {@code quartz.jar}.
205206
* To use custom Quartz properties, specify the "configLocation"
206207
* or "quartzProperties" bean property on this FactoryBean.
207208
* @see org.quartz.impl.StdSchedulerFactory
208209
* @see #setConfigLocation
209210
* @see #setQuartzProperties
210211
*/
211-
public void setSchedulerFactoryClass(Class schedulerFactoryClass) {
212-
if (schedulerFactoryClass == null || !SchedulerFactory.class.isAssignableFrom(schedulerFactoryClass)) {
213-
throw new IllegalArgumentException("schedulerFactoryClass must implement [org.quartz.SchedulerFactory]");
214-
}
212+
public void setSchedulerFactoryClass(Class<? extends SchedulerFactory> schedulerFactoryClass) {
213+
Assert.isAssignable(SchedulerFactory.class, schedulerFactoryClass);
215214
this.schedulerFactoryClass = schedulerFactoryClass;
216215
}
217216

@@ -313,7 +312,7 @@ public void setNonTransactionalDataSource(DataSource nonTransactionalDataSource)
313312
* values (for example Spring-managed beans)
314313
* @see JobDetailBean#setJobDataAsMap
315314
*/
316-
public void setSchedulerContextAsMap(Map schedulerContextAsMap) {
315+
public void setSchedulerContextAsMap(Map<String, ?> schedulerContextAsMap) {
317316
this.schedulerContextMap = schedulerContextAsMap;
318317
}
319318

0 commit comments

Comments
 (0)