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 NoMinCharConverter extends JdbcConverterBase { 33 private char defaultChar; 34 public static class Factory extends NoArgJdbcConverterFactory { 35 36 private NoMinCharConverter converter; 37 38 42 public JdbcConverter createJdbcConverter(JdbcColumn col, Object args, 43 JdbcTypeRegistry jdbcTypeRegistry) { 44 if (converter == null) converter = new NoMinCharConverter(); 45 return converter; 46 } 47 48 } 49 50 55 public Object get(ResultSet rs, int index, JdbcColumn col) 56 throws SQLException , JDOFatalDataStoreException { 57 String s = rs.getString(index); 58 if (s == null || s.length() == 0) { 59 if (rs.wasNull()) { 60 if (col.javaTypeCode == MDStatics.CHAR) { 61 return new Character (defaultChar); 62 } else { 63 return null; 64 } 65 } else { 66 return new Character (defaultChar); 67 } 68 } 69 return new Character (s.charAt(0)); 70 } 71 72 77 public void set(PreparedStatement ps, int index, JdbcColumn col, Object value) 78 throws SQLException , JDOFatalDataStoreException { 79 if (value == null) { 80 ps.setNull(index, col.jdbcType); 81 } else { 82 Character c = (Character )value; 83 char cv = c.charValue(); 84 String s = cv == Character.MIN_VALUE ? "" : new String (new char[]{cv}); 85 ps.setString(index, s); 86 } 87 } 88 89 93 public Class getValueType() { 94 return Character .class; 95 } 96 97 } 98 99 | Popular Tags |