Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright 2010-2016 Boxfuse GmbH
*
* 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.flywaydb.core.internal.dbsupport.derby;
import org.flywaydb.core.internal.dbsupport.JdbcTemplate;
import org.flywaydb.core.internal.dbsupport.Schema;
import org.flywaydb.core.internal.dbsupport.Table;
import org.flywaydb.core.internal.util.StringUtils;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Derby implementation of Schema.
*/
public class DerbySchema extends Schema {
/**
* Creates a new Derby schema.
*
* @param jdbcTemplate The Jdbc Template for communicating with the DB.
* @param dbSupport The database-specific support.
* @param name The name of the schema.
*/
public DerbySchema(JdbcTemplate jdbcTemplate, DerbyDbSupport dbSupport, String name) {
super(jdbcTemplate, dbSupport, name);
}
@Override
protected boolean doExists() throws SQLException {
return jdbcTemplate.queryForInt("SELECT COUNT (*) FROM sys.sysschemas WHERE schemaname=?", name) > 0;
}
@Override
protected boolean doEmpty() throws SQLException {
return allTables().length == 0;
}
@Override
protected void doCreate() throws SQLException {
jdbcTemplate.execute("CREATE SCHEMA " + dbSupport.quote(name));
}
@Override
protected void doDrop() throws SQLException {
clean();
jdbcTemplate.execute("DROP SCHEMA " + dbSupport.quote(name) + " RESTRICT");
}
@Override
protected void doClean() throws SQLException {
List triggerNames = listObjectNames("TRIGGER", "");
for (String statement : generateDropStatements("TRIGGER", triggerNames, "")) {
jdbcTemplate.execute(statement);
}
for (String statement : generateDropStatementsForConstraints()) {
jdbcTemplate.execute(statement);
}
List viewNames = listObjectNames("TABLE", "TABLETYPE='V'");
for (String statement : generateDropStatements("VIEW", viewNames, "")) {
jdbcTemplate.execute(statement);
}
for (Table table : allTables()) {
table.drop();
}
List sequenceNames = listObjectNames("SEQUENCE", "");
for (String statement : generateDropStatements("SEQUENCE", sequenceNames, "RESTRICT")) {
jdbcTemplate.execute(statement);
}
}
/**
* Generate the statements for dropping all the constraints in this schema.
*
* @return The list of statements.
* @throws SQLException when the statements could not be generated.
*/
private List generateDropStatementsForConstraints() throws SQLException {
List