1 22 package org.jboss.test.cmp2.lob; 23 24 import java.sql.PreparedStatement ; 25 import java.sql.SQLException ; 26 import java.sql.Types ; 27 import java.sql.ResultSet ; 28 import java.sql.Blob ; 29 import java.io.IOException ; 30 31 import org.jboss.ejb.plugins.cmp.jdbc.JDBCParameterSetter; 32 import org.jboss.ejb.plugins.cmp.jdbc.JDBCResultSetReader; 33 import org.jboss.logging.Logger; 34 import org.jboss.invocation.MarshalledValue; 35 36 40 public class GetSetObjectParameter 41 implements JDBCParameterSetter, JDBCResultSetReader 42 { 43 public Object get(ResultSet rs, int index, Class destination, Logger log) throws SQLException 44 { 45 Object value = rs.getObject(index); 46 log.debug("get: i=" + index + ", destination="+destination+", value=" + value); 47 Object result = value; 48 if(rs.wasNull()) 49 { 50 result = null; 51 } 52 else if( value instanceof MarshalledValue ) 53 { 54 MarshalledValue mv = (MarshalledValue) value; 55 try 56 { 57 result = mv.get(); 58 } 59 catch (Exception e) 60 { 61 SQLException sqe = new SQLException ("Unable to extract MarshalledValue"); 62 sqe.initCause(e); 63 throw sqe; 64 } 65 } 66 return result; 67 } 68 69 public void set(PreparedStatement ps, int index, int jdbcType, Object value, 70 Logger log) throws SQLException 71 { 72 log.debug("set: i=" + index + ", jdbcType="+jdbcType+", value=" + value); 73 if( value instanceof MarshalledValue ) 74 { 75 MarshalledValue mv = (MarshalledValue) value; 76 try 77 { 78 value = mv.get(); 79 } 80 catch (Exception e) 81 { 82 SQLException sqe = new SQLException ("Unable to extract MarshalledValue"); 83 sqe.initCause(e); 84 throw sqe; 85 } 86 } 87 88 switch( jdbcType ) 89 { 90 case Types.BLOB: 91 { 92 ps.setObject(index, value, jdbcType); 93 break; 94 } 95 case Types.OTHER: 96 ps.setObject(index, value); 97 break; 98 default: 99 throw new SQLException ("Unsupported jdbcType: "+jdbcType); 100 } 101 } 102 } 103 | Popular Tags |