01: /*
02: * Copyright (c) 2006 Your Corporation. All Rights Reserved.
03: */
04:
05: package com.technoetic.xplanner.upgrade;
06:
07: import java.util.Properties;
08:
09: import com.tacitknowledge.util.migration.MigrationException;
10: import com.tacitknowledge.util.migration.jdbc.DataSourceMigrationContext;
11: import com.tacitknowledge.util.migration.jdbc.DatabaseType;
12: import com.tacitknowledge.util.migration.jdbc.JdbcMigrationLauncher;
13: import com.tacitknowledge.util.migration.jdbc.JdbcMigrationLauncherFactory;
14: import com.tacitknowledge.util.migration.jdbc.util.NonPooledDataSource;
15:
16: import com.technoetic.xplanner.XPlannerProperties;
17:
18: public class XPlannerMigrationLauncherFactory extends
19: JdbcMigrationLauncherFactory {
20: public static final String SYSTEM_NAME = "xplanner";
21:
22: private Properties properties;
23:
24: public XPlannerMigrationLauncherFactory() {
25: this (new XPlannerProperties().get());
26: }
27:
28: public XPlannerMigrationLauncherFactory(Properties properties) {
29: this .properties = properties;
30: }
31:
32: public JdbcMigrationLauncher createMigrationLauncher()
33: throws MigrationException {
34: JdbcMigrationLauncher launcher = new JdbcMigrationLauncher();
35: configureFromXPlannerProperties(launcher);
36: return launcher;
37: }
38:
39: public JdbcMigrationLauncher createMigrationLauncher(
40: String systemName) throws MigrationException {
41: return createMigrationLauncher();
42: }
43:
44: public void configureFromXPlannerProperties(
45: JdbcMigrationLauncher launcher) throws MigrationException {
46: launcher.setJdbcMigrationContext(createMigrationContext());
47: launcher.setPatchPath(getRequiredParameter(properties,
48: XPlannerProperties.PATCH_PATH_KEY));
49: }
50:
51: private DataSourceMigrationContext createMigrationContext() {
52: DatabaseType databaseType = new DatabaseType(
53: getRequiredParameter(properties,
54: XPlannerProperties.PATCH_DATABASE_TYPE_KEY));
55: DataSourceMigrationContext context = new DataSourceMigrationContext();
56: context.setDatabaseType(databaseType);
57: context.setDataSource(createDataSource());
58: context.setSystemName(SYSTEM_NAME);
59: return context;
60: }
61:
62: private NonPooledDataSource createDataSource() {
63: NonPooledDataSource dataSource = new NonPooledDataSource();
64: dataSource.setDatabaseUrl(getRequiredParameter(properties,
65: XPlannerProperties.CONNECTION_URL_KEY));
66: dataSource.setDriverClass(getRequiredParameter(properties,
67: XPlannerProperties.DRIVER_CLASS_KEY));
68: dataSource.setUsername(getRequiredParameter(properties,
69: XPlannerProperties.CONNECTION_USERNAME_KEY));
70: dataSource.setPassword(getRequiredParameter(properties,
71: XPlannerProperties.CONNECTION_PASSWORD_KEY));
72: return dataSource;
73: }
74:
75: protected String getRequiredParameter(Properties properties,
76: String parameterKey) {
77:
78: String value = properties.getProperty(parameterKey);
79: if (value == null) {
80: throw new IllegalArgumentException(
81: "Autopatching aborted. Required init param '"
82: + parameterKey + "' was not found");
83: }
84: return value;
85:
86: }
87: }
|