com.tacitknowledge.util.migration.jdbc.DistributedStandaloneMigrationLauncher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of autopatch Show documentation
Show all versions of autopatch Show documentation
An automated Java patching system
/* Copyright 2004 Tacit Knowledge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.tacitknowledge.util.migration.jdbc;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.tacitknowledge.util.migration.jdbc.util.ConfigurationUtil;
/**
* Launches the migration process as a standalone application.
*
* This class expects the following Java environment parameters:
*
* - migration.systemname - the name of the logical system being migrated
*
*
* Below is an example of how this class can be configured in build.xml:
*
* ...
* <target name="patch.database" description="Runs the migration system">
* <java
* fork="true"
* classpathref="patch.classpath"
* failonerror="true"
* classname=
* "com.tacitknowledge.util.migration.jdbc.DistributedStandaloneMigrationLauncher">
* <sysproperty key="migration.systemname" value="${application.name}"/>
* </java>
* </target>
* ...
*
*
* @author Mike Hardy ([email protected])
* @see com.tacitknowledge.util.migration.DistributedMigrationProcess
*/
public class DistributedStandaloneMigrationLauncher
{
/**
* Class logger
*/
private static Log log = LogFactory.getLog(DistributedStandaloneMigrationLauncher.class);
/**
* Private constructor - this object shouldn't be instantiated
*/
private DistributedStandaloneMigrationLauncher()
{
// does nothing
}
/**
* Run the migrations for the given system name
*
* @param arguments the command line arguments, if any (none are used)
* @exception Exception if anything goes wrong
*/
public static void main(String[] arguments) throws Exception
{
String systemName = ConfigurationUtil.getRequiredParam("migration.systemname",
System.getProperties(), arguments);
String migrationSettings = ConfigurationUtil.getOptionalParam("migration.settings",
System.getProperties(), arguments, 1);
// The MigrationLauncher is responsible for handling the interaction
// between the PatchTable and the underlying MigrationTasks; as each
// task is executed, the patch level is incremented, etc.
try
{
DistributedJdbcMigrationLauncherFactory factory =
new DistributedJdbcMigrationLauncherFactory();
JdbcMigrationLauncher launcher = null;
if (migrationSettings == null)
{
log.info("Using migration.properties (default)");
launcher = factory.createMigrationLauncher(systemName);
}
else
{
log.info("Using " + migrationSettings);
launcher = factory.createMigrationLauncher(systemName, migrationSettings);
}
launcher.doMigrations();
}
catch (Exception e)
{
log.error(e);
throw e;
}
}
}