Make use of generics for the Dialect and TypeNames class

This commit is contained in:
Yoryos Valotasios 2010-11-14 23:31:20 +02:00
parent ae271db9ba
commit 9e2902807c
2 changed files with 10 additions and 13 deletions

View File

@ -99,7 +99,7 @@ public abstract class Dialect {
private final Properties properties = new Properties(); private final Properties properties = new Properties();
private final Map<String, SQLFunction> sqlFunctions = new HashMap<String, SQLFunction>(); private final Map<String, SQLFunction> sqlFunctions = new HashMap<String, SQLFunction>();
private final Set sqlKeywords = new HashSet(); private final Set<String> sqlKeywords = new HashSet<String>();
// constructors and factory methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // constructors and factory methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -373,7 +373,7 @@ public abstract class Dialect {
* *
* @return The map of registered functions. * @return The map of registered functions.
*/ */
public final Map getFunctions() { public final Map<String, SQLFunction> getFunctions() {
return sqlFunctions; return sqlFunctions;
} }
@ -384,7 +384,7 @@ public abstract class Dialect {
sqlKeywords.add(word); sqlKeywords.add(word);
} }
public Set getKeywords() { public Set<String> getKeywords() {
return sqlKeywords; return sqlKeywords;
} }

View File

@ -26,7 +26,6 @@ package org.hibernate.dialect;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.Iterator;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.util.StringHelper; import org.hibernate.util.StringHelper;
@ -65,8 +64,8 @@ import org.hibernate.util.StringHelper;
*/ */
public class TypeNames { public class TypeNames {
private HashMap weighted = new HashMap(); private Map<Integer, Map<Integer, String>> weighted = new HashMap<Integer, Map<Integer, String>>();
private HashMap defaults = new HashMap(); private Map<Integer, String> defaults = new HashMap<Integer, String>();
/** /**
* get default type name for specified type * get default type name for specified type
@ -74,7 +73,7 @@ public class TypeNames {
* @return the default type name associated with specified key * @return the default type name associated with specified key
*/ */
public String get(int typecode) throws MappingException { public String get(int typecode) throws MappingException {
String result = (String) defaults.get( new Integer(typecode) ); String result = defaults.get( new Integer(typecode) );
if (result==null) throw new MappingException("No Dialect mapping for JDBC type: " + typecode); if (result==null) throw new MappingException("No Dialect mapping for JDBC type: " + typecode);
return result; return result;
} }
@ -89,12 +88,10 @@ public class TypeNames {
* if available and the default type name otherwise * if available and the default type name otherwise
*/ */
public String get(int typecode, int size, int precision, int scale) throws MappingException { public String get(int typecode, int size, int precision, int scale) throws MappingException {
Map map = (Map) weighted.get( new Integer(typecode) ); Map<Integer, String> map = weighted.get( new Integer(typecode) );
if ( map!=null && map.size()>0 ) { if ( map!=null && map.size()>0 ) {
// iterate entries ordered by capacity to find first fit // iterate entries ordered by capacity to find first fit
Iterator entries = map.entrySet().iterator(); for (Map.Entry<Integer, String> entry: map.entrySet()) {
while ( entries.hasNext() ) {
Map.Entry entry = (Map.Entry)entries.next();
if ( size <= ( (Integer) entry.getKey() ).intValue() ) { if ( size <= ( (Integer) entry.getKey() ).intValue() ) {
return replace( (String) entry.getValue(), size, precision, scale ); return replace( (String) entry.getValue(), size, precision, scale );
} }
@ -114,9 +111,9 @@ public class TypeNames {
* @param typecode the type key * @param typecode the type key
*/ */
public void put(int typecode, int capacity, String value) { public void put(int typecode, int capacity, String value) {
TreeMap map = (TreeMap)weighted.get( new Integer(typecode) ); Map<Integer, String> map = weighted.get( new Integer(typecode) );
if (map == null) {// add new ordered map if (map == null) {// add new ordered map
map = new TreeMap(); map = new TreeMap<Integer, String>();
weighted.put( new Integer(typecode), map ); weighted.put( new Integer(typecode), map );
} }
map.put(new Integer(capacity), value); map.put(new Integer(capacity), value);