AbstractDdlBuilder implements IDdlBuilder { public String createTables(Database database, boolean dropTables) { StringBuilder ddl = new StringBuilder(); createTables(database, dropTables, ddl); return ddl.toString(); } AbstractDdlBuilder(String databaseName); DefaultValueHelper getDefaultValueHelper(); String getIndent(); void setIndent(String indent); String getValueLocale(); void setValueLocale(String localeStr); String createTables(Database database, boolean dropTables); void createTables(Database database, boolean dropTables, StringBuilder ddl); String alterDatabase(Database currentModel, Database desiredModel,
            IAlterDatabaseInterceptor... alterDatabaseInterceptors); String alterTable(Table currentTable, Table desiredTable,
            IAlterDatabaseInterceptor... alterDatabaseInterceptors); void alterDatabase(Database currentModel, Database desiredModel, StringBuilder ddl,
            IAlterDatabaseInterceptor... alterDatabaseInterceptors); boolean isAlterDatabase(Database currentModel, Database desiredModel,
            IAlterDatabaseInterceptor... alterDatabaseInterceptors); List<IModelChange> getDetectedChanges(Database currentModel, Database desiredModel, IAlterDatabaseInterceptor... alterDatabaseInterceptors); Table getBackupTableFor(Table sourceTable); Table createBackupTableFor(Database model, Table sourceTable, StringBuilder ddl); void restoreTableFromBackup(Table backupTable, Table targetTable, LinkedHashMap<Column, Column> columnMap,
            StringBuilder ddl); void writeCopyDataStatement(Table sourceTable, Table targetTable, StringBuilder ddl); void writeCopyDataStatement(Table sourceTable, Table targetTable, LinkedHashMap<Column, Column> columnMap,
            StringBuilder ddl); LinkedHashMap<Column, Column> getCopyDataColumnMapping(Table sourceTable, Table targetTable); LinkedHashMap<Column, Column> getCopyDataColumnOrderedMapping(Table sourceTable, Table targetTable); String createTable(Table table); void createExternalForeignKeys(Database database, StringBuilder ddl); void createExternalForeignKeys(Database database, Table table, StringBuilder ddl); String dropTables(Database database); void dropTables(Database database, StringBuilder ddl); void dropTable(Database database, Table table, StringBuilder ddl); void dropExternalForeignKeys(Table table, StringBuilder ddl); String getInsertSql(Table table, Map<String, Object> columnValues, boolean genPlaceholders); String getUpdateSql(Table table, Map<String, Object> columnValues, boolean genPlaceholders); String getDeleteSql(Table table, Map<String, Object> pkValues, boolean genPlaceholders); String getSelectLastIdentityValues(Table table); String fixLastIdentityValues(Table table); void writeFixLastIdentityValues(Table table, StringBuilder ddl); String shortenName(String name, int desiredLength); String getTableName(String tableName); String getColumnTypeDdl(Table table, Column column); boolean areColumnSizesTheSame(Column sourceColumn, Column targetColumn); String getForeignKeyName(Table table, ForeignKey fk); String getConstraintName(String prefix, Table table, String secondPart, String suffix); String getIndexName(IIndex index); void writeExternalIndexDropStmt(Table table, IIndex index, StringBuilder ddl); boolean isScriptModeOn(); void setScriptModeOn(boolean scriptModeOn); boolean isSqlCommentsOn(); void setSqlCommentsOn(boolean sqlCommentsOn); boolean isDelimitedIdentifierModeOn(); void setDelimitedIdentifierModeOn(boolean delimitedIdentifierModeOn); DatabaseInfo getDatabaseInfo(); void setCaseSensitive(boolean caseSensitive); boolean isCaseSensitive();  }
@Test public void testForeignKeySupport() throws Exception { for(DdlBuilderForeignKeySupport dbfs : foreignKeyDdlBuilders) { String ddl = dbfs.getDdlBuilder().createTables(database, false); if(dbfs.isSupportsOnDelete()) { if(Arrays.asList(dbfs.getOnDeleteForeignKeyAction()).contains(ForeignKeyAction.CASCADE)) { assertTrue("Failed to generate ON DELETE CASCADE for the following platform: " + dbfs.getDdlBuilder().databaseName, ddl.contains(" ON DELETE CASCADE")); } else { assertTrue("Failed to generate ddl without ON DELETE CASCADE for the following platform: " + dbfs.getDdlBuilder().databaseName, ! ddl.contains("ON DELETE CASCADE")); } assertTrue("Failed to generate ddl without ON DELETE RESTRICT for the following platform: " + dbfs.getDdlBuilder().databaseName, ! ddl.contains("ON DELETE RESTRICT")); assertTrue("Failed to generate ddl without ON DELETE NO ACTION for the following platform: " + dbfs.getDdlBuilder().databaseName, ! ddl.contains("ON DELETE NO ACTION")); if(Arrays.asList(dbfs.getOnDeleteForeignKeyAction()).contains(ForeignKeyAction.SETDEFAULT)) { assertTrue("Failed to generate ON DELETE SET DEFAULT for the following platform: " + dbfs.getDdlBuilder().databaseName, ddl.contains(" ON DELETE SET DEFAULT")); } else { assertTrue("Failed to generate ddl without ON DELETE SET DEFAULT for the following platform: " + dbfs.getDdlBuilder().databaseName, ! ddl.contains("ON DELETE SET DEFAULT")); } if(Arrays.asList(dbfs.getOnDeleteForeignKeyAction()).contains(ForeignKeyAction.SETNULL)) { assertTrue("Failed to generate ON DELETE SET NULL for the following platform: " + dbfs.getDdlBuilder().databaseName, ddl.contains(" ON DELETE SET NULL")); } else { assertTrue("Failed to generate ddl without ON DELETE SET NULL for the following platform: " + dbfs.getDdlBuilder().databaseName, ! ddl.contains("ON DELETE SET NULL")); } } if(dbfs.isSupportsOnUpdate()) { if(Arrays.asList(dbfs.getOnUpdateForeignKeyAction()).contains(ForeignKeyAction.CASCADE)) { assertTrue("Failed to generate ON UPDATE CASCADE for the following platform: " + dbfs.getDdlBuilder().databaseName, ddl.contains(" ON UPDATE CASCADE")); } else { assertTrue("Failed to generate ddl without ON UPDATE CASCADE for the following platform: " + dbfs.getDdlBuilder().databaseName, ! ddl.contains("ON UPDATE CASCADE")); } assertTrue("Failed to generate ddl without ON UPDATE RESTRICT for the following platform: " + dbfs.getDdlBuilder().databaseName, ! ddl.contains("ON UPDATE RESTRICT")); assertTrue("Failed to generate ddl without ON UPDATE NO ACTION for the following platform: " + dbfs.getDdlBuilder().databaseName, ! ddl.contains("ON UPDATE NO ACTION")); if(Arrays.asList(dbfs.getOnUpdateForeignKeyAction()).contains(ForeignKeyAction.SETDEFAULT)) { assertTrue("Failed to generate ON UPDATE SET DEFAULT for the following platform: " + dbfs.getDdlBuilder().databaseName, ddl.contains(" ON UPDATE SET DEFAULT")); } else { assertTrue("Failed to generate ddl without ON UPDATE SET DEFAULT for the following platform: " + dbfs.getDdlBuilder().databaseName, ! ddl.contains("ON UPDATE SET DEFAULT")); } if(Arrays.asList(dbfs.getOnUpdateForeignKeyAction()).contains(ForeignKeyAction.SETNULL)) { assertTrue("Failed to generate ON UPDATE SET NULL for the following platform: " + dbfs.getDdlBuilder().databaseName, ddl.contains(" ON UPDATE SET NULL")); } else { assertTrue("Failed to generate ddl without ON UPDATE SET NULL for the following platform: " + dbfs.getDdlBuilder().databaseName, ! ddl.contains("ON UPDATE SET NULL")); } } } }