CptPicard
CptPicard

Reputation: 325

Quartz scheduler and programmatically setting datasource

I'm integrating Quartz into my application and wondering if there is a way to set up my scheduler with a DataSource that I already have configured and at hand? Do I need to use the SchedulerFactory somehow?

Upvotes: 2

Views: 3375

Answers (2)

Sergio
Sergio

Reputation: 438

To expand on @Javadroider answer, you have to have a ConnectionProvider implementation and have configured quartz to instantiate it. "After instantiating the class, Quartz can automatically set configuration properties on the instance, bean-style". This means you have to have fields on your properties, and setters for them; quartz will take care of calling the setters.

Ex:

public class FooConnectionProvider implements ConnectionProvider {

private String connectionString;

@Override 
public Connection getConnection() throws SQLException {
    return null;
}

@Override 
public void shutdown() throws SQLException {

}

@Override public void initialize() throws SQLException {

}

public void setConnectionString(String connectionString) {
    this.connectionString = connectionString;
}

}

properties file: org.quartz.dataSource.myCustomDS.connectionProvider.class = com.foo.FooConnectionProvider org.quartz.dataSource.myCustomDS.connectionString=connectionString

Upvotes: 2

Javadroider
Javadroider

Reputation: 2450

You need to implement ConnectionProvider

And specify property org.quartz.dataSource.standalone.connectionProvider.class in quart.properties

for ex : org.quartz.dataSource.standalone.connectionProvider.class = com.mycompany.CustomConnectionProvider

Upvotes: 2

Related Questions