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.SQLException ; 22 import java.sql.ResultSet ; 23 import java.sql.PreparedStatement ; 24 25 31 public class BooleanConverter extends JdbcConverterBase { 32 33 public static class Factory extends NoArgJdbcConverterFactory { 34 35 private BooleanConverter converter; 36 37 41 public JdbcConverter createJdbcConverter(JdbcColumn col, Object args, 42 JdbcTypeRegistry jdbcTypeRegistry) { 43 if (converter == null) converter = new BooleanConverter(); 44 return converter; 45 } 46 47 } 48 49 54 public Object get(ResultSet rs, int index, JdbcColumn col) 55 throws SQLException , JDOFatalDataStoreException { 56 int i = rs.getInt(index); 57 if (rs.wasNull()){ 58 if (col.javaTypeCode == MDStatics.BOOLEAN){ 59 return Boolean.FALSE; 60 } else { 61 return null; 62 } 63 } 64 return i == 0 ? Boolean.FALSE : Boolean.TRUE; 65 } 66 67 68 69 70 75 public void set(PreparedStatement ps, int index, JdbcColumn col, Object value) 76 throws SQLException , JDOFatalDataStoreException { 77 if (value == null) { 78 ps.setNull(index, col.jdbcType); 79 } else { 80 81 { 82 boolean v = ((Boolean )value).booleanValue(); 83 ps.setInt(index, v ? 1 : 0); 84 } 85 } 86 } 87 88 92 public Class getValueType() { 93 return Boolean .class; 94 } 95 96 } 97 98 | Popular Tags |