1 package org.andromda.schema2xmi;
2
3 import java.lang.reflect.Field;
4
5 import java.sql.Types;
6
7 import java.util.HashMap;
8 import java.util.Map;
9
10
11 /***
12 * <p>
13 * Provides the ability to find a <code>java.sql.Types</code> field name based
14 * on an int value.
15 * </p>
16 *
17 * @author Chad Brandon
18 */
19 public class JdbcTypeFinder
20 {
21 private static final Map jdbcTypes = new HashMap();
22
23 /***
24 * Initialize the <code>jdbcTypes</code> Map.
25 */
26 static
27 {
28 try
29 {
30 Field[] fields = Types.class.getFields();
31 int fieldsNum = fields.length;
32 Field field;
33 for (int ctr = 0; ctr < fieldsNum; ctr++)
34 {
35 field = fields[ctr];
36 jdbcTypes.put(
37 field.get(null),
38 field.getName());
39 }
40 }
41 catch (Throwable th)
42 {
43 throw new SchemaTransformerException(th);
44 }
45 }
46
47 /***
48 * Finds the name of the <code>jdbcType</code> passed in, or null if there
49 * is no type in the java.sql.Types class matching the given
50 * <code>jdbcType</code>.
51 *
52 * @param jdbcType the JDBC type to find.
53 * @return the JDBC type name.
54 */
55 public static String find(int jdbcType)
56 {
57 return (String)jdbcTypes.get(new Integer(jdbcType));
58 }
59 }