01: /*
02: * Copyright 2002-2005 the original author or authors.
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:
17: package org.springframework.orm.ibatis.support;
18:
19: import java.sql.PreparedStatement;
20: import java.sql.ResultSet;
21: import java.sql.SQLException;
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(PreparedStatement ps,
61: int index, Object value, String jdbcType,
62: LobCreator lobCreator) throws SQLException {
63: lobCreator.setClobAsString(ps, index, (String) value);
64: }
65:
66: protected Object getResultInternal(ResultSet rs, int index,
67: LobHandler lobHandler) throws SQLException {
68: return lobHandler.getClobAsString(rs, index);
69: }
70:
71: public Object valueOf(String s) {
72: return s;
73: }
74:
75: }
|