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

#697: add support for cleaning 'JAVA SOURCE' in Oracle DB #698

Merged
merged 2 commits into from Feb 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -126,6 +126,10 @@ protected void doClean() throws SQLException {
for (String statement : generateDropStatementsForObjectType("TYPE", "FORCE")) {
jdbcTemplate.execute(statement);
}

for (String statement : generateDropStatementsForObjectType("JAVA SOURCE", "")) {
jdbcTemplate.execute(statement);
}
}

/**
Expand Down
Expand Up @@ -26,6 +26,7 @@
import com.googlecode.flyway.core.DbCategory;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -281,4 +282,25 @@ public void referencePartitionedTable() throws FlywayException {
flyway.clean();
flyway.migrate();
}

/**
* Tests support for cleaning together with JAVA SOURCE Type.
*/
@Test
public void javaSource() throws FlywayException, SQLException {
flyway.setLocations("com/googlecode/flyway/core/dbsupport/oracle/sql/javaSource");

flyway.migrate();
assertTrue(isExistMyJavaSource());

flyway.clean();
assertFalse(isExistMyJavaSource());
}

private boolean isExistMyJavaSource() throws SQLException {
String query = "SELECT count(*) FROM all_objects WHERE object_name = ? AND owner = ?";
String objectName = "MyJavaSource";
String owner = flyway.getSchemas()[0];
return jdbcTemplate.queryForInt(query, objectName, owner) != 0;
}
}
@@ -0,0 +1,32 @@
package com.googlecode.flyway.core.dbsupport.oracle.sql.javaSource;

import java.sql.Connection;
import java.sql.PreparedStatement;

import com.googlecode.flyway.core.api.migration.jdbc.JdbcMigration;

public class V1__JavaSource implements JdbcMigration {

private static final String SOURCE_SQL =
"CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED \"MyJavaSource\" AS\n" +
"public class MyJavaSource {\n" +
" public static int sum(int a, int b) { return a + b; }\n" +
"}";

public static void main(String[] args) {
System.out.println(SOURCE_SQL);
}

public void migrate(Connection connection) throws Exception {
PreparedStatement statement =
connection.prepareStatement(SOURCE_SQL);
try {
statement.setEscapeProcessing(false);
statement.execute();
} finally {
statement.close();
}
}


}