KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > ibatis > support > BlobByteArrayTypeHandler


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
17 package org.springframework.orm.ibatis.support;
18
19 import java.sql.PreparedStatement JavaDoc;
20 import java.sql.ResultSet JavaDoc;
21 import java.sql.SQLException JavaDoc;
22
23 import org.springframework.jdbc.support.lob.LobCreator;
24 import org.springframework.jdbc.support.lob.LobHandler;
25
26 /**
27  * iBATIS TypeHandler implementation for byte arrays that get mapped to BLOBs.
28  * Retrieves the LobHandler to use from SqlMapClientFactoryBean at config time.
29  *
30  * <p>Can also be defined in generic iBATIS mappings, as DefaultLobCreator will
31  * work with most JDBC-compliant database drivers. In this case, the field type
32  * does not have to be BLOB: For databases like MySQL and MS SQL Server, any
33  * large enough binary type will work.
34  *
35  * @author Juergen Hoeller
36  * @since 1.1.5
37  * @see org.springframework.orm.ibatis.SqlMapClientFactoryBean#setLobHandler
38  */

39 public class BlobByteArrayTypeHandler extends AbstractLobTypeHandler {
40
41     /**
42      * Constructor used by iBATIS: fetches config-time LobHandler from
43      * SqlMapClientFactoryBean.
44      * @see org.springframework.orm.ibatis.SqlMapClientFactoryBean#getConfigTimeLobHandler
45      */

46     public BlobByteArrayTypeHandler() {
47         super();
48     }
49
50     /**
51      * Constructor used for testing: takes an explicit LobHandler.
52      */

53     protected BlobByteArrayTypeHandler(LobHandler lobHandler) {
54         super(lobHandler);
55     }
56
57     protected void setParameterInternal(
58             PreparedStatement JavaDoc ps, int index, Object JavaDoc value, String JavaDoc jdbcType, LobCreator lobCreator)
59             throws SQLException JavaDoc {
60         lobCreator.setBlobAsBytes(ps, index, (byte[]) value);
61     }
62
63     protected Object JavaDoc getResultInternal(ResultSet JavaDoc rs, int index, LobHandler lobHandler)
64             throws SQLException JavaDoc {
65         return lobHandler.getBlobAsBytes(rs, index);
66     }
67
68     public Object JavaDoc valueOf(String JavaDoc s) {
69         return s.getBytes();
70     }
71
72 }
73
Popular Tags