001/* 002 * Copyright 2012-2017 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.batch; 018 019import org.springframework.boot.context.properties.ConfigurationProperties; 020 021/** 022 * Configuration properties for Spring Batch. 023 * 024 * @author Stephane Nicoll 025 * @author Eddú Meléndez 026 * @author Vedran Pavic 027 * @since 1.2.0 028 */ 029@ConfigurationProperties(prefix = "spring.batch") 030public class BatchProperties { 031 032 private static final String DEFAULT_SCHEMA_LOCATION = "classpath:org/springframework/" 033 + "batch/core/schema-@@platform@@.sql"; 034 035 /** 036 * Path to the SQL file to use to initialize the database schema. 037 */ 038 private String schema = DEFAULT_SCHEMA_LOCATION; 039 040 /** 041 * Table prefix for all the batch meta-data tables. 042 */ 043 private String tablePrefix; 044 045 private final Initializer initializer = new Initializer(); 046 047 private final Job job = new Job(); 048 049 public String getSchema() { 050 return this.schema; 051 } 052 053 public void setSchema(String schema) { 054 this.schema = schema; 055 } 056 057 public String getTablePrefix() { 058 return this.tablePrefix; 059 } 060 061 public void setTablePrefix(String tablePrefix) { 062 this.tablePrefix = tablePrefix; 063 } 064 065 public Initializer getInitializer() { 066 return this.initializer; 067 } 068 069 public Job getJob() { 070 return this.job; 071 } 072 073 public class Initializer { 074 075 /** 076 * Create the required batch tables on startup if necessary. Enabled automatically 077 * if no custom table prefix is set or if a custom schema is configured. 078 */ 079 private Boolean enabled; 080 081 public boolean isEnabled() { 082 if (this.enabled != null) { 083 return this.enabled; 084 } 085 boolean defaultTablePrefix = BatchProperties.this.getTablePrefix() == null; 086 boolean customSchema = !DEFAULT_SCHEMA_LOCATION 087 .equals(BatchProperties.this.getSchema()); 088 return (defaultTablePrefix || customSchema); 089 } 090 091 public void setEnabled(boolean enabled) { 092 this.enabled = enabled; 093 } 094 095 } 096 097 public static class Job { 098 099 /** 100 * Comma-separated list of job names to execute on startup. By default, all Jobs 101 * found in the context are executed. 102 */ 103 private String names = ""; 104 105 public String getNames() { 106 return this.names; 107 } 108 109 public void setNames(String names) { 110 this.names = names; 111 } 112 113 } 114 115}