Skip to content

Commit

Permalink
test: add and drop a materialized view
Browse files Browse the repository at this point in the history
Add to TestUtil and also to DatabaseMetaData setup and teardown

fixes pgjdbc#2060
  • Loading branch information
mgrobaker committed Jul 6, 2021
1 parent 0077af2 commit f13ab15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
25 changes: 25 additions & 0 deletions pgjdbc/src/test/java/org/postgresql/test/TestUtil.java
Expand Up @@ -525,6 +525,24 @@ public static void createView(Connection con, String viewName, String query)
}
}

/*
* Helper - creates a materialized view
*/
public static void createMaterializedView(Connection con, String matViewName, String query)
throws SQLException {
Statement st = con.createStatement();
try {
// Drop the view
dropView(con, matViewName);

String sql = "CREATE MATERIALIZED VIEW " + matViewName + " AS " + query;

st.executeUpdate(sql);
} finally {
closeQuietly(st);
}
}

/**
* Helper creates an enum type.
*
Expand Down Expand Up @@ -628,6 +646,13 @@ public static void dropView(Connection con, String view) throws SQLException {
dropObject(con, "VIEW", view);
}

/*
* Helper - drops a materialized view
*/
public static void dropMaterializedView(Connection con, String matView) throws SQLException {
dropObject(con, "MATERIALIZED VIEW", matView);
}

/*
* Helper - drops a type
*/
Expand Down
Expand Up @@ -81,6 +81,7 @@ public void setUp() throws Exception {
TestUtil.createTable(con, "arraytable", "a numeric(5,2)[], b varchar(100)[]");
TestUtil.createTable(con, "intarraytable", "a int4[], b int4[][]");
TestUtil.createView(con, "viewtest", "SELECT id, quest FROM metadatatest");
TestUtil.createMaterializedView(con, "matViewtest", "SELECT id, quest FROM metadatatest");
TestUtil.dropType(con, "custom");
TestUtil.dropType(con, "_custom");
TestUtil.createCompositeType(con, "custom", "i int", false);
Expand Down Expand Up @@ -126,6 +127,7 @@ public void tearDown() throws Exception {
stmt.execute("DROP FUNCTION f4(int)");

TestUtil.dropView(con, "viewtest");
TestUtil.dropMaterializedView(con, "matViewtest");
TestUtil.dropTable(con, "metadatatest");
TestUtil.dropTable(con, "sercoltest");
TestUtil.dropSequence(con, "sercoltest_b_seq");
Expand Down Expand Up @@ -208,7 +210,7 @@ public void testTables() throws Exception {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);

ResultSet rs = dbmd.getTables(null, null, "metadatates%", new String[]{"TABLE"});
ResultSet rs = dbmd.getTables(null, null, "metadatatest", new String[]{"TABLE"});
assertTrue(rs.next());
String tableName = rs.getString("TABLE_NAME");
assertEquals("metadatatest", tableName);
Expand Down

0 comments on commit f13ab15

Please sign in to comment.