1 2 12 package com.versant.core.jdbc.sql.conv; 13 14 import com.versant.core.jdbc.JdbcConverter; 15 import com.versant.core.jdbc.JdbcConverterFactory; 16 import com.versant.core.jdbc.JdbcTypeRegistry; 17 import com.versant.core.jdbc.metadata.JdbcColumn; 18 import com.versant.core.metadata.MDStatics; 19 20 import javax.jdo.JDOFatalDataStoreException; import java.sql.PreparedStatement ; 22 import java.sql.SQLException ; 23 import java.sql.ResultSet ; 24 25 32 public class CharConverter extends JdbcConverterBase { 33 private char defaultChar; 34 35 public static class Factory extends NoArgJdbcConverterFactory { 36 37 private CharConverter converter; 38 39 43 public JdbcConverter createJdbcConverter(JdbcColumn col, Object args, 44 JdbcTypeRegistry jdbcTypeRegistry) { 45 if (converter == null) converter = new CharConverter(); 46 return converter; 47 } 48 49 } 50 51 56 public Object get(ResultSet rs, int index, JdbcColumn col) 57 throws SQLException , JDOFatalDataStoreException { 58 String s = rs.getString(index); 59 if (s == null || s.length() == 0) { 60 if (rs.wasNull()) { 61 if (col.javaTypeCode == MDStatics.CHAR) { 62 return new Character (defaultChar); 63 } else { 64 return null; 65 } 66 } else { 67 return new Character (defaultChar); 68 } 69 } 70 return new Character (s.charAt(0)); 71 } 72 73 74 75 76 81 public void set(PreparedStatement ps, int index, JdbcColumn col, 82 Object value) 83 throws SQLException , JDOFatalDataStoreException { 84 if (value == null) { 85 ps.setNull(index, col.jdbcType); 86 } else { 87 88 89 { 90 Character c = (Character )value; 91 String s = new String (new char[]{c.charValue()}); 92 ps.setString(index, s); 93 } 94 95 } 96 } 97 98 102 public Class getValueType() { 103 return Character .class; 104 } 105 106 } 107 108 | Popular Tags |