1 22 23 package org.xquark.extractor.sybase; 24 25 import java.sql.Types ; 26 27 import org.xquark.extractor.common.MessageLibrary; 28 import org.xquark.extractor.common.SqlWrapperException; 29 import org.xquark.jdbc.typing.DbType; 30 31 public class TypeMapper { 32 private static final String RCSRevision = "$Revision: 1.5 $"; 33 private static final String RCSName = "$Name: $"; 34 35 public static String mapType(DbType type) { 36 StringBuffer retVal = new StringBuffer (); 37 38 int typeCode = type.getJDBCType(); 39 switch (typeCode) { 40 case Types.BIT: retVal.append("BIT"); 51 break; 52 case Types.CHAR: 56 retVal.append("NCHAR"); 57 break; 58 case Types.DATE: 62 retVal.append("DATETIME"); 63 break; 64 case Types.DECIMAL: 65 retVal.append("DECIMAL"); 66 break; 67 case Types.DOUBLE: retVal.append("DOUBLE"); 72 break; 73 case Types.FLOAT: retVal.append("REAL"); 75 break; 76 case Types.INTEGER: retVal.append("INTEGER"); 78 break; 79 case Types.REAL: retVal.append("REAL"); 96 break; 97 case Types.SMALLINT: retVal.append("SMALLINT"); 99 break; 100 case Types.TIME: 104 retVal.append("DATETIME"); 105 break; 106 case Types.TIMESTAMP: retVal.append("TIMESTAMP"); 108 break; 109 case Types.TINYINT: retVal.append("TINYINT"); 111 break; 112 case Types.VARCHAR: 116 retVal.append("NVARCHAR"); 117 break; 118 default: 119 throw new SqlWrapperException(MessageLibrary.getMessage("T_N_SUP_TYPE", type.name())); 120 } 122 123 if (Types.CHAR == typeCode || Types.VARCHAR== typeCode || Types.DECIMAL == typeCode) { 124 retVal.append('('); 125 retVal.append(Long.toString(type.getLength())); 126 } 127 if (Types.CHAR == typeCode || Types.VARCHAR == typeCode) { 128 retVal.append(')'); 129 } 130 else if (Types.DECIMAL == typeCode) { 131 retVal.append(", "); 132 retVal.append(Integer.toString(type.getScale())); 133 retVal.append(')'); 134 } 135 return retVal.toString(); 136 } 137 138 } 139 | Popular Tags |