From 71223895ac458f18e7d1ca6d7c2b01d99bce43fb Mon Sep 17 00:00:00 2001 From: rbygrave Date: Mon, 2 Aug 2021 20:38:05 +1200 Subject: [PATCH] #2283 - ddl-generator - Refactor tidy whitespace etc --- .../io/ebean/dbmigration/DbMigration.java | 19 ++---- .../dbmigration/LastMigration.java | 3 +- .../UnknownResourcePathException.java | 1 - .../dbmigration/model/CurrentModel.java | 10 +-- .../model/MCompoundUniqueConstraint.java | 4 -- .../dbmigration/model/MConfiguration.java | 3 +- .../dbmigration/model/MIndex.java | 4 +- .../dbmigration/model/MTable.java | 65 ++----------------- .../dbmigration/model/MTableIdentity.java | 2 - .../dbmigration/model/MigrationModel.java | 16 +---- .../dbmigration/model/MigrationResource.java | 3 +- .../dbmigration/model/ModelContainer.java | 5 +- .../dbmigration/model/ModelDiff.java | 16 ++--- .../dbmigration/model/PendingDrops.java | 12 ---- .../dbmigration/model/PlatformDdlWriter.java | 5 -- 15 files changed, 22 insertions(+), 146 deletions(-) diff --git a/ebean-ddl-generator/src/main/java/io/ebean/dbmigration/DbMigration.java b/ebean-ddl-generator/src/main/java/io/ebean/dbmigration/DbMigration.java index 36a53ba48..55753f4a2 100644 --- a/ebean-ddl-generator/src/main/java/io/ebean/dbmigration/DbMigration.java +++ b/ebean-ddl-generator/src/main/java/io/ebean/dbmigration/DbMigration.java @@ -16,7 +16,6 @@ import java.util.ServiceLoader; *

* Typically this is run as a main method in src/test once a developer is happy * with the next set of changes to the model. - *

* *

Example: Run for a single specific platform

* @@ -39,11 +38,9 @@ import java.util.ServiceLoader; * are no longer being used by the application. These changes are called * "pending drops" and we must explicitly specify to include these in * a generated migration. - *

*

* Use setGeneratePendingDrop() to specify a prior migration * that has drop column changes that we want to generate a migration for. - *

* *

Example: Generate for pending drops

* @@ -67,7 +64,6 @@ public interface DbMigration { * Create a DbMigration implementation to use. */ static DbMigration create() { - Iterator loader = ServiceLoader.load(DbMigration.class).iterator(); if (loader.hasNext()) { return loader.next(); @@ -76,7 +72,7 @@ public interface DbMigration { } /** - * Set to false to suppress logging to System out. + * Set logging to System out (defaults to true). */ void setLogToSystemOut(boolean logToSystemOut); @@ -105,13 +101,12 @@ public interface DbMigration { void setMigrationPath(String migrationPath); /** - * Set the server to use to determine the current model. - * Typically this is not called explicitly. + * Set the server to use to determine the current model. Usually this is not called explicitly. */ void setServer(Database database); /** - * Set the DatabaseConfig to use. Typically this is not called explicitly. + * Set the DatabaseConfig to use. Usually this is not called explicitly. */ void setServerConfig(DatabaseConfig config); @@ -119,7 +114,6 @@ public interface DbMigration { * Set the specific platform to generate DDL for. *

* If not set this defaults to the platform of the default database. - *

*/ void setPlatform(Platform platform); @@ -127,17 +121,15 @@ public interface DbMigration { * Set the specific platform to generate DDL for. *

* If not set this defaults to the platform of the default database. - *

*/ void setPlatform(DatabasePlatform databasePlatform); /** - * Set to false to turn off strict mode. + * Set to false in order to turn off strict mode. *

* Strict mode checks that a column changed to non-null on an existing table via DB migration has a default * value specified. Set this to false if that isn't the case but it is known that all the existing rows have * a value specified (there are no existing null values for the column). - *

*/ void setStrictMode(boolean strictMode); @@ -182,7 +174,6 @@ public interface DbMigration { * Set to true if ALTER TABLE ADD FOREIGN KEY should be generated with an option to skip validation. *

* Currently this is only useful for Postgres DDL adding the NOT VALID option. - *

*/ void setAddForeignKeySkipCheck(boolean addForeignKeySkipCheck); @@ -191,7 +182,6 @@ public interface DbMigration { *

* Currently this is only useful for Postgres migrations adding a set lock_timeout * statement to the generated database migration. - *

*/ void setLockTimeout(int seconds); @@ -200,7 +190,6 @@ public interface DbMigration { *

* Use this when you want to generate sql scripts for multiple database platforms * from the migration (e.g. generate migration sql for MySql, Postgres and Oracle). - *

*/ void addPlatform(Platform platform); diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/LastMigration.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/LastMigration.java index 0a3353068..07a80add9 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/LastMigration.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/LastMigration.java @@ -29,10 +29,9 @@ class LastMigration { } /** - * Return the last migation version given the migration directory. + * Return the last migration version given the migration directory. */ static String lastVersion(File migDirectory, File modelDir) { - List versions = new ArrayList<>(); File[] sqlFiles = migDirectory.listFiles(pathname -> includeSqlFile(pathname.getName().toLowerCase())); diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/UnknownResourcePathException.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/UnknownResourcePathException.java index 9ecfde157..c8b29872a 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/UnknownResourcePathException.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/UnknownResourcePathException.java @@ -4,7 +4,6 @@ package io.ebeaninternal.dbmigration; * Exception when db migration resource path does not exist. *

* Typically the working directory or pathToResources is incorrect. - *

*/ public class UnknownResourcePathException extends RuntimeException { diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/CurrentModel.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/CurrentModel.java index 11189be94..0ff9a9bc4 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/CurrentModel.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/CurrentModel.java @@ -27,25 +27,17 @@ import static io.ebeaninternal.api.PlatformMatch.matchPlatform; public class CurrentModel { private final SpiEbeanServer server; - private final DatabasePlatform databasePlatform; - private final DbConstraintNaming constraintNaming; - private final boolean platformTypes; - private final boolean jaxbPresent; - private final String ddlHeader; + private final DdlOptions ddlOptions = new DdlOptions(); private ModelContainer model; - private ChangeSet changeSet; - private DdlWrite write; - private DdlOptions ddlOptions = new DdlOptions(); - /** * Construct with a given EbeanServer instance for DDL create all generation, not migration. */ diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MCompoundUniqueConstraint.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MCompoundUniqueConstraint.java index c7c63769d..fbb2e2460 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MCompoundUniqueConstraint.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MCompoundUniqueConstraint.java @@ -20,19 +20,15 @@ import static io.ebeaninternal.dbmigration.ddlgeneration.platform.SplitColumns.s public class MCompoundUniqueConstraint { private final String name; - /** * Flag if true indicates this was specifically created for a OneToOne mapping. */ private final boolean oneToOne; - /** * The columns combined to be unique. */ private final String[] columns; - private final String platforms; - private String[] nullableColumns; /** diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MConfiguration.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MConfiguration.java index 43387a5c7..178f35c8d 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MConfiguration.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MConfiguration.java @@ -4,7 +4,7 @@ import io.ebeaninternal.dbmigration.migration.Configuration; import io.ebeaninternal.dbmigration.migration.DefaultTablespace; /** - * Holds configuration such as the default tablespaces to use for tables, + * Holds configuration such as the default tablespace to use for tables, * indexes, history tables etc. */ public class MConfiguration { @@ -32,7 +32,6 @@ public class MConfiguration { *

*/ public void apply(Configuration configuration) { - DefaultTablespace defaultTablespace = configuration.getDefaultTablespace(); if (defaultTablespace != null) { String tables = defaultTablespace.getTables(); diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MIndex.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MIndex.java index 976bde5f3..710241a69 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MIndex.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MIndex.java @@ -13,8 +13,8 @@ import java.util.Objects; */ public class MIndex { - private String tableName; - private String indexName; + private final String tableName; + private final String indexName; private String platforms; private List columns = new ArrayList<>(); private boolean unique; diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java index 82a687eb7..71faa1c44 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java @@ -48,67 +48,32 @@ public class MTable { private static final Logger logger = LoggerFactory.getLogger(MTable.class); - /** - * Table name. - */ private final String name; - - /** - * The associated draft table. - */ private MTable draftTable; - /** * Marked true for draft tables. These need to have their FK references adjusted * after all the draft tables have been identified. */ private boolean draft; - private PartitionMeta partitionMeta; - - /** - * Primary key name. - */ private String pkName; - - /** - * Table comment. - */ private String comment; - - /** - * Tablespace to use. - */ private String tablespace; - private String storageEngine; - - /** - * Tablespace to use for indexes on this table. - */ private String indexTablespace; - private IdentityMode identityMode; - - /** - * If set to true this table should has history support. - */ private boolean withHistory; - - /** - * The columns on the table. - */ - private Map columns = new LinkedHashMap<>(); + private final Map columns = new LinkedHashMap<>(); /** * Compound unique constraints. */ - private List uniqueConstraints = new ArrayList<>(); + private final List uniqueConstraints = new ArrayList<>(); /** * Compound foreign keys. */ - private List compoundKeys = new ArrayList<>(); + private final List compoundKeys = new ArrayList<>(); /** * Column name for the 'When created' column. This can be used for the initial effective start date when adding @@ -121,7 +86,7 @@ public class MTable { */ private AddColumn addColumn; - private List droppedColumns = new ArrayList<>(); + private final List droppedColumns = new ArrayList<>(); public MTable(BeanDescriptor descriptor) { this.name = descriptor.getBaseTable(); @@ -153,18 +118,15 @@ public class MTable { * later when creating the CreateTable object. */ public MTable createDraftTable() { - draftTable = new MTable(name + "_draft"); draftTable.draft = true; draftTable.whenCreatedColumn = whenCreatedColumn; // compoundKeys // compoundUniqueConstraints draftTable.identityMode = identityMode; - for (MColumn col : allColumns()) { draftTable.addColumn(col.copyForDraft()); } - return draftTable; } @@ -239,7 +201,6 @@ public class MTable { * Return the CreateTable migration for this table. */ public CreateTable createTable() { - CreateTable createTable = new CreateTable(); createTable.setName(name); createTable.setPkName(pkName); @@ -258,22 +219,18 @@ public class MTable { if (draft) { createTable.setDraft(Boolean.TRUE); } - for (MColumn column : allColumns()) { // filter out draftOnly columns from the base table if (draft || !column.isDraftOnly()) { createTable.getColumn().add(column.createColumn()); } } - for (MCompoundForeignKey compoundKey : compoundKeys) { createTable.getForeignKey().add(compoundKey.createForeignKey()); } - for (MCompoundUniqueConstraint constraint : uniqueConstraints) { createTable.getUniqueConstraint().add(constraint.getUniqueConstraint()); } - return createTable; } @@ -281,7 +238,6 @@ public class MTable { * Compare to another version of the same table to perform a diff. */ public void compare(ModelDiff modelDiff, MTable newTable) { - if (withHistory != newTable.withHistory) { if (withHistory) { DropHistoryTable dropHistoryTable = new DropHistoryTable(); @@ -308,14 +264,12 @@ public class MTable { modelDiff.addTableComment(addTableComment); } - compareCompoundKeys(modelDiff, newTable); compareUniqueKeys(modelDiff, newTable); } private void compareColumns(ModelDiff modelDiff, MTable newTable) { addColumn = null; - Map newColumnMap = newTable.getColumns(); // compare newColumns to existing columns (look for new and diff columns) @@ -374,10 +328,10 @@ public class MTable { currentKeys.removeAll(newTable.getUniqueConstraints()); newKeys.removeAll(getUniqueConstraints()); - for (MCompoundUniqueConstraint currentKey: currentKeys) { + for (MCompoundUniqueConstraint currentKey : currentKeys) { modelDiff.addUniqueConstraint(currentKey.dropUniqueConstraint(name)); } - for (MCompoundUniqueConstraint newKey: newKeys) { + for (MCompoundUniqueConstraint newKey : newKeys) { modelDiff.addUniqueConstraint(newKey.addUniqueConstraint(name)); } } @@ -489,7 +443,6 @@ public class MTable { } public List allHistoryColumns(boolean includeDropped) { - List columnNames = new ArrayList<>(columns.size()); for (MColumn column : columns.values()) { if (column.isIncludeInHistory()) { @@ -595,7 +548,6 @@ public class MTable { * Sometimes the case for a primaryKey that is also a foreign key. */ public MColumn addColumn(String dbCol, String columnDefn, boolean notnull) { - MColumn existingColumn = getColumn(dbCol); if (existingColumn != null) { if (notnull) { @@ -613,7 +565,6 @@ public class MTable { * Add a 'new column' to the AddColumn migration object. */ private void diffNewColumn(MColumn newColumn) { - if (addColumn == null) { addColumn = new AddColumn(); addColumn.setTableName(name); @@ -631,7 +582,6 @@ public class MTable { * Add a 'drop column' to the diff. */ private void diffDropColumn(ModelDiff modelDiff, MColumn existingColumn) { - DropColumn dropColumn = new DropColumn(); dropColumn.setTableName(name); dropColumn.setColumnName(existingColumn.getName()); @@ -640,7 +590,6 @@ public class MTable { // table as well as the base table dropColumn.setWithHistory(Boolean.TRUE); } - modelDiff.addDropColumn(dropColumn); } @@ -661,7 +610,6 @@ public class MTable { *

*/ public void checkDuplicateForeignKeys() { - if (hasDuplicateForeignKeys()) { int counter = 1; for (MCompoundForeignKey fk : compoundKeys) { @@ -687,7 +635,6 @@ public class MTable { * Adjust the references (FK) if it should relate to a draft table. */ public void adjustReferences(ModelContainer modelContainer) { - Collection cols = allColumns(); for (MColumn col : cols) { String references = col.getReferences(); diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTableIdentity.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTableIdentity.java index 5e4bb2306..f226ebaec 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTableIdentity.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTableIdentity.java @@ -17,7 +17,6 @@ public class MTableIdentity { * Return the IdentityMode from CreateTable. */ public static IdentityMode fromCreateTable(CreateTable createTable) { - IdType type = fromType(createTable.getIdentityType()); IdentityGenerated generated = fromGenerated(createTable.getIdentityGenerated()); int start = toInt(createTable.getIdentityStart(), createTable.getSequenceInitial()); @@ -39,7 +38,6 @@ public class MTableIdentity { * Set the IdentityMode to the CreateTable model. */ public static void toCreateTable(IdentityMode identityMode, CreateTable createTable) { - if (!identityMode.isPlatformDefault()) { createTable.setIdentityType(toType(identityMode.getIdType())); } diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationModel.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationModel.java index 2ad1001bb..9c49ad0aa 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationModel.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationModel.java @@ -18,13 +18,9 @@ public class MigrationModel { private static final Logger logger = LoggerFactory.getLogger(MigrationModel.class); private final ModelContainer model = new ModelContainer(); - private final File modelDirectory; - private final String modelSuffix; - private MigrationVersion lastVersion; - public MigrationModel(File modelDirectory, String modelSuffix) { this.modelDirectory = modelDirectory; this.modelSuffix = modelSuffix; @@ -58,14 +54,9 @@ public class MigrationModel { if (!initMigration) { for (MigrationResource migrationResource : resources) { logger.debug("read {}", migrationResource); - model.apply(migrationResource.read(), migrationResource.getVersion()); + model.apply(migrationResource.read(), migrationResource.version()); } } - - // remember the last version - if (!resources.isEmpty()) { - lastVersion = resources.get(resources.size() - 1).getVersion(); - } } private MigrationVersion createVersion(File xmlFile) { @@ -73,9 +64,4 @@ public class MigrationModel { String versionName = fileName.substring(0, fileName.length() - modelSuffix.length()); return MigrationVersion.parse(versionName); } - - public String getNextVersion(String initialVersion) { - - return lastVersion == null ? initialVersion : lastVersion.nextVersion(); - } } diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationResource.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationResource.java index eff454813..ae4950a4e 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationResource.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationResource.java @@ -31,7 +31,7 @@ public class MigrationResource implements Comparable { /** * Return the version associated with this resource. */ - public MigrationVersion getVersion() { + public MigrationVersion version() { return version; } @@ -39,7 +39,6 @@ public class MigrationResource implements Comparable { * Read and return the migration from the resource. */ public Migration read() { - return MigrationXmlReader.read(migrationFile); } diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java index 3f75064d2..dc19ef137 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java @@ -37,19 +37,16 @@ import java.util.TreeSet; public class ModelContainer { private final Set schemas = new TreeSet<>(); - /** * All the tables in the model. */ private final Map tables = new LinkedHashMap<>(); /** - * All the non unique non foreign key indexes. + * All the non-unique non-foreign key indexes. */ private final Map indexes = new LinkedHashMap<>(); - private final PendingDrops pendingDrops = new PendingDrops(); - private final List partitionedTables = new ArrayList<>(); public ModelContainer() { diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelDiff.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelDiff.java index 2babc7c6c..367c13ca5 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelDiff.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelDiff.java @@ -53,29 +53,24 @@ public class ModelDiff { this.baseModel = new ModelContainer(); } - /** - * Return true if the apply and drop changes are both empty. - * This means there are no migration changes. + * Return true if apply and drop changes are both empty. This means there are no migration changes. */ public boolean isEmpty() { return applyChanges.isEmpty() && dropChanges.isEmpty(); } /** - * Return the diff as a migration potentially containing - * an apply changeSet and a drop changeSet. + * Return the diff as a migration potentially containing an apply changeSet and a drop changeSet. */ public Migration getMigration() { - Migration migration = new Migration(); if (!applyChanges.isEmpty()) { - // add a non empty apply changeSet + // add a non-empty apply changeSet migration.getChangeSet().add(getApplyChangeSet()); } - if (!dropChanges.isEmpty()) { - // add a non empty drop changeSet + // add a non-empty drop changeSet migration.getChangeSet().add(getDropChangeSet()); } return migration; @@ -121,7 +116,6 @@ public class ModelDiff { * Compare to a 'newer' model and collect the differences. */ public void compareTo(ModelContainer newModel) { - Map newTables = newModel.getTables(); for (MTable newTable : newTables.values()) { @@ -179,7 +173,6 @@ public class ModelDiff { * Compare tables looking for add/drop/modify columns etc. */ protected void compareTables(MTable currentTable, MTable newTable) { - currentTable.compare(this, newTable); } @@ -187,7 +180,6 @@ public class ModelDiff { * Compare tables looking for add/drop/modify columns etc. */ protected void compareIndexes(MIndex currentIndex, MIndex newIndex) { - currentIndex.compare(this, newIndex); } diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PendingDrops.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PendingDrops.java index 9a0bdd242..bd7e7c96b 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PendingDrops.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PendingDrops.java @@ -24,7 +24,6 @@ public class PendingDrops { * Add a 'pending drops' changeSet for the given version. */ public void add(MigrationVersion version, ChangeSet changeSet) { - Entry entry = map.computeIfAbsent(version.normalised(), k -> new Entry(version)); entry.add(changeSet); } @@ -33,7 +32,6 @@ public class PendingDrops { * Return the list of versions with pending drops. */ public List pendingDrops() { - List versions = new ArrayList<>(); for (Entry value : map.values()) { if (value.hasPendingDrops()) { @@ -48,7 +46,6 @@ public class PendingDrops { * to remove the (unsuppressed) pending drops for this version. */ public boolean appliedDropsFor(ChangeSet changeSet) { - MigrationVersion version = MigrationVersion.parse(changeSet.getDropsFor()); Entry entry = map.get(version.normalised()); @@ -68,7 +65,6 @@ public class PendingDrops { *

*/ public Migration migrationForVersion(String pendingVersion) { - Entry entry = getEntry(pendingVersion); Migration migration = new Migration(); @@ -96,7 +92,6 @@ public class PendingDrops { } private Entry getEntry(String pendingVersion) { - if ("next".equalsIgnoreCase(pendingVersion)) { Iterator it = map.values().iterator(); if (it.hasNext()) { @@ -115,7 +110,6 @@ public class PendingDrops { * Register pending drop columns on history tables to the new model. */ public void registerPendingHistoryDropColumns(ModelContainer newModel) { - for (Entry entry : map.values()) { for (ChangeSet changeSet : entry.list) { newModel.registerPendingHistoryDropColumns(changeSet); @@ -140,7 +134,6 @@ public class PendingDrops { static class Entry { final MigrationVersion version; - final List list = new ArrayList<>(); Entry(MigrationVersion version) { @@ -180,7 +173,6 @@ public class PendingDrops { * removed all the changeSets (and there are no suppressForever ones). */ boolean removeDrops(ChangeSet appliedDrops) { - Iterator iterator = list.iterator(); while (iterator.hasNext()) { ChangeSet next = iterator.next(); @@ -199,20 +191,16 @@ public class PendingDrops { * Remove the applied drops from the pending ones matching by table name and column name. */ private void removeMatchingChanges(ChangeSet pendingDrops, ChangeSet appliedDrops) { - List pending = pendingDrops.getChangeSetChildren(); Iterator iterator = pending.iterator(); while (iterator.hasNext()) { Object pendingDrop = iterator.next(); if (pendingDrop instanceof DropColumn && dropColumnIn((DropColumn) pendingDrop, appliedDrops)) { iterator.remove(); - } else if (pendingDrop instanceof DropTable && dropTableIn((DropTable) pendingDrop, appliedDrops)) { iterator.remove(); - } else if (pendingDrop instanceof DropHistoryTable && dropHistoryTableIn((DropHistoryTable) pendingDrop, appliedDrops)) { iterator.remove(); - } } } diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PlatformDdlWriter.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PlatformDdlWriter.java index f56384477..59da934e4 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PlatformDdlWriter.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PlatformDdlWriter.java @@ -27,9 +27,7 @@ public class PlatformDdlWriter { private static final Logger logger = LoggerFactory.getLogger(PlatformDdlWriter.class); private final DatabaseConfig databaseConfig; - private final PlatformDdl platformDdl; - private final int lockTimeoutSeconds; public PlatformDdlWriter(DatabasePlatform platform, DatabaseConfig dbConfig, int lockTimeoutSeconds) { @@ -42,7 +40,6 @@ public class PlatformDdlWriter { * Write the migration as platform specific ddl. */ public void processMigration(Migration dbMigration, DdlWrite write, File writePath, String fullVersion) throws IOException { - DdlHandler handler = handler(); handler.generateProlog(write); if (lockTimeoutSeconds > 0) { @@ -51,7 +48,6 @@ public class PlatformDdlWriter { write.apply().append(lockSql).endOfStatement().newLine(); } } - List changeSets = dbMigration.getChangeSet(); for (ChangeSet changeSet : changeSets) { if (isApply(changeSet)) { @@ -59,7 +55,6 @@ public class PlatformDdlWriter { } } handler.generateEpilog(write); - writePlatformDdl(write, writePath, fullVersion); }