%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.torque.engine.platform.PlatformFactory |
|
|
1 | package org.apache.torque.engine.platform; |
|
2 | ||
3 | /* |
|
4 | * Licensed to the Apache Software Foundation (ASF) under one |
|
5 | * or more contributor license agreements. See the NOTICE file |
|
6 | * distributed with this work for additional information |
|
7 | * regarding copyright ownership. The ASF licenses this file |
|
8 | * to you under the Apache License, Version 2.0 (the |
|
9 | * "License"); you may not use this file except in compliance |
|
10 | * with the License. You may obtain a copy of the License at |
|
11 | * |
|
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
13 | * |
|
14 | * Unless required by applicable law or agreed to in writing, |
|
15 | * software distributed under the License is distributed on an |
|
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
17 | * KIND, either express or implied. See the License for the |
|
18 | * specific language governing permissions and limitations |
|
19 | * under the License. |
|
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 | 0 | public class PlatformFactory |
36 | { |
|
37 | 70 | private static HashMap platforms = new HashMap(); |
38 | 140 | 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 | 25788 | Platform result = null; |
48 | 25788 | String platformName = null; |
49 | ||
50 | 25788 | result = (Platform) getPlatforms().get(dbms); |
51 | 25788 | if (result == null) |
52 | { |
|
53 | try |
|
54 | { |
|
55 | 70 | platformName = getClassnameFor(dbms); |
56 | 70 | Class platformClass = Class.forName(platformName); |
57 | 70 | result = (Platform) platformClass.newInstance(); |
58 | ||
59 | } |
|
60 | 0 | catch (Throwable t) |
61 | { |
|
62 | 0 | log.warn("problems with platform " + platformName |
63 | + ": " + t.getMessage()); |
|
64 | 0 | log.warn("Torque will use PlatformDefaultImpl instead"); |
65 | ||
66 | 0 | result = new PlatformDefaultImpl(); |
67 | 70 | } |
68 | 70 | getPlatforms().put(dbms, result); // cache the Platform |
69 | } |
|
70 | 25788 | 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 | 70 | String pf = "Default"; |
82 | 70 | if (platform != null) |
83 | { |
|
84 | 70 | pf = platform; |
85 | } |
|
86 | 70 | 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 | 25858 | return platforms; |
97 | } |
|
98 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |