001/* 002 * Copyright 2002-2014 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 */ 032public interface DatabasePopulator { 033 034 /** 035 * Populate, initialize, or clean up the database using the provided JDBC 036 * connection. 037 * <p>Concrete implementations <em>may</em> throw an {@link SQLException} if 038 * an error is encountered but are <em>strongly encouraged</em> to throw a 039 * specific {@link ScriptException} instead. For example, Spring's 040 * {@link ResourceDatabasePopulator} and {@link DatabasePopulatorUtils} wrap 041 * all {@code SQLExceptions} in {@code ScriptExceptions}. 042 * @param connection the JDBC connection to use to populate the db; already 043 * configured and ready to use; never {@code null} 044 * @throws SQLException if an unrecoverable data access exception occurs 045 * during database population 046 * @throws ScriptException in all other error cases 047 * @see DatabasePopulatorUtils#execute 048 */ 049 void populate(Connection connection) throws SQLException, ScriptException; 050 051}