01: package org.kuali.core.dbplatform;
02:
03: import javax.sql.DataSource;
04:
05: import org.apache.commons.lang.StringUtils;
06: import org.apache.log4j.Logger;
07:
08: public class ConfigurableKualiDBPlatformFactory {
09: private static final Logger LOG = Logger
10: .getLogger(ConfigurableKualiDBPlatformFactory.class);
11: public static final String DERBY_PLATFORM = "Derby";
12: public static final String ORACLE_PLATFORM = "Oracle9i";
13: public static final String MY_SQL_PLATFORM = "MySQL";
14: private String ojbPlatform;
15: private String dataSourcePlatformClass;
16: private DataSource dataSource;
17: private KualiDBPlatform platform;
18:
19: public KualiDBPlatform getPlatform() {
20: if (platform == null) {
21: try {
22: // use temp variable to avoid use of incompletely initialized platform Dao
23: KualiDBPlatform tempPlatform = null;
24: if (StringUtils.isBlank(dataSourcePlatformClass)) {
25: if (ORACLE_PLATFORM.equals(ojbPlatform)) {
26: tempPlatform = new KualiDBPlatformOracle();
27: } else if (MY_SQL_PLATFORM.equals(ojbPlatform)) {
28: tempPlatform = new KualiDBPlatformMySQL();
29: } else if (DERBY_PLATFORM.equals(ojbPlatform)) {
30: tempPlatform = new KualiDBPlatformDerby();
31: } else {
32: throw new RuntimeException(
33: "No dataSourcePlatformClass was provided and specified ojbPlatform is unknown: "
34: + ojbPlatform);
35: }
36: } else {
37: try {
38: tempPlatform = (KualiDBPlatform) Class.forName(
39: dataSourcePlatformClass).newInstance();
40: } catch (Exception e) {
41: throw new RuntimeException(
42: "Specified dataSourcePlatformClass was invalid - unable to load, instantiate, or cast to KualiDBPlatform: "
43: + dataSourcePlatformClass);
44: }
45: }
46: if (dataSource != null) {
47: tempPlatform.setDataSource(dataSource);
48: } else {
49: throw new RuntimeException(
50: "Specified dataSource was null");
51: }
52: platform = tempPlatform;
53: } catch (RuntimeException e) {
54: LOG.fatal("Unable to configure KualiDBPlatform", e);
55: throw e;
56: }
57: }
58: return platform;
59: }
60:
61: public DataSource getDataSource() {
62: return dataSource;
63: }
64:
65: public void setOjbPlatform(String ojbPlatform) {
66: this .ojbPlatform = ojbPlatform;
67: }
68:
69: public void setDataSourcePlatformClass(
70: String dataSourcePlatformClass) {
71: this .dataSourcePlatformClass = dataSourcePlatformClass;
72: }
73:
74: public void setDataSource(DataSource dataSource) {
75: this.dataSource = dataSource;
76: }
77: }
|