KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > sqlmap > engine > type > ClobTypeHandlerCallback


1 /*
2  * Copyright 2004 Clinton Begin
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 package com.ibatis.sqlmap.engine.type;
17
18 import com.ibatis.sqlmap.client.extensions.*;
19
20 import java.io.StringReader JavaDoc;
21 import java.sql.*;
22
23 public class ClobTypeHandlerCallback implements TypeHandlerCallback {
24
25   public Object JavaDoc getResult(ResultGetter getter)
26       throws SQLException {
27     String JavaDoc value = "";
28     Clob clob = getter.getClob();
29     if (clob != null) {
30       int size = (int) clob.length();
31       value = clob.getSubString(1, size);
32     }
33     return value;
34   }
35
36   public void setParameter(ParameterSetter setter, Object JavaDoc parameter)
37       throws SQLException {
38     String JavaDoc s = (String JavaDoc) parameter;
39     if (s != null) {
40       StringReader JavaDoc reader = new StringReader JavaDoc(s);
41       setter.setCharacterStream(reader, s.length());
42     } else {
43       setter.setString(null);
44     }
45     setter.setString((String JavaDoc) parameter);
46   }
47
48   public Object JavaDoc valueOf(String JavaDoc s) {
49     return s;
50   }
51
52 }
53
Popular Tags