1 16 17 package org.springframework.orm.hibernate3.support; 18 19 import java.io.UnsupportedEncodingException ; 20 import java.sql.PreparedStatement ; 21 import java.sql.ResultSet ; 22 import java.sql.SQLException ; 23 import java.sql.Types ; 24 25 import javax.transaction.TransactionManager ; 26 27 import org.springframework.jdbc.support.lob.LobCreator; 28 import org.springframework.jdbc.support.lob.LobHandler; 29 30 49 public class BlobStringType extends AbstractLobType { 50 51 57 public BlobStringType() { 58 super(); 59 } 60 61 65 protected BlobStringType(LobHandler lobHandler, TransactionManager jtaTransactionManager) { 66 super(lobHandler, jtaTransactionManager); 67 } 68 69 public int[] sqlTypes() { 70 return new int[] {Types.BLOB}; 71 } 72 73 public Class returnedClass() { 74 return String .class; 75 } 76 77 protected Object nullSafeGetInternal( 78 ResultSet rs, String [] names, Object owner, LobHandler lobHandler) 79 throws SQLException , UnsupportedEncodingException { 80 81 byte[] bytes = lobHandler.getBlobAsBytes(rs, names[0]); 82 if (bytes != null) { 83 String encoding = getCharacterEncoding(); 84 return (encoding != null ? new String (bytes, encoding) : new String (bytes)); 85 } 86 else { 87 return null; 88 } 89 } 90 91 protected void nullSafeSetInternal( 92 PreparedStatement ps, int index, Object value, LobCreator lobCreator) 93 throws SQLException , UnsupportedEncodingException { 94 95 if (value != null) { 96 String str = (String ) value; 97 String encoding = getCharacterEncoding(); 98 byte[] bytes = (encoding != null ? str.getBytes(encoding) : str.getBytes()); 99 lobCreator.setBlobAsBytes(ps, index, bytes); 100 } 101 else { 102 lobCreator.setBlobAsBytes(ps, index, null); 103 } 104 } 105 106 117 protected String getCharacterEncoding() { 118 return null; 119 } 120 121 } 122 | Popular Tags |