01: /*
02: * Copyright 2006-2007, Unitils.org
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.unitils.dbmaintainer.util;
17:
18: import static org.unitils.util.ConfigUtils.getConfiguredInstance;
19:
20: import java.util.Properties;
21:
22: import org.unitils.core.dbsupport.SQLHandler;
23: import org.unitils.util.PropertyUtils;
24:
25: /**
26: * Class containing configuration utility methods specifically for the {@link org.unitils.database.DatabaseModule} and
27: * related modules
28: *
29: * @author Filip Neven
30: * @author Tim Ducheyne
31: */
32: public class DatabaseModuleConfigUtils {
33:
34: /**
35: * Property key of the SQL dialect of the underlying DBMS implementation
36: */
37: public static final String PROPKEY_DATABASE_DIALECT = "database.dialect";
38:
39: /**
40: * Retrieves the concrete instance of the class with the given type as configured by the given <code>Configuration</code>.
41: * The concrete instance must extend the class {@link DatabaseTask}.
42: *
43: * @param <T> The type of the DatabaseTask
44: * @param databaseTaskType The type of the DatabaseTask, not null
45: * @param configuration The config, not null
46: * @param sqlHandler The sql handler, not null
47: * @return The configured instance
48: */
49: @SuppressWarnings({"unchecked"})
50: public static <T extends DatabaseTask> T getConfiguredDatabaseTaskInstance(
51: Class<T> databaseTaskType, Properties configuration,
52: SQLHandler sqlHandler) {
53: String databaseDialect = PropertyUtils.getString(
54: PROPKEY_DATABASE_DIALECT, configuration);
55: DatabaseTask instance = getConfiguredInstance(databaseTaskType,
56: configuration, databaseDialect);
57: instance.init(configuration, sqlHandler);
58: return (T) instance;
59: }
60:
61: }
|