1 16 17 package org.springframework.orm.hibernate.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(ResultSet rs, int index, LobHandler lobHandler) 78 throws SQLException , UnsupportedEncodingException { 79 80 byte[] bytes = lobHandler.getBlobAsBytes(rs, index); 81 if (bytes != null) { 82 String encoding = getCharacterEncoding(); 83 return (encoding != null ? new String (bytes, encoding) : new String (bytes)); 84 } 85 else { 86 return null; 87 } 88 } 89 90 protected void nullSafeSetInternal(PreparedStatement ps, int index, Object value, LobCreator lobCreator) 91 throws SQLException , UnsupportedEncodingException { 92 93 if (value != null) { 94 String str = (String ) value; 95 String encoding = getCharacterEncoding(); 96 byte[] bytes = (encoding != null ? str.getBytes(encoding) : str.getBytes()); 97 lobCreator.setBlobAsBytes(ps, index, bytes); 98 } 99 else { 100 lobCreator.setBlobAsBytes(ps, index, null); 101 } 102 } 103 104 115 protected String getCharacterEncoding() { 116 return null; 117 } 118 119 } 120 | Popular Tags |