KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > sql > conv > ClobStringConverter


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.sql.conv;
13
14 import com.versant.core.jdbc.JdbcConverter;
15 import com.versant.core.jdbc.JdbcConverterFactory;
16 import com.versant.core.jdbc.JdbcTypeRegistry;
17 import com.versant.core.jdbc.metadata.JdbcColumn;
18
19 import javax.jdo.JDOFatalDataStoreException; //todo: appears only in throws clause
20
import java.sql.PreparedStatement JavaDoc;
21 import java.sql.SQLException JavaDoc;
22 import java.sql.ResultSet JavaDoc;
23 import java.sql.Types JavaDoc;
24
25 /**
26  * This converter treats CLOB columns as normal String columns. It is used
27  * for JDBC drivers that do not support CLOB as a data type e.g. Sybase
28  * and Microsoft SQL Server to avoid getting an exception when doing a
29  * setNull(index, Types.CLOB).
30  * @keep-all
31  */

32 public class ClobStringConverter extends JdbcConverterBase {
33
34     public static class Factory extends NoArgJdbcConverterFactory {
35
36         private ClobStringConverter converter;
37
38         /**
39          * Create a converter for col using args as parameters. Return null if
40          * no converter is required.
41          */

42         public JdbcConverter createJdbcConverter(JdbcColumn col, Object JavaDoc args,
43                 JdbcTypeRegistry jdbcTypeRegistry) {
44             if (converter == null) converter = new ClobStringConverter();
45             return converter;
46         }
47
48     }
49
50     /**
51      * Get the value of col from rs at position index.
52      * @exception SQLException on SQL errors
53      * @exception JDOFatalDataStoreException if the ResultSet value is invalid
54      */

55     public Object JavaDoc get(ResultSet JavaDoc rs, int index, JdbcColumn col)
56             throws SQLException JavaDoc, JDOFatalDataStoreException {
57         return rs.getString(index);
58     }
59
60     /**
61      * Set parameter index on ps to value (for col).
62      * @exception SQLException on SQL errors
63      * @exception JDOFatalDataStoreException if value is invalid
64      */

65     public void set(PreparedStatement JavaDoc ps, int index, JdbcColumn col, Object JavaDoc value)
66             throws SQLException JavaDoc, JDOFatalDataStoreException {
67         if (value == null) {
68             ps.setNull(index, Types.LONGVARCHAR);
69         } else {
70             ps.setString(index, (String JavaDoc)value);
71         }
72     }
73
74     /**
75      * Get the type of our expected value objects (e.g. java.util.Locale
76      * for a converter for Locale's).
77      */

78     public Class JavaDoc getValueType() {
79         return String JavaDoc.class;
80     }
81
82 }
83
84
Popular Tags