XMLCatalogSchemaManager { public void dropBaseSchema(Connection conn) throws CatalogException { if (!isLoaded()) { throw new CatalogException("Schema files are not loaded yet."); } List<DatabaseObject> failedObjects = new ArrayList<DatabaseObject>(); Statement stmt = null; try { stmt = conn.createStatement(); } catch (SQLException e) { throw new CatalogException(e.getMessage(), e); } for (DatabaseObject object: catalogStore.getSchema().getObjects()) { try { if (DatabaseObjectType.TABLE == object.getType() || DatabaseObjectType.SEQUENCE == object.getType() || DatabaseObjectType.VIEW == object.getType()) { stmt.executeUpdate(getDropSQL(object.getType(), object.getName())); } } catch (SQLException e) { failedObjects.add(object); } } CatalogUtil.closeQuietly(stmt); if (failedObjects.size() > 0) { StringBuffer errorMessage = new StringBuffer(64); errorMessage.append("Failed to drop database objects "); for (int idx = 0; idx < failedObjects.size(); idx++) { DatabaseObject object = failedObjects.get(idx); errorMessage.append(object.getType().toString()).append(" ") .append(object.getName()); if ((idx+1) < failedObjects.size()) { errorMessage.append(','); } } LOG.warn(errorMessage.toString()); } } XMLCatalogSchemaManager(String schemaPath); void dropBaseSchema(Connection conn); void createBaseSchema(Connection conn); void upgradeBaseSchema(Connection conn, int currentVersion); boolean isInitialized(Connection conn); boolean isLoaded();  }
@Test public void testDropBaseSchema() throws Exception { XMLCatalogSchemaManager manager; DatabaseMetaData meta; Statement stmt; manager = new XMLCatalogSchemaManager("schemas/derbytest/querytest"); assertThat(manager.isLoaded(), is(true)); assertThat(manager.getCatalogStore().getDropStatements(), hasSize(1)); stmt = conn.createStatement(); stmt.addBatch("CREATE SCHEMA " + manager.getCatalogStore().getSchema().getSchemaName()); stmt.addBatch("SET CURRENT SCHEMA " + manager.getCatalogStore().getSchema().getSchemaName()); stmt.addBatch("CREATE TABLE TESTTABLE1 (COL1 INT, COL2 VARCHAR(10))"); stmt.addBatch("CREATE TABLE TESTTABLE2 (COL1 INT, COL2 VARCHAR(10))"); stmt.addBatch("CREATE INDEX TESTINDEX1 ON TESTTABLE1 (COL1)"); stmt.addBatch("CREATE TRIGGER TESTTRIGGER1 " + " AFTER INSERT ON TESTTABLE1 " + " REFERENCING NEW AS NEWROW " + " FOR EACH ROW " + " INSERT INTO TESTTABLE2 " + " (COL1, COL2) " + " VALUES " + " (NEWROW.COL1, NEWROW.COL2)"); stmt.addBatch("CREATE SEQUENCE TESTSEQ AS INT"); stmt.addBatch("CREATE VIEW TESTVIEW (TESTTEXT) AS VALUES 'Text1', 'Text2'"); stmt.executeBatch(); meta = conn.getMetaData(); assertThat(meta.getTables(null, manager.getCatalogStore().getSchema().getSchemaName().toUpperCase(), null, new String[] {"TABLE"}), allOf(hasItemInResultSet("TESTTABLE1", "TABLE_NAME"), hasItemInResultSet("TESTTABLE2", "TABLE_NAME"))); assertThat(meta.getIndexInfo(null, manager.getCatalogStore().getSchema().getSchemaName().toUpperCase(), "TESTTABLE1", false, true), hasItemInResultSet("TESTINDEX1", "INDEX_NAME")); manager.dropBaseSchema(conn); assertThat(meta.getTables(null, manager.getCatalogStore().getSchema().getSchemaName().toUpperCase(), null, new String[] {"TABLE"}), allOf(not(hasItemInResultSet("TESTTABLE1", "TABLE_NAME")), not(hasItemInResultSet("TESTTABLE2", "TABLE_NAME")))); ResultSet triggers = stmt.executeQuery("select a.TRIGGERNAME from SYS.SYSTRIGGERS a inner join SYS.SYSSCHEMAS b " + " on a.SCHEMAID = b.SCHEMAID where b.SCHEMANAME = '" + manager.getCatalogStore().getSchema().getSchemaName().toUpperCase() + "'"); assertThat(triggers, not(hasItemInResultSet("TESTTRIGGER1", "TRIGGERNAME"))); ResultSet views = stmt.executeQuery("select a.TABLENAME from SYS.SYSTABLES a inner join SYS.SYSSCHEMAS b " + " on a.SCHEMAID = b.SCHEMAID where a.TABLETYPE = 'V' and b.SCHEMANAME = '" + manager.getCatalogStore().getSchema().getSchemaName().toUpperCase() + "'"); assertThat(views, not(hasItemInResultSet("TESTVIEW", "TABLENAME"))); }