1 package org.hibernate.dialect; 3 4 import java.util.Map ; 5 import java.util.HashMap ; 6 import java.util.TreeMap ; 7 import java.util.Iterator ; 8 9 import org.hibernate.MappingException; 10 import org.hibernate.util.StringHelper; 11 12 44 public class TypeNames { 45 46 private HashMap weighted = new HashMap (); 47 private HashMap defaults = new HashMap (); 48 49 54 public String get(int typecode) throws MappingException { 55 String result = (String ) defaults.get( new Integer (typecode) ); 56 if (result==null) throw new MappingException("No Dialect mapping for JDBC type: " + typecode); 57 return result; 58 } 59 60 69 public String get(int typecode, int size, int precision, int scale) throws MappingException { 70 Map map = (Map ) weighted.get( new Integer (typecode) ); 71 if ( map!=null && map.size()>0 ) { 72 Iterator entries = map.entrySet().iterator(); 74 while ( entries.hasNext() ) { 75 Map.Entry entry = (Map.Entry )entries.next(); 76 if ( size <= ( (Integer ) entry.getKey() ).intValue() ) { 77 return replace( (String ) entry.getValue(), size, precision, scale ); 78 } 79 } 80 } 81 return replace( get(typecode), size, precision, scale ); 82 } 83 84 private static String replace(String type, int size, int precision, int scale) { 85 type = StringHelper.replaceOnce(type, "$s", Integer.toString(scale) ); 86 type = StringHelper.replaceOnce(type, "$l", Integer.toString(size) ); 87 return StringHelper.replaceOnce(type, "$p", Integer.toString(precision) ); 88 } 89 90 94 public void put(int typecode, int capacity, String value) { 95 TreeMap map = (TreeMap )weighted.get( new Integer (typecode) ); 96 if (map == null) { map = new TreeMap (); 98 weighted.put( new Integer (typecode), map ); 99 } 100 map.put(new Integer (capacity), value); 101 } 102 103 107 public void put(int typecode, String value) { 108 defaults.put( new Integer (typecode), value ); 109 } 110 } 111 112 113 114 115 116 117 | Popular Tags |