1 24 package org.riotfamily.revolt.dialect; 25 26 import java.util.HashMap ; 27 import java.util.HashSet ; 28 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 import org.riotfamily.revolt.Dialect; 32 import org.riotfamily.revolt.definition.Column; 33 import org.riotfamily.revolt.support.TypeMap; 34 35 39 public abstract class AbstractDialect implements Dialect { 40 41 private static Log log = LogFactory.getLog(AbstractDialect.class); 42 43 private HashMap nativeTypes = new HashMap (); 44 45 private HashSet typesWithLength = new HashSet (); 46 47 public AbstractDialect() { 48 registerTypes(); 49 if (!TypeMap.isComplete(nativeTypes)) { 50 log.warn("Dialect does not support all JDBC types!"); 51 } 52 } 53 54 public String getName() { 55 String s = getClass().getName(); 56 s = s.substring(s.lastIndexOf('.') + 1); 57 return s.substring(0, s.indexOf("Dialect")); 58 } 59 60 protected abstract void registerTypes(); 61 62 protected final void registerType(String jdbcName, String nativeName) { 63 registerType(jdbcName, nativeName, false); 64 } 65 66 protected final void registerType(String jdbcName, String nativeName, 67 boolean hasLength) { 68 69 nativeTypes.put(jdbcName, nativeName); 70 if (hasLength) { 71 typesWithLength.add(jdbcName); 72 } 73 } 74 75 protected boolean typeHasLength(String type) { 76 return typesWithLength.contains(type); 77 } 78 79 protected final String getColumnType(Column column) { 80 String type = (String ) nativeTypes.get(column.getType()); 81 if (type == null) { 82 throw new TypeNotSupportedException(column.getType()); 83 } 84 if (column.isLengthSet() && typeHasLength(type)) { 85 type += "(" + column.getLength() + ")"; 86 } 87 return type; 88 } 89 90 } 91 | Popular Tags |