From cdeb8eac8aadf6c81f7ce21a195769f89f891694 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 10 Feb 2010 16:47:31 +0000 Subject: [PATCH] Fail with a useful error message any time a migration tries to reference a non-existent field. --- .../com/samskivert/depot/SchemaMigration.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/java/com/samskivert/depot/SchemaMigration.java b/src/java/com/samskivert/depot/SchemaMigration.java index 92938eb..68c0080 100644 --- a/src/java/com/samskivert/depot/SchemaMigration.java +++ b/src/java/com/samskivert/depot/SchemaMigration.java @@ -89,11 +89,7 @@ public abstract class SchemaMigration extends Modifier @Override public void init (String tableName, Map> marshallers) { super.init(tableName, marshallers); - FieldMarshaller fm = marshallers.get(_newColumnName); - if (fm == null) { - throw new IllegalArgumentException( - _tableName + " does not contain '" + _newColumnName + "' field."); - } + FieldMarshaller fm = requireMarshaller(marshallers, _newColumnName); _newColumnDef = fm.getColumnDefinition(); } @@ -146,8 +142,9 @@ public abstract class SchemaMigration extends Modifier @Override public void init (String tableName, Map> marshallers) { super.init(tableName, marshallers); - _columnName = marshallers.get(_fieldName).getColumnName(); - _newColumnDef = marshallers.get(_fieldName).getColumnDefinition(); + FieldMarshaller marsh = requireMarshaller(marshallers, _fieldName); + _columnName = marsh.getColumnName(); + _newColumnDef = marsh.getColumnDefinition(); } @Override @@ -185,8 +182,9 @@ public abstract class SchemaMigration extends Modifier @Override public void init (String tableName, Map> marshallers) { super.init(tableName, marshallers); - _columnName = marshallers.get(_fieldName).getColumnName(); - _newColumnDef = marshallers.get(_fieldName).getColumnDefinition(); + FieldMarshaller marsh = requireMarshaller(marshallers, _fieldName); + _columnName = marsh.getColumnName(); + _newColumnDef = marsh.getColumnDefinition(); } @Override @@ -271,6 +269,17 @@ public abstract class SchemaMigration extends Modifier _targetVersion = targetVersion; } + protected FieldMarshaller requireMarshaller ( + Map> marshallers, String fieldName) + { + FieldMarshaller marsh = marshallers.get(fieldName); + if (marsh == null) { + throw new IllegalArgumentException( + "'" + _tableName + "' does not contain field '" + fieldName + "'"); + } + return marsh; + } + protected int _targetVersion; protected String _tableName; }