Skip to content
Snippets Groups Projects
Commit 6006c60d authored by ribeaudc's avatar ribeaudc
Browse files

minor: - Improve javadoc.

- Simplify a bit 'JavaMigrationStepExecutor'.

SVN: 7858
parent c1e92f15
No related branches found
No related tags found
No related merge requests found
...@@ -22,10 +22,20 @@ import ch.systemsx.cisd.common.exceptions.Status; ...@@ -22,10 +22,20 @@ import ch.systemsx.cisd.common.exceptions.Status;
/** /**
* An interface which must be implemented by all classes providing Java code that performs migration * An interface which must be implemented by all classes providing Java code that performs migration
* steps prior (pre) or after (post) the SQL migration script ran. Canonical name of class * steps prior (<i>pre</i>) or after (<i>post</i>) the SQL migration script ran.
* implementing this interface (preceded by <code>-- JAVA </code>) may be included in the first * <p>
* line of SQL migration script. <Example: * Canonical name of class implementing this interface (preceded by <code>-- JAVA </code>) may be
* <code> -- JAVA ch.systemsx.cisd.openbis.db.migration.MigrationStepFrom022To023</code> * included in the first line of SQL migration script.<br>
* Example:
*
* <pre>
* -- JAVA ch.systemsx.cisd.openbis.db.migration.MigrationStepFrom022To023
* </pre>
*
* </p>
* <p>
* Implementations are expected to be stateless and have a public empty constructor.
* </p>
* *
* @author Izabela Adamczyk * @author Izabela Adamczyk
*/ */
......
...@@ -27,10 +27,12 @@ import org.springframework.jdbc.core.support.JdbcDaoSupport; ...@@ -27,10 +27,12 @@ import org.springframework.jdbc.core.support.JdbcDaoSupport;
import ch.systemsx.cisd.common.Script; import ch.systemsx.cisd.common.Script;
import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
import ch.systemsx.cisd.common.exceptions.Status; import ch.systemsx.cisd.common.exceptions.Status;
import ch.systemsx.cisd.common.utilities.ClassUtils;
/** /**
* Allows to extract {@link IMigrationStep} class from migration script and run the pre- and post- * Allows to extract {@link IMigrationStep} class from migration script and run the <i>pre</i>- and
* migration java steps. Example of the script containing Java Migration Step definition: * <i>post</i>- migration java steps.<br>
* Example of the script containing Java Migration Step definition:
* *
* <pre> * <pre>
* -- JAVA ch.systemsx.cisd.openbis.db.migration.MigrationStepFrom022To023 * -- JAVA ch.systemsx.cisd.openbis.db.migration.MigrationStepFrom022To023
...@@ -89,55 +91,36 @@ public class JavaMigrationStepExecutor extends JdbcDaoSupport implements IJavaMi ...@@ -89,55 +91,36 @@ public class JavaMigrationStepExecutor extends JdbcDaoSupport implements IJavaMi
{ {
msg = msg =
String String.format("Migration script '%s' contains more "
.format( + "than one Java Migration Steps.", sqlScript.getName());
"Migration script '%s' contains more than one Java Migration Steps.",
sqlScript.getName());
} else } else
{ {
msg = msg =
String String.format("Java Migration Step should be defined in the first "
.format( + "non-blank line of the migration script '%s'.", sqlScript
"Java Migration Step should be defined in the first non-blank line of the migration script '%s'.", .getName());
sqlScript.getName());
} }
throw new EnvironmentFailureException(msg); throw new EnvironmentFailureException(msg);
} }
} }
@SuppressWarnings("unchecked") private final IMigrationStep tryExtractMigrationStepFromLine(final String lineToProcess)
private IMigrationStep tryExtractMigrationStepFromLine(final String lineToProcess)
{ {
final String line = StringUtils.deleteWhitespace(lineToProcess); final String line = StringUtils.deleteWhitespace(lineToProcess);
if (line != null && line.startsWith(JAVA_MIGRATION_STEP_PREFIX)) if (line != null && line.startsWith(JAVA_MIGRATION_STEP_PREFIX))
{ {
final String className = StringUtils.removeStart(line, JAVA_MIGRATION_STEP_PREFIX); final String className = StringUtils.removeStart(line, JAVA_MIGRATION_STEP_PREFIX);
String msg;
try try
{ {
final Class clazz = Class.forName(className); return (IMigrationStep) ClassUtils.createInstance(Class.forName(className));
final Object object = clazz.newInstance();
return (IMigrationStep) object;
} catch (final ClassNotFoundException ex) } catch (final ClassNotFoundException ex)
{ {
msg = String.format("Class '%s' not found.", className); throw new EnvironmentFailureException(String.format("Class '%s' not found.",
className));
} catch (final InstantiationException ex) } catch (final RuntimeException ex)
{ {
msg = throw new EnvironmentFailureException(ex.getMessage());
String.format(
"Cannot instantiate class '%s' (EnvironmentFailureException).",
className);
} catch (final IllegalAccessException ex)
{
msg =
String.format("Cannot instantiate class '%s' (IllegalAccessException).",
className);
} }
throw new EnvironmentFailureException(msg);
} else } else
{ {
return null; return null;
...@@ -155,7 +138,6 @@ public class JavaMigrationStepExecutor extends JdbcDaoSupport implements IJavaMi ...@@ -155,7 +138,6 @@ public class JavaMigrationStepExecutor extends JdbcDaoSupport implements IJavaMi
final IMigrationStep migrationStep = tryExtractMigrationStep(sqlScript); final IMigrationStep migrationStep = tryExtractMigrationStep(sqlScript);
if (migrationStep != null) if (migrationStep != null)
{ {
final Status preMigrationStatus = migrationStep.performPreMigration(getJdbcTemplate()); final Status preMigrationStatus = migrationStep.performPreMigration(getJdbcTemplate());
return preMigrationStatus; return preMigrationStatus;
} else } else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment