001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.autoconfigure.quartz;
018
019import java.time.Duration;
020import java.util.HashMap;
021import java.util.Map;
022
023import org.springframework.boot.context.properties.ConfigurationProperties;
024import org.springframework.boot.jdbc.DataSourceInitializationMode;
025
026/**
027 * Configuration properties for the Quartz Scheduler integration.
028 *
029 * @author Vedran Pavic
030 * @author Stephane Nicoll
031 * @since 2.0.0
032 */
033@ConfigurationProperties("spring.quartz")
034public class QuartzProperties {
035
036        /**
037         * Quartz job store type.
038         */
039        private JobStoreType jobStoreType = JobStoreType.MEMORY;
040
041        /**
042         * Name of the scheduler.
043         */
044        private String schedulerName;
045
046        /**
047         * Whether to automatically start the scheduler after initialization.
048         */
049        private boolean autoStartup = true;
050
051        /**
052         * Delay after which the scheduler is started once initialization completes. Setting
053         * this property makes sense if no jobs should be run before the entire application
054         * has started up.
055         */
056        private Duration startupDelay = Duration.ofSeconds(0);
057
058        /**
059         * Whether to wait for running jobs to complete on shutdown.
060         */
061        private boolean waitForJobsToCompleteOnShutdown = false;
062
063        /**
064         * Whether configured jobs should overwrite existing job definitions.
065         */
066        private boolean overwriteExistingJobs = false;
067
068        /**
069         * Additional Quartz Scheduler properties.
070         */
071        private final Map<String, String> properties = new HashMap<>();
072
073        private final Jdbc jdbc = new Jdbc();
074
075        public JobStoreType getJobStoreType() {
076                return this.jobStoreType;
077        }
078
079        public void setJobStoreType(JobStoreType jobStoreType) {
080                this.jobStoreType = jobStoreType;
081        }
082
083        public String getSchedulerName() {
084                return this.schedulerName;
085        }
086
087        public void setSchedulerName(String schedulerName) {
088                this.schedulerName = schedulerName;
089        }
090
091        public boolean isAutoStartup() {
092                return this.autoStartup;
093        }
094
095        public void setAutoStartup(boolean autoStartup) {
096                this.autoStartup = autoStartup;
097        }
098
099        public Duration getStartupDelay() {
100                return this.startupDelay;
101        }
102
103        public void setStartupDelay(Duration startupDelay) {
104                this.startupDelay = startupDelay;
105        }
106
107        public boolean isWaitForJobsToCompleteOnShutdown() {
108                return this.waitForJobsToCompleteOnShutdown;
109        }
110
111        public void setWaitForJobsToCompleteOnShutdown(
112                        boolean waitForJobsToCompleteOnShutdown) {
113                this.waitForJobsToCompleteOnShutdown = waitForJobsToCompleteOnShutdown;
114        }
115
116        public boolean isOverwriteExistingJobs() {
117                return this.overwriteExistingJobs;
118        }
119
120        public void setOverwriteExistingJobs(boolean overwriteExistingJobs) {
121                this.overwriteExistingJobs = overwriteExistingJobs;
122        }
123
124        public Map<String, String> getProperties() {
125                return this.properties;
126        }
127
128        public Jdbc getJdbc() {
129                return this.jdbc;
130        }
131
132        public static class Jdbc {
133
134                private static final String DEFAULT_SCHEMA_LOCATION = "classpath:org/quartz/impl/"
135                                + "jdbcjobstore/tables_@@platform@@.sql";
136
137                /**
138                 * Path to the SQL file to use to initialize the database schema.
139                 */
140                private String schema = DEFAULT_SCHEMA_LOCATION;
141
142                /**
143                 * Database schema initialization mode.
144                 */
145                private DataSourceInitializationMode initializeSchema = DataSourceInitializationMode.EMBEDDED;
146
147                /**
148                 * Prefix for single-line comments in SQL initialization scripts.
149                 */
150                private String commentPrefix = "--";
151
152                public String getSchema() {
153                        return this.schema;
154                }
155
156                public void setSchema(String schema) {
157                        this.schema = schema;
158                }
159
160                public DataSourceInitializationMode getInitializeSchema() {
161                        return this.initializeSchema;
162                }
163
164                public void setInitializeSchema(DataSourceInitializationMode initializeSchema) {
165                        this.initializeSchema = initializeSchema;
166                }
167
168                public String getCommentPrefix() {
169                        return this.commentPrefix;
170                }
171
172                public void setCommentPrefix(String commentPrefix) {
173                        this.commentPrefix = commentPrefix;
174                }
175
176        }
177
178}