1 package org.apache.torque.oid;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 /***
35 * Private constructor to prevent initialisation.
36 *
37 * This class contains only static methods and thus should not be
38 * instantiated.
39 */
40 private IDGeneratorFactory()
41 {
42 }
43
44 /***
45 * The list of ID generation method types which have associated
46 * {@link org.apache.torque.oid.IdGenerator} implementations.
47 */
48 public static final String[] ID_GENERATOR_METHODS =
49 {
50 IDMethod.NATIVE, IDMethod.AUTO_INCREMENT, IDMethod.SEQUENCE
51 };
52
53 /***
54 * Factory method which instantiates {@link
55 * org.apache.torque.oid.IdGenerator} implementations based on the
56 * return value of the provided adapter's {@link
57 * org.apache.torque.adapter.DB#getIDMethodType()} method.
58 * Returns <code>null</code> for unknown types.
59 *
60 * @param dbAdapter The type of adapter to create an ID generator for.
61 * @return The appropriate ID generator (possibly <code>null</code>).
62 */
63 public static IdGenerator create(DB dbAdapter, String name)
64 {
65 String idMethod = dbAdapter.getIDMethodType();
66 if (IDMethod.AUTO_INCREMENT.equals(idMethod))
67 {
68 return new AutoIncrementIdGenerator(dbAdapter, name);
69 }
70 else if (IDMethod.SEQUENCE.equals(idMethod))
71 {
72 return new SequenceIdGenerator(dbAdapter, name);
73 }
74 else
75 {
76 return null;
77 }
78 }
79 }