XMLCatalogSchemaManager { public void createBaseSchema(Connection conn) throws CatalogException { Statement stmt; if (!isLoaded()) { throw new CatalogException("Database schema files are not loaded."); } try { stmt = conn.createStatement(); } catch (SQLException e) { throw new CatalogException(e.getMessage(), e); } for (DatabaseObject object: catalogStore.getSchema().getObjects()) { try { String[] params; if (DatabaseObjectType.INDEX == object.getType()) { params = new String[2]; params[0] = object.getDependsOn(); params[1] = object.getName(); } else { params = new String[1]; params[0] = object.getName(); } if (checkExistence(conn, object.getType(), params)) { LOG.info("Skip to create " + object.getName() + " databse object. Already exists."); } else { stmt.executeUpdate(object.getSql()); LOG.info(object.getName() + " " + object.getType() + " is created."); } } catch (SQLException e) { throw new CatalogException(e.getMessage(), e); } } CatalogUtil.closeQuietly(stmt); } 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 testCreateBaseSchema() throws Exception { XMLCatalogSchemaManager manager; Statement stmt; manager = new XMLCatalogSchemaManager("schemas/derbytest/loadtest"); assertThat(manager.isLoaded(), is(true)); stmt = conn.createStatement(); stmt.addBatch("create schema " + manager.getCatalogStore().getSchema().getSchemaName()); stmt.addBatch("set current schema " + manager.getCatalogStore().getSchema().getSchemaName()); stmt.executeBatch(); manager.createBaseSchema(conn); DatabaseMetaData metadata = conn.getMetaData(); ResultSet tables = metadata.getTables(null, manager.getCatalogStore().getSchema().getSchemaName().toUpperCase(), CatalogConstants.TB_PARTITION_METHODS, new String[] {"TABLE"}); assertTrue(tables.next()); assertEquals(CatalogConstants.TB_PARTITION_METHODS, tables.getString("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 = 'TAJO'"); assertThat(triggers, hasItemInResultSet("TABLESPACES_HIST_TRG", "TRIGGERNAME")); }