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.ResultSet ; 21 import java.sql.SQLException ; 22 import java.sql.PreparedStatement ; 23 import java.math.BigDecimal ; 24 25 26 29 public class BigDecimalConverter extends JdbcConverterBase { 30 31 public static class Factory extends NoArgJdbcConverterFactory { 32 33 private BigDecimalConverter converter; 34 35 39 public JdbcConverter createJdbcConverter(JdbcColumn col, Object args, 40 JdbcTypeRegistry jdbcTypeRegistry) { 41 if (converter == null) converter = new BigDecimalConverter(); 42 return converter; 43 } 44 45 } 46 47 52 public Object get(ResultSet rs, int index, JdbcColumn col) 53 throws SQLException , JDOFatalDataStoreException { 54 double d = rs.getDouble(index); 55 if (rs.wasNull())return null; 56 return new BigDecimal (d); 57 } 58 59 64 public void set(PreparedStatement ps, int index, JdbcColumn col, Object value) 65 throws SQLException , JDOFatalDataStoreException { 66 if (value == null) { 67 ps.setNull(index, col.jdbcType); 68 } else { 69 BigDecimal bigDecimal = (BigDecimal )value; 70 ps.setDouble(index, bigDecimal.doubleValue()); 71 } 72 } 73 74 78 public Class getValueType() { 79 return BigDecimal .class; 80 } 81 82 } 83 | Popular Tags |