01: package org.apache.ojb.broker.accesslayer.sql;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ojb.broker.util.factory.ConfigurableFactory;
19: import org.apache.ojb.broker.platforms.Platform;
20:
21: import java.util.Map;
22: import java.util.HashMap;
23:
24: /**
25: * This factory creates SqlGenerator instances. it is a configurable factory and
26: * can be used to generate user defined implementations too.
27: * @author Thomas Mahler
28: */
29: public class SqlGeneratorFactory extends ConfigurableFactory {
30: private static SqlGeneratorFactory instance = null;
31:
32: private Map generatorMap = new HashMap();
33:
34: /**
35: * @see org.apache.ojb.broker.util.factory.ConfigurableFactory#getConfigurationKey()
36: */
37: protected String getConfigurationKey() {
38: return "SqlGeneratorClass";
39: }
40:
41: public SqlGenerator createSqlGenerator(Platform pf) {
42: SqlGenerator gen = (SqlGenerator) generatorMap.get(pf
43: .getClass().getName());
44: if (gen == null) {
45: gen = (SqlGenerator) this .createNewInstance(Platform.class,
46: pf);
47: generatorMap.put(pf.getClass(), gen);
48: }
49: return gen;
50: }
51:
52: public static SqlGeneratorFactory getInstance() {
53: if (instance == null) {
54: instance = new SqlGeneratorFactory();
55: }
56: return instance;
57: }
58: }
|