001: /*
002: * Copyright (c) 2006 Your Corporation. All Rights Reserved.
003: */
004:
005: /*
006: * Created by IntelliJ IDEA.
007: * User: Jacques
008: * Date: Feb 27, 2006
009: * Time: 8:11:56 PM
010: */
011: package com.tacitknowledge.util.migration.jdbc;
012:
013: import org.apache.commons.logging.Log;
014: import org.apache.commons.logging.LogFactory;
015:
016: /**
017: * Launches the migration process as a standalone application.
018: * <p>
019: * This class expects the following Java environment parameters:
020: * <ul>
021: * <li>migration.systemname - the name of the logical system being migrated</li>
022: * </ul>
023: * <p>
024: * Below is an example of how this class can be configured in an Ant build.xml file:
025: * <pre>
026: * ...
027: * <target name="patch.information" description="Prints out information about patch levels">
028: * <java
029: * fork="true"
030: * classpathref="patch.classpath"
031: * failonerror="true"
032: * classname="com.tacitknowledge.util.migration.jdbc.MigrationInformation">
033: * <sysproperty key="migration.systemname" value="${application.name}"/>
034: * </java>
035: * </target>
036: * ...
037: * </pre>
038: *
039: * @author Mike Hardy (mike@tacitknowledge.com)
040: * @version $Id: MigrationInformation.java,v 1.10 2005/09/07 22:20:34 chrisa Exp $
041: * @see com.tacitknowledge.util.migration.MigrationProcess
042: */
043: public class MigrationInformation {
044: /** Class logger */
045: private static Log log = LogFactory
046: .getLog(MigrationInformation.class);
047:
048: /**
049: * Private constructor - this object shouldn't be instantiated
050: */
051: private MigrationInformation() {
052: // does nothing
053: }
054:
055: /**
056: * Get the migration level information for the given system name
057: *
058: * @param arguments the command line arguments, if any (none are used)
059: * @exception Exception if anything goes wrong
060: */
061: public static void main(String[] arguments) throws Exception {
062: MigrationInformation info = new MigrationInformation();
063: String migrationName = System
064: .getProperty("migration.systemname");
065: if (migrationName == null) {
066: if ((arguments != null) && (arguments.length > 0)) {
067: migrationName = arguments[0].trim();
068: }
069: }
070: info.getMigrationInformation(migrationName);
071: }
072:
073: /**
074: * Get the migration level information for the given system name
075: *
076: * @param systemName the name of the system
077: * @throws Exception if anything goes wrong
078: */
079: public void getMigrationInformation(String systemName)
080: throws Exception {
081: if (systemName == null) {
082: throw new IllegalArgumentException(
083: "The migration.systemname "
084: + "system property is required");
085: }
086:
087: // The MigrationLauncher is responsible for handling the interaction
088: // between the PatchTable and the underlying MigrationTasks; as each
089: // task is executed, the patch level is incremented, etc.
090: try {
091: JdbcMigrationLauncherFactory launcherFactory = MigrationLauncherFactoryLoader
092: .createFactory();
093: JdbcMigrationLauncher launcher = launcherFactory
094: .createMigrationLauncher(systemName);
095: log.info("Current Database patch level is : "
096: + launcher.getDatabasePatchLevel());
097: int unappliedPatches = launcher.getNextPatchLevel()
098: - launcher.getDatabasePatchLevel() - 1;
099: log.info("Current number of unapplied patches is : "
100: + unappliedPatches);
101: log.info("The next patch to author should be : "
102: + launcher.getNextPatchLevel());
103: } catch (Exception e) {
104: log.error(e);
105: throw e;
106: }
107: }
108: }
|