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 19 import java.sql.PreparedStatement ; 20 import java.sql.SQLException ; 21 import java.sql.ResultSet ; 22 import java.io.*; 23 24 import javax.jdo.JDOFatalDataStoreException; 26 import com.versant.core.common.BindingSupportImpl; 27 28 33 public class AsciiStreamConverter extends JdbcConverterBase { 34 35 public static class Factory extends NoArgJdbcConverterFactory { 36 37 private AsciiStreamConverter converter; 38 39 43 public JdbcConverter createJdbcConverter(JdbcColumn col, Object args, 44 JdbcTypeRegistry jdbcTypeRegistry) { 45 if (converter == null) converter = new AsciiStreamConverter(); 46 return converter; 47 } 48 49 } 50 51 56 public Object get(ResultSet rs, int index, JdbcColumn col) 57 throws SQLException , JDOFatalDataStoreException { 58 try { 59 InputStream in = rs.getAsciiStream(index); 60 if (in == null) return null; 61 return StreamUtils.readAll(in, "UTF8"); 62 } catch (IOException x) { 63 throw BindingSupportImpl.getInstance().fatalDatastore( 64 "Error reading " + col + ": " + 65 x.getClass().getName() + ": " + x.getMessage(), x); 66 } 67 } 68 69 74 public void set(PreparedStatement ps, int index, JdbcColumn col, Object value) 75 throws SQLException , JDOFatalDataStoreException { 76 if (value == null) { 77 ps.setNull(index, col.jdbcType); 78 return; 79 } 80 String s = (String )value; 81 byte[] b = s.getBytes(); 82 ps.setAsciiStream(index, new ByteArrayInputStream(b), b.length); 83 } 84 85 89 public Class getValueType() { 90 return String .class; 91 } 92 } 93 94 | Popular Tags |