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 javax.jdo.JDOFatalDataStoreException; import java.sql.PreparedStatement ; 21 import java.sql.SQLException ; 22 import java.sql.ResultSet ; 23 import java.sql.Types ; 24 import java.util.Locale ; 25 26 32 public class InformixSETrimStringConverter extends JdbcConverterBase { 33 34 public static class Factory extends NoArgJdbcConverterFactory { 35 36 private InformixSETrimStringConverter converter; 37 38 42 public JdbcConverter createJdbcConverter(JdbcColumn col, Object args, 43 JdbcTypeRegistry jdbcTypeRegistry) { 44 if (converter == null) converter = new InformixSETrimStringConverter(); 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) return null; 59 int n = s.length() - 1; 60 int pos; 61 for (pos = n; pos >= 0 && s.charAt(pos) <= ' '; --pos); 62 return pos == n ? s : s.substring(0, pos + 1); 63 } 64 65 70 public void set(PreparedStatement ps, int index, JdbcColumn col, Object value) 71 throws SQLException , JDOFatalDataStoreException { 72 if (value == null) { 73 ps.setNull(index, Types.CHAR); 74 } else { 75 ps.setString(index, (String )value); 76 } 77 } 78 79 83 public Class getValueType() { 84 return String .class; 85 } 86 87 } 88 89 | Popular Tags |