All pastes #250903 Raw Edit

wysefrito

public java v1 · immutable
#250903 ·published 2006-11-17 14:50 UTC
rendered paste body
package com.sbs.wceeconvert.migrate;import java.util.HashMap;import java.util.Map;import com.sbs.wceeconvert.Converter;import com.sbs.wceeconvert.WCEEConvertVersion;/** * The migration class contains information from converting * one <code>WCEEConvertVersion<code> to another, all the way up to * <code>WCEEConvertVersion.CURRENT_VERSION</code>. */public final class Migration{	protected WCEEConvertVersion oldVersion;	protected Map migrationPatterns;	/**	 * Formal constructor to initialize what version we are currently on	 * so we know how to upgrade to <code>CURRENT_VERSION</code>.	 * 	 * @param oldVersion The version contained in the database.	 */	public Migration(WCEEConvertVersion oldVersion)	{		this.oldVersion = oldVersion;		this.initVersionUpgrades();	}	/**	 * Register the classes, versions, and upgrade advisors.	 */	private void initVersionUpgrades()	{		migrationPatterns = new HashMap();		migrationPatterns.put("0.0.0", "com.sbs.wceeconvert.migrate.MigrationPattern_0_0_0");		migrationPatterns.put("1.0.0", "com.sbs.wceeconvert.migrate.MigrationPattern_1_0_0");	}	/**	 * Migrate the database versions.	 * 	 * @param converter The converter that is converting the database.	 */	public void migrate(Converter converter)	throws MigrationException	{		String patternClassName = (String)migrationPatterns.get(oldVersion.toString());		while (patternClassName != null)		{			try			{				MigrationPattern migration = (MigrationPattern)Class.forName(patternClassName).newInstance();				migration.migrate(converter);				//				// get the next migration pattern				//				patternClassName = (String)migrationPatterns.get(migration.toVersion());			}			catch (ClassNotFoundException e)			{				throw new MigrationException();			}			catch (InstantiationException e)			{				throw new MigrationException(e);			}			catch (IllegalAccessException e)			{				throw new MigrationException(e);			}		}	}}