1 package xdoclet.modules.ojb.constraints; 2 3 import java.util.HashMap ; 4 5 19 20 25 public class JdbcTypeHelper 26 { 27 public final static String JDBC_DEFAULT_TYPE = "LONGVARBINARY"; 28 public final static String JDBC_DEFAULT_TYPE_FOR_ARRAY = "LONGVARBINARY"; 29 public final static String JDBC_DEFAULT_CONVERSION = "org.apache.ojb.broker.accesslayer.conversions.Object2ByteArrFieldConversion"; 30 31 34 private static HashMap _jdbcMappings = new HashMap (); 35 38 private static HashMap _jdbcConversions = new HashMap (); 39 42 private static HashMap _jdbcLengths = new HashMap (); 43 46 private static HashMap _jdbcPrecisions = new HashMap (); 47 50 private static HashMap _jdbcScales = new HashMap (); 51 52 static 53 { 54 _jdbcMappings.put("boolean", "BIT"); 56 _jdbcMappings.put("byte", "TINYINT"); 57 _jdbcMappings.put("short", "SMALLINT"); 58 _jdbcMappings.put("int", "INTEGER"); 59 _jdbcMappings.put("long", "BIGINT"); 60 _jdbcMappings.put("char", "CHAR"); 61 _jdbcMappings.put("float", "REAL"); 62 _jdbcMappings.put("double", "FLOAT"); 63 _jdbcMappings.put("java.lang.Boolean", "BIT"); 64 _jdbcMappings.put("java.lang.Byte", "TINYINT"); 65 _jdbcMappings.put("java.lang.Short", "SMALLINT"); 66 _jdbcMappings.put("java.lang.Integer", "INTEGER"); 67 _jdbcMappings.put("java.lang.Long", "BIGINT"); 68 _jdbcMappings.put("java.lang.Character", "CHAR"); 69 _jdbcMappings.put("java.lang.Float", "REAL"); 70 _jdbcMappings.put("java.lang.Double", "FLOAT"); 71 _jdbcMappings.put("java.lang.String", "VARCHAR"); 72 _jdbcMappings.put("java.util.Date", "DATE"); 73 _jdbcMappings.put("java.sql.Blob", "BLOB"); 74 _jdbcMappings.put("java.sql.Clob", "CLOB"); 75 _jdbcMappings.put("java.sql.Date", "DATE"); 76 _jdbcMappings.put("java.sql.Time", "TIME"); 77 _jdbcMappings.put("java.sql.Timestamp", "TIMESTAMP"); 78 _jdbcMappings.put("java.math.BigDecimal", "DECIMAL"); 79 _jdbcMappings.put("org.apache.ojb.broker.util.GUID", "VARCHAR"); 80 81 _jdbcConversions.put("org.apache.ojb.broker.util.GUID", 83 "org.apache.ojb.broker.accesslayer.conversions.GUID2StringFieldConversion"); 84 85 _jdbcLengths.put("CHAR", "1"); 87 _jdbcLengths.put("VARCHAR", "254"); 88 89 _jdbcPrecisions.put("DECIMAL", "20"); 91 _jdbcPrecisions.put("NUMERIC", "20"); 92 93 _jdbcScales.put("DECIMAL", "0"); 95 _jdbcScales.put("NUMERIC", "0"); 96 } 97 98 104 public static String getDefaultJdbcTypeFor(String javaType) 105 { 106 return _jdbcMappings.containsKey(javaType) ? (String )_jdbcMappings.get(javaType) : JDBC_DEFAULT_TYPE; 107 } 108 109 115 public static String getDefaultConversionFor(String javaType) 116 { 117 return _jdbcConversions.containsKey(javaType) ? (String )_jdbcConversions.get(javaType) : null; 118 } 119 120 126 public static String getDefaultLengthFor(String jdbcType) 127 { 128 return (String )_jdbcLengths.get(jdbcType); 129 } 130 131 137 public static String getDefaultPrecisionFor(String jdbcType) 138 { 139 return (String )_jdbcPrecisions.get(jdbcType); 140 } 141 142 148 public static String getDefaultScaleFor(String jdbcType) 149 { 150 return (String )_jdbcScales.get(jdbcType); 151 } 152 } 153 | Popular Tags |