1 package com.quadcap.sql.types; 2 3 40 41 import java.io.Externalizable ; 42 import java.io.IOException ; 43 import java.io.ObjectInput ; 44 import java.io.ObjectOutput ; 45 46 import java.sql.ResultSet ; 47 import java.sql.SQLException ; 48 import java.sql.Types ; 49 50 import com.quadcap.util.Debug; 51 52 57 public class TypeReal implements Type, Externalizable { 58 public static final TypeReal typeFloat = new TypeReal(Types.FLOAT,23); 59 public static final TypeReal typeReal = new TypeReal(Types.REAL,23); 60 public static final TypeReal typeDouble = new TypeReal(Types.DOUBLE,53); 61 62 int type; 63 int precision; 64 65 public TypeReal() {} 66 67 public TypeReal(int type, int precision) { 68 this.type = type; 69 this.precision = precision; 70 } 71 72 public String getTypeName() { 73 switch (type) { 74 case Types.DOUBLE: 75 return "DOUBLE PRECISION"; 76 case Types.FLOAT: 77 return "FLOAT"; 78 case Types.REAL: 79 return "REAL"; 80 default: 81 throw new RuntimeException ("Bad type: " + type); 82 } 83 } 84 85 public int getJDBCType() { return type; } 86 87 public String getJDBCClassName() { 88 switch (type) { 89 case Types.DOUBLE: 90 return "java.lang.Double"; 91 case Types.FLOAT: 92 if (precision > 23) { 93 return "java.lang.Double"; 94 } else { 95 return "java.lang.Float"; 96 } 97 case Types.REAL: 98 return "java.lang.Float"; 99 default: 100 throw new RuntimeException ("Bad type: " + type); 101 } 102 } 103 104 public int getPrecision() { return precision; } 105 106 public int getScale() { return 0; } 107 108 public int getMaxPrecision() { 109 switch (type) { 110 case Types.DOUBLE: 111 return 53; 112 case Types.FLOAT: 113 return 23; 114 case Types.REAL: 115 return 23; 116 } 117 return 53; 118 } 119 120 public int getMinScale() { return -1; } 121 122 public int getMaxScale() { return -1; } 123 124 public boolean isCharType() { return false; } 125 126 public boolean isCaseSensitive() { return false; } 127 128 public boolean isCurrency() { return false; } 129 130 public boolean isSigned() { return true; } 131 132 public int getDisplayWidth() { return 12; } 133 134 public String toString() { 135 StringBuffer sb = new StringBuffer (getTypeName()); 136 if (type == Types.FLOAT) { 137 sb.append('('); 138 sb.append(Integer.toString(precision)); 139 sb.append(')'); 140 } 141 return sb.toString(); 142 } 143 144 148 public void readExternal(ObjectInput in) throws IOException { 149 type = in.read(); 150 precision = in.read(); 151 } 152 153 public void writeExternal(ObjectOutput out) throws IOException { 154 out.write(type); 155 out.write(precision); 156 } 157 158 public Value convert(Value v) throws ValueException { 159 return v.convert(this); 160 } 161 162 public String getCreateParams() { 163 if (type == Types.FLOAT) { 164 return "precision"; 165 } 166 return null; 167 } 168 } 169 | Popular Tags |