01: /*
02: * Copyright 2004 Clinton Begin
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package com.ibatis.sqlmap.engine.type;
17:
18: import com.ibatis.sqlmap.client.extensions.ParameterSetter;
19: import com.ibatis.sqlmap.client.extensions.ResultGetter;
20: import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
21:
22: import java.sql.Blob;
23: import java.sql.SQLException;
24: import java.io.ByteArrayInputStream;
25:
26: public class BlobTypeHandlerCallback implements TypeHandlerCallback {
27:
28: public Object getResult(ResultGetter getter) throws SQLException {
29: Blob blob = getter.getBlob();
30: byte[] returnValue = null;
31: if (null != blob) {
32: returnValue = blob.getBytes(1, (int) blob.length());
33: } else {
34: returnValue = null;
35: }
36: return returnValue;
37: }
38:
39: public void setParameter(ParameterSetter setter, Object parameter)
40: throws SQLException {
41: if (null != parameter) {
42: byte[] bytes = (byte[]) parameter;
43: ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
44: setter.setBinaryStream(bis, (int) (bytes.length));
45: }
46: }
47:
48: public Object valueOf(String s) {
49: return s;
50: }
51:
52: }
|