001: /*
002: $Header: /cvsroot/xorm/xorm/src/org/xorm/datastore/sql/SQLType.java,v 1.2 2002/11/26 22:51:43 wbiggs Exp $
003:
004: This file is part of XORM.
005:
006: XORM is free software; you can redistribute it and/or modify
007: it under the terms of the GNU General Public License as published by
008: the Free Software Foundation; either version 2 of the License, or
009: (at your option) any later version.
010:
011: XORM is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU General Public License for more details.
015:
016: You should have received a copy of the GNU General Public License
017: along with XORM; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package org.xorm.datastore.sql;
021:
022: import java.sql.Types;
023: import java.util.Hashtable;
024:
025: /**
026: * Helper class to get JDBC Type values by name. Note that while
027: * this class includes the full set of constants defined in
028: * java.sql.Types, some of these may not work with XORM.
029: */
030: public class SQLType {
031: private SQLType() {
032: }
033:
034: private static Hashtable nameToType;
035: static {
036: nameToType = new Hashtable();
037: nameToType.put("array", new Integer(Types.ARRAY));
038: nameToType.put("bigint", new Integer(Types.BIGINT));
039: nameToType.put("binary", new Integer(Types.BINARY));
040: nameToType.put("bit", new Integer(Types.BIT));
041: nameToType.put("blob", new Integer(Types.BLOB));
042: nameToType.put("boolean", new Integer(Types.BOOLEAN));
043: nameToType.put("char", new Integer(Types.CHAR));
044: nameToType.put("clob", new Integer(Types.CLOB));
045: nameToType.put("datalink", new Integer(Types.DATALINK));
046: nameToType.put("date", new Integer(Types.DATE));
047: nameToType.put("decimal", new Integer(Types.DECIMAL));
048: nameToType.put("distinct", new Integer(Types.DISTINCT));
049: nameToType.put("double", new Integer(Types.DOUBLE));
050: nameToType.put("float", new Integer(Types.FLOAT));
051: nameToType.put("integer", new Integer(Types.INTEGER));
052: nameToType.put("longvarbinary",
053: new Integer(Types.LONGVARBINARY));
054: nameToType.put("longvarchar", new Integer(Types.LONGVARCHAR));
055: nameToType.put("null", new Integer(Types.NULL));
056: nameToType.put("numeric", new Integer(Types.NUMERIC));
057: nameToType.put("real", new Integer(Types.REAL));
058: nameToType.put("ref", new Integer(Types.REF));
059: nameToType.put("smallint", new Integer(Types.SMALLINT));
060: nameToType.put("struct", new Integer(Types.STRUCT));
061: nameToType.put("time", new Integer(Types.TIME));
062: nameToType.put("timestamp", new Integer(Types.TIMESTAMP));
063: nameToType.put("tinyint", new Integer(Types.TINYINT));
064: nameToType.put("varbinary", new Integer(Types.VARBINARY));
065: nameToType.put("varchar", new Integer(Types.VARCHAR));
066: }
067:
068: /**
069: * Returns the constant value from java.sql.Types that represents
070: * the named JDBC type, or -1 on failure. The match is case-insensitive.
071: */
072: public static int forName(String name) {
073: if (name == null)
074: return -1;
075: Integer i = (Integer) nameToType.get(name.toLowerCase());
076: if (i == null)
077: return -1;
078: return i.intValue();
079: }
080:
081: /**
082: * Returns the name for the java.sql.Type constant, or null if not found.
083: */
084: public static String nameFor(int type) {
085: switch (type) {
086: case Types.ARRAY:
087: return "array";
088: case Types.BIGINT:
089: return "bigint";
090: case Types.BINARY:
091: return "binary";
092: case Types.BIT:
093: return "bit";
094: case Types.BLOB:
095: return "blob";
096: case Types.BOOLEAN:
097: return "boolean";
098: case Types.CHAR:
099: return "char";
100: case Types.CLOB:
101: return "clob";
102: case Types.DATALINK:
103: return "datalink";
104: case Types.DATE:
105: return "date";
106: case Types.DECIMAL:
107: return "decimal";
108: case Types.DISTINCT:
109: return "distinct";
110: case Types.DOUBLE:
111: return "double";
112: case Types.FLOAT:
113: return "float";
114: case Types.INTEGER:
115: return "integer";
116: case Types.LONGVARBINARY:
117: return "longvarbinary";
118: case Types.LONGVARCHAR:
119: return "longvarchar";
120: case Types.NULL:
121: return "null";
122: case Types.NUMERIC:
123: return "numeric";
124: case Types.REAL:
125: return "real";
126: case Types.REF:
127: return "ref";
128: case Types.SMALLINT:
129: return "smallint";
130: case Types.STRUCT:
131: return "struct";
132: case Types.TIME:
133: return "time";
134: case Types.TIMESTAMP:
135: return "timestamp";
136: case Types.TINYINT:
137: return "tinyint";
138: case Types.VARBINARY:
139: return "varbinary";
140: case Types.VARCHAR:
141: return "varchar";
142: }
143: return null;
144: }
145:
146: }
|