diff --git a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java index c1ec6d3..5f024de 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java +++ b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java @@ -514,9 +514,9 @@ public class DepotMarshaller * This is called by the persistence context to register a migration for the entity managed by * this marshaller. */ - protected void registerMigration (EntityMigration migration) + protected void registerMigration (SchemaMigration migration) { - _migrations.add(migration); + _schemaMigs.add(migration); } /** @@ -727,9 +727,9 @@ public class DepotMarshaller log.info("Migrating " + getTableName() + " from " + currentVersion + " to " + _schemaVersion + "..."); - if (_migrations.size() > 0) { + if (_schemaMigs.size() > 0) { // run our pre-default-migrations - for (EntityMigration migration : _migrations) { + for (SchemaMigration migration : _schemaMigs) { if (migration.runBeforeDefault() && migration.shouldRunMigration(currentVersion, _schemaVersion)) { migration.init(getTableName(), _fields); @@ -887,7 +887,7 @@ public class DepotMarshaller }); } - // we do not auto-remove columns but rather require that EntityMigration.Drop records be + // we do not auto-remove columns but rather require that SchemaMigration.Drop records be // registered by hand to avoid accidentally causing the loss of data // we don't auto-remove indices either because we'd have to sort out the potentially @@ -895,7 +895,7 @@ public class DepotMarshaller // index was hand defined in a @Column clause) // run our post-default-migrations - for (EntityMigration migration : _migrations) { + for (SchemaMigration migration : _schemaMigs) { if (!migration.runBeforeDefault() && migration.shouldRunMigration(currentVersion, _schemaVersion)) { migration.init(getTableName(), _fields); @@ -1107,8 +1107,8 @@ public class DepotMarshaller /** Indicates that we have been initialized (created or migrated our tables). */ protected boolean _initialized; - /** A list of hand registered entity migrations to run prior to doing the default migration. */ - protected ArrayList _migrations = new ArrayList(); + /** A list of hand registered schema migrations to run prior to doing the default migration. */ + protected ArrayList _schemaMigs = new ArrayList(); /** The name of the table we use to track schema versions. */ protected static final String SCHEMA_VERSION_TABLE = "DepotSchemaVersion"; diff --git a/src/java/com/samskivert/jdbc/depot/PersistenceContext.java b/src/java/com/samskivert/jdbc/depot/PersistenceContext.java index 73d4866..d51a0d5 100644 --- a/src/java/com/samskivert/jdbc/depot/PersistenceContext.java +++ b/src/java/com/samskivert/jdbc/depot/PersistenceContext.java @@ -189,19 +189,18 @@ public class PersistenceContext } /** - * Registers a migration for the specified entity class. + * Registers a schema migration for the specified entity class. * *

This method must be called before an Entity is used by any repository. Thus you - * should register all migrations immediately after creating your persistence context or if you - * are careful to ensure that your Entities are only used by a single repository, you can - * register your migrations in the constructor for that repository. + * should register all migrations in the constructor of the repository that declares them in + * its {@link DepotRepository#getManagedRecords} method. * *

Note that the migration process is as follows: * *

  • Note the difference between the entity's declared version and the version recorded * in the database. *
  • Run all registered pre-migrations - *
  • Perform all default migrations (column additions and removals) + *
  • Perform all default migrations (column and index additions, index removals) *
  • Run all registered post-migrations
* * Thus you must either be prepared for the entity to be at any version prior to your @@ -215,7 +214,7 @@ public class PersistenceContext * guaranteed to be run in registration order and with predictable pre- and post-conditions. */ public void registerMigration ( - Class type, EntityMigration migration) + Class type, SchemaMigration migration) { getRawMarshaller(type).registerMigration(migration); } diff --git a/src/java/com/samskivert/jdbc/depot/EntityMigration.java b/src/java/com/samskivert/jdbc/depot/SchemaMigration.java similarity index 96% rename from src/java/com/samskivert/jdbc/depot/EntityMigration.java rename to src/java/com/samskivert/jdbc/depot/SchemaMigration.java index b802f02..7c220d9 100644 --- a/src/java/com/samskivert/jdbc/depot/EntityMigration.java +++ b/src/java/com/samskivert/jdbc/depot/SchemaMigration.java @@ -35,12 +35,12 @@ import static com.samskivert.jdbc.depot.Log.log; * migrations. See {@link PersistenceContext#registerPreMigration} and {@link * PersistenceContext#registerPostMigration}. */ -public abstract class EntityMigration extends Modifier +public abstract class SchemaMigration extends Modifier { /** * A convenient migration for dropping a column from an entity. */ - public static class Drop extends EntityMigration + public static class Drop extends SchemaMigration { public Drop (int targetVersion, String columnName) { super(targetVersion); @@ -64,7 +64,7 @@ public abstract class EntityMigration extends Modifier /** * A convenient migration for renaming a column in an entity. */ - public static class Rename extends EntityMigration + public static class Rename extends SchemaMigration { public Rename (int targetVersion, String oldColumnName, String newColumnName) { super(targetVersion); @@ -121,7 +121,7 @@ public abstract class EntityMigration extends Modifier * instantiated with the name of a persistent field, not the name of a database column. These * can be very different things for classes that use @Column annotations. */ - public static class Retype extends EntityMigration + public static class Retype extends SchemaMigration { public Retype (int targetVersion, String fieldName) { super(targetVersion); @@ -158,7 +158,7 @@ public abstract class EntityMigration extends Modifier * * @see Column#defaultValue */ - public static class Add extends EntityMigration + public static class Add extends SchemaMigration { public Add (int targetVersion, String fieldName, String defaultValue) { super(targetVersion); @@ -215,7 +215,7 @@ public abstract class EntityMigration extends Modifier return (currentVersion < _targetVersion); } - protected EntityMigration (int targetVersion) + protected SchemaMigration (int targetVersion) { super(); _targetVersion = targetVersion;