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