1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 import javax.transaction.TransactionManager;
25
26 import org.springframework.jdbc.support.lob.LobCreator;
27 import org.springframework.jdbc.support.lob.LobHandler;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class BlobByteArrayType extends AbstractLobType {
43
44
45
46
47
48
49
50 public BlobByteArrayType() {
51 super();
52 }
53
54
55
56
57
58 protected BlobByteArrayType(LobHandler lobHandler, TransactionManager jtaTransactionManager) {
59 super(lobHandler, jtaTransactionManager);
60 }
61
62 @Override
63 public int[] sqlTypes() {
64 return new int[] {Types.BLOB};
65 }
66
67 @Override
68 public Class<?> returnedClass() {
69 return byte[].class;
70 }
71
72 @Override
73 public boolean isMutable() {
74 return true;
75 }
76
77 @Override
78 public boolean equals(Object x, Object y) {
79 return (x == y) ||
80 (x instanceof byte[] && y instanceof byte[] && Arrays.equals((byte[]) x, (byte[]) y));
81 }
82
83 @Override
84 public Object deepCopy(Object value) {
85 if (value == null) {
86 return null;
87 }
88 byte[] original = (byte[]) value;
89 byte[] copy = new byte[original.length];
90 System.arraycopy(original, 0, copy, 0, original.length);
91 return copy;
92 }
93
94 @Override
95 protected Object nullSafeGetInternal(
96 ResultSet rs, String[] names, Object owner, LobHandler lobHandler)
97 throws SQLException {
98
99 return lobHandler.getBlobAsBytes(rs, names[0]);
100 }
101
102 @Override
103 protected void nullSafeSetInternal(
104 PreparedStatement ps, int index, Object value, LobCreator lobCreator)
105 throws SQLException {
106
107 lobCreator.setBlobAsBytes(ps, index, (byte[]) value);
108 }
109
110 }