1 16 17 package org.springframework.orm.hibernate3.support; 18 19 import java.sql.PreparedStatement ; 20 import java.sql.ResultSet ; 21 import java.sql.SQLException ; 22 import java.sql.Types ; 23 import java.util.Arrays ; 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 43 public class BlobByteArrayType extends AbstractLobType { 44 45 51 public BlobByteArrayType() { 52 super(); 53 } 54 55 59 protected BlobByteArrayType(LobHandler lobHandler, TransactionManager jtaTransactionManager) { 60 super(lobHandler, jtaTransactionManager); 61 } 62 63 public int[] sqlTypes() { 64 return new int[] {Types.BLOB}; 65 } 66 67 public Class returnedClass() { 68 return byte[].class; 69 } 70 71 public boolean isMutable() { 72 return true; 73 } 74 75 public boolean equals(Object x, Object y) { 76 return (x == y) || 77 (x instanceof byte[] && y instanceof byte[] && Arrays.equals((byte[]) x, (byte[]) y)); 78 } 79 80 public Object deepCopy(Object value) { 81 if (value == null) { 82 return null; 83 } 84 byte[] original = (byte[]) value; 85 byte[] copy = new byte[original.length]; 86 System.arraycopy(original, 0, copy, 0, original.length); 87 return copy; 88 } 89 90 protected Object nullSafeGetInternal( 91 ResultSet rs, String [] names, Object owner, LobHandler lobHandler) 92 throws SQLException { 93 94 return lobHandler.getBlobAsBytes(rs, names[0]); 95 } 96 97 protected void nullSafeSetInternal( 98 PreparedStatement ps, int index, Object value, LobCreator lobCreator) 99 throws SQLException { 100 101 lobCreator.setBlobAsBytes(ps, index, (byte[]) value); 102 } 103 104 } 105 | Popular Tags |