%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.torque.oid.IDGeneratorFactory |
|
|
1 | package org.apache.torque.oid; |
|
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 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 | 0 | { |
42 | 0 | } |
43 | ||
44 | /** |
|
45 | * The list of ID generation method types which have associated |
|
46 | * {@link org.apache.torque.oid.IdGenerator} implementations. |
|
47 | */ |
|
48 | 64 | 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 | 192 | String idMethod = dbAdapter.getIDMethodType(); |
66 | 192 | if (IDMethod.AUTO_INCREMENT.equals(idMethod)) |
67 | { |
|
68 | 192 | return new AutoIncrementIdGenerator(dbAdapter, name); |
69 | } |
|
70 | 0 | else if (IDMethod.SEQUENCE.equals(idMethod)) |
71 | { |
|
72 | 0 | return new SequenceIdGenerator(dbAdapter, name); |
73 | } |
|
74 | else |
|
75 | { |
|
76 | 0 | return null; |
77 | } |
|
78 | } |
|
79 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |