1 package org.apache.torque.engine.platform;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashMap;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 /***
28 * Factory class responsible to create Platform objects that
29 * define RDBMS platform specific behaviour.
30 *
31 * @author Thomas Mahler
32 * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
33 * @version $Id: PlatformFactory.java 473814 2006-11-11 22:30:30Z tv $
34 */
35 public class PlatformFactory
36 {
37 private static HashMap platforms = new HashMap();
38 private static Log log = LogFactory.getLog(PlatformFactory.class);
39
40 /***
41 * Returns the Platform for a platform name.
42 *
43 * @param dbms name of the platform
44 */
45 public static Platform getPlatformFor(String dbms)
46 {
47 Platform result = null;
48 String platformName = null;
49
50 result = (Platform) getPlatforms().get(dbms);
51 if (result == null)
52 {
53 try
54 {
55 platformName = getClassnameFor(dbms);
56 Class platformClass = Class.forName(platformName);
57 result = (Platform) platformClass.newInstance();
58
59 }
60 catch (Throwable t)
61 {
62 log.warn("problems with platform " + platformName
63 + ": " + t.getMessage());
64 log.warn("Torque will use PlatformDefaultImpl instead");
65
66 result = new PlatformDefaultImpl();
67 }
68 getPlatforms().put(dbms, result);
69 }
70 return result;
71 }
72
73 /***
74 * compute the name of the concrete Class representing the Platform
75 * specified by <code>platform</code>
76 *
77 * @param platform the name of the platform as specified in the repository
78 */
79 private static String getClassnameFor(String platform)
80 {
81 String pf = "Default";
82 if (platform != null)
83 {
84 pf = platform;
85 }
86 return "org.apache.torque.engine.platform.Platform" + pf.substring(0, 1).toUpperCase() + pf.substring(1) + "Impl";
87 }
88
89 /***
90 * Gets the platforms.
91 *
92 * @return Returns a HashMap
93 */
94 private static HashMap getPlatforms()
95 {
96 return platforms;
97 }
98 }