KickJava   Java API By Example, From Geeks To Geeks.

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


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 Strings that get mapped to CLOBs.
28  * Retrieves the LobHandler to use from SqlMapClientFactoryBean at config time.
29  *
30  * <p>Particularly useful for storing Strings with more than 4000 characters in an
31  * Oracle database (only possible via CLOBs), in combination with OracleLobHandler.
32  *
33  * <p>Can also be defined in generic iBATIS mappings, as DefaultLobCreator will
34  * work with most JDBC-compliant database drivers. In this case, the field type
35  * does not have to be BLOB: For databases like MySQL and MS SQL Server, any
36  * large enough binary type will work.
37  *
38  * @author Juergen Hoeller
39  * @since 1.1.5
40  * @see org.springframework.orm.ibatis.SqlMapClientFactoryBean#setLobHandler
41  */

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

49     public ClobStringTypeHandler() {
50         super();
51     }
52
53     /**
54      * Constructor used for testing: takes an explicit LobHandler.
55      */

56     protected ClobStringTypeHandler(LobHandler lobHandler) {
57         super(lobHandler);
58     }
59
60     protected void setParameterInternal(
61             PreparedStatement JavaDoc ps, int index, Object JavaDoc value, String JavaDoc jdbcType, LobCreator lobCreator)
62             throws SQLException JavaDoc {
63         lobCreator.setClobAsString(ps, index, (String JavaDoc) value);
64     }
65
66     protected Object JavaDoc getResultInternal(ResultSet JavaDoc rs, int index, LobHandler lobHandler)
67             throws SQLException JavaDoc {
68         return lobHandler.getClobAsString(rs, index);
69     }
70
71     public Object JavaDoc valueOf(String JavaDoc s) {
72         return s;
73     }
74
75 }
76
Popular Tags