001/* 002 * Copyright 2002-2016 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 * https://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.jdbc.datasource.init; 018 019import java.sql.Connection; 020import java.sql.SQLException; 021 022/** 023 * Strategy used to populate, initialize, or clean up a database. 024 * 025 * @author Keith Donald 026 * @author Sam Brannen 027 * @since 3.0 028 * @see ResourceDatabasePopulator 029 * @see DatabasePopulatorUtils 030 * @see DataSourceInitializer 031 */ 032@FunctionalInterface 033public interface DatabasePopulator { 034 035 /** 036 * Populate, initialize, or clean up the database using the provided JDBC 037 * connection. 038 * <p>Concrete implementations <em>may</em> throw an {@link SQLException} if 039 * an error is encountered but are <em>strongly encouraged</em> to throw a 040 * specific {@link ScriptException} instead. For example, Spring's 041 * {@link ResourceDatabasePopulator} and {@link DatabasePopulatorUtils} wrap 042 * all {@code SQLExceptions} in {@code ScriptExceptions}. 043 * @param connection the JDBC connection to use to populate the db; already 044 * configured and ready to use; never {@code null} 045 * @throws SQLException if an unrecoverable data access exception occurs 046 * during database population 047 * @throws ScriptException in all other error cases 048 * @see DatabasePopulatorUtils#execute 049 */ 050 void populate(Connection connection) throws SQLException, ScriptException; 051 052}