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 javax.sql.DataSource;
020
021import org.springframework.boot.jdbc.AbstractDataSourceInitializer;
022import org.springframework.boot.jdbc.DataSourceInitializationMode;
023import org.springframework.core.io.ResourceLoader;
024import org.springframework.util.Assert;
025
026/**
027 * Initialize the Spring Batch schema (ignoring errors, so should be idempotent).
028 *
029 * @author Dave Syer
030 * @author Vedran Pavic
031 */
032public class BatchDataSourceInitializer extends AbstractDataSourceInitializer {
033
034        private final BatchProperties properties;
035
036        public BatchDataSourceInitializer(DataSource dataSource,
037                        ResourceLoader resourceLoader, BatchProperties properties) {
038                super(dataSource, resourceLoader);
039                Assert.notNull(properties, "BatchProperties must not be null");
040                this.properties = properties;
041        }
042
043        @Override
044        protected DataSourceInitializationMode getMode() {
045                return this.properties.getInitializeSchema();
046        }
047
048        @Override
049        protected String getSchemaLocation() {
050                return this.properties.getSchema();
051        }
052
053        @Override
054        protected String getDatabaseName() {
055                String databaseName = super.getDatabaseName();
056                if ("oracle".equals(databaseName)) {
057                        return "oracle10g";
058                }
059                return databaseName;
060        }
061
062}