1 package org.apache.torque.oid;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.apache.torque.adapter.DB;
20 import org.apache.torque.adapter.IDMethod;
21
22 /***
23 * A factory which instantiates {@link
24 * org.apache.torque.oid.IdGenerator} implementations.
25 *
26 * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
27 * @version $Id: IDGeneratorFactory.java 239630 2005-08-24 12:25:32Z henning $
28 */
29 public class IDGeneratorFactory
30 {
31 /***
32 * The list of ID generation method types which have associated
33 * {@link org.apache.torque.oid.IdGenerator} implementations.
34 */
35 public static final String[] ID_GENERATOR_METHODS =
36 {
37 IDMethod.NATIVE, IDMethod.AUTO_INCREMENT, IDMethod.SEQUENCE
38 };
39
40 /***
41 * Factory method which instantiates {@link
42 * org.apache.torque.oid.IdGenerator} implementations based on the
43 * return value of the provided adapter's {@link
44 * org.apache.torque.adapter.DB#getIDMethodType()} method.
45 * Returns <code>null</code> for unknown types.
46 *
47 * @param dbAdapter The type of adapter to create an ID generator for.
48 * @return The appropriate ID generator (possibly <code>null</code>).
49 */
50 public static IdGenerator create(DB dbAdapter, String name)
51 {
52 String idMethod = dbAdapter.getIDMethodType();
53 if (IDMethod.AUTO_INCREMENT.equals(idMethod))
54 {
55 return new AutoIncrementIdGenerator(dbAdapter, name);
56 }
57 else if (IDMethod.SEQUENCE.equals(idMethod))
58 {
59 return new SequenceIdGenerator(dbAdapter, name);
60 }
61 else
62 {
63 return null;
64 }
65 }
66 }