1 16 17 package org.springframework.jdbc.support.lob; 18 19 import java.io.InputStream ; 20 import java.io.Reader ; 21 import java.sql.PreparedStatement ; 22 import java.sql.ResultSet ; 23 import java.sql.SQLException ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 52 public class DefaultLobHandler extends AbstractLobHandler { 53 54 protected final Log logger = LogFactory.getLog(getClass()); 55 56 57 public byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException { 58 logger.debug("Returning BLOB as bytes"); 59 return rs.getBytes(columnIndex); 60 } 61 62 public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException { 63 logger.debug("Returning BLOB as binary stream"); 64 return rs.getBinaryStream(columnIndex); 65 } 66 67 public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException { 68 logger.debug("Returning CLOB as string"); 69 return rs.getString(columnIndex); 70 } 71 72 public InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws SQLException { 73 logger.debug("Returning CLOB as ASCII stream"); 74 return rs.getAsciiStream(columnIndex); 75 } 76 77 public Reader getClobAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException { 78 logger.debug("Returning CLOB as character stream"); 79 return rs.getCharacterStream(columnIndex); 80 } 81 82 public LobCreator getLobCreator() { 83 logger.debug("Creating new DefaultLobCreator"); 84 return new DefaultLobCreator(); 85 } 86 87 88 protected class DefaultLobCreator implements LobCreator { 89 90 public void setBlobAsBytes(PreparedStatement ps, int paramIndex, byte[] content) 91 throws SQLException { 92 93 ps.setBytes(paramIndex, content); 94 if (logger.isDebugEnabled()) { 95 logger.debug(content != null ? "Set bytes for BLOB with length " + content.length : 96 "Set BLOB to null"); 97 } 98 } 99 100 public void setBlobAsBinaryStream( 101 PreparedStatement ps, int paramIndex, InputStream binaryStream, int contentLength) 102 throws SQLException { 103 104 ps.setBinaryStream(paramIndex, binaryStream, contentLength); 105 if (logger.isDebugEnabled()) { 106 logger.debug(binaryStream != null ? "Set binary stream for BLOB with length " + contentLength : 107 "Set BLOB to null"); 108 } 109 } 110 111 public void setClobAsString(PreparedStatement ps, int paramIndex, String content) 112 throws SQLException { 113 114 ps.setString(paramIndex, content); 115 if (logger.isDebugEnabled()) { 116 logger.debug(content != null ? "Set string for CLOB with length " + content.length() : 117 "Set CLOB to null"); 118 } 119 } 120 121 public void setClobAsAsciiStream( 122 PreparedStatement ps, int paramIndex, InputStream asciiStream, int contentLength) 123 throws SQLException { 124 125 ps.setAsciiStream(paramIndex, asciiStream, contentLength); 126 if (logger.isDebugEnabled()) { 127 logger.debug(asciiStream != null ? "Set ASCII stream for CLOB with length " + contentLength : 128 "Set CLOB to null"); 129 } 130 } 131 132 133 public void setClobAsCharacterStream( 134 PreparedStatement ps, int paramIndex, Reader characterStream, int contentLength) 135 throws SQLException { 136 137 ps.setCharacterStream(paramIndex, characterStream, contentLength); 138 if (logger.isDebugEnabled()) { 139 logger.debug(characterStream != null ? "Set character stream for CLOB with length " + contentLength : 140 "Set CLOB to null"); 141 } 142 } 143 144 public void close() { 145 logger.debug("Closing DefaultLobCreator"); 146 } 148 } 149 150 } 151 | Popular Tags |