01: package org.apache.torque.oid;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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 org.apache.torque.adapter.DB;
23: import org.apache.torque.adapter.IDMethod;
24:
25: /**
26: * A factory which instantiates {@link
27: * org.apache.torque.oid.IdGenerator} implementations.
28: *
29: * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
30: * @version $Id: IDGeneratorFactory.java 476550 2006-11-18 16:08:37Z tfischer $
31: */
32: public class IDGeneratorFactory {
33: /**
34: * Private constructor to prevent initialisation.
35: *
36: * This class contains only static methods and thus should not be
37: * instantiated.
38: */
39: private IDGeneratorFactory() {
40: }
41:
42: /**
43: * The list of ID generation method types which have associated
44: * {@link org.apache.torque.oid.IdGenerator} implementations.
45: */
46: public static final String[] ID_GENERATOR_METHODS = {
47: IDMethod.NATIVE, IDMethod.AUTO_INCREMENT, IDMethod.SEQUENCE };
48:
49: /**
50: * Factory method which instantiates {@link
51: * org.apache.torque.oid.IdGenerator} implementations based on the
52: * return value of the provided adapter's {@link
53: * org.apache.torque.adapter.DB#getIDMethodType()} method.
54: * Returns <code>null</code> for unknown types.
55: *
56: * @param dbAdapter The type of adapter to create an ID generator for.
57: * @return The appropriate ID generator (possibly <code>null</code>).
58: */
59: public static IdGenerator create(DB dbAdapter, String name) {
60: String idMethod = dbAdapter.getIDMethodType();
61: if (IDMethod.AUTO_INCREMENT.equals(idMethod)) {
62: return new AutoIncrementIdGenerator(dbAdapter, name);
63: } else if (IDMethod.SEQUENCE.equals(idMethod)) {
64: return new SequenceIdGenerator(dbAdapter, name);
65: } else {
66: return null;
67: }
68: }
69: }
|