package com.quantum.util.sql;
import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.sql.Types;
/**
- * @author holmesbc
+ * This class provides some utilities for working with Types, as well as providing some
+ * support around SQL types that exist in certain versions of the JDK.
+ *
+ * @author BC Holmes
+ * @see java.lang.Types
*/
public class TypesHelper {
public static final int BLOB = Types.BLOB;
public static final int CLOB = Types.CLOB;
public static final int REF = Types.REF;
+ /**
+ * <p>The constant in the Java programming language, somtimes referred to
+ * as a type code, that identifies the generic SQL type <code>DATALINK</code>.
+ *
+ * <p>Note: For some reason, some versions of DB2 and/or the DB2 driver use an invalid
+ * type code for DATALINK. The correct value should be 70, but DB2/NT 7.01.00 uses
+ * -400.
+ */
public static final int DATALINK;
public static final int BOOLEAN;
return defaultValue;
}
+ public static String getTypeName(int type) {
+ String name = null;
+ try {
+ Field[] fields = TypesHelper.class.getFields();
+ for (int i = 0, length = fields == null ? 0 : fields.length;
+ name == null && i < length; i++) {
+ if (Modifier.isStatic(fields[i].getModifiers())
+ && Modifier.isPublic(fields[i].getModifiers())
+ && fields[i].getType() == Integer.TYPE
+ && type == fields[i].getInt(null)) {
+ name = fields[i].getName();
+ }
+ }
+ } catch (IllegalAccessException e) {
+ }
+ return name;
+ }
+
}