1 5 package org.h2.value; 6 7 import java.io.InputStream ; 8 import java.io.Reader ; 9 import java.math.BigDecimal ; 10 import java.sql.Clob ; 11 import java.sql.Date ; 12 import java.sql.ResultSet ; 13 import java.sql.SQLException ; 14 import java.sql.Time ; 15 import java.sql.Timestamp ; 16 import java.sql.Types ; 17 import java.util.HashMap ; 18 19 import org.h2.engine.Constants; 20 import org.h2.engine.SessionInterface; 21 import org.h2.jdbc.JdbcBlob; 22 import org.h2.jdbc.JdbcClob; 23 import org.h2.jdbc.JdbcConnection; 24 import org.h2.jdbc.JdbcSQLException; 25 import org.h2.message.Message; 26 import org.h2.util.ByteUtils; 27 import org.h2.util.ObjectArray; 28 import org.h2.util.StringUtils; 29 30 public class DataType { 31 private static ObjectArray types = new ObjectArray(); 32 private static HashMap typesByName = new HashMap (); 33 private static DataType[] typesByValueType = new DataType[Value.TYPE_COUNT]; 34 public int type; 35 public String name; 36 public int sqlType; 37 public String jdbc; 38 39 public int order; 41 42 public int maxPrecision; 43 public int minScale, maxScale; 44 public boolean decimal; 45 public String prefix, suffix; 46 public String params; 47 public boolean autoInc; 48 public boolean caseSensitive; 49 public boolean supportsPrecision, supportsScale; 50 public long defaultPrecision; 51 public int defaultScale; 52 public boolean hidden; 53 54 public static final int TYPE_BOOLEAN = 16; 56 public static final int TYPE_DATALINK = 70; 58 59 static { 60 if(TYPE_BOOLEAN != Types.BOOLEAN) { 62 new Exception ("Types.BOOLEAN: " + Types.BOOLEAN).printStackTrace(); 63 } 64 if(TYPE_DATALINK != Types.DATALINK) { 65 new Exception ("Types.DATALINK: " + Types.DATALINK).printStackTrace(); 66 } 67 add(Value.NULL, Types.NULL, "Null", 69 new DataType(), 70 new String []{"NULL"} 71 ); 72 add(Value.BOOLEAN, DataType.TYPE_BOOLEAN, "Boolean", 73 createDecimal(ValueBoolean.PRECISION, ValueBoolean.PRECISION, 0, false, false), 74 new String []{"BOOLEAN", "BIT", "BOOL"} 75 ); 76 add(Value.BYTE, Types.TINYINT, "Byte", 77 createDecimal(ValueByte.PRECISION, ValueByte.PRECISION, 0, false, false), 78 new String []{"TINYINT"} 79 ); 80 add(Value.SHORT, Types.SMALLINT, "Short", 81 createDecimal(ValueShort.PRECISION, ValueShort.PRECISION, 0, false, false), 82 new String []{"SMALLINT", "YEAR", "INT2"} 83 ); 84 add(Value.INT, Types.INTEGER, "Int", 85 createDecimal(ValueInt.PRECISION, ValueInt.PRECISION, 0, false, false), 86 new String []{"INTEGER", "INT", "MEDIUMINT", "INT4", "SIGNED"} 87 ); 88 add(Value.LONG, Types.BIGINT, "Long", 89 createDecimal(ValueLong.PRECISION, ValueLong.PRECISION, 0, false, false), 90 new String []{"BIGINT", "INT8"} 91 ); 92 add(Value.LONG, Types.BIGINT, "Long", 93 createDecimal(ValueLong.PRECISION, ValueLong.PRECISION, 0, false, true), 94 new String []{"IDENTITY"} 95 ); 96 add(Value.DECIMAL, Types.DECIMAL, "BigDecimal", 97 createDecimal(Integer.MAX_VALUE, ValueDecimal.DEFAULT_PRECISION, ValueDecimal.DEFAULT_SCALE, true, false), 98 new String []{"DECIMAL", "DEC"} 99 ); 101 add(Value.DECIMAL, Types.NUMERIC, "BigDecimal", 102 createDecimal(Integer.MAX_VALUE, ValueDecimal.DEFAULT_PRECISION, ValueDecimal.DEFAULT_SCALE, true, false), 103 new String []{"NUMERIC", "NUMBER"} 104 ); 106 add(Value.DOUBLE, Types.DOUBLE, "Double", 107 createDecimal(ValueDouble.PRECISION, ValueDouble.PRECISION, 0, false, false), 108 new String [] { "DOUBLE", "DOUBLE PRECISION" } 109 ); 110 add(Value.DOUBLE, Types.FLOAT, "Double", 111 createDecimal(ValueDouble.PRECISION, ValueDouble.PRECISION, 0, false, false), 112 new String [] {"FLOAT", "FLOAT8" } 113 ); 115 add(Value.FLOAT, Types.REAL, "Float", 116 createDecimal(ValueFloat.PRECISION, ValueFloat.PRECISION, 0, false, false), 117 new String [] {"REAL", "FLOAT4"} 118 ); 119 add(Value.TIME, Types.TIME, "Time", 120 createDate(ValueTime.PRECISION, "TIME", 0), 121 new String []{"TIME"} 122 ); 124 add(Value.DATE, Types.DATE, "Date", 125 createDate(ValueDate.PRECISION, "DATE", 0), 126 new String []{"DATE"} 127 ); 129 add(Value.TIMESTAMP, Types.TIMESTAMP, "Timestamp", 130 createDate(ValueTimestamp.PRECISION, "TIMESTAMP", ValueTimestamp.DEFAULT_SCALE), 131 new String []{"TIMESTAMP", "DATETIME", "SMALLDATETIME"} 132 ); 134 add(Value.BYTES, Types.VARBINARY, "Bytes", 135 createString(false), 136 new String []{"VARBINARY"} 137 ); 138 add(Value.BYTES, Types.BINARY, "Bytes", 139 createString(false), 140 new String []{"BINARY", "RAW", "BYTEA", "LONG RAW"} 141 ); 142 add(Value.UUID, Types.BINARY, "Bytes", 143 createString(false), 144 new String []{"UUID"} 145 ); 146 add(Value.BYTES, Types.LONGVARBINARY, "Bytes", 147 createString(false), 148 new String []{"LONGVARBINARY"} 149 ); 150 add(Value.JAVA_OBJECT, Types.OTHER, "Object", 151 createString(false), 152 new String []{"OTHER", "OBJECT", "JAVA_OBJECT"} 153 ); 154 add(Value.STRING, Types.VARCHAR, "String", 155 createString(true), 156 new String []{"VARCHAR", "VARCHAR2", "NVARCHAR", "NVARCHAR2", "VARCHAR_CASESENSITIVE"} 157 ); 158 add(Value.STRING, Types.LONGVARCHAR, "String", 159 createString(true), 160 new String []{"LONGVARCHAR"} 161 ); 162 add(Value.STRING, Types.CHAR, "String", 163 createString(true), 164 new String []{"CHAR", "CHARACTER", "NCHAR"} 165 ); 166 add(Value.STRING_IGNORECASE, Types.VARCHAR, "String", 167 createString(false), 168 new String []{"VARCHAR_IGNORECASE"} 169 ); 170 add(Value.BLOB, Types.BLOB, "Bytes", 171 createString(false), 172 new String []{"BLOB", "TINYBLOB", "MEDIUMBLOB", "LONGBLOB", "IMAGE", "OID"} 173 ); 174 add(Value.CLOB, Types.CLOB, "String", 175 createString(true), 176 new String []{"CLOB", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "NTEXT", "NCLOB"} 177 ); 178 add(Value.ARRAY, Types.ARRAY, "Array", 179 createString(false), 180 new String []{"ARRAY"} 181 ); 182 183 } 185 186 private static void add(int type, int sqlType, String jdbc, DataType dataType, String [] names) { 187 for(int i=0; i<names.length; i++) { 188 DataType dt = new DataType(); 189 dt.type = type; 190 dt.sqlType = sqlType; 191 dt.jdbc = jdbc; 192 dt.name = names[i]; 193 dt.autoInc = dataType.autoInc; 194 dt.decimal = dataType.decimal; 195 dt.maxPrecision = dataType.maxPrecision; 196 dt.maxScale = dataType.maxScale; 197 dt.minScale = dataType.minScale; 198 dt.params = dataType.params; 199 dt.prefix = dataType.prefix; 200 dt.suffix = dataType.suffix; 201 dt.supportsPrecision = dataType.supportsPrecision; 202 dt.supportsScale = dataType.supportsScale; 203 dt.defaultPrecision = dataType.defaultPrecision; 204 dt.defaultScale = dataType.defaultScale; 205 dt.caseSensitive = dataType.caseSensitive; 206 dt.hidden = i > 0; 207 for(int j=0; j<types.size(); j++) { 208 DataType t2 = (DataType) types.get(j); 209 if(t2.sqlType == dt.sqlType) { 210 dt.order++; 211 } 212 } 213 typesByName.put(dt.name, dt); 214 if(typesByValueType[type] == null) { 215 typesByValueType[type] = dt; 216 } 217 types.add(dt); 218 } 219 } 220 221 public static String getJdbcString(int type) { 222 return typesByValueType[type].jdbc; 223 } 224 225 private static DataType createDecimal(int maxPrecision, int defaultPrecision, int defaultScale, boolean needsPrecisionAndScale, boolean autoInc) { 226 DataType dataType = new DataType(); 227 dataType.maxPrecision = maxPrecision; 228 dataType.defaultPrecision = defaultPrecision; 229 dataType.defaultScale = defaultScale; 230 if(needsPrecisionAndScale) { 231 dataType.params = "PRECISION,SCALE"; 232 dataType.supportsPrecision = true; 233 dataType.supportsScale = true; 234 } 235 dataType.decimal = true; 236 dataType.autoInc = autoInc; 237 return dataType; 238 } 239 240 private static DataType createDate(int precision, String prefix, int scale) { 241 DataType dataType = new DataType(); 242 dataType.prefix = prefix + " '"; 243 dataType.suffix = "'"; 244 dataType.maxPrecision = precision; 245 dataType.supportsScale = scale != 0; 246 dataType.maxScale = scale; 247 dataType.defaultPrecision = precision; 248 dataType.defaultScale = scale; 249 return dataType; 250 } 251 252 private static DataType createString(boolean caseSensitive) { 253 DataType dataType = new DataType(); 254 dataType.prefix = "'"; 255 dataType.suffix = "'"; 256 dataType.params = "LENGTH"; 257 dataType.caseSensitive = caseSensitive; 258 dataType.supportsPrecision = true; 259 dataType.maxPrecision = Integer.MAX_VALUE; 260 dataType.defaultPrecision = Integer.MAX_VALUE; 261 return dataType; 262 } 263 264 public static ObjectArray getTypes() { 265 return types; 266 } 267 268 public static Value readValue(SessionInterface session, ResultSet rs, int columnIndex, int type) throws SQLException { 269 Value v; 270 switch(type) { 271 case Value.NULL: { 272 return ValueNull.INSTANCE; 273 } 274 case Value.BYTES: { 275 byte[] buff = rs.getBytes(columnIndex); 276 v = buff==null ? (Value)ValueNull.INSTANCE : ValueBytes.getNoCopy(buff); 277 break; 278 } 279 case Value.UUID: { 280 byte[] buff = rs.getBytes(columnIndex); 281 v = buff==null ? (Value)ValueNull.INSTANCE : ValueUuid.get(buff); 282 break; 283 } 284 case Value.BOOLEAN: { 285 boolean value = rs.getBoolean(columnIndex); 286 v = rs.wasNull() ? (Value)ValueNull.INSTANCE : ValueBoolean.get(value); 287 break; 288 } 289 case Value.BYTE: { 290 byte value = rs.getByte(columnIndex); 291 v = rs.wasNull() ? (Value)ValueNull.INSTANCE : ValueByte.get(value); 292 break; 293 } 294 case Value.DATE: { 295 Date value = rs.getDate(columnIndex); 296 v = value == null ? (Value)ValueNull.INSTANCE : ValueDate.get(value); 297 break; 298 } 299 case Value.TIME: { 300 Time value = rs.getTime(columnIndex); 301 v = value == null ? (Value)ValueNull.INSTANCE : ValueTime.get(value); 302 break; 303 } 304 case Value.TIMESTAMP: { 305 Timestamp value = rs.getTimestamp(columnIndex); 306 v = value == null ? (Value)ValueNull.INSTANCE : ValueTimestamp.get(value); 307 break; 308 } 309 case Value.DECIMAL: { 310 BigDecimal value = rs.getBigDecimal(columnIndex); 311 v = value == null ? (Value)ValueNull.INSTANCE : ValueDecimal.get(value); 312 break; 313 } 314 case Value.DOUBLE: { 315 double value = rs.getDouble(columnIndex); 316 v = rs.wasNull() ? (Value)ValueNull.INSTANCE : ValueDouble.get(value); 317 break; 318 } 319 case Value.FLOAT: { 320 float value = rs.getFloat(columnIndex); 321 v = rs.wasNull() ? (Value)ValueNull.INSTANCE : ValueFloat.get(value); 322 break; 323 } 324 case Value.INT: { 325 int value = rs.getInt(columnIndex); 326 v = rs.wasNull() ? (Value)ValueNull.INSTANCE : ValueInt.get(value); 327 break; 328 } 329 case Value.LONG: { 330 long value = rs.getLong(columnIndex); 331 v = rs.wasNull() ? (Value)ValueNull.INSTANCE : ValueLong.get(value); 332 break; 333 } 334 case Value.SHORT: { 335 short value = rs.getShort(columnIndex); 336 v = rs.wasNull() ? (Value)ValueNull.INSTANCE : ValueShort.get(value); 337 break; 338 } 339 case Value.STRING_IGNORECASE: 340 case Value.STRING: { 341 String s = rs.getString(columnIndex); 342 v = (s == null) ? (Value)ValueNull.INSTANCE : ValueString.get(s); 343 break; 344 } 345 case Value.CLOB: { 346 if(session == null) { 347 v = ValueLob.createSmallLob(Value.CLOB, StringUtils.utf8Encode(rs.getString(columnIndex))); 348 } else { 349 Reader in = rs.getCharacterStream(columnIndex); 350 v = (in == null) ? (Value)ValueNull.INSTANCE : ValueLob.createClob(in, -1, session.getDataHandler()); 351 } 352 break; 353 } 354 case Value.BLOB: { 355 if(session == null) { 356 v = ValueLob.createSmallLob(Value.BLOB, rs.getBytes(columnIndex)); 357 } else { 358 InputStream in = rs.getBinaryStream(columnIndex); 359 v = (in == null) ? (Value)ValueNull.INSTANCE : ValueLob.createBlob(in, -1, session.getDataHandler()); 360 } 361 break; 362 } 363 case Value.JAVA_OBJECT: { 364 byte[] buff = rs.getBytes(columnIndex); 365 v = buff==null ? (Value)ValueNull.INSTANCE : ValueJavaObject.getNoCopy(buff); 366 break; 367 } 368 default: 369 throw Message.getInternalError("type="+type); 370 } 371 return v; 372 } 373 374 public static String getTypeClassName(int type) { 375 switch(type) { 376 case Value.BOOLEAN: 377 return Boolean .class.getName(); case Value.BYTE: 379 return Byte .class.getName(); case Value.SHORT: 381 return Short .class.getName(); case Value.INT: 383 return Integer .class.getName(); case Value.LONG: 385 return Long .class.getName(); case Value.DECIMAL: 387 return BigDecimal .class.getName(); case Value.TIME: 389 return Time .class.getName(); case Value.DATE: 391 return Date .class.getName(); case Value.TIMESTAMP: 393 return Timestamp .class.getName(); case Value.BYTES: 395 case Value.UUID: 396 return byte[].class.getName(); case Value.STRING: 398 case Value.STRING_IGNORECASE: 399 return String .class.getName(); case Value.BLOB: 401 return java.sql.Blob .class.getName(); case Value.CLOB: 403 return java.sql.Clob .class.getName(); case Value.DOUBLE: 405 return Double .class.getName(); case Value.FLOAT: 407 return Float .class.getName(); case Value.NULL: 409 return null; 410 case Value.JAVA_OBJECT: 411 return Object .class.getName(); default: 413 throw Message.getInternalError("type="+type); 414 } 415 } 416 417 public static DataType getDataType(int type) { 418 DataType dt = typesByValueType[type]; 419 if(dt == null) { 420 dt = typesByValueType[Value.NULL]; 421 } 422 return dt; 423 } 424 425 public static int convertTypeToSQLType(int type) { 426 return getDataType(type).sqlType; 427 } 428 429 public static int convertSQLTypeToValueType(int sqlType) throws SQLException { 430 switch(sqlType) { 431 case Types.VARCHAR: 432 case Types.CHAR: 433 case Types.LONGVARCHAR: 434 return Value.STRING; 435 case Types.NUMERIC: 436 case Types.DECIMAL: 437 return Value.DECIMAL; 438 case Types.BIT: 439 case DataType.TYPE_BOOLEAN: 440 return Value.BOOLEAN; 441 case Types.INTEGER: 442 return Value.INT; 443 case Types.SMALLINT: 444 return Value.SHORT; 445 case Types.TINYINT: 446 return Value.BYTE; 447 case Types.BIGINT: 448 return Value.LONG; 449 case Types.REAL: 450 return Value.FLOAT; 451 case Types.DOUBLE: 452 case Types.FLOAT: 453 return Value.DOUBLE; 454 case Types.BINARY: 455 case Types.VARBINARY: 456 case Types.LONGVARBINARY: 457 return Value.BYTES; 458 case Types.OTHER: 459 case Types.JAVA_OBJECT: 460 return Value.JAVA_OBJECT; 461 case Types.DATE: 462 return Value.DATE; 463 case Types.TIME: 464 return Value.TIME; 465 case Types.TIMESTAMP: 466 return Value.TIMESTAMP; 467 case Types.BLOB: 468 return Value.BLOB; 469 case Types.CLOB: 470 return Value.CLOB; 471 case Types.NULL: 472 return Value.NULL; 473 default: 474 throw Message.getSQLException(Message.UNKNOWN_DATA_TYPE_1, ""+sqlType); 475 } 476 } 477 478 public static int getTypeFromClass(Class x) throws SQLException { 479 if(x==null) { 481 return Value.NULL; 482 } 483 if(ResultSet .class.isAssignableFrom(x)) { 484 return Value.RESULT_SET; 485 } else if(String .class.isAssignableFrom(x)) { 486 return Value.STRING; 487 } else if(BigDecimal .class.isAssignableFrom(x)) { 488 return Value.DECIMAL; 489 } else if(Boolean .class.isAssignableFrom(x) || boolean.class.isAssignableFrom(x)) { 490 return Value.BOOLEAN; 491 } else if(Byte .class.isAssignableFrom(x) || byte.class.isAssignableFrom(x)) { 492 return Value.BYTE; 493 } else if(Short .class.isAssignableFrom(x) || short.class.isAssignableFrom(x)) { 494 return Value.SHORT; 495 } else if(Integer .class.isAssignableFrom(x) || int.class.isAssignableFrom(x)) { 496 return Value.INT; 497 } else if(Character .class.isAssignableFrom(x) || char.class.isAssignableFrom(x)) { 498 throw Message.getSQLException(Message.DATA_CONVERSION_ERROR_1, "char (not supported)"); 499 } else if(Long .class.isAssignableFrom(x) || long.class.isAssignableFrom(x)) { 500 return Value.LONG; 501 } else if(Float .class.isAssignableFrom(x) || float.class.isAssignableFrom(x)) { 502 return Value.FLOAT; 503 } else if(Double .class.isAssignableFrom(x) || double.class.isAssignableFrom(x)) { 504 return Value.DOUBLE; 505 } else if(byte[].class.isAssignableFrom(x)) { 506 return Value.BYTES; 507 } else if(Date .class.isAssignableFrom(x)) { 508 return Value.DATE; 509 } else if(Time .class.isAssignableFrom(x)) { 510 return Value.TIME; 511 } else if(Timestamp .class.isAssignableFrom(x)) { 512 return Value.TIMESTAMP; 513 } else if(java.util.Date .class.isAssignableFrom(x)) { 514 return Value.DATE; 515 } else if(java.io.Reader .class.isAssignableFrom(x)) { 516 return Value.CLOB; 517 } else if(java.sql.Clob .class.isAssignableFrom(x)) { 518 return Value.CLOB; 519 } else if(java.io.InputStream .class.isAssignableFrom(x)) { 520 return Value.BLOB; 521 } else if(java.sql.Blob .class.isAssignableFrom(x)) { 522 return Value.BLOB; 523 } else if(Object [].class.isAssignableFrom(x)) { 524 return Value.ARRAY; 525 } else if(Void.TYPE==x) { 526 return Value.NULL; 527 } else { 528 return Value.JAVA_OBJECT; 529 } 530 } 531 532 public static Value convertToValue(SessionInterface session, Object x, int type) throws SQLException { 533 if(x==null) { 534 return ValueNull.INSTANCE; 535 } 536 if(type == Value.JAVA_OBJECT) { 537 if(Constants.SERIALIZE_JAVA_OBJECTS) { 539 return ValueJavaObject.getNoCopy(ByteUtils.serialize(x)); 540 } 541 } 542 if(x instanceof String ) { 543 return ValueString.get((String )x); 544 } else if(x instanceof BigDecimal ) { 545 return ValueDecimal.get((BigDecimal )x); 546 } else if(x instanceof Boolean ) { 547 return ValueBoolean.get(((Boolean )x).booleanValue()); 548 } else if(x instanceof Byte ) { 549 return ValueByte.get(((Byte )x).byteValue()); 550 } else if(x instanceof Short ) { 551 return ValueShort.get(((Short )x).shortValue()); 552 } else if(x instanceof Integer ) { 553 return ValueInt.get(((Integer )x).intValue()); 554 } else if(x instanceof Long ) { 555 return ValueLong.get(((Long )x).longValue()); 556 } else if(x instanceof Float ) { 557 return ValueFloat.get(((Float )x).floatValue()); 558 } else if(x instanceof Double ) { 559 return ValueDouble.get(((Double )x).doubleValue()); 560 } else if(x instanceof byte[]) { 561 return ValueBytes.get((byte[])x); 562 } else if(x instanceof Date ) { 563 return ValueDate.get((Date )x); 564 } else if(x instanceof Time ) { 565 return ValueTime.get((Time )x); 566 } else if(x instanceof Timestamp ) { 567 return ValueTimestamp.get((Timestamp )x); 568 } else if(x instanceof java.util.Date ) { 569 return ValueDate.get(new Date (((java.util.Date )x).getTime())); 570 } else if(x instanceof java.io.Reader ) { 571 return ValueLob.createClob((java.io.Reader )x, -1, session.getDataHandler()); 572 } else if(x instanceof java.sql.Clob ) { 573 return ValueLob.createClob(((java.sql.Clob )x).getCharacterStream(), -1, session.getDataHandler()); 574 } else if(x instanceof java.io.InputStream ) { 575 return ValueLob.createBlob((java.io.InputStream )x, -1, session.getDataHandler()); 576 } else if(x instanceof java.sql.Blob ) { 577 return ValueLob.createBlob(((java.sql.Blob )x).getBinaryStream(), -1, session.getDataHandler()); 578 } else if(x instanceof ResultSet ) { 579 return ValueResultSet.get((ResultSet )x); 580 } else if(x instanceof Object []) { 581 Object [] o = (Object []) x; 584 int len = o.length; 585 Value[] v = new Value[len]; 586 for(int i=0; i<len; i++) { 587 v[i] = convertToValue(session, o[i], type); 588 } 589 return ValueArray.get(v); 590 } else { 591 if(Constants.SERIALIZE_JAVA_OBJECTS) { 592 return ValueJavaObject.getNoCopy(ByteUtils.serialize(x)); 593 } else { 594 throw Message.getSQLException(Message.UNKNOWN_DATA_TYPE_1, x.getClass().getName()); 595 } 596 } 597 } 598 599 public static DataType getTypeByName(String s) { 600 return (DataType) typesByName.get(s); 601 } 602 603 public static boolean isLargeObject(int type) { 604 if(type == Value.BLOB || type == Value.CLOB) { 605 return true; 606 } 607 return false; 608 } 609 610 public static boolean supportsAdd(int type) { 611 switch(type) { 612 case Value.BYTE: 613 case Value.DECIMAL: 614 case Value.DOUBLE: 615 case Value.FLOAT: 616 case Value.INT: 617 case Value.LONG: 618 case Value.SHORT: 619 return true; 620 } 621 return false; 622 } 623 624 public static Object getDefaultForPrimitiveType(Class clazz) { 625 if(clazz == Boolean.TYPE) { 626 return Boolean.FALSE; 627 } else if(clazz == Byte.TYPE) { 628 return new Byte ((byte)0); 629 } else if(clazz == Character.TYPE) { 630 return new Character ((char)0); 631 } else if(clazz == Short.TYPE) { 632 return new Short ((short)0); 633 } else if(clazz == Integer.TYPE) { 634 return new Integer (0); 635 } else if(clazz == Long.TYPE) { 636 return new Long (0); 637 } else if(clazz == Float.TYPE) { 638 return new Float (0); 639 } else if(clazz == Double.TYPE) { 640 return new Double (0); 641 } else { 642 throw Message.getInternalError("primitive="+ clazz.toString()); 643 } 644 } 645 646 public static Object convertTo(SessionInterface session, JdbcConnection conn, Value v, Class paramClass) throws JdbcSQLException { 647 if(paramClass == java.sql.Blob .class) { 648 return new JdbcBlob(session, conn, v, 0); 649 } else if(paramClass == Clob .class) { 650 return new JdbcClob(session, conn, v, 0); 651 } else { 652 throw Message.getUnsupportedException(); 653 } 654 } 655 656 } 657 | Popular Tags |