
org.apache.ibatis.migration.operations.DatabaseOperation Maven / Gradle / Ivy
/**
* Copyright 2010-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.migration.operations;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.jdbc.SqlRunner;
import org.apache.ibatis.migration.Change;
import org.apache.ibatis.migration.ConnectionProvider;
import org.apache.ibatis.migration.MigrationException;
import org.apache.ibatis.migration.MigrationLoader;
import org.apache.ibatis.migration.options.DatabaseOperationOption;
public abstract class DatabaseOperation> {
public abstract T operate(ConnectionProvider connectionProvider, MigrationLoader migrationsLoader, DatabaseOperationOption option, PrintStream printStream);
protected void insertChangelog(Change change, ConnectionProvider connectionProvider, DatabaseOperationOption option) {
SqlRunner runner = getSqlRunner(connectionProvider);
change.setAppliedTimestamp(generateAppliedTimeStampAsString());
try {
runner.insert("insert into " + option.getChangelogTable() + " (ID, APPLIED_AT, DESCRIPTION) values (?,?,?)", change.getId(), change.getAppliedTimestamp(), change.getDescription());
} catch (SQLException e) {
throw new MigrationException("Error querying last applied migration. Cause: " + e, e);
} finally {
runner.closeConnection();
}
}
protected Change getLastAppliedChange(ConnectionProvider connectionProvider, DatabaseOperationOption option) {
List changelog = getChangelog(connectionProvider, option);
return changelog.isEmpty() ? null : changelog.get(changelog.size() - 1);
}
protected List getChangelog(ConnectionProvider connectionProvider, DatabaseOperationOption option) {
SqlRunner runner = getSqlRunner(connectionProvider);
try {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy