Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB2/Z Support cleanup of stored procedures with dependent procedures #82

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,19 @@ protected void doClean() throws SQLException {
jdbcTemplate.execute(dropStatement);
}

// procedures
for (String dropStatement : generateDropStatementsForProcedures()) {
jdbcTemplate.execute(dropStatement);
}

// triggers
for (String dropStatement : generateDropStatementsForTriggers()) {
jdbcTemplate.execute(dropStatement);
}

// drop procedures by iteratively dropping procedues without dependents (until no procedures are remaining)
do {
dropStatements = generateDropStatementsForProceduresWithoutDependents();
for (String dropStatement : dropStatements) {
jdbcTemplate.execute(dropStatement);
}
} while (dropStatements.size() > 0);

for (Function function : allFunctions()) {
function.drop();
}
Expand All @@ -176,14 +179,16 @@ private String getSqlId() {
}

/**
* Generates DROP statements for the procedures in this schema.
* Generates DROP statements for the procedures in this schema that do not have dependent procedures.
*
* @return The drop statements.
* @throws SQLException when the statements could not be generated.
*/
private List<String> generateDropStatementsForProcedures() throws SQLException {
String dropProcGenQuery = "select rtrim(NAME) from SYSIBM.SYSROUTINES where CAST_FUNCTION = 'N' " +
" and ROUTINETYPE = 'P' and SCHEMA = '" + name + "' and OWNER = '" + this.getSqlId() + "'";
private List<String> generateDropStatementsForProceduresWithoutDependents() throws SQLException {
String dropProcGenQuery = "select rtrim(sr.NAME) from SYSIBM.SYSROUTINES sr where sr.CAST_FUNCTION = 'N'" +
" and sr.ROUTINETYPE = 'P' and sr.SCHEMA = '" + name + "' and sr.OWNER = '" + this.getSqlId() + "'" +
" and not exists ( select * from SYSIBM.SYSDEPENDENCIES sd where sd.BNAME=sr.NAME" +
" and sd.BSCHEMA=sr.SCHEMA and sd.DTYPE='O' )";
return buildDropStatements("DROP PROCEDURE", dropProcGenQuery);
}

Expand Down