1 2 12 package com.versant.core.jdbc.sql.conv; 13 14 import com.versant.core.jdbc.JdbcConverter; 15 import com.versant.core.jdbc.JdbcTypeRegistry; 16 import com.versant.core.jdbc.metadata.JdbcColumn; 17 18 import javax.jdo.JDOFatalDataStoreException; 19 import java.sql.PreparedStatement ; 20 import java.sql.SQLException ; 21 import java.sql.ResultSet ; 22 import java.sql.Types ; 23 24 29 public class NullBytesAsBinaryConverter extends JdbcConverterBase { 30 31 public static class Factory extends NoArgJdbcConverterFactory { 32 33 private NullBytesAsBinaryConverter asBinaryConverter; 34 35 39 public JdbcConverter createJdbcConverter(JdbcColumn col, Object args, 40 JdbcTypeRegistry jdbcTypeRegistry) { 41 if (asBinaryConverter == null) asBinaryConverter = new NullBytesAsBinaryConverter(); 42 return asBinaryConverter; 43 } 44 45 } 46 47 52 public Object get(ResultSet rs, int index, JdbcColumn col) 53 throws SQLException , JDOFatalDataStoreException { 54 return rs.getBytes(index); 55 } 56 57 62 public void set(PreparedStatement ps, int index, JdbcColumn col, Object value) 63 throws SQLException , JDOFatalDataStoreException { 64 if (value == null) { 65 if (col.jdbcType == Types.BLOB) { 66 ps.setNull(index, Types.BINARY); 67 } else { 68 ps.setNull(index, col.jdbcType); 69 } 70 } else { 71 ps.setBytes(index, (byte[])value); 72 } 73 } 74 75 79 public Class getValueType() { 80 return byte[].class; 81 } 82 83 } 84 85 | Popular Tags |